Search in sources :

Example 11 with ImageThread

use of com.ibm.dtfj.image.ImageThread 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 12 with ImageThread

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

the class ImageThreadComparator method testEquals.

// id
// properties
// registers
// stack frames
// stack sections
public void testEquals(Object ddrObject, Object jextractObject, int members) {
    ImageThread ddrImageThread = (ImageThread) ddrObject;
    ImageThread jextractImageThread = (ImageThread) jextractObject;
    // getID()
    if ((ID & members) != 0)
        testJavaEquals(ddrImageThread, jextractImageThread, "getID");
    // getProperties()
    if ((PROPERTIES & members) != 0)
        testPropertiesEquals(ddrImageThread, jextractImageThread, "getProperties");
    // getRegisters
    if ((REGISTERS & members) != 0)
        new ImageRegisterComparator().testComparatorIteratorEquals(ddrImageThread, jextractImageThread, "getRegisters", ImageRegister.class);
    // getStackFrames();
    if ((STACK_FRAMES & members) != 0)
        new ImageStackFrameComparator().testComparatorIteratorEquals(ddrImageThread, jextractImageThread, "getStackFrames", ImageStackFrame.class);
    // getStackSections();
    if ((STACK_SECTIONS & members) != 0)
        new ImageSectionComparator().testComparatorIteratorEquals(ddrImageThread, jextractImageThread, "getStackSections", ImageSection.class);
}
Also used : ImageRegister(com.ibm.dtfj.image.ImageRegister) ImageSection(com.ibm.dtfj.image.ImageSection) ImageThread(com.ibm.dtfj.image.ImageThread) ImageStackFrame(com.ibm.dtfj.image.ImageStackFrame)

Example 13 with ImageThread

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

the class ImageRegisterTest method loadTestObjects.

protected void loadTestObjects(JavaRuntime ddrRuntime, List<Object> ddrObjects, JavaRuntime jextractRuntime, List<Object> jextractObjects) {
    // Extract registers from all threads
    List<Object> ddrThreads = new LinkedList<Object>();
    List<Object> jextractThreads = new LinkedList<Object>();
    Comparator<Object> c = new Comparator<Object>() {

        public int compare(Object o1, Object o2) {
            if (o1 instanceof ImageThread && o2 instanceof ImageThread) {
                ImageThread t1 = (ImageThread) o1;
                ImageThread t2 = (ImageThread) o2;
                try {
                    return t1.getID().compareTo(t2.getID());
                } catch (CorruptDataException e) {
                    return 0;
                }
            } else {
                return 0;
            }
        }
    };
    fillLists(ddrThreads, ddrProcess.getThreads(), jextractThreads, jextractProcess.getThreads(), c);
    assertEquals("Different numbers of threads", jextractThreads.size(), ddrThreads.size());
    Collections.sort(ddrThreads, c);
    Collections.sort(jextractThreads, c);
    for (Object o : ddrThreads) {
        if (o instanceof ImageThread) {
            ImageThread t = (ImageThread) o;
            Iterator<?> it = t.getRegisters();
            slurpIterator(it, ddrObjects);
        }
    }
    for (Object o : jextractThreads) {
        if (o instanceof ImageThread) {
            ImageThread t = (ImageThread) o;
            Iterator<?> it = t.getRegisters();
            slurpIterator(it, jextractObjects);
        }
    }
}
Also used : ImageThread(com.ibm.dtfj.image.ImageThread) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) LinkedList(java.util.LinkedList) ImageRegisterComparator(com.ibm.j9ddr.view.dtfj.comparators.ImageRegisterComparator) Comparator(java.util.Comparator)

Example 14 with ImageThread

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

the class InfoProcCommand method printThreads.

private void printThreads() {
    ImageProcess ip = ctx.getProcess();
    out.print("\t Native thread IDs:");
    out.print("\n\t  ");
    // normal tab plus 2 spaces
    int lineLength = 10;
    // FIXME: should output architecture (32/64-bit), endianness before threads
    Iterator<?> itThread = ip.getThreads();
    while (itThread.hasNext()) {
        Object next = itThread.next();
        if (next instanceof CorruptData) {
            out.print("\n\t  <corrupt data>");
            continue;
        }
        ImageThread it = (ImageThread) next;
        try {
            String threadID = it.getID();
            if (threadID != null) {
                if (lineLength + threadID.length() > 80) {
                    out.print("\n\t  ");
                    lineLength = 10;
                }
                out.print(it.getID() + " ");
                lineLength += threadID.length() + 1;
            }
        } catch (CorruptDataException e) {
            out.print(Exceptions.getCorruptDataExceptionString());
        }
    }
    out.print("\n");
}
Also used : ImageProcess(com.ibm.dtfj.image.ImageProcess) CorruptData(com.ibm.dtfj.image.CorruptData) ImageThread(com.ibm.dtfj.image.ImageThread) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 15 with ImageThread

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

the class InfoThreadCommand method doCommand.

public void doCommand(String[] args) {
    try {
        _is_zOS = ctx.getImage().getSystemType().toLowerCase().indexOf("z/os") >= 0;
    } catch (DataUnavailable e) {
        out.print(Exceptions.getDataUnavailableString());
    } catch (CorruptDataException e) {
        out.print(Exceptions.getCorruptDataExceptionString());
    }
    String param = null;
    switch(args.length) {
        case 0:
            try {
                ImageThread it = ctx.getProcess().getCurrentThread();
                if (null != it) {
                    param = it.getID();
                } else {
                    out.print("\nNo current (failing) thread, try specifying a native thread ID, \"all\" or \"*\"\n");
                    ImageProcess ip = ctx.getProcess();
                    if (ip != null) {
                        printThreadSummary(ip);
                    }
                    return;
                }
            } catch (CorruptDataException e) {
                out.println("exception encountered while getting information about current thread");
                return;
            }
            break;
        case 1:
            if (args[0].equalsIgnoreCase("ALL")) {
                param = "*";
            } else {
                param = args[0];
            }
            break;
        default:
            out.println("\"info thread\" takes at most one parameter, which, if specified, must be a native thread ID or \"all\" or \"*\"");
            return;
    }
    if (param.equals("*")) {
        printAddressSpaceInfo(null, getJavaThreads(null));
    } else {
        printAddressSpaceInfo(param, getJavaThreads(param));
    }
}
Also used : ImageProcess(com.ibm.dtfj.image.ImageProcess) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) StateToString(com.ibm.jvm.dtfjview.commands.helpers.StateToString) ImageThread(com.ibm.dtfj.image.ImageThread)

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