use of com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer in project openj9 by eclipse.
the class DumpRomMethodCommand method run.
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
try {
Iterable<J9ROMClassAndMethod> methodIterator = null;
if (args.length < 1) {
printUsage(out);
return;
}
String selector = args[0];
if (selector.equals("-a")) {
if (args.length != 2) {
printUsage(out);
return;
}
/* decimal or hexadecimal */
long methodAddress = CommandUtils.parsePointer(args[1], J9BuildFlags.env_data64);
J9MethodPointer ramMethod = J9MethodPointer.cast(methodAddress);
if (ramMethod.isNull()) {
CommandUtils.dbgPrint(out, "bad ram method addr\n");
return;
}
methodIterator = romMethodIteratorFromRamMethod(ramMethod);
} else if (selector.equals("-o")) {
if (args.length != 2) {
printUsage(out);
return;
}
long methodAddress = CommandUtils.parsePointer(args[1], J9BuildFlags.env_data64);
J9ROMMethodPointer romMethod = J9ROMMethodPointer.cast(methodAddress);
if (romMethod.isNull()) {
CommandUtils.dbgPrint(out, "bad rom method addr\n");
return;
}
J9ROMMethodPointer bytecodesStart = romMethod.add(1);
/* bytecodes immediately follow the J9ROMMethod struct */
U8Pointer pc = U8Pointer.cast(bytecodesStart.getAddress());
J9MethodPointer ramMethod = J9JavaVMHelper.getMethodFromPC(J9RASHelper.getVM(DataType.getJ9RASPointer()), pc);
methodIterator = romMethodIteratorFromRamMethod(ramMethod);
} else {
try {
methodIterator = new FilteredROMMethodsIterator(out, context, selector);
} catch (CorruptDataException e) {
throw new DDRInteractiveCommandException(e);
}
}
for (J9ROMClassAndMethod mi : methodIterator) {
out.println(String.format("Class: %s", J9UTF8Helper.stringValue(mi.romClass.className())));
J9BCUtil.j9bcutil_dumpRomMethod(out, mi.romMethod, mi.romClass, dumpFlags, J9BCUtil.BCUtil_DumpAnnotations);
}
} catch (CorruptDataException e) {
throw new DDRInteractiveCommandException(e);
} catch (NullPointerException e) {
e.printStackTrace();
throw e;
}
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer in project openj9 by eclipse.
the class MethodForNameCommand method dbgGetMethodsForName.
int dbgGetMethodsForName(PrintStream out, String pattern) throws CorruptDataException {
int matchCount = 0;
// J9ClassWalkState walkState;
String classNeedle, methodNeedle, sigNeedle;
long classMatchFlags, methodMatchFlags, sigMatchFlags;
String classStart, nameStart, sigStart;
if (pattern.indexOf('.') != -1) {
// skip the .
nameStart = pattern.substring(pattern.indexOf('.') + 1);
classStart = pattern.substring(0, pattern.indexOf('.'));
} else {
classStart = "*";
nameStart = pattern;
}
if (pattern.indexOf('(') != -1) {
sigStart = pattern.substring(pattern.indexOf('('));
} else {
sigStart = "*";
}
StringBuffer needleBuffer = new StringBuffer();
classMatchFlags = WildCard.parseWildcard(classStart, needleBuffer);
classNeedle = needleBuffer.toString();
if (classMatchFlags == -1) {
CommandUtils.dbgError(out, "Invalid wildcards in class name\n");
return 0;
}
needleBuffer = new StringBuffer();
methodMatchFlags = WildCard.parseWildcard(nameStart, needleBuffer);
methodNeedle = needleBuffer.toString();
if (methodMatchFlags == -1) {
CommandUtils.dbgError(out, "Invalid wildcards in method name\n");
return 0;
}
needleBuffer = new StringBuffer();
sigMatchFlags = WildCard.parseWildcard(sigStart, needleBuffer);
sigNeedle = needleBuffer.toString();
if (methodMatchFlags == -1) {
CommandUtils.dbgError(out, "Invalid wildcards in method name\n");
return 0;
}
Hashtable<String, J9ClassPointer> loadedClasses = new Hashtable<String, J9ClassPointer>();
GCClassLoaderIterator classLoaderIterator = GCClassLoaderIterator.from();
while (classLoaderIterator.hasNext()) {
J9ClassLoaderPointer loader = classLoaderIterator.next();
Iterator<J9ClassPointer> classItterator = ClassIterator.fromJ9Classloader(loader);
while (classItterator.hasNext()) {
J9ClassPointer clazz = classItterator.next();
J9ROMClassPointer romClazz = clazz.romClass();
String className = J9UTF8Helper.stringValue(romClazz.className());
if (loadedClasses.containsValue(clazz)) {
continue;
} else {
loadedClasses.put(clazz.toString(), clazz);
}
if (WildCard.wildcardMatch(classMatchFlags, classNeedle, className)) {
J9MethodPointer methodCursor = clazz.ramMethods();
for (long count = romClazz.romMethodCount().longValue(); count > 0; count--, methodCursor = methodCursor.add(1)) {
J9ROMMethodPointer romMethod = J9MethodHelper.romMethod(methodCursor);
J9ROMNameAndSignaturePointer nameAndSignature = romMethod.nameAndSignature();
String nameUTF = J9UTF8Helper.stringValue(nameAndSignature.name());
if (WildCard.wildcardMatch(methodMatchFlags, methodNeedle, nameUTF)) {
String sigUTF = J9UTF8Helper.stringValue(nameAndSignature.signature());
if (WildCard.wildcardMatch(sigMatchFlags, sigNeedle, sigUTF)) {
matchCount++;
CommandUtils.dbgPrint(out, String.format("!j9method %s --> %s.%s%s\n", methodCursor.getHexAddress(), className, nameUTF, sigUTF));
}
}
}
}
}
}
return matchCount;
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer in project openj9 by eclipse.
the class VmCheckCommand method findMethodInVTable.
private boolean findMethodInVTable(J9MethodPointer method, J9ClassPointer classPointer) throws CorruptDataException {
UDATAPointer vTable = J9ClassHelper.vTable(classPointer);
long vTableSize = vTable.at(0).longValue();
/* skip magic first entry */
for (long vTableIndex = 2; vTableIndex <= vTableSize + 1; vTableIndex++) {
// System.out.printf("%d COMP 0x%s vs. 0x%s\n", (int)vTableIndex, Long.toHexString(method.getAddress()), Long.toHexString(vTable.at(vTableIndex).longValue()));
if (method.eq(J9MethodPointer.cast(vTable.at(vTableIndex)))) {
return true;
}
}
return false;
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer in project openj9 by eclipse.
the class StackmapCommand method run.
/**
* Java representation of j9dbgext.c#dbgext_stackmap function.
*
* @param command DDR extension command of stackmap.
* It is supposed to be "stackmap" if this method is being called.
* @param args Arguments passed to !stackmap DDR extension.
* Only one argument is expected since !stackmap expects only the address.
* @param context Current context that DDR is running on.
* @param out Print stream to write the output.
*
* @return void
*/
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
if (args.length != 1) {
printUsage(out);
return;
}
try {
J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
if (null == vm) {
out.println("vm can not be found.");
}
long address = CommandUtils.parsePointer(args[0], J9BuildFlags.env_data64);
U8Pointer pc = U8Pointer.cast(address);
CommandUtils.dbgPrint(out, "Searching for PC=%d in VM=%s...\n", pc.longValue(), vm.getHexAddress());
J9MethodPointer remoteMethod = J9JavaVMHelper.getMethodFromPC(vm, pc);
if (remoteMethod.notNull()) {
int[] stackMap = new int[MAX_STACKSLOTS_COUNT / INT_SIZE_IN_BITS];
int leftMostBitIntMask = 1 << (INT_SIZE_IN_BITS - 1);
CommandUtils.dbgPrint(out, "Found method %s !j9method %s\n", J9MethodHelper.getName(remoteMethod), remoteMethod.getHexAddress());
UDATA offsetPC = new UDATA(pc.sub(U8Pointer.cast(remoteMethod.bytecodes())));
CommandUtils.dbgPrint(out, "Relative PC = %d\n", offsetPC.longValue());
J9ClassPointer localClass = J9_CLASS_FROM_CP(remoteMethod.constantPool());
long methodIndex = new UDATA(remoteMethod.sub(localClass.ramMethods())).longValue();
CommandUtils.dbgPrint(out, "Method index is %d\n", methodIndex);
J9ROMMethodPointer localROMMethod = J9ROMCLASS_ROMMETHODS(localClass.romClass());
while (methodIndex != 0) {
localROMMethod = ROMHelp.nextROMMethod(localROMMethod);
--methodIndex;
}
CommandUtils.dbgPrint(out, "Using ROM method %s\n", localROMMethod.getHexAddress());
/*
* This call will return the depth of the stack or errorcode in case of a failure.
*/
int errorCode = StackMap.j9stackmap_StackBitsForPC(offsetPC, localClass.romClass(), localROMMethod, null, 0);
if (0 > errorCode) {
CommandUtils.dbgPrint(out, "Stack map failed, error code = %d\n", errorCode);
} else {
int stackMapIndex = 0;
if (0 != errorCode) {
/* This call to j9stackmap_StackBitsForPC will fill the stackMap */
errorCode = StackMap.j9stackmap_StackBitsForPC(offsetPC, localClass.romClass(), localROMMethod, stackMap, errorCode);
int currentDescription = stackMap[stackMapIndex];
int descriptionInt = 0;
CommandUtils.dbgPrint(out, "Stack map (%d slots mapped): ", errorCode);
long bitsRemaining = errorCode % INT_SIZE_IN_BITS;
if (bitsRemaining != 0) {
descriptionInt = currentDescription << (INT_SIZE_IN_BITS - bitsRemaining);
currentDescription++;
}
while (errorCode != 0) {
if (bitsRemaining == 0) {
descriptionInt = currentDescription;
currentDescription = stackMap[++stackMapIndex];
bitsRemaining = INT_SIZE_IN_BITS;
}
CommandUtils.dbgPrint(out, "%d", (descriptionInt & (leftMostBitIntMask)) != 0 ? 1 : 0);
descriptionInt = descriptionInt << 1;
--bitsRemaining;
--errorCode;
}
CommandUtils.dbgPrint(out, "\n");
} else {
CommandUtils.dbgPrint(out, "Stack is empty\n");
}
}
} else {
CommandUtils.dbgPrint(out, "Not found\n");
}
} catch (CorruptDataException e) {
}
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer in project openj9 by eclipse.
the class J9MethodFieldFormatter method postFormat.
/* (non-Javadoc)
* @see com.ibm.j9ddr.tools.ddrinteractive.IFieldFormatter#postFormat(java.lang.String, java.lang.String, int, long, java.io.PrintStream, com.ibm.j9ddr.tools.ddrinteractive.Context, com.ibm.j9ddr.tools.ddrinteractive.IStructureFormatter)
*/
@Override
public FormatWalkResult postFormat(String name, String type, String declaredType, int typeCode, long address, PrintStream out, Context context, IStructureFormatter structureFormatter) throws CorruptDataException {
if (typeCode == TYPE_STRUCTURE_POINTER && StructureCommandUtil.typeToCommand(type).equals("!j9method")) {
PointerPointer slotPtr = PointerPointer.cast(address);
J9MethodPointer method = J9MethodPointer.cast(slotPtr.at(0));
if (method.isNull()) {
return FormatWalkResult.KEEP_WALKING;
}
out.print(" // ");
J9ROMMethodPointer j9romMethod = J9MethodHelper.romMethod(method);
J9ClassPointer clazz = ConstantPoolHelpers.J9_CLASS_FROM_METHOD(method);
out.print(J9ClassHelper.getName(clazz));
out.print(".");
out.print(J9ROMMethodHelper.getName(j9romMethod));
out.print(J9ROMMethodHelper.getSignature(j9romMethod));
}
return FormatWalkResult.KEEP_WALKING;
}
Aggregations