use of com.ibm.j9ddr.vm29.pointer.generated.J9ROMSingleSlotConstantRefPointer in project openj9 by eclipse.
the class J9BCUtil method dumpCallSiteData.
/**
* This method is Java implementation of rdump.c#dumpCallSiteData function.
* This method is called when dumping a ROMClass.
* This method has only affect for invokedDynamic stuff,
* for other ROMClasses, there wont be anything to print since their callsite and bsm count are zero.
*
* @param out PrintStream to print the user info to the console
* @param romClass ROMClass address in the dump file.
*
* @throws CorruptDataException
*/
private static void dumpCallSiteData(PrintStream out, J9ROMClassPointer romClass) throws CorruptDataException {
int HEX_RADIX = 16;
long callSiteCount = romClass.callSiteCount().longValue();
long bsmCount = romClass.bsmCount().longValue();
SelfRelativePointer callSiteData = SelfRelativePointer.cast(romClass.callSiteData());
U16Pointer bsmIndices = U16Pointer.cast(callSiteData.addOffset(4 * callSiteCount));
if (0 != callSiteCount) {
out.println(String.format(" Call Sites (%d):\n", callSiteCount));
for (int i = 0; i < callSiteCount; i++) {
J9ROMNameAndSignaturePointer nameAndSig = J9ROMNameAndSignaturePointer.cast(callSiteData.add(i).get());
out.println(" Name: " + J9UTF8Helper.stringValue(nameAndSig.name()));
out.println(" Signature: " + J9UTF8Helper.stringValue(nameAndSig.signature()));
out.println(" Bootstrap Method Index: " + bsmIndices.at(i).longValue());
out.println();
}
}
if (0 != bsmCount) {
J9ROMConstantPoolItemPointer constantPool = ConstantPoolHelpers.J9_ROM_CP_FROM_ROM_CLASS(romClass);
U32Pointer cpShapeDescription = romClass.cpShapeDescription();
U16Pointer bsmDataCursor = bsmIndices.add(callSiteCount);
out.println(String.format(" Bootstrap Methods (%d):", bsmCount));
for (int i = 0; i < bsmCount; i++) {
J9ROMMethodHandleRefPointer methodHandleRef = J9ROMMethodHandleRefPointer.cast(constantPool.add(bsmDataCursor.at(0).longValue()));
bsmDataCursor = bsmDataCursor.add(1);
/* methodRef will be either a field or a method ref - they both have the same shape so we can pretend it is always a methodref */
J9ROMMethodRefPointer methodRef = J9ROMMethodRefPointer.cast(constantPool.add(methodHandleRef.methodOrFieldRefIndex().longValue()));
J9ROMClassRefPointer classRef = J9ROMClassRefPointer.cast(constantPool.add(methodRef.classRefCPIndex().longValue()));
J9ROMNameAndSignaturePointer nameAndSig = methodRef.nameAndSignature();
long bsmArgumentCount = bsmDataCursor.at(0).longValue();
bsmDataCursor = bsmDataCursor.add(1);
out.println(" Name: " + J9UTF8Helper.stringValue(classRef.name()) + "." + J9UTF8Helper.stringValue(nameAndSig.name()));
out.println(" Signature: " + J9UTF8Helper.stringValue(nameAndSig.signature()));
out.println(String.format(" Bootstrap Method Arguments (%d):", bsmArgumentCount));
for (; 0 != bsmArgumentCount; bsmArgumentCount--) {
long argCPIndex = bsmDataCursor.at(0).longValue();
bsmDataCursor = bsmDataCursor.add(1);
J9ROMConstantPoolItemPointer item = constantPool.add(argCPIndex);
long shapeDesc = ConstantPoolHelpers.J9_CP_TYPE(cpShapeDescription, (int) argCPIndex);
if (shapeDesc == J9CPTYPE_CLASS) {
J9ROMClassRefPointer romClassRef = J9ROMClassRefPointer.cast(item);
out.println(" Class: " + J9UTF8Helper.stringValue(romClassRef.name()));
} else if (shapeDesc == J9CPTYPE_STRING) {
J9ROMStringRefPointer romStringRef = J9ROMStringRefPointer.cast(item);
out.println(" String: " + J9UTF8Helper.stringValue(romStringRef.utf8Data()));
} else if (shapeDesc == J9CPTYPE_INT) {
J9ROMSingleSlotConstantRefPointer singleSlotConstantRef = J9ROMSingleSlotConstantRefPointer.cast(item);
out.println(" Int: " + singleSlotConstantRef.data().getHexValue());
} else if (shapeDesc == J9CPTYPE_FLOAT) {
J9ROMSingleSlotConstantRefPointer singleSlotConstantRef = J9ROMSingleSlotConstantRefPointer.cast(item);
FloatPointer floatPtr = FloatPointer.cast(singleSlotConstantRef.dataEA());
out.println(" Float: " + floatPtr.getHexValue() + " (" + floatPtr.floatAt(0) + ")");
} else if (shapeDesc == J9CPTYPE_LONG) {
String hexValue = "";
if (J9BuildFlags.env_littleEndian) {
hexValue += item.slot2().getHexValue();
hexValue += item.slot1().getHexValue().substring(2);
} else {
hexValue += item.slot1().getHexValue();
hexValue += item.slot2().getHexValue().substring(2);
}
long longValue = Long.parseLong(hexValue.substring(2), HEX_RADIX);
out.println(" Long: " + hexValue + "(" + longValue + ")");
} else if (shapeDesc == J9CPTYPE_DOUBLE) {
String hexValue = "";
if (J9BuildFlags.env_littleEndian) {
hexValue += item.slot2().getHexValue();
hexValue += item.slot1().getHexValue().substring(2);
} else {
hexValue += item.slot1().getHexValue();
hexValue += item.slot2().getHexValue().substring(2);
}
long longValue = Long.parseLong(hexValue.substring(2), HEX_RADIX);
double doubleValue = Double.longBitsToDouble(longValue);
out.println(" Double: " + hexValue + "(" + Double.toString(doubleValue) + ")");
} else if (shapeDesc == J9CPTYPE_FIELD) {
J9ROMFieldRefPointer romFieldRef = J9ROMFieldRefPointer.cast(item);
classRef = J9ROMClassRefPointer.cast(constantPool.add(romFieldRef.classRefCPIndex()));
nameAndSig = romFieldRef.nameAndSignature();
out.println(" Field: " + J9UTF8Helper.stringValue(classRef.name()) + "." + J9UTF8Helper.stringValue(nameAndSig.name()) + " " + J9UTF8Helper.stringValue(nameAndSig.signature()));
} else if ((shapeDesc == J9CPTYPE_INSTANCE_METHOD) || (shapeDesc == J9CPTYPE_STATIC_METHOD) || (shapeDesc == J9CPTYPE_HANDLE_METHOD) || (shapeDesc == J9CPTYPE_INTERFACE_METHOD)) {
J9ROMMethodRefPointer romMethodRef = J9ROMMethodRefPointer.cast(item);
classRef = J9ROMClassRefPointer.cast(constantPool.add(romMethodRef.classRefCPIndex()));
nameAndSig = romMethodRef.nameAndSignature();
out.println(" Method: " + J9UTF8Helper.stringValue(classRef.name()) + "." + J9UTF8Helper.stringValue(nameAndSig.name()) + " " + J9UTF8Helper.stringValue(nameAndSig.signature()));
} else if (shapeDesc == J9CPTYPE_METHOD_TYPE) {
J9ROMMethodTypeRefPointer romMethodTypeRef = J9ROMMethodTypeRefPointer.cast(item);
out.println(" Method Type: " + J9UTF8Helper.stringValue(J9UTF8Pointer.cast(romMethodTypeRef.signature())));
} else if (shapeDesc == J9CPTYPE_METHODHANDLE) {
methodHandleRef = J9ROMMethodHandleRefPointer.cast(item);
methodRef = J9ROMMethodRefPointer.cast(constantPool.add(methodHandleRef.methodOrFieldRefIndex()));
classRef = J9ROMClassRefPointer.cast(constantPool.add(methodRef.classRefCPIndex()));
nameAndSig = methodRef.nameAndSignature();
out.print(" Method Handle: " + J9UTF8Helper.stringValue(classRef.name()) + "." + J9UTF8Helper.stringValue(nameAndSig.name()));
long methodType = methodHandleRef.handleTypeAndCpType().rightShift((int) J9DescriptionCpTypeShift).longValue();
if ((methodType == MH_REF_GETFIELD) || (methodType == MH_REF_PUTFIELD) || (methodType == MH_REF_GETSTATIC) || (methodType == MH_REF_PUTSTATIC)) {
out.print(" ");
}
out.println(J9UTF8Helper.stringValue(nameAndSig.signature()));
} else {
out.println(" <unknown type>");
}
}
}
}
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9ROMSingleSlotConstantRefPointer in project openj9 by eclipse.
the class ByteCodeDumper method j9bcutil_dumpBytecodes.
private static IDATA j9bcutil_dumpBytecodes(PrintStream out, J9ROMClassPointer romClass, U8Pointer bytecodes, UDATA walkStartPC, UDATA walkEndPC, U32 flags, String indent) throws Exception {
J9ROMConstantPoolItemPointer constantPool = J9ROMClassHelper.constantPool(romClass);
J9ROMConstantPoolItemPointer info;
J9ROMNameAndSignaturePointer nameAndSig;
bigEndian = flags.anyBitsIn(BCT_BigEndianOutput);
UDATA index = new UDATA(0);
UDATA target = new UDATA(0);
UDATA start;
UDATA pc;
UDATA bc;
I32 low, high;
U32 npairs;
J9ROMMethodPointer romMethod = (J9ROMMethodPointer.cast(bytecodes.sub(J9ROMMethod.SIZEOF)));
U32 localsCount = new U32(ROMHelp.J9_ARG_COUNT_FROM_ROM_METHOD(romMethod).add(ROMHelp.J9_TEMP_COUNT_FROM_ROM_METHOD(romMethod)));
int[] resultArray = new int[8192];
String environment = "0";
boolean envVarDefined = false;
int result;
if (System.getenv().containsKey("j9bcutil_dumpBytecodes")) {
envVarDefined = true;
environment = System.getenv().get("j9bcutil_dumpBytecodes");
}
pc = new UDATA(walkStartPC);
// cell address
bcIndex = bytecodes.add(pc);
while (pc.lte(walkEndPC)) {
if (flags.anyBitsIn(BCT_DumpMaps)) {
for (int j = LOCAL_MAP; j < MAP_COUNT; j++) {
if (envVarDefined && (!pc.eq(Integer.parseInt(environment)))) {
continue;
}
boolean wrapLine = false;
UDATA outputCount = new UDATA(0);
U8 mapChar = new U8('0');
switch(j) {
case LOCAL_MAP:
result = LocalMap.j9localmap_LocalBitsForPC(romMethod, pc, resultArray);
mapChar = new U8('l');
outputCount = new UDATA(localsCount);
break;
case DEBUG_MAP:
result = DebugLocalMap.j9localmap_DebugLocalBitsForPC(romMethod, pc, resultArray);
mapChar = new U8('d');
outputCount = new UDATA(localsCount);
break;
case STACK_MAP:
/* First call is to get the stack depth */
result = StackMap.j9stackmap_StackBitsForPC(pc, romClass, romMethod, null, 0);
mapChar = new U8('s');
outputCount = new UDATA(result);
break;
}
if (outputCount.eq(0)) {
out.append(String.format(" %cmap [empty]", (char) mapChar.intValue()));
} else {
out.append(String.format(" %cmap [%5d] =", (char) mapChar.intValue(), outputCount.intValue()));
}
for (int i = 0; outputCount.gt(i); i++) {
int x = i / 32;
if ((i % 8) == 0) {
out.append(" ");
if (wrapLine) {
out.append(nl);
}
}
out.append(String.format("%d ", resultArray[x] & 1));
resultArray[x] >>= 1;
wrapLine = (((i + 1) % 32) == 0);
}
out.append(nl);
}
}
// _GETNEXT_U8(bc, bcIndex);
// #define _GETNEXT_U8(value, index) (bc = *(bcIndex++))
// error
bc = new UDATA(_GETNEXT_U8());
out.append(String.format("%s%5d %s ", indent, pc.intValue(), BCNames.getName(bc.intValue())));
start = new UDATA(pc);
pc = pc.add(1);
switch(bc.intValue()) {
case JBbipush:
index = new UDATA(_GETNEXT_U8());
out.append(String.format("%d\n", new I8(index).intValue()));
pc = pc.add(1);
break;
case JBsipush:
index = new UDATA(_GETNEXT_U16());
out.append(String.format("%d\n", new I16(index).intValue()));
pc = pc.add(2);
break;
case JBldc:
case JBldcw:
if (bc.eq(JBldc)) {
index = new UDATA(_GETNEXT_U8());
pc = pc.add(1);
} else {
index = new UDATA(_GETNEXT_U16());
pc = pc.add(2);
}
out.append(String.format("%d ", index.intValue()));
info = constantPool.add(index);
J9ROMSingleSlotConstantRefPointer romSingleSlotConstantRef = J9ROMSingleSlotConstantRefPointer.cast(info);
if (!romSingleSlotConstantRef.cpType().eq(BCT_J9DescriptionCpTypeScalar)) {
/* this is a string or class constant */
if (romSingleSlotConstantRef.cpType().eq(BCT_J9DescriptionCpTypeClass)) {
/* ClassRef */
out.append("(java.lang.Class) ");
} else {
/* StringRef */
out.append("(java.lang.String) ");
}
out.append(J9UTF8Helper.stringValue(J9ROMStringRefPointer.cast(info).utf8Data()));
out.append(nl);
} else {
/* this is a float/int constant */
out.append(String.format("(int/float) 0x%08X", romSingleSlotConstantRef.data().longValue()));
out.append(nl);
}
break;
case JBldc2lw:
index = new UDATA(_GETNEXT_U16());
out.append(String.format("%d ", index.intValue()));
info = constantPool.add(index);
out.append(String.format("(long) 0x%08X%08X\n", bigEndian ? info.slot1().longValue() : info.slot2().longValue(), bigEndian ? info.slot2().longValue() : info.slot1().longValue()));
pc = pc.add(2);
break;
case JBldc2dw:
index = new UDATA(_GETNEXT_U16());
out.append(String.format("%d ", index.intValue()));
info = constantPool.add(index);
/* this will print incorrectly on Linux ARM! FIX ME! */
out.append(String.format("(double) 0x%08X%08X\n", bigEndian ? info.slot1().longValue() : info.slot2().longValue(), bigEndian ? info.slot2().longValue() : info.slot1().longValue()));
pc = pc.add(2);
break;
case JBiload:
case JBlload:
case JBfload:
case JBdload:
case JBaload:
case JBistore:
case JBlstore:
case JBfstore:
case JBdstore:
case JBastore:
index = new UDATA(_GETNEXT_U8());
pc = pc.add(1);
out.append(String.format("%d\n", index.intValue()));
break;
case JBiloadw:
case JBlloadw:
case JBfloadw:
case JBdloadw:
case JBaloadw:
case JBistorew:
case JBlstorew:
case JBfstorew:
case JBdstorew:
case JBastorew:
index = new UDATA(_GETNEXT_U16());
incIndex();
pc = pc.add(3);
out.append(String.format("%d\n", index.intValue()));
break;
case JBiinc:
index = new UDATA(_GETNEXT_U8());
out.append(String.format("%d ", index.intValue()));
target = new UDATA(_GETNEXT_U8());
out.append(String.format("%d\n", new I8(target).intValue()));
pc = pc.add(2);
break;
case JBiincw:
index = new UDATA(_GETNEXT_U16());
out.append(String.format("%d ", index.intValue()));
index = new UDATA(_GETNEXT_U16());
out.append(String.format("%d\n", new I16(index).intValue()));
incIndex();
pc = pc.add(5);
break;
case JBifeq:
case JBifne:
case JBiflt:
case JBifge:
case JBifgt:
case JBifle:
case JBificmpeq:
case JBificmpne:
case JBificmplt:
case JBificmpge:
case JBificmpgt:
case JBificmple:
case JBifacmpeq:
case JBifacmpne:
case JBgoto:
case JBifnull:
case JBifnonnull:
index = new UDATA(_GETNEXT_U16());
pc = pc.add(2);
if (OPCODE_RELATIVE_BRANCHES != 0) {
target = start.add(new I16(index));
} else {
target = pc.add(new I16(index));
}
out.append(String.format("%d\n", target.intValue()));
break;
case JBtableswitch:
switch(start.intValue() % 4) {
case 0:
incIndex();
// fall through
pc = pc.add(1);
case 1:
incIndex();
// fall through
pc = pc.add(1);
case 2:
incIndex();
// fall through
pc = pc.add(1);
case 3:
break;
}
index = new UDATA(_GETNEXT_U32());
target = start.add(index);
index = new UDATA(_GETNEXT_U32());
low = new I32(index);
index = new UDATA(_GETNEXT_U32());
high = new I32(index);
pc = pc.add(12);
out.append(String.format("low %d high %d\n", low.intValue(), high.intValue()));
out.append(String.format(" default %10d\n", target.intValue()));
npairs = new U32(high.sub(low).add(1));
for (int i = 0; npairs.gt(i); i++) {
index = new UDATA(_GETNEXT_U32());
target = start.add(index);
out.append(String.format(" %10d %10d\n", low.add(i).intValue(), target.intValue()));
pc = pc.add(4);
}
break;
case JBlookupswitch:
switch(start.intValue() % 4) {
case 0:
incIndex();
pc = pc.add(1);
break;
case 1:
incIndex();
pc = pc.add(1);
break;
case 2:
incIndex();
pc = pc.add(1);
break;
case 3:
break;
}
index = new UDATA(_GETNEXT_U32());
target = start.add(index);
npairs = new U32(_GETNEXT_U32());
out.append(String.format("pairs %d\n", npairs.intValue()));
out.append(String.format(" default %10d\n", target.intValue()));
pc = pc.add(8);
for (int i = 0; npairs.gt(i); i++) {
index = new UDATA(_GETNEXT_U32());
out.append(String.format(" %10d", index.intValue()));
index = new UDATA(_GETNEXT_U32());
target = start.add(index);
out.append(String.format(" %10d\n", target.intValue()));
pc = pc.add(8);
}
break;
case JBgetstatic:
case JBputstatic:
case JBgetfield:
case JBputfield:
index = new UDATA(_GETNEXT_U16());
info = constantPool.add(index);
out.append(String.format("%d ", index.intValue()));
// dump declaringClassName
J9ROMFieldRefPointer romFieldRef = J9ROMFieldRefPointer.cast(info);
out.append(J9UTF8Helper.stringValue(J9ROMClassRefPointer.cast(constantPool.add(romFieldRef.classRefCPIndex())).name()));
nameAndSig = romFieldRef.nameAndSignature();
out.append(".");
/* dump name */
out.append(J9UTF8Helper.stringValue(nameAndSig.name()));
out.append(" ");
/* dump signature */
out.append(J9UTF8Helper.stringValue(nameAndSig.signature()));
out.append(nl);
pc = pc.add(2);
break;
case JBinvokedynamic:
index = new UDATA(_GETNEXT_U16());
out.append(String.format("%d ", index.intValue()));
long callSiteCount = romClass.callSiteCount().longValue();
SelfRelativePointer callSiteData = SelfRelativePointer.cast(romClass.callSiteData());
U16Pointer bsmIndices = U16Pointer.cast(callSiteData.addOffset(4 * callSiteCount));
nameAndSig = J9ROMNameAndSignaturePointer.cast(callSiteData.add(index).get());
out.append("bsm #" + String.valueOf(bsmIndices.at(index).longValue()));
/* Bootstrap method index */
out.append(":");
out.append(J9UTF8Helper.stringValue(nameAndSig.name()));
/* dump name */
out.append(J9UTF8Helper.stringValue(nameAndSig.signature()));
/* dump signature */
out.append(nl);
pc = pc.add(4);
break;
case JBinvokeinterface2:
incIndex();
pc = pc.add(1);
out.append(nl);
break;
case JBinvokehandle:
case JBinvokehandlegeneric:
case JBinvokevirtual:
case JBinvokespecial:
case JBinvokestatic:
case JBinvokeinterface:
case JBinvokespecialsplit:
case JBinvokestaticsplit:
if (bcIndex.longValue() == 0) {
bcIndex = bcIndex.sub(1);
}
index = new UDATA(_GETNEXT_U16());
if (bc.intValue() == JBinvokestaticsplit) {
index = new UDATA(romClass.staticSplitMethodRefIndexes().at(index));
} else if (bc.intValue() == JBinvokespecialsplit) {
index = new UDATA(romClass.specialSplitMethodRefIndexes().at(index));
}
info = constantPool.add(index);
out.append(String.format("%d ", index.intValue()));
/* dump declaringClassName and signature */
J9ROMMethodRefPointer romMethodRef = J9ROMMethodRefPointer.cast(info);
U32 classRefCPIndex = romMethodRef.classRefCPIndex();
J9ROMConstantPoolItemPointer cpItem = constantPool.add(classRefCPIndex);
J9ROMClassRefPointer romClassRef = J9ROMClassRefPointer.cast(cpItem);
String name = J9UTF8Helper.stringValue(romClassRef.name());
out.append(name);
nameAndSig = romMethodRef.nameAndSignature();
out.append(".");
out.append(J9UTF8Helper.stringValue(nameAndSig.name()));
/* dump name */
out.append(J9UTF8Helper.stringValue(nameAndSig.signature()));
/*
* dump
* signature
*/
out.append(nl);
pc = pc.add(2);
break;
case JBnew:
case JBnewdup:
case JBanewarray:
case JBcheckcast:
case JBinstanceof:
index = new UDATA(_GETNEXT_U16());
info = constantPool.add(index);
out.append(String.format("%d ", index.intValue()));
out.append(J9UTF8Helper.stringValue(J9ROMStringRefPointer.cast(info).utf8Data()));
out.append(nl);
pc = pc.add(2);
break;
case JBnewarray:
index = new UDATA(_GETNEXT_U8());
switch(index.intValue()) {
case /* T_BOOLEAN */
4:
out.append("boolean\n");
break;
case /* T_CHAR */
5:
out.append("char\n");
break;
case /* T_FLOAT */
6:
out.append("float\n");
break;
case /* T_DOUBLE */
7:
out.append("double\n");
break;
case /* T_BYTE */
8:
out.append("byte\n");
break;
case /* T_SHORT */
9:
out.append("short\n");
break;
case /* T_INT */
10:
out.append("int\n");
break;
case /* T_LONG */
11:
out.append("long\n");
break;
default:
out.append(String.format("(unknown type %d)\n", index.intValue()));
break;
}
pc = pc.add(1);
break;
case JBmultianewarray:
index = new UDATA(_GETNEXT_U16());
info = constantPool.add(index);
out.append(String.format("%d ", index.intValue()));
index = new UDATA(_GETNEXT_U8());
out.append(String.format("dims %d ", index.intValue()));
/* dump name */
out.append(J9UTF8Helper.stringValue(J9ROMStringRefPointer.cast(info).utf8Data()));
out.append(nl);
pc = pc.add(3);
break;
case JBgotow:
index = new UDATA(_GETNEXT_U32());
pc = pc.add(4);
if (OPCODE_RELATIVE_BRANCHES != 0) {
target = start.add(index);
} else {
target = pc.add(index);
}
out.append(String.format("%d\n", target.intValue()));
break;
default:
out.append(nl);
break;
}
}
return new IDATA(BCT_ERR_NO_ERROR);
}
Aggregations