Skip to content

Commit

Permalink
8312623: SA add NestHost and NestMembers attributes when dumping class
Browse files Browse the repository at this point in the history
Reviewed-by: cjplummer, sspitsyn, stuefe
  • Loading branch information
ashu-mehra authored and plummercj committed Aug 4, 2023
1 parent 017e0c7 commit 873d117
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/hotspot/share/runtime/vmStructs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,15 @@
nonstatic_field(InstanceKlass, _constants, ConstantPool*) \
nonstatic_field(InstanceKlass, _source_debug_extension, const char*) \
nonstatic_field(InstanceKlass, _inner_classes, Array<jushort>*) \
nonstatic_field(InstanceKlass, _nest_members, Array<jushort>*) \
nonstatic_field(InstanceKlass, _nonstatic_field_size, int) \
nonstatic_field(InstanceKlass, _static_field_size, int) \
nonstatic_field(InstanceKlass, _static_oop_field_count, u2) \
nonstatic_field(InstanceKlass, _nonstatic_oop_map_size, int) \
volatile_nonstatic_field(InstanceKlass, _init_state, InstanceKlass::ClassState) \
volatile_nonstatic_field(InstanceKlass, _init_thread, JavaThread*) \
nonstatic_field(InstanceKlass, _itable_len, int) \
nonstatic_field(InstanceKlass, _nest_host_index, u2) \
nonstatic_field(InstanceKlass, _reference_type, u1) \
volatile_nonstatic_field(InstanceKlass, _oop_map_cache, OopMapCache*) \
nonstatic_field(InstanceKlass, _jni_ids, JNIid*) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ private static synchronized void initialize(TypeDataBase db) throws WrongTypeExc
constants = new MetadataField(type.getAddressField("_constants"), 0);
sourceDebugExtension = type.getAddressField("_source_debug_extension");
innerClasses = type.getAddressField("_inner_classes");
nestMembers = type.getAddressField("_nest_members");
nonstaticFieldSize = new CIntField(type.getCIntegerField("_nonstatic_field_size"), 0);
staticFieldSize = new CIntField(type.getCIntegerField("_static_field_size"), 0);
staticOopFieldCount = new CIntField(type.getCIntegerField("_static_oop_field_count"), 0);
nonstaticOopMapSize = new CIntField(type.getCIntegerField("_nonstatic_oop_map_size"), 0);
initState = new CIntField(type.getCIntegerField("_init_state"), 0);
itableLen = new CIntField(type.getCIntegerField("_itable_len"), 0);
nestHostIndex = new CIntField(type.getCIntegerField("_nest_host_index"), 0);
if (VM.getVM().isJvmtiSupported()) {
breakpoints = type.getAddressField("_breakpoints");
}
Expand Down Expand Up @@ -142,12 +144,14 @@ public InstanceKlass(Address addr) {
private static MetadataField constants;
private static AddressField sourceDebugExtension;
private static AddressField innerClasses;
private static AddressField nestMembers;
private static CIntField nonstaticFieldSize;
private static CIntField staticFieldSize;
private static CIntField staticOopFieldCount;
private static CIntField nonstaticOopMapSize;
private static CIntField initState;
private static CIntField itableLen;
private static CIntField nestHostIndex;
private static AddressField breakpoints;

// type safe enum for ClassState from instanceKlass.hpp
Expand Down Expand Up @@ -374,6 +378,7 @@ public int getAllFieldsCount() {
public long getStaticOopFieldCount() { return staticOopFieldCount.getValue(this); }
public long getNonstaticOopMapSize() { return nonstaticOopMapSize.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 minorVersion() { return getConstants().minorVersion(); }
public Symbol getGenericSignature() { return getConstants().getGenericSignature(); }
Expand Down Expand Up @@ -900,6 +905,11 @@ public U1Array getFieldTypeAnnotations(int fieldIndex) {
}
}

public U2Array getNestMembers() {
Address addr = getAddress().getAddressAt(nestMembers.getOffset());
return VMObjectFactory.newObject(U2Array.class, addr);
}

//----------------------------------------------------------------------
// Internals only below this point
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ protected void debugMessage(String message) {

protected short _sourceFileIndex;
protected short _innerClassesIndex;
protected short _nestHostIndex;
protected short _nestMembersIndex;
protected short _syntheticIndex;
protected short _deprecatedIndex;
protected short _constantValueIndex;
Expand Down Expand Up @@ -143,6 +145,14 @@ else if(cpConstType == JVM_CONSTANT_Long ||
_innerClassesIndex = (innerClassesIndex != null)? innerClassesIndex.shortValue() : 0;
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");
_bootstrapMethodsIndex = (bootstrapMethodsIndex != null) ? bootstrapMethodsIndex.shortValue() : 0;
// field attributes
Expand Down Expand Up @@ -780,6 +790,17 @@ protected void writeClassAttributes() throws IOException {
if (numInnerClasses != 0)
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();
if (bsmCount != 0) {
classAttributeCount++;
Expand Down Expand Up @@ -835,6 +856,23 @@ protected void writeClassAttributes() throws IOException {
}
}

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
if (bsmCount != 0) {
ConstantPool cpool = klass.getConstants();
Expand Down

1 comment on commit 873d117

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.