Skip to content

Commit

Permalink
8316342: CLHSDB "dumpclass" command produces invalid classes
Browse files Browse the repository at this point in the history
Reviewed-by: cjplummer, sspitsyn
  • Loading branch information
Ashutosh Mehra committed Nov 14, 2023
1 parent 97ea5bf commit 7bb1999
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,42 +80,6 @@ protected short getConstantPoolIndexFromRefMap(int rawcode, int bci) {
return (short)cpool.objectToCPIndex(refIndex);
}

protected short getConstantPoolIndex(int rawcode, int bci) {
// get ConstantPool index from ConstantPoolCacheIndex at given bci
String fmt = Bytecodes.format(rawcode);
int cpCacheIndex;
switch (fmt.length()) {
case 2: cpCacheIndex = method.getBytecodeByteArg(bci); break;
case 3: cpCacheIndex = method.getBytecodeShortArg(bci); break;
case 5:
if (fmt.contains("__"))
cpCacheIndex = method.getBytecodeShortArg(bci);
else
cpCacheIndex = method.getBytecodeIntArg(bci);
break;
default: throw new IllegalArgumentException();
}

if (cpCache == null) {
return (short) cpCacheIndex;
} else if (fmt.contains("JJJJ")) {
// Invokedynamic require special handling
cpCacheIndex = ~cpCacheIndex;
cpCacheIndex = bytes.swapInt(cpCacheIndex);
short cpIndex = (short) cpCache.getIndyEntryAt(cpCacheIndex).getConstantPoolIndex();
Assert.that(cpool.getTagAt(cpIndex).isInvokeDynamic(), "CP Entry should be InvokeDynamic");
return cpIndex;
} else if (fmt.contains("JJ")) {
// change byte-ordering and go via cache
return (short) cpCache.getEntryAt((int) (0xFFFF & bytes.swapShort((short)cpCacheIndex))).getConstantPoolIndex();
} else if (fmt.contains("j")) {
// go via cache
return (short) cpCache.getEntryAt((int) (0xFF & cpCacheIndex)).getConstantPoolIndex();
} else {
return (short) cpCacheIndex;
}
}

private static void writeShort(byte[] buf, int index, short value) {
buf[index] = (byte) ((value >> 8) & 0x00FF);
buf[index + 1] = (byte) (value & 0x00FF);
Expand Down Expand Up @@ -152,22 +116,29 @@ public void rewrite() {
case Bytecodes._getstatic:
case Bytecodes._putstatic:
case Bytecodes._getfield:
case Bytecodes._putfield:
case Bytecodes._putfield: {
int fieldIndex = method.getNativeShortArg(bci + 1);
cpoolIndex = (short) cpCache.getFieldEntryAt(fieldIndex).getConstantPoolIndex();
writeShort(code, bci + 1, cpoolIndex);
break;
}
case Bytecodes._invokevirtual:
case Bytecodes._invokespecial:
case Bytecodes._invokestatic:
case Bytecodes._invokeinterface: {
cpoolIndex = getConstantPoolIndex(hotspotcode, bci + 1);
int cpci = method.getNativeShortArg(bci + 1);
cpoolIndex = (short) cpCache.getEntryAt(cpci).getConstantPoolIndex();
writeShort(code, bci + 1, cpoolIndex);
break;
}

case Bytecodes._invokedynamic:
cpoolIndex = getConstantPoolIndex(hotspotcode, bci + 1);
case Bytecodes._invokedynamic: {
int cpci = method.getNativeIntArg(bci + 1);
cpoolIndex = (short) cpCache.getIndyEntryAt(~cpci).getConstantPoolIndex();
writeShort(code, bci + 1, cpoolIndex);
writeShort(code, bci + 3, (short)0); // clear out trailing bytes
break;

}
case Bytecodes._ldc_w:
if (hotspotcode != bytecode) {
// fast_aldc_w puts constant in reference map
Expand Down
1 change: 0 additions & 1 deletion test/hotspot/jtreg/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ serviceability/sa/ClhsdbPmap.java#core 8267433 macosx-x64
serviceability/sa/ClhsdbPstack.java#core 8267433 macosx-x64
serviceability/sa/TestJmapCore.java 8267433 macosx-x64
serviceability/sa/TestJmapCoreMetaspace.java 8267433 macosx-x64
serviceability/sa/ClhsdbDumpclass.java 8316342 generic-all

serviceability/attach/ConcAttachTest.java 8290043 linux-all

Expand Down

1 comment on commit 7bb1999

@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.