use of com.ibm.j9ddr.vm29.j9.stackwalker.WalkState 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.j9.stackwalker.WalkState in project openj9 by eclipse.
the class CheckVMThreadStacks method check.
@Override
public void check() {
try {
GCVMThreadListIterator vmThreadListIterator = GCVMThreadListIterator.from();
while (vmThreadListIterator.hasNext()) {
J9VMThreadPointer walkThread = vmThreadListIterator.next();
// GC_VMThreadStackSlotIterator::scanSlots(toScanWalkThread, toScanWalkThread, (void *)&localData, checkStackSlotIterator, false, false);
WalkState walkState = new WalkState();
walkState.walkThread = walkThread;
walkState.flags = J9_STACKWALK_ITERATE_O_SLOTS | J9_STACKWALK_DO_NOT_SNIFF_AND_WHACK | J9_STACKWALK_SKIP_INLINES;
walkState.callBacks = new BaseStackWalkerCallbacks() {
public void objectSlotWalkFunction(J9VMThreadPointer walkThread, WalkState walkState, PointerPointer objectSlot, VoidPointer stackAddress) {
_engine.checkSlotStack(objectSlot, walkThread, stackAddress);
}
};
StackWalker.walkStackFrames(walkState);
}
} catch (CorruptDataException e) {
// TODO: handle exception
}
}
use of com.ibm.j9ddr.vm29.j9.stackwalker.WalkState in project openj9 by eclipse.
the class CheckVMThreadStacks method print.
@Override
public void print() {
try {
GCVMThreadListIterator vmThreadListIterator = GCVMThreadListIterator.from();
final ScanFormatter formatter = new ScanFormatter(this, "thread stacks");
while (vmThreadListIterator.hasNext()) {
J9VMThreadPointer walkThread = vmThreadListIterator.next();
formatter.section("thread slots", walkThread);
WalkState walkState = new WalkState();
walkState.walkThread = walkThread;
walkState.flags = J9_STACKWALK_ITERATE_O_SLOTS | J9_STACKWALK_DO_NOT_SNIFF_AND_WHACK | J9_STACKWALK_SKIP_INLINES;
walkState.callBacks = new BaseStackWalkerCallbacks() {
public void objectSlotWalkFunction(J9VMThreadPointer walkThread, WalkState walkState, PointerPointer objectSlot, VoidPointer stackAddress) {
try {
formatter.entry(objectSlot.at(0));
} catch (CorruptDataException e) {
}
}
};
StackWalker.walkStackFrames(walkState);
formatter.endSection();
formatter.section("thread stack", walkThread);
dumpStackTrace(walkThread);
formatter.endSection();
}
formatter.end("thread stacks");
} catch (CorruptDataException e) {
// TODO: handle exception
}
}
use of com.ibm.j9ddr.vm29.j9.stackwalker.WalkState in project openj9 by eclipse.
the class DTFJJavaThread method walkStack.
// this function is the entry point for the stack walking and provides the top level catch for Exceptions and NoSuchFieldErrors
private void walkStack() {
frames = new LinkedList<Object>();
WalkState walkState = new WalkState();
walkState.walkThread = thread;
walkState.flags = J9_STACKWALK_VISIBLE_ONLY | J9_STACKWALK_INCLUDE_NATIVES | J9_STACKWALK_ITERATE_FRAMES | J9_STACKWALK_RECORD_BYTECODE_PC_OFFSET | J9_STACKWALK_ITERATE_O_SLOTS;
walkState.callBacks = new StackWalkerCallbacks();
register((IEventListener) walkState.callBacks);
StackWalkResult result = StackWalkResult.STACK_CORRUPT;
try {
result = StackWalker.walkStackFrames(walkState);
} catch (Throwable t) {
J9DDRDTFJUtils.handleAsCorruptDataException(DTFJContext.getProcess(), t);
result = StackWalkResult.STACK_CORRUPT;
}
unregister((IEventListener) walkState.callBacks);
if (result != StackWalkResult.NONE) {
frames.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), "Bad return from stack walker walking thread 0x" + Long.toHexString(walkState.walkThread.getAddress()) + ". Some stack frames may be missing. Final state = " + result));
}
}
use of com.ibm.j9ddr.vm29.j9.stackwalker.WalkState in project openj9 by eclipse.
the class JitstackCommand method run.
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
if (!J9BuildFlags.interp_nativeSupport) {
CommandUtils.dbgPrint(out, "No JIT in this build\n");
return;
}
try {
String[] realArgs = null;
if (args.length != 0) {
realArgs = args[0].split(",");
}
if (args.length == 0 || !((realArgs.length == 3) || (realArgs.length == 4))) {
CommandUtils.dbgPrint(out, "Usage:\n");
CommandUtils.dbgPrint(out, "\t!jitstack thread,sp,pc\n");
CommandUtils.dbgPrint(out, "\t!jitstack thread,sp,pc,els\n");
CommandUtils.dbgPrint(out, "\tUse !jitstackslots instead of !jitstack to see slot values\n");
return;
}
long address = CommandUtils.parsePointer(realArgs[0], J9BuildFlags.env_data64);
J9VMThreadPointer thread = J9VMThreadPointer.cast(address);
StackWalkerUtils.enableVerboseLogging(2, out);
WalkState walkState = new WalkState();
address = CommandUtils.parsePointer(realArgs[1], J9BuildFlags.env_data64);
UDATAPointer sp = UDATAPointer.cast(address);
address = CommandUtils.parsePointer(realArgs[2], J9BuildFlags.env_data64);
U8Pointer pc = U8Pointer.cast(address);
UDATAPointer arg0EA = UDATAPointer.NULL;
J9MethodPointer literals = J9MethodPointer.NULL;
J9VMEntryLocalStoragePointer entryLocalStorage = J9VMEntryLocalStoragePointer.NULL;
if (realArgs.length == 4) {
address = CommandUtils.parsePointer(realArgs[3], J9BuildFlags.env_data64);
entryLocalStorage = J9VMEntryLocalStoragePointer.cast(address);
} else {
entryLocalStorage = thread.entryLocalStorage();
}
walkState.flags = J9_STACKWALK_RECORD_BYTECODE_PC_OFFSET;
walkState.flags |= J9_STACKWALK_START_AT_JIT_FRAME;
if (command.equalsIgnoreCase("!jitstackslots")) {
walkState.flags |= J9_STACKWALK_ITERATE_O_SLOTS;
// 100 is highly arbitrary but basically means "print everything".
// It is used in jextract where the message levels have been copied
// from to begin with, so it should mean we get the same output.
StackWalkerUtils.enableVerboseLogging(100, out);
}
walkState.walkThread = thread;
walkState.callBacks = new BaseStackWalkerCallbacks();
walkState.frameFlags = new UDATA(0);
StackWalkResult result = StackWalker.walkStackFrames(walkState, sp, arg0EA, pc, literals, entryLocalStorage);
if (result != StackWalkResult.NONE) {
out.println("Stack walk result: " + result);
}
StackWalkerUtils.disableVerboseLogging();
out.flush();
} catch (CorruptDataException e) {
throw new DDRInteractiveCommandException(e);
}
}
Aggregations