use of com.ibm.dtfj.java.JavaThread in project openj9 by eclipse.
the class NodeList method toString.
// Print this list of monitor nodes (ie the owning threads and there object addresses)
public String toString() {
String retval = "";
MonitorNode currNode = tail;
MonitorNode lastNode = null;
boolean firstTime = true;
boolean done = false;
do {
String name = "";
String objAddr = "";
JavaObject object = null;
JavaThread owner = null;
try {
owner = currNode.getOwner();
name = owner.getName();
ImageThread nativeThread = owner.getImageThread();
if (nativeThread != null) {
name = name + " id: " + nativeThread.getID();
}
} catch (CorruptDataException e) {
name = Exceptions.getCorruptDataExceptionString();
} catch (DataUnavailable e) {
name = Exceptions.getDataUnavailableString();
} catch (MemoryAccessException e) {
name = Exceptions.getMemoryAccessExceptionString();
}
object = currNode.getObject();
if (null == object) {
objAddr = " at : " + Utils.toHex(currNode.getMonitorAddress());
} else {
objAddr = " object : " + Utils.toHex(object.getID().getAddress());
}
String lockName = currNode.getType();
retval += "thread: " + name + " (owns " + lockName + objAddr + ") waiting for =>\n\t ";
lastNode = currNode;
currNode = currNode.waitingOn;
if (head == lastNode) {
if (firstTime && head == tail)
done = false;
else
done = true;
}
firstTime = false;
} while (!done);
// removes the tail of the last entry
retval = retval.substring(0, retval.length() - 18);
return retval;
}
use of com.ibm.dtfj.java.JavaThread in project openj9 by eclipse.
the class JavaStackFrameTest method loadTestObjects.
protected void loadTestObjects(JavaRuntime ddrRuntime, List<Object> ddrObjects, JavaRuntime jextractRuntime, List<Object> jextractObjects) {
List<Object> ddrThreads = new LinkedList<Object>();
List<Object> jextractThreads = new LinkedList<Object>();
fillLists(ddrThreads, ddrRuntime.getThreads(), jextractThreads, jextractRuntime.getThreads(), null);
for (int i = 0; i < ddrThreads.size(); i++) {
JavaThread ddrThread = (JavaThread) ddrThreads.get(i);
JavaThread jextractThread = (JavaThread) jextractThreads.get(i);
try {
fillLists(ddrObjects, ddrThread.getStackFrames(), jextractObjects, jextractThread.getStackFrames(), null);
} catch (AssertionError e) {
System.err.println("Assertion failed in fillLists.");
try {
System.err.println("Processing DDRThread: " + Long.toHexString(ddrThread.getJNIEnv().getAddress()) + " and JExtract/DTFJ thread " + Long.toHexString(jextractThread.getJNIEnv().getAddress()));
System.err.println("DDR trace is:");
printStackTrace(ddrThread);
System.err.println("J9JExtractTrace is:");
printStackTrace(jextractThread);
} catch (Exception e2) {
e.printStackTrace();
}
throw e;
}
}
}
use of com.ibm.dtfj.java.JavaThread in project openj9 by eclipse.
the class ThreadSectionParser method addThread.
/**
* @param javaThreadResults
* @param nativeStacks list of attributes of the native stacks
* @param currentFileLineNumber
* @return java thread
* @throws ParserException if error handler decides to throw it due java thread or image thread error creation
*/
private JavaThread addThread(IAttributeValueMap javaThreadResults, IAttributeValueMap nativeResults, List nativeStacks, IAttributeValueMap blockerInfo, IAttributeValueMap cpuTimes, int currentFileLineNumber) throws ParserException {
long imageThreadID = (nativeResults != null) ? nativeResults.getLongValue(NATIVE_THREAD_ID) : javaThreadResults.getLongValue(NATIVE_THREAD_ID);
long tid = javaThreadResults.getLongValue(VM_THREAD_ID);
if (imageThreadID == IBuilderData.NOT_AVAILABLE) {
imageThreadID = tid;
}
ImageThread imageThread = null;
JavaThread javaThread = null;
// CMVC 158108 : fixed so that if the thread name is not present then it is not subsequently parsed
String threadName = javaThreadResults.getTokenValue(JAVA_THREAD_NAME);
if (threadName != null && threadName.length() >= 2) {
// remove quotes
threadName = threadName.substring(1, threadName.length() - 1);
}
String threadState = javaThreadResults.getTokenValue(JAVA_STATE);
int threadPriority = javaThreadResults.getIntValue(VM_THREAD_PRIORITY);
long abstractThreadID = javaThreadResults.getLongValue(ABSTRACT_THREAD_ID);
Properties properties = new Properties();
if (abstractThreadID != IBuilderData.NOT_AVAILABLE) {
addAsProperty(properties, ABSTRACT_THREAD_ID, "0x" + Long.toHexString(abstractThreadID));
}
if (nativeResults != null) {
addAsProperty(properties, NATIVE_THREAD_PRIORITY, nativeResults.getTokenValue(NATIVE_THREAD_PRIORITY));
addAsProperty(properties, NATIVE_THREAD_POLICY, nativeResults.getTokenValue(NATIVE_THREAD_POLICY));
addAsProperty(properties, SCOPE, nativeResults.getTokenValue(SCOPE));
addAsProperty(properties, VM_STATE, nativeResults.getTokenValue(VM_STATE));
addAsProperty(properties, VM_FLAGS, nativeResults.getTokenValue(VM_FLAGS));
}
if (cpuTimes != null) {
addAsProperty(properties, CPU_TIME_TOTAL, cpuTimes.getTokenValue(CPU_TIME_TOTAL));
addAsProperty(properties, CPU_TIME_USER, cpuTimes.getTokenValue(CPU_TIME_USER));
addAsProperty(properties, CPU_TIME_SYSTEM, cpuTimes.getTokenValue(CPU_TIME_SYSTEM));
}
String blockerObjectClassName = null;
// CMVC 180977 : the parser expects missing data to be represented by a -ve number, so change the default address from 0 to IBuilderData.NOT_AVAILABLE (currently -1)
// this parser check will break on a sufficiently large 64bit number, but fixing that is beyond the scope of this defect.
long blockerObjectAddress = IBuilderData.NOT_AVAILABLE;
if (blockerInfo != null) {
blockerObjectClassName = blockerInfo.getTokenValue(BLOCKER_OBJECT_FULL_JAVA_NAME);
blockerObjectAddress = blockerInfo.getLongValue(BLOCKER_OBJECT_ADDRESS);
}
long javaObjID = javaThreadResults.getLongValue(JAVA_THREAD_OBJ);
if (javaObjID == IBuilderData.NOT_AVAILABLE && nativeResults == null) {
String vmthread = javaThreadResults.getTokenValue(VM_THREAD_ID);
// Java 5.0 vmthreads tend to start with 0x0, and are not Java objects
if (vmthread != null && !vmthread.startsWith("0x0"))
javaObjID = tid;
}
try {
imageThread = fImageProcessBuilder.addImageThread(imageThreadID, abstractThreadID, properties);
if (threadName != null || tid != IBuilderData.NOT_AVAILABLE) {
javaThread = fRuntimeBuilder.addJavaThread(imageThread, threadName, tid, abstractThreadID, javaObjID, IBuilderData.NOT_AVAILABLE, threadState, threadPriority, blockerObjectAddress, blockerObjectClassName);
}
} catch (BuilderFailureException e) {
handleErrorAtLineNumber(currentFileLineNumber, "Failed to add thread: " + threadName + " " + imageThreadID, e);
}
for (Iterator it = nativeStacks.iterator(); it.hasNext(); ) {
IAttributeValueMap stackInfo = (IAttributeValueMap) it.next();
long from = stackInfo.getLongValue(NATIVE_STACK_FROM);
long to = stackInfo.getLongValue(NATIVE_STACK_TO);
long size = stackInfo.getLongValue(NATIVE_STACK_SIZE);
if (from != IBuilderData.NOT_AVAILABLE && size != IBuilderData.NOT_AVAILABLE) {
ImageSection section = fImageAddressSpaceBuilder.addImageSection("Native stack section", from, size);
fImageProcessBuilder.addImageStackSection(imageThread, section);
}
}
return javaThread;
}
use of com.ibm.dtfj.java.JavaThread in project openj9 by eclipse.
the class DTFJJavaSystemMonitor method getOwner.
public JavaThread getOwner() throws CorruptDataException {
JavaThread javaThread = null;
try {
J9ThreadPointer owner = monitor.owner();
if (!owner.isNull()) {
int vmThreadKey = DTFJContext.getVm().omrVM()._vmThreadKey().intValue() - 1;
OMR_VMThreadPointer omrVmThread = OMR_VMThreadPointer.cast(owner.tlsEA().at(vmThreadKey));
if (!omrVmThread.isNull()) {
javaThread = new DTFJJavaThread(J9VMThreadPointer.cast(omrVmThread._language_vmthread()));
}
}
} catch (Throwable t) {
throw J9DDRDTFJUtils.handleAsCorruptDataException(DTFJContext.getProcess(), t);
}
return javaThread;
}
use of com.ibm.dtfj.java.JavaThread in project openj9 by eclipse.
the class JavaLocationTest method loadTestObjects.
protected void loadTestObjects(JavaRuntime ddrRuntime, List<Object> ddrObjects, JavaRuntime jextractRuntime, List<Object> jextractObjects) {
List<Object> ddrThreads = new LinkedList<Object>();
List<Object> jextractThreads = new LinkedList<Object>();
fillLists(ddrThreads, ddrRuntime.getThreads(), jextractThreads, jextractRuntime.getThreads(), null);
for (int i = 0; i < ddrThreads.size(); i++) {
JavaThread ddrThread = (JavaThread) ddrThreads.get(i);
JavaThread jextractThread = (JavaThread) jextractThreads.get(i);
Iterator<?> ddrStackFrameIt = ddrThread.getStackFrames();
Iterator<?> jextractStackFrameIt = jextractThread.getStackFrames();
while (ddrStackFrameIt.hasNext()) {
assertTrue(jextractStackFrameIt.hasNext());
Object ddrStackFrameObj = ddrStackFrameIt.next();
Object jextractStackFrameObj = jextractStackFrameIt.next();
if ((ddrStackFrameObj instanceof CorruptData) ^ (jextractStackFrameObj instanceof CorruptData)) {
fail("Different CorruptData from DDR & jextract. DDR returned : " + ddrStackFrameObj + ", jextract returned " + jextractStackFrameObj);
}
if (ddrStackFrameObj instanceof CorruptData) {
continue;
}
JavaStackFrame ddrStackFrame = (JavaStackFrame) ddrStackFrameObj;
JavaStackFrame jextractStackFrame = (JavaStackFrame) jextractStackFrameObj;
boolean ddrFaulted = false;
boolean jextractFaulted = false;
try {
ddrObjects.add(ddrStackFrame.getLocation());
} catch (CorruptDataException e) {
e.printStackTrace();
ddrFaulted = true;
}
try {
jextractObjects.add(jextractStackFrame.getLocation());
} catch (CorruptDataException e) {
e.printStackTrace();
jextractFaulted = true;
}
if (ddrFaulted ^ jextractFaulted) {
fail("Getting location from stackframe behaved differently on DDR/jextract. DDR faulted: " + ddrFaulted + ", DDR object: " + ddrStackFrame + ", jextract faulted: " + jextractFaulted + " jextract object: " + jextractStackFrame);
}
}
}
}
Aggregations