Path: blob/master/test/lib/sun/hotspot/code/CodeBlob.java
41149 views
/*1* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package sun.hotspot.code;2425import sun.hotspot.WhiteBox;2627public class CodeBlob {28private static final WhiteBox WB = WhiteBox.getWhiteBox();29public static CodeBlob[] getCodeBlobs(BlobType type) {30Object[] obj = WB.getCodeHeapEntries(type.id);31if (obj == null) {32return null;33}34CodeBlob[] result = new CodeBlob[obj.length];35for (int i = 0, n = result.length; i < n; ++i) {36result[i] = new CodeBlob((Object[]) obj[i]);37}38return result;39}40public static CodeBlob getCodeBlob(long addr) {41Object[] obj = WB.getCodeBlob(addr);42if (obj == null) {43return null;44}45return new CodeBlob(obj);46}47protected CodeBlob(Object[] obj) {48assert obj.length == 4;49name = (String) obj[0];50size = (Integer) obj[1];51int blob_type_index = (Integer) obj[2];52code_blob_type = BlobType.values()[blob_type_index];53assert code_blob_type.id == (Integer) obj[2];54address = (Long) obj[3];55}56public final String name;57public final int size;58public final BlobType code_blob_type;59public final long address;60@Override61public String toString() {62return "CodeBlob{"63+ "name=" + name64+ ", size=" + size65+ ", code_blob_type=" + code_blob_type66+ ", address=" + address67+ '}';68}69}707172