74 private static int MISC_HAS_NONSTATIC_CONCRETE_METHODS;
75 private static int MISC_DECLARES_NONSTATIC_CONCRETE_METHODS;
76 private static int MISC_HAS_BEEN_REDEFINED;
77 private static int MISC_HAS_PASSED_FINGERPRINT_CHECK;
78 private static int MISC_IS_SCRATCH_CLASS;
79 private static int MISC_IS_SHARED_BOOT_CLASS;
80 private static int MISC_IS_SHARED_PLATFORM_CLASS;
81 private static int MISC_IS_SHARED_APP_CLASS;
82
83 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
84 Type type = db.lookupType("InstanceKlass");
85 arrayKlasses = new MetadataField(type.getAddressField("_array_klasses"), 0);
86 methods = type.getAddressField("_methods");
87 defaultMethods = type.getAddressField("_default_methods");
88 methodOrdering = type.getAddressField("_method_ordering");
89 localInterfaces = type.getAddressField("_local_interfaces");
90 transitiveInterfaces = type.getAddressField("_transitive_interfaces");
91 fields = type.getAddressField("_fields");
92 javaFieldsCount = new CIntField(type.getCIntegerField("_java_fields_count"), 0);
93 constants = new MetadataField(type.getAddressField("_constants"), 0);
94 classLoaderData = type.getAddressField("_class_loader_data");
95 sourceDebugExtension = type.getAddressField("_source_debug_extension");
96 innerClasses = type.getAddressField("_inner_classes");
97 sourceFileNameIndex = new CIntField(type.getCIntegerField("_source_file_name_index"), 0);
98 nonstaticFieldSize = new CIntField(type.getCIntegerField("_nonstatic_field_size"), 0);
99 staticFieldSize = new CIntField(type.getCIntegerField("_static_field_size"), 0);
100 staticOopFieldCount = new CIntField(type.getCIntegerField("_static_oop_field_count"), 0);
101 nonstaticOopMapSize = new CIntField(type.getCIntegerField("_nonstatic_oop_map_size"), 0);
102 isMarkedDependent = new CIntField(type.getCIntegerField("_is_marked_dependent"), 0);
103 initState = new CIntField(type.getCIntegerField("_init_state"), 0);
104 itableLen = new CIntField(type.getCIntegerField("_itable_len"), 0);
105 if (VM.getVM().isJvmtiSupported()) {
106 breakpoints = type.getAddressField("_breakpoints");
107 }
108 genericSignatureIndex = new CIntField(type.getCIntegerField("_generic_signature_index"), 0);
109 miscFlags = new CIntField(type.getCIntegerField("_misc_flags"), 0);
110 majorVersion = new CIntField(type.getCIntegerField("_major_version"), 0);
111 minorVersion = new CIntField(type.getCIntegerField("_minor_version"), 0);
112 headerSize = type.getSize();
113
114 // read field offset constants
149 public InstanceKlass(Address addr) {
150 super(addr);
151 if (getJavaFieldsCount() != getAllFieldsCount()) {
152 // Exercise the injected field logic
153 for (int i = getJavaFieldsCount(); i < getAllFieldsCount(); i++) {
154 getFieldName(i);
155 getFieldSignature(i);
156 }
157 }
158 }
159
160 private static MetadataField arrayKlasses;
161 private static AddressField methods;
162 private static AddressField defaultMethods;
163 private static AddressField methodOrdering;
164 private static AddressField localInterfaces;
165 private static AddressField transitiveInterfaces;
166 private static AddressField fields;
167 private static CIntField javaFieldsCount;
168 private static MetadataField constants;
169 private static AddressField classLoaderData;
170 private static AddressField sourceDebugExtension;
171 private static AddressField innerClasses;
172 private static CIntField sourceFileNameIndex;
173 private static CIntField nonstaticFieldSize;
174 private static CIntField staticFieldSize;
175 private static CIntField staticOopFieldCount;
176 private static CIntField nonstaticOopMapSize;
177 private static CIntField isMarkedDependent;
178 private static CIntField initState;
179 private static CIntField itableLen;
180 private static AddressField breakpoints;
181 private static CIntField genericSignatureIndex;
182 private static CIntField miscFlags;
183 private static CIntField majorVersion;
184 private static CIntField minorVersion;
185
186 // type safe enum for ClassState from instanceKlass.hpp
187 public static class ClassState {
188 public static final ClassState ALLOCATED = new ClassState("allocated");
189 public static final ClassState LOADED = new ClassState("loaded");
311 return false;
312 }
313
314 public boolean hasStoredFingerprint() {
315 return shouldStoreFingerprint() || isShared();
316 }
317
318 public boolean isShared() {
319 VM vm = VM.getVM();
320 if (vm.isSharingEnabled()) {
321 // This is not the same implementation as the C++ function MetaspaceObj::is_shared()
322 // bool MetaspaceObj::is_shared() const {
323 // return MetaspaceShared::is_in_shared_space(this);
324 // }
325 // However, MetaspaceShared::is_in_shared_space is complicated and hard to emulate in
326 // Java code, so let's do this by looking up from the shared dictionary. Of course,
327 // this works for shared InstanceKlass only and does not work for other types of
328 // MetaspaceObj in the CDS shared archive.
329 Dictionary sharedDictionary = vm.getSystemDictionary().sharedDictionary();
330 if (sharedDictionary != null) {
331 if (sharedDictionary.contains(this, null)) {
332 return true;
333 }
334 }
335 }
336 return false;
337 }
338
339 public static long getHeaderSize() { return headerSize; }
340
341 public short getFieldAccessFlags(int index) {
342 return getFields().at(index * FIELD_SLOTS + ACCESS_FLAGS_OFFSET);
343 }
344
345 public short getFieldNameIndex(int index) {
346 if (index >= getJavaFieldsCount()) throw new IndexOutOfBoundsException("not a Java field;");
347 return getFields().at(index * FIELD_SLOTS + NAME_INDEX_OFFSET);
348 }
349
350 public Symbol getFieldName(int index) {
351 int nameIndex = getFields().at(index * FIELD_SLOTS + NAME_INDEX_OFFSET);
431 return null;
432 }
433 }
434
435 public KlassArray getLocalInterfaces() { return new KlassArray(localInterfaces.getValue(getAddress())); }
436 public KlassArray getTransitiveInterfaces() { return new KlassArray(transitiveInterfaces.getValue(getAddress())); }
437 public int getJavaFieldsCount() { return (int) javaFieldsCount.getValue(this); }
438 public int getAllFieldsCount() {
439 int len = getFields().length();
440 int allFieldsCount = 0;
441 for (; allFieldsCount*FIELD_SLOTS < len; allFieldsCount++) {
442 short flags = getFieldAccessFlags(allFieldsCount);
443 AccessFlags access = new AccessFlags(flags);
444 if (access.fieldHasGenericSignature()) {
445 len --;
446 }
447 }
448 return allFieldsCount;
449 }
450 public ConstantPool getConstants() { return (ConstantPool) constants.getValue(this); }
451 public ClassLoaderData getClassLoaderData() { return ClassLoaderData.instantiateWrapperFor(classLoaderData.getValue(getAddress())); }
452 public Oop getClassLoader() { return getClassLoaderData().getClassLoader(); }
453 public Symbol getSourceFileName() { return getConstants().getSymbolAt(sourceFileNameIndex.getValue(this)); }
454 public String getSourceDebugExtension(){ return CStringUtilities.getString(sourceDebugExtension.getValue(getAddress())); }
455 public long getNonstaticFieldSize() { return nonstaticFieldSize.getValue(this); }
456 public long getStaticOopFieldCount() { return staticOopFieldCount.getValue(this); }
457 public long getNonstaticOopMapSize() { return nonstaticOopMapSize.getValue(this); }
458 public boolean getIsMarkedDependent() { return isMarkedDependent.getValue(this) != 0; }
459 public long getItableLen() { return itableLen.getValue(this); }
460 public long majorVersion() { return majorVersion.getValue(this); }
461 public long minorVersion() { return minorVersion.getValue(this); }
462 public Symbol getGenericSignature() {
463 long index = genericSignatureIndex.getValue(this);
464 if (index != 0) {
465 return getConstants().getSymbolAt(index);
466 } else {
467 return null;
468 }
469 }
470
471 // "size helper" == instance size in words
472 public long getSizeHelper() {
|
74 private static int MISC_HAS_NONSTATIC_CONCRETE_METHODS;
75 private static int MISC_DECLARES_NONSTATIC_CONCRETE_METHODS;
76 private static int MISC_HAS_BEEN_REDEFINED;
77 private static int MISC_HAS_PASSED_FINGERPRINT_CHECK;
78 private static int MISC_IS_SCRATCH_CLASS;
79 private static int MISC_IS_SHARED_BOOT_CLASS;
80 private static int MISC_IS_SHARED_PLATFORM_CLASS;
81 private static int MISC_IS_SHARED_APP_CLASS;
82
83 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
84 Type type = db.lookupType("InstanceKlass");
85 arrayKlasses = new MetadataField(type.getAddressField("_array_klasses"), 0);
86 methods = type.getAddressField("_methods");
87 defaultMethods = type.getAddressField("_default_methods");
88 methodOrdering = type.getAddressField("_method_ordering");
89 localInterfaces = type.getAddressField("_local_interfaces");
90 transitiveInterfaces = type.getAddressField("_transitive_interfaces");
91 fields = type.getAddressField("_fields");
92 javaFieldsCount = new CIntField(type.getCIntegerField("_java_fields_count"), 0);
93 constants = new MetadataField(type.getAddressField("_constants"), 0);
94 sourceDebugExtension = type.getAddressField("_source_debug_extension");
95 innerClasses = type.getAddressField("_inner_classes");
96 sourceFileNameIndex = new CIntField(type.getCIntegerField("_source_file_name_index"), 0);
97 nonstaticFieldSize = new CIntField(type.getCIntegerField("_nonstatic_field_size"), 0);
98 staticFieldSize = new CIntField(type.getCIntegerField("_static_field_size"), 0);
99 staticOopFieldCount = new CIntField(type.getCIntegerField("_static_oop_field_count"), 0);
100 nonstaticOopMapSize = new CIntField(type.getCIntegerField("_nonstatic_oop_map_size"), 0);
101 isMarkedDependent = new CIntField(type.getCIntegerField("_is_marked_dependent"), 0);
102 initState = new CIntField(type.getCIntegerField("_init_state"), 0);
103 itableLen = new CIntField(type.getCIntegerField("_itable_len"), 0);
104 if (VM.getVM().isJvmtiSupported()) {
105 breakpoints = type.getAddressField("_breakpoints");
106 }
107 genericSignatureIndex = new CIntField(type.getCIntegerField("_generic_signature_index"), 0);
108 miscFlags = new CIntField(type.getCIntegerField("_misc_flags"), 0);
109 majorVersion = new CIntField(type.getCIntegerField("_major_version"), 0);
110 minorVersion = new CIntField(type.getCIntegerField("_minor_version"), 0);
111 headerSize = type.getSize();
112
113 // read field offset constants
148 public InstanceKlass(Address addr) {
149 super(addr);
150 if (getJavaFieldsCount() != getAllFieldsCount()) {
151 // Exercise the injected field logic
152 for (int i = getJavaFieldsCount(); i < getAllFieldsCount(); i++) {
153 getFieldName(i);
154 getFieldSignature(i);
155 }
156 }
157 }
158
159 private static MetadataField arrayKlasses;
160 private static AddressField methods;
161 private static AddressField defaultMethods;
162 private static AddressField methodOrdering;
163 private static AddressField localInterfaces;
164 private static AddressField transitiveInterfaces;
165 private static AddressField fields;
166 private static CIntField javaFieldsCount;
167 private static MetadataField constants;
168 private static AddressField sourceDebugExtension;
169 private static AddressField innerClasses;
170 private static CIntField sourceFileNameIndex;
171 private static CIntField nonstaticFieldSize;
172 private static CIntField staticFieldSize;
173 private static CIntField staticOopFieldCount;
174 private static CIntField nonstaticOopMapSize;
175 private static CIntField isMarkedDependent;
176 private static CIntField initState;
177 private static CIntField itableLen;
178 private static AddressField breakpoints;
179 private static CIntField genericSignatureIndex;
180 private static CIntField miscFlags;
181 private static CIntField majorVersion;
182 private static CIntField minorVersion;
183
184 // type safe enum for ClassState from instanceKlass.hpp
185 public static class ClassState {
186 public static final ClassState ALLOCATED = new ClassState("allocated");
187 public static final ClassState LOADED = new ClassState("loaded");
309 return false;
310 }
311
312 public boolean hasStoredFingerprint() {
313 return shouldStoreFingerprint() || isShared();
314 }
315
316 public boolean isShared() {
317 VM vm = VM.getVM();
318 if (vm.isSharingEnabled()) {
319 // This is not the same implementation as the C++ function MetaspaceObj::is_shared()
320 // bool MetaspaceObj::is_shared() const {
321 // return MetaspaceShared::is_in_shared_space(this);
322 // }
323 // However, MetaspaceShared::is_in_shared_space is complicated and hard to emulate in
324 // Java code, so let's do this by looking up from the shared dictionary. Of course,
325 // this works for shared InstanceKlass only and does not work for other types of
326 // MetaspaceObj in the CDS shared archive.
327 Dictionary sharedDictionary = vm.getSystemDictionary().sharedDictionary();
328 if (sharedDictionary != null) {
329 if (sharedDictionary.contains(this)) {
330 return true;
331 }
332 }
333 }
334 return false;
335 }
336
337 public static long getHeaderSize() { return headerSize; }
338
339 public short getFieldAccessFlags(int index) {
340 return getFields().at(index * FIELD_SLOTS + ACCESS_FLAGS_OFFSET);
341 }
342
343 public short getFieldNameIndex(int index) {
344 if (index >= getJavaFieldsCount()) throw new IndexOutOfBoundsException("not a Java field;");
345 return getFields().at(index * FIELD_SLOTS + NAME_INDEX_OFFSET);
346 }
347
348 public Symbol getFieldName(int index) {
349 int nameIndex = getFields().at(index * FIELD_SLOTS + NAME_INDEX_OFFSET);
429 return null;
430 }
431 }
432
433 public KlassArray getLocalInterfaces() { return new KlassArray(localInterfaces.getValue(getAddress())); }
434 public KlassArray getTransitiveInterfaces() { return new KlassArray(transitiveInterfaces.getValue(getAddress())); }
435 public int getJavaFieldsCount() { return (int) javaFieldsCount.getValue(this); }
436 public int getAllFieldsCount() {
437 int len = getFields().length();
438 int allFieldsCount = 0;
439 for (; allFieldsCount*FIELD_SLOTS < len; allFieldsCount++) {
440 short flags = getFieldAccessFlags(allFieldsCount);
441 AccessFlags access = new AccessFlags(flags);
442 if (access.fieldHasGenericSignature()) {
443 len --;
444 }
445 }
446 return allFieldsCount;
447 }
448 public ConstantPool getConstants() { return (ConstantPool) constants.getValue(this); }
449 public Symbol getSourceFileName() { return getConstants().getSymbolAt(sourceFileNameIndex.getValue(this)); }
450 public String getSourceDebugExtension(){ return CStringUtilities.getString(sourceDebugExtension.getValue(getAddress())); }
451 public long getNonstaticFieldSize() { return nonstaticFieldSize.getValue(this); }
452 public long getStaticOopFieldCount() { return staticOopFieldCount.getValue(this); }
453 public long getNonstaticOopMapSize() { return nonstaticOopMapSize.getValue(this); }
454 public boolean getIsMarkedDependent() { return isMarkedDependent.getValue(this) != 0; }
455 public long getItableLen() { return itableLen.getValue(this); }
456 public long majorVersion() { return majorVersion.getValue(this); }
457 public long minorVersion() { return minorVersion.getValue(this); }
458 public Symbol getGenericSignature() {
459 long index = genericSignatureIndex.getValue(this);
460 if (index != 0) {
461 return getConstants().getSymbolAt(index);
462 } else {
463 return null;
464 }
465 }
466
467 // "size helper" == instance size in words
468 public long getSizeHelper() {
|