Search in sources :

Example 11 with JavaThread

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;
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) JavaThread(com.ibm.dtfj.java.JavaThread) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) ImageThread(com.ibm.dtfj.image.ImageThread) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 12 with JavaThread

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;
        }
    }
}
Also used : JavaThread(com.ibm.dtfj.java.JavaThread) LinkedList(java.util.LinkedList) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 13 with JavaThread

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;
}
Also used : BuilderFailureException(com.ibm.dtfj.javacore.builder.BuilderFailureException) IAttributeValueMap(com.ibm.dtfj.javacore.parser.j9.IAttributeValueMap) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) ImageSection(com.ibm.dtfj.image.ImageSection) ImageThread(com.ibm.dtfj.image.ImageThread) Properties(java.util.Properties)

Example 14 with 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;
}
Also used : J9ThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer) OMR_VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.OMR_VMThreadPointer) JavaThread(com.ibm.dtfj.java.JavaThread)

Example 15 with 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);
            }
        }
    }
}
Also used : JavaThread(com.ibm.dtfj.java.JavaThread) JavaStackFrame(com.ibm.dtfj.java.JavaStackFrame) CorruptData(com.ibm.dtfj.image.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) LinkedList(java.util.LinkedList)

Aggregations

JavaThread (com.ibm.dtfj.java.JavaThread)22 Iterator (java.util.Iterator)14 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)13 JavaObject (com.ibm.dtfj.java.JavaObject)13 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)9 CorruptData (com.ibm.dtfj.image.CorruptData)5 ImageThread (com.ibm.dtfj.image.ImageThread)5 JavaMonitor (com.ibm.dtfj.java.JavaMonitor)5 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)4 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)4 LinkedList (java.util.LinkedList)4 StateToString (com.ibm.jvm.dtfjview.commands.helpers.StateToString)3 ImageSection (com.ibm.dtfj.image.ImageSection)2 JavaClass (com.ibm.dtfj.java.JavaClass)2 JavaStackFrame (com.ibm.dtfj.java.JavaStackFrame)2 IAttributeValueMap (com.ibm.dtfj.javacore.parser.j9.IAttributeValueMap)2 MonitorState (com.ibm.jvm.dtfjview.commands.helpers.MonitorState)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2