use of com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer in project openj9 by eclipse.
the class DeadlockDetector method findDeadlocks.
/**
* @param out
* @throws DDRInteractiveCommandException
*/
public static void findDeadlocks(PrintStream out) throws DDRInteractiveCommandException {
// Based on JavaCoreDumpWriter::writeDeadLocks()
// Modified to work for both J9VMThreads and J9Threads.
HashMap<Integer, NativeDeadlockGraphNode> map = new HashMap<Integer, NativeDeadlockGraphNode>();
try {
J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
HashMap<J9ObjectPointer, Object> objectMonitorsMap = DeadlockUtils.readObjectMonitors(vm);
J9ThreadLibraryPointer lib = vm.mainThread().osThread().library();
J9PoolPointer pool = lib.thread_pool();
Pool<J9ThreadPointer> threadPool = Pool.fromJ9Pool(pool, J9ThreadPointer.class);
SlotIterator<J9ThreadPointer> poolIterator = threadPool.iterator();
J9ThreadPointer osThreadPtr = null;
while (poolIterator.hasNext()) {
osThreadPtr = poolIterator.next();
DeadlockUtils.findThreadCycle(osThreadPtr, map, objectMonitorsMap);
// Is there an associated J9VMThread?
J9VMThreadPointer vmThread = J9ThreadHelper.getVMThread(osThreadPtr);
if ((null != vmThread) && (vmThread.notNull()) && vmThread.publicFlags().allBitsIn(J9Consts.J9_PUBLIC_FLAGS_HALT_THREAD_INSPECTION)) {
break;
}
}
// Identifier for each (independent) cycle.
int cycle = 0;
Iterator<Map.Entry<Integer, NativeDeadlockGraphNode>> iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
NativeDeadlockGraphNode node = iterator.next().getValue();
cycle++;
while (null != node) {
if (node.cycle > 0) {
// it means we've looped around!
if (node.cycle == cycle) {
// Output header for each deadlock:
out.println("Deadlock Detected !!!");
out.println("---------------------");
out.println();
NativeDeadlockGraphNode head = node;
boolean isCycleRoot = true;
do {
DeadlockUtils.writeDeadlockNode(node, isCycleRoot, objectMonitorsMap, out);
node = node.next;
isCycleRoot = false;
} while (node != head);
out.println(node.toString());
}
// Skip already visited nodes
break;
} else {
node.cycle = cycle;
}
node = node.next;
}
}
} catch (CorruptDataException e) {
throw new DDRInteractiveCommandException(e);
}
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer in project openj9 by eclipse.
the class CheckVMThreadStacks method dumpStackTrace.
/* TODO : this is an implementation of the internal VM function dumpStackTrace
* and really should be somewhere global and public */
private void dumpStackTrace(J9VMThreadPointer walkThread) {
WalkState walkState = new WalkState();
walkState.walkThread = walkThread;
walkState.flags = J9_STACKWALK_VISIBLE_ONLY | J9_STACKWALK_INCLUDE_NATIVES | J9_STACKWALK_ITERATE_FRAMES;
walkState.callBacks = new BaseStackWalkerCallbacks() {
public FrameCallbackResult frameWalkFunction(J9VMThreadPointer walkThread, WalkState walkState) {
String className = "(unknown class)";
if (walkState.constantPool.notNull()) {
try {
className = J9ClassHelper.getName(walkState.constantPool.ramClass());
} catch (CorruptDataException e) {
// TODO Auto-generated catch block
}
}
if (walkState.method.isNull()) {
getReporter().println(String.format("0x%08X %s (unknown method)", walkState.pc.getAddress(), className));
} else {
if (walkState.jitInfo.isNull()) {
boolean isNative = false;
U8Pointer bytecodes = U8Pointer.NULL;
String name = "(corrupt)";
String sig = "(corrupt)";
try {
J9ROMMethodPointer romMethod = J9MethodHelper.romMethod(walkState.method);
isNative = romMethod.modifiers().allBitsIn(J9_JAVA_NATIVE);
if (!isNative) {
bytecodes = J9ROMMethodHelper.bytecodes(romMethod);
}
name = J9ROMMethodHelper.getName(romMethod);
sig = J9ROMMethodHelper.getSignature(romMethod);
} catch (CorruptDataException e) {
// This should never happen
}
if (isNative) {
getReporter().println(String.format(" NATIVE %s.%s%s", className, name, sig));
} else {
getReporter().println(String.format(" %08X %s.%s%s", walkState.pc.sub(bytecodes).longValue(), className, name, sig));
}
} else {
boolean isInlined = walkState.inlineDepth != 0;
U8Pointer jitPC = walkState.pc;
String name = "(corrupt)";
String sig = "(corrupt)";
try {
J9ROMMethodPointer romMethod = J9MethodHelper.romMethod(walkState.method);
name = J9UTF8Helper.stringValue(romMethod.nameAndSignature().name());
sig = J9UTF8Helper.stringValue(romMethod.nameAndSignature().signature());
if (!isInlined) {
jitPC = U8Pointer.cast(jitPC.sub(U8Pointer.cast(walkState.method.extra())).longValue());
}
} catch (CorruptDataException e) {
// This should never happen
}
if (isInlined) {
getReporter().println(String.format(" INLINED %s.%s%s (@%s)", className, name, sig, formatPointer(walkState.pc)));
} else {
getReporter().println(String.format(" %08X %s.%s%s (@%s)", jitPC.getAddress(), className, name, sig, formatPointer(walkState.pc)));
}
}
}
return FrameCallbackResult.KEEP_ITERATING;
}
};
StackWalker.walkStackFrames(walkState);
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer in project openj9 by eclipse.
the class CheckVMThreads method print.
@Override
public void print() {
try {
GCVMThreadListIterator vmThreadListIterator = GCVMThreadListIterator.from();
ScanFormatter formatter = new ScanFormatter(this, "VMThread Slots");
while (vmThreadListIterator.hasNext()) {
J9VMThreadPointer walkThread = vmThreadListIterator.next();
formatter.section("thread", walkThread);
GCVMThreadIterator vmthreadIterator = GCVMThreadIterator.fromJ9VMThread(walkThread);
while (vmthreadIterator.hasNext()) {
formatter.entry(vmthreadIterator.next());
}
formatter.endSection();
}
formatter.end("VMThread Slots");
} catch (CorruptDataException e) {
// TODO: handle exception
}
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer in project openj9 by eclipse.
the class DTFJJavaRuntime method getThreads.
@SuppressWarnings("rawtypes")
public Iterator getThreads() {
GCVMThreadListIterator threadIterator;
try {
threadIterator = GCVMThreadListIterator.from();
} catch (Throwable t) {
CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
return corruptIterator(cd);
}
List<Object> toIterate = new LinkedList<Object>();
AddCorruptionToListListener listener = new AddCorruptionToListListener(toIterate);
register(listener);
try {
while (threadIterator.hasNext() && !listener.fatalCorruption()) {
J9VMThreadPointer next = threadIterator.next();
if (next != null) {
toIterate.add(new DTFJJavaThread(next));
}
}
} catch (Throwable t) {
CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
toIterate.add(cd);
}
unregister(listener);
return toIterate.iterator();
}
Aggregations