8312623: SA add NestHost and NestMembers attributes when dumping class

Reviewed-by: cjplummer, sspitsyn, stuefe
This commit is contained in:
Ashutosh Mehra 2023-08-04 18:42:37 +00:00 committed by Chris Plummer
parent 017e0c7850
commit 873d117932
3 changed files with 50 additions and 0 deletions

View File

@ -237,6 +237,7 @@
nonstatic_field(InstanceKlass, _constants, ConstantPool*) \ nonstatic_field(InstanceKlass, _constants, ConstantPool*) \
nonstatic_field(InstanceKlass, _source_debug_extension, const char*) \ nonstatic_field(InstanceKlass, _source_debug_extension, const char*) \
nonstatic_field(InstanceKlass, _inner_classes, Array<jushort>*) \ nonstatic_field(InstanceKlass, _inner_classes, Array<jushort>*) \
nonstatic_field(InstanceKlass, _nest_members, Array<jushort>*) \
nonstatic_field(InstanceKlass, _nonstatic_field_size, int) \ nonstatic_field(InstanceKlass, _nonstatic_field_size, int) \
nonstatic_field(InstanceKlass, _static_field_size, int) \ nonstatic_field(InstanceKlass, _static_field_size, int) \
nonstatic_field(InstanceKlass, _static_oop_field_count, u2) \ nonstatic_field(InstanceKlass, _static_oop_field_count, u2) \
@ -244,6 +245,7 @@
volatile_nonstatic_field(InstanceKlass, _init_state, InstanceKlass::ClassState) \ volatile_nonstatic_field(InstanceKlass, _init_state, InstanceKlass::ClassState) \
volatile_nonstatic_field(InstanceKlass, _init_thread, JavaThread*) \ volatile_nonstatic_field(InstanceKlass, _init_thread, JavaThread*) \
nonstatic_field(InstanceKlass, _itable_len, int) \ nonstatic_field(InstanceKlass, _itable_len, int) \
nonstatic_field(InstanceKlass, _nest_host_index, u2) \
nonstatic_field(InstanceKlass, _reference_type, u1) \ nonstatic_field(InstanceKlass, _reference_type, u1) \
volatile_nonstatic_field(InstanceKlass, _oop_map_cache, OopMapCache*) \ volatile_nonstatic_field(InstanceKlass, _oop_map_cache, OopMapCache*) \
nonstatic_field(InstanceKlass, _jni_ids, JNIid*) \ nonstatic_field(InstanceKlass, _jni_ids, JNIid*) \

View File

@ -77,12 +77,14 @@ public class InstanceKlass extends Klass {
constants = new MetadataField(type.getAddressField("_constants"), 0); constants = new MetadataField(type.getAddressField("_constants"), 0);
sourceDebugExtension = type.getAddressField("_source_debug_extension"); sourceDebugExtension = type.getAddressField("_source_debug_extension");
innerClasses = type.getAddressField("_inner_classes"); innerClasses = type.getAddressField("_inner_classes");
nestMembers = type.getAddressField("_nest_members");
nonstaticFieldSize = new CIntField(type.getCIntegerField("_nonstatic_field_size"), 0); nonstaticFieldSize = new CIntField(type.getCIntegerField("_nonstatic_field_size"), 0);
staticFieldSize = new CIntField(type.getCIntegerField("_static_field_size"), 0); staticFieldSize = new CIntField(type.getCIntegerField("_static_field_size"), 0);
staticOopFieldCount = new CIntField(type.getCIntegerField("_static_oop_field_count"), 0); staticOopFieldCount = new CIntField(type.getCIntegerField("_static_oop_field_count"), 0);
nonstaticOopMapSize = new CIntField(type.getCIntegerField("_nonstatic_oop_map_size"), 0); nonstaticOopMapSize = new CIntField(type.getCIntegerField("_nonstatic_oop_map_size"), 0);
initState = new CIntField(type.getCIntegerField("_init_state"), 0); initState = new CIntField(type.getCIntegerField("_init_state"), 0);
itableLen = new CIntField(type.getCIntegerField("_itable_len"), 0); itableLen = new CIntField(type.getCIntegerField("_itable_len"), 0);
nestHostIndex = new CIntField(type.getCIntegerField("_nest_host_index"), 0);
if (VM.getVM().isJvmtiSupported()) { if (VM.getVM().isJvmtiSupported()) {
breakpoints = type.getAddressField("_breakpoints"); breakpoints = type.getAddressField("_breakpoints");
} }
@ -142,12 +144,14 @@ public class InstanceKlass extends Klass {
private static MetadataField constants; private static MetadataField constants;
private static AddressField sourceDebugExtension; private static AddressField sourceDebugExtension;
private static AddressField innerClasses; private static AddressField innerClasses;
private static AddressField nestMembers;
private static CIntField nonstaticFieldSize; private static CIntField nonstaticFieldSize;
private static CIntField staticFieldSize; private static CIntField staticFieldSize;
private static CIntField staticOopFieldCount; private static CIntField staticOopFieldCount;
private static CIntField nonstaticOopMapSize; private static CIntField nonstaticOopMapSize;
private static CIntField initState; private static CIntField initState;
private static CIntField itableLen; private static CIntField itableLen;
private static CIntField nestHostIndex;
private static AddressField breakpoints; private static AddressField breakpoints;
// type safe enum for ClassState from instanceKlass.hpp // type safe enum for ClassState from instanceKlass.hpp
@ -374,6 +378,7 @@ public class InstanceKlass extends Klass {
public long getStaticOopFieldCount() { return staticOopFieldCount.getValue(this); } public long getStaticOopFieldCount() { return staticOopFieldCount.getValue(this); }
public long getNonstaticOopMapSize() { return nonstaticOopMapSize.getValue(this); } public long getNonstaticOopMapSize() { return nonstaticOopMapSize.getValue(this); }
public long getItableLen() { return itableLen.getValue(this); } public long getItableLen() { return itableLen.getValue(this); }
public short getNestHostIndex() { return (short) nestHostIndex.getValue(this); }
public long majorVersion() { return getConstants().majorVersion(); } public long majorVersion() { return getConstants().majorVersion(); }
public long minorVersion() { return getConstants().minorVersion(); } public long minorVersion() { return getConstants().minorVersion(); }
public Symbol getGenericSignature() { return getConstants().getGenericSignature(); } public Symbol getGenericSignature() { return getConstants().getGenericSignature(); }
@ -900,6 +905,11 @@ public class InstanceKlass extends Klass {
} }
} }
public U2Array getNestMembers() {
Address addr = getAddress().getAddressAt(nestMembers.getOffset());
return VMObjectFactory.newObject(U2Array.class, addr);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Internals only below this point // Internals only below this point
// //

View File

@ -52,6 +52,8 @@ public class ClassWriter implements /* imports */ ClassConstants
protected short _sourceFileIndex; protected short _sourceFileIndex;
protected short _innerClassesIndex; protected short _innerClassesIndex;
protected short _nestHostIndex;
protected short _nestMembersIndex;
protected short _syntheticIndex; protected short _syntheticIndex;
protected short _deprecatedIndex; protected short _deprecatedIndex;
protected short _constantValueIndex; protected short _constantValueIndex;
@ -143,6 +145,14 @@ public class ClassWriter implements /* imports */ ClassConstants
_innerClassesIndex = (innerClassesIndex != null)? innerClassesIndex.shortValue() : 0; _innerClassesIndex = (innerClassesIndex != null)? innerClassesIndex.shortValue() : 0;
if (DEBUG) debugMessage("InnerClasses index = " + _innerClassesIndex); if (DEBUG) debugMessage("InnerClasses index = " + _innerClassesIndex);
Short nestHostIndex = utf8ToIndex.get("NestHost");
_nestHostIndex = (nestHostIndex != null)? nestHostIndex.shortValue() : 0;
if (DEBUG) debugMessage("NestHost index = " + _nestHostIndex);
Short nestMembersIndex = utf8ToIndex.get("NestMembers");
_nestMembersIndex = (nestMembersIndex != null)? nestMembersIndex.shortValue() : 0;
if (DEBUG) debugMessage("NestMembers index = " + _nestMembersIndex);
Short bootstrapMethodsIndex = utf8ToIndex.get("BootstrapMethods"); Short bootstrapMethodsIndex = utf8ToIndex.get("BootstrapMethods");
_bootstrapMethodsIndex = (bootstrapMethodsIndex != null) ? bootstrapMethodsIndex.shortValue() : 0; _bootstrapMethodsIndex = (bootstrapMethodsIndex != null) ? bootstrapMethodsIndex.shortValue() : 0;
// field attributes // field attributes
@ -780,6 +790,17 @@ public class ClassWriter implements /* imports */ ClassConstants
if (numInnerClasses != 0) if (numInnerClasses != 0)
classAttributeCount++; classAttributeCount++;
short nestHost = klass.getNestHostIndex();
if (nestHost != 0) {
classAttributeCount++;
}
U2Array nestMembers = klass.getNestMembers();
final int numNestMembers = nestMembers.length();
if (numNestMembers != 0) {
classAttributeCount++;
}
int bsmCount = klass.getConstants().getBootstrapMethodsCount(); int bsmCount = klass.getConstants().getBootstrapMethodsCount();
if (bsmCount != 0) { if (bsmCount != 0) {
classAttributeCount++; classAttributeCount++;
@ -835,6 +856,23 @@ public class ClassWriter implements /* imports */ ClassConstants
} }
} }
if (nestHost != 0) {
writeIndex(_nestHostIndex);
final int nestHostAttrLen = 2;
dos.writeInt(nestHostAttrLen);
dos.writeShort(nestHost);
}
if (numNestMembers != 0) {
writeIndex(_nestMembersIndex);
final int nestMembersAttrLen = 2 + numNestMembers * 2;
dos.writeInt(nestMembersAttrLen);
dos.writeShort(numNestMembers);
for (int index = 0; index < numNestMembers; index++) {
dos.writeShort(nestMembers.at(index));
}
}
// write bootstrap method attribute, if any // write bootstrap method attribute, if any
if (bsmCount != 0) { if (bsmCount != 0) {
ConstantPool cpool = klass.getConstants(); ConstantPool cpool = klass.getConstants();