Search in sources :

Example 11 with BuilderFailureException

use of com.ibm.dtfj.javacore.builder.BuilderFailureException 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 BuilderFailureException

use of com.ibm.dtfj.javacore.builder.BuilderFailureException in project openj9 by eclipse.

the class JavaRuntimeBuilder method addVMOption.

/**
 * Adds an individual VM option to JavaVMInitArgs, with 'extra information' field
 */
public void addVMOption(String option, long extraInfo) throws BuilderFailureException {
    if (fJavaVMInitArgs == null) {
        throw new BuilderFailureException("JCJavaVMInitArgs must be created before options added");
    }
    try {
        ImagePointer pointer = fAddressSpace.getPointer(extraInfo);
        fJavaVMInitArgs.addOption(new JCJavaVMOption(option, pointer));
    } catch (JCInvalidArgumentsException e) {
        throw new BuilderFailureException(e);
    }
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer) JCJavaVMOption(com.ibm.dtfj.java.javacore.JCJavaVMOption) BuilderFailureException(com.ibm.dtfj.javacore.builder.BuilderFailureException) JCInvalidArgumentsException(com.ibm.dtfj.java.javacore.JCInvalidArgumentsException)

Example 13 with BuilderFailureException

use of com.ibm.dtfj.javacore.builder.BuilderFailureException in project openj9 by eclipse.

the class JavaRuntimeBuilder method addJavaMonitor.

/**
 * Required: monitor ID (throws exception if invalid)
 * <br>
 * Optional: object ID, class name, monitor name, owning thread
 * @return successfully created JavaMonitor
 * @throws BuilderFailureException if an invalid monitor ID is passed.
 */
public JavaMonitor addJavaMonitor(String monitorName, long monitorID, long objectID, String className, long owningThread) throws BuilderFailureException {
    try {
        JCJavaMonitor monitor = getJavaRuntime().findMonitor(monitorID);
        if (monitor == null) {
            ImagePointer pointerMonitorID = fAddressSpace.getPointer(monitorID);
            monitor = new JCJavaMonitor(getJavaRuntime(), pointerMonitorID, monitorName);
        }
        monitor.setOwner(owningThread);
        if (className != null) {
            JCJavaClass jClass = generateJavaClass(getJavaRuntime(), className, IBuilderData.NOT_AVAILABLE);
            /*
				 * Add the object only if the class is also present and object ID is valid.
				 */
            if (jClass != null && fAddressSpace.isValidAddressID(objectID)) {
                ImagePointer pointerObjectID = fAddressSpace.getPointer(objectID);
                JCJavaObject jobject = new JCJavaObject(pointerObjectID, jClass);
                monitor.setObject(jobject);
            }
        }
        return monitor;
    } catch (JCInvalidArgumentsException e) {
        throw new BuilderFailureException(e);
    }
}
Also used : JCJavaObject(com.ibm.dtfj.java.javacore.JCJavaObject) ImagePointer(com.ibm.dtfj.image.ImagePointer) BuilderFailureException(com.ibm.dtfj.javacore.builder.BuilderFailureException) JCInvalidArgumentsException(com.ibm.dtfj.java.javacore.JCInvalidArgumentsException) JCJavaMonitor(com.ibm.dtfj.java.javacore.JCJavaMonitor) JCJavaClass(com.ibm.dtfj.java.javacore.JCJavaClass)

Aggregations

BuilderFailureException (com.ibm.dtfj.javacore.builder.BuilderFailureException)13 ImagePointer (com.ibm.dtfj.image.ImagePointer)7 JCInvalidArgumentsException (com.ibm.dtfj.java.javacore.JCInvalidArgumentsException)7 JCJavaClass (com.ibm.dtfj.java.javacore.JCJavaClass)5 JCJavaObject (com.ibm.dtfj.java.javacore.JCJavaObject)4 IAttributeValueMap (com.ibm.dtfj.javacore.parser.j9.IAttributeValueMap)4 Iterator (java.util.Iterator)3 JCJavaClassLoader (com.ibm.dtfj.java.javacore.JCJavaClassLoader)2 JCJavaThread (com.ibm.dtfj.java.javacore.JCJavaThread)2 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)1 ImageRegister (com.ibm.dtfj.image.ImageRegister)1 ImageSection (com.ibm.dtfj.image.ImageSection)1 ImageThread (com.ibm.dtfj.image.ImageThread)1 JCImageRegister (com.ibm.dtfj.image.javacore.JCImageRegister)1 JCImageThread (com.ibm.dtfj.image.javacore.JCImageThread)1 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)1 JavaObject (com.ibm.dtfj.java.JavaObject)1 JavaThread (com.ibm.dtfj.java.JavaThread)1 JCJavaLocation (com.ibm.dtfj.java.javacore.JCJavaLocation)1 JCJavaMethod (com.ibm.dtfj.java.javacore.JCJavaMethod)1