Search in sources :

Example 1 with ImageThread

use of com.ibm.dtfj.image.ImageThread in project openj9 by eclipse.

the class JavaThreadTest method getImageThreadTest.

@Test
public // JEXTRACT: only EVER throws DataUnavailableException with TCK core.  We do better.
void getImageThreadTest() {
    for (int i = 0; i < jextractTestObjects.size(); i++) {
        JavaThread t1 = (JavaThread) jextractTestObjects.get(i);
        ImageThread i1;
        try {
            i1 = (ImageThread) t1.getImageThread();
        // System.out.println(i1.getID());
        } catch (CorruptDataException e) {
            System.out.println("CDE on thread: " + i);
        } catch (DataUnavailable e) {
            System.out.println("DUA on thread: " + i);
        }
    }
    imageThreadComparator.testComparatorEquals(ddrTestObjects, jextractTestObjects, "getImageThread");
}
Also used : JavaThread(com.ibm.dtfj.java.JavaThread) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) ImageThread(com.ibm.dtfj.image.ImageThread) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) Test(org.junit.Test)

Example 2 with ImageThread

use of com.ibm.dtfj.image.ImageThread in project openj9 by eclipse.

the class JCImageProcess method getCurrentThread.

/**
 */
public ImageThread getCurrentThread() throws CorruptDataException {
    ImageThread currentThread = null;
    if (fCurrentThreadID != IBuilderData.NOT_AVAILABLE) {
        // Return the indicated thread
        ImagePointer ip = fImageAddressSpace.getPointer(fCurrentThreadID);
        currentThread = getImageThread(ip);
        if (currentThread == null) {
            throw new CorruptDataException(new JCCorruptData("Bad native thread ID", ip));
        }
    }
    return currentThread;
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer) ImageThread(com.ibm.dtfj.image.ImageThread) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 3 with ImageThread

use of com.ibm.dtfj.image.ImageThread in project openj9 by eclipse.

the class InfoThreadCommand method getJavaThreads.

private Map getJavaThreads(String id) {
    Map threads = new HashMap();
    ManagedRuntime mr = ctx.getRuntime();
    if (mr instanceof JavaRuntime) {
        JavaRuntime jr = (JavaRuntime) mr;
        Iterator itThread = jr.getThreads();
        while (itThread.hasNext()) {
            Object next = itThread.next();
            // skip any corrupt threads
            if (next instanceof CorruptData)
                continue;
            JavaThread jt = (JavaThread) next;
            // Obtain the native thread ID for this thread, and for zOS also obtain the TCB
            String currentTID = null;
            String currentTCB = null;
            try {
                ImageThread it = jt.getImageThread();
                currentTID = it.getID();
                if (_is_zOS) {
                    currentTCB = it.getProperties().getProperty("TCB");
                }
            } catch (DTFJException e) {
            // Continue with what we have obtained so far
            }
            if (null == id) {
                // save all orphaned java threads in a list within the hashmap
                if (null == currentTID) {
                    if (threads.containsKey(null)) {
                        ArrayList ta = (ArrayList) threads.get(null);
                        ta.add(new ThreadData(jt, jr));
                    } else {
                        ArrayList ta = new ArrayList(1);
                        ta.add(new ThreadData(jt, jr));
                        threads.put(null, ta);
                    }
                } else {
                    threads.put(currentTID, new ThreadData(jt, jr));
                }
            } else if (id.equalsIgnoreCase(currentTID) || id.equalsIgnoreCase(currentTCB)) {
                // We just want the specific Java thread that matches the native thread ID or zOS TCB
                threads.put(currentTID, new ThreadData(jt, jr));
            }
        }
    }
    return threads;
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) HashMap(java.util.HashMap) DTFJException(com.ibm.dtfj.image.DTFJException) ArrayList(java.util.ArrayList) StateToString(com.ibm.jvm.dtfjview.commands.helpers.StateToString) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) ImageThread(com.ibm.dtfj.image.ImageThread) HashMap(java.util.HashMap) Map(java.util.Map) ManagedRuntime(com.ibm.dtfj.runtime.ManagedRuntime) ThreadData(com.ibm.jvm.dtfjview.commands.helpers.ThreadData)

Example 4 with ImageThread

use of com.ibm.dtfj.image.ImageThread in project openj9 by eclipse.

the class InfoThreadCommand method printThreadSummary.

private void printThreadSummary(ImageProcess ip) {
    // Prints a summary list of native thread IDs
    int count = 0;
    Iterator itThread = ip.getThreads();
    while (itThread.hasNext()) {
        Object next = itThread.next();
        if (next instanceof CorruptData)
            continue;
        ImageThread it = (ImageThread) next;
        if (count % 8 == 0) {
            if (0 == count)
                out.print("\n\nNative thread IDs for current process:");
            out.print("\n ");
        }
        try {
            out.print(Utils.padWithSpaces(it.getID(), 8));
        } catch (CorruptDataException e) {
            out.print(Exceptions.getCorruptDataExceptionString());
        }
        count++;
    }
    out.print("\n");
}
Also used : Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) ImageThread(com.ibm.dtfj.image.ImageThread) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 5 with ImageThread

use of com.ibm.dtfj.image.ImageThread in project openj9 by eclipse.

the class DTFJJavaThread method equals.

public boolean equals(Object object) {
    // note that we can't get image threads on all platforms and in all situations but we still need to return equals correctly
    ImageThread imageThread = null;
    try {
        imageThread = getImageThread();
    } catch (DataUnavailable e) {
    // Do nothing
    } catch (CorruptDataException e) {
    // Do nothing
    }
    boolean isEqual = (null == imageThread) ? (this == object) : false;
    // By definition objects from different images can not be equal
    if ((null != imageThread) && (object instanceof DTFJJavaThread)) {
        DTFJJavaThread local = (DTFJJavaThread) object;
        try {
            isEqual = imageThread.getID().equals(local.getImageThread().getID());
        } catch (CorruptDataException e) {
        // Do nothing
        } catch (DataUnavailable e) {
        // Do nothing
        }
    }
    return isEqual;
}
Also used : DataUnavailable(com.ibm.dtfj.image.DataUnavailable) ImageThread(com.ibm.dtfj.image.ImageThread) J9DDRStubImageThread(com.ibm.j9ddr.view.dtfj.image.J9DDRStubImageThread) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Aggregations

ImageThread (com.ibm.dtfj.image.ImageThread)15 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)12 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)7 Iterator (java.util.Iterator)6 CorruptData (com.ibm.dtfj.image.CorruptData)5 JavaObject (com.ibm.dtfj.java.JavaObject)5 JavaThread (com.ibm.dtfj.java.JavaThread)5 ImageSection (com.ibm.dtfj.image.ImageSection)3 StateToString (com.ibm.jvm.dtfjview.commands.helpers.StateToString)3 LinkedList (java.util.LinkedList)3 ImageProcess (com.ibm.dtfj.image.ImageProcess)2 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)2 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)2 ThreadData (com.ibm.jvm.dtfjview.commands.helpers.ThreadData)2 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DTFJException (com.ibm.dtfj.image.DTFJException)1 ImageModule (com.ibm.dtfj.image.ImageModule)1 ImagePointer (com.ibm.dtfj.image.ImagePointer)1