use of com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer in project openj9 by eclipse.
the class WhatIsCommand method runWhatIs.
private void runWhatIs(String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
if (args.length == 0) {
badOrMissingSearchValue(out);
return;
}
long address = CommandUtils.parsePointer(args[0], J9BuildFlags.env_data64);
UDATA localSearchValue = new UDATA(address);
if (localSearchValue.eq(0)) {
badOrMissingSearchValue(out);
return;
}
if (searchValue == null || !searchValue.eq(localSearchValue)) {
searchValue = localSearchValue;
} else {
out.println("Skip count now " + (++skipCount) + ". Run !whatis 0 to reset it.");
}
resetFieldData();
long startTime = System.currentTimeMillis();
// Walk from the VM
J9JavaVMPointer vm = null;
try {
vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
} catch (CorruptDataException e) {
throw new DDRInteractiveCommandException("Couldn't get VM", e);
}
boolean found = walkStructuresFrom(vm);
// Walk from each VM thread
if (!found) {
try {
J9VMThreadPointer mainThread = vm.mainThread();
List<J9VMThreadPointer> threads = new LinkedList<J9VMThreadPointer>();
if (mainThread.notNull()) {
J9VMThreadPointer threadCursor = vm.mainThread();
do {
threads.add(threadCursor);
threadCursor = threadCursor.linkNext();
} while (!threadCursor.eq(mainThread) && !found);
/* Walk the thread list backwards so we will find the match next to the closest thread (prevents walkStructures from doing anything useful with the linkNext list) */
Collections.reverse(threads);
for (J9VMThreadPointer thisThread : threads) {
found = walkStructuresFrom(thisThread);
if (found) {
break;
}
}
}
} catch (CorruptDataException e) {
out.println("CDE walking thread list.");
e.printStackTrace(out);
}
}
// Walk from each class
if (!found) {
try {
GCClassLoaderIterator it = GCClassLoaderIterator.from();
OUTER: while (it.hasNext()) {
J9ClassLoaderPointer loader = it.next();
Iterator<J9ClassPointer> classIt = ClassIterator.fromJ9Classloader(loader);
while (classIt.hasNext()) {
J9ClassPointer clazz = classIt.next();
found = walkStructuresFrom(clazz);
if (found) {
break OUTER;
}
}
}
} catch (CorruptDataException e) {
out.println("CDE walking classes.");
e.printStackTrace(out);
}
}
long stopTime = System.currentTimeMillis();
if (found) {
out.println("Match found");
} else {
out.println("No match found");
if (closestAboveStack != null) {
out.print("Closest above was: ");
closestAboveStack.dump(out);
out.print(" at " + closestAbove.getHexValue());
out.println();
} else {
out.println("No values found above search value");
}
if (closestBelowStack != null) {
out.print("Closest below was: ");
closestBelowStack.dump(out);
out.print(" at " + closestBelow.getHexValue());
out.println();
} else {
out.println("No values found below search value");
}
if (shortestHammingDistanceStack != null) {
out.print("Value with shortest hamming distance (fewest single-bit changes required) was: ");
shortestHammingDistanceStack.dump(out);
out.print(" at " + shortestHammingDistance.getHexValue());
out.print(". Hamming distance = " + hammingDistance);
out.println();
}
/* Reset search value - so if someone reruns the same (unsuccessful) search again it won't set skipCount to 1 */
searchValue = null;
}
out.println("Searched " + fieldCount + " fields to a depth of " + maxDepth + " in " + (stopTime - startTime) + " ms");
resetFieldData();
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer in project openj9 by eclipse.
the class ClassForNameCommand method run.
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
if (args.length == 0) {
printUsage(out);
return;
}
try {
J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
ClassSegmentIterator iterator = new ClassSegmentIterator(vm.classMemorySegments());
int hitCount = 0;
String searchClassName = args[0];
PatternString pattern = new PatternString(searchClassName);
out.println(String.format("Searching for classes named '%1$s' in VM=%2$s", searchClassName, Long.toHexString(vm.getAddress())));
while (iterator.hasNext()) {
J9ClassPointer classPointer = (J9ClassPointer) iterator.next();
String javaName = J9ClassHelper.getJavaName(classPointer);
if (pattern.isMatch(javaName)) {
hitCount++;
String hexString = classPointer.getHexAddress();
out.println(String.format("!j9class %1$s named %2$s", hexString, javaName));
}
}
out.println(String.format("Found %1$d class(es) named %2$s", hitCount, searchClassName));
} catch (CorruptDataException e) {
throw new DDRInteractiveCommandException(e);
}
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer in project openj9 by eclipse.
the class HashCodeCommand method run.
public void run(String command, String[] args, Context context, final PrintStream out) throws DDRInteractiveCommandException {
if (args.length != 1) {
throw new DDRInteractiveCommandException("This debug extension needs a single address argument: !hashcode <object addr>");
}
long address = CommandUtils.parsePointer(args[0], J9BuildFlags.env_data64);
final J9ObjectPointer objectPointer = J9ObjectPointer.cast(address);
try {
J9ClassPointer clazz = J9ObjectHelper.clazz(objectPointer);
if (!J9ClassHelper.hasValidEyeCatcher(clazz)) {
throw new DDRInteractiveCommandException("object class is not valid (eyecatcher is not 0x99669966)");
}
} catch (CorruptDataException cde) {
throw new DDRInteractiveCommandException("memory fault de-referencing address argument", cde);
}
try {
out.println(ObjectModel.getObjectHashCode(objectPointer).getHexValue());
} catch (CorruptDataException cde) {
throw new DDRInteractiveCommandException("error calculating hashcode", cde);
}
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer in project openj9 by eclipse.
the class DumpRamClassLinearCommand method run.
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
if (args.length == 0)
throw new DDRInteractiveCommandException("This debug extension needs an address argument !dumpramclasslinear <addr>[,n]");
String[] arguments = args[0].split(",");
long addr = Long.decode(arguments[0]);
long nestingThreshold;
if (arguments.length > 1) {
nestingThreshold = Long.decode(arguments[1]);
} else {
nestingThreshold = 1;
}
J9ClassPointer clazz = J9ClassPointer.cast(addr);
try {
out.println(String.format("RAM Class '%s' at %s", J9UTF8Helper.stringValue(clazz.romClass().className()), clazz.getHexAddress()));
ClassWalker classWalker = new RamClassWalker(clazz, context);
new LinearDumper().gatherLayoutInfo(out, classWalker, nestingThreshold);
} catch (CorruptDataException e) {
throw new DDRInteractiveCommandException(e);
}
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer in project openj9 by eclipse.
the class LocalMapCommand method run.
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
try {
if (args.length != 1) {
CommandUtils.dbgPrint(out, "bad or missing PC\n");
return;
}
J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
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 localMethod = J9JavaVMHelper.getMethodFromPC(vm, pc);
if (localMethod.notNull()) {
int[] localMap = new int[65536 / 32];
CommandUtils.dbgPrint(out, "Found method %s !j9method %s\n", J9MethodHelper.getName(localMethod), localMethod.getHexAddress());
UDATA offsetPC = new UDATA(pc.sub(U8Pointer.cast(localMethod.bytecodes())));
CommandUtils.dbgPrint(out, "Relative PC = %d\n", offsetPC.longValue());
J9ClassPointer localClass = J9_CLASS_FROM_CP(localMethod.constantPool());
long methodIndex = new UDATA(localMethod.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());
U16 tempCount = localROMMethod.tempCount();
U8 argCount = localROMMethod.argCount();
long localCount = tempCount.add(argCount).longValue();
if (localCount > 0) {
int errorCode = LocalMap.j9localmap_LocalBitsForPC(localROMMethod, offsetPC, localMap);
if (errorCode != 0) {
CommandUtils.dbgPrint(out, "Local map failed, error code = %d\n", errorCode);
} else {
int currentDescription = localMap[(int) ((localCount + 31) / 32)];
long descriptionLong = 0;
CommandUtils.dbgPrint(out, "Local map (%d slots mapped): local %d --> ", localCount, localCount - 1);
long bitsRemaining = localCount % 32;
if (bitsRemaining != 0) {
descriptionLong = currentDescription << (32 - bitsRemaining);
currentDescription--;
}
while (localCount != 0) {
if (bitsRemaining == 0) {
descriptionLong = currentDescription;
currentDescription--;
bitsRemaining = 32;
}
CommandUtils.dbgPrint(out, "%d", (descriptionLong & (1 << 32)) != 0 ? 1 : 0);
descriptionLong = descriptionLong << 1;
--bitsRemaining;
--localCount;
}
CommandUtils.dbgPrint(out, " <-- local 0\n");
}
} else {
CommandUtils.dbgPrint(out, "No locals to map\n");
}
} else {
CommandUtils.dbgPrint(out, "Not found\n");
}
} catch (CorruptDataException e) {
throw new DDRInteractiveCommandException(e);
}
}
Aggregations