Search in sources :

Example 1 with JCInvalidArgumentsException

use of com.ibm.dtfj.java.javacore.JCInvalidArgumentsException in project openj9 by eclipse.

the class JavaRuntimeBuilder method addJavaThread.

/**
 * If successfully added a JavaThread, or updated an existing JavaThread, return the javathread, or otherwise
 * throw an exception. Note that a javathread cannot be successfully added if no valid threadID is passed.
 * <br><br>
 * REQUIREMENT: Thread Id must be valid to properly create a Java Thread, or exception is thrown.
 *
 * @throws BuilderFailureException if arguments lead to an invalid DTFJ object, particularly an invalid threadID
 * @return a non null JavaThread that was successfully added or updated.
 */
public JavaThread addJavaThread(ImageThread imageThread, String name, long tid, long j9thread_t, long javaObjID, long jniEnv, String state, int priority, long blockingObject, String blockingObjectClass) throws BuilderFailureException {
    try {
        if (j9thread_t != IBuilderData.NOT_AVAILABLE && jniEnv != IBuilderData.NOT_AVAILABLE) {
            // Save the JNIEnv for later
            ImagePointer pointer = fAddressSpace.getPointer(jniEnv);
            j9ThreadToJNIEnv.put(new Long(j9thread_t), pointer);
        }
        if (!fAddressSpace.isValidAddressID(tid)) {
            throw new JCInvalidArgumentsException("Must pass a valid thread id");
        }
        JCJavaThread javaThread = getJavaRuntime().findJavaThread(tid);
        if (javaThread == null) {
            ImagePointer pointer = fAddressSpace.getPointer(tid);
            javaThread = new JCJavaThread(getJavaRuntime(), pointer);
        }
        javaThread.setName(name);
        javaThread.setPriority(priority);
        javaThread.setState(state);
        javaThread.setImageThread((JCImageThread) imageThread);
        if (jniEnv == IBuilderData.NOT_AVAILABLE) {
            // Retrieve the JNIEnv
            ImagePointer pointer = (ImagePointer) j9ThreadToJNIEnv.get(new Long(j9thread_t));
            if (pointer != null) {
                // Set it for 1.4.2
                javaThread.setJNIEnv(pointer);
            } else {
                // Else TID for J9 seems to be JNIEnv
                javaThread.setJNIEnv(javaThread.getThreadID());
            }
        }
        /*
			 * Add the object only if the object ID is valid.
			 */
        if (fAddressSpace.isValidAddressID(javaObjID)) {
            // Make the type just java.lang.Thread - later we can do better if there is a stack trace.
            JCJavaClass jClass = generateJavaClass(getJavaRuntime(), "java/lang/Thread", IBuilderData.NOT_AVAILABLE);
            ImagePointer pointerObjectID = fAddressSpace.getPointer(javaObjID);
            JCJavaObject jobject = new JCJavaObject(pointerObjectID, jClass);
            javaThread.setObject(jobject);
        }
        if (fAddressSpace.isValidAddressID(blockingObject)) {
            JCJavaClass jClass = generateJavaClass(getJavaRuntime(), blockingObjectClass, IBuilderData.NOT_AVAILABLE);
            ImagePointer pointerObjectID = fAddressSpace.getPointer(javaObjID);
            JCJavaObject jobject = new JCJavaObject(pointerObjectID, jClass);
            javaThread.setBlockingObject(jobject);
        }
        return javaThread;
    } 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) JCJavaClass(com.ibm.dtfj.java.javacore.JCJavaClass) JCJavaThread(com.ibm.dtfj.java.javacore.JCJavaThread)

Example 2 with JCInvalidArgumentsException

use of com.ibm.dtfj.java.javacore.JCInvalidArgumentsException in project openj9 by eclipse.

the class JavaRuntimeBuilder method generateJavaClass.

/**
 * Either retrieves an existing java class registered with the java runtime or it creates one and it fills in missing information,
 * if the latter is available.
 * <br><br>
 * A valid runtime and class name must be passed in order to successfully generate a java class. An invalid argument exception is
 * thrown if either one of them is invalid.
 * <br><br>
 * A null value should not be returned, as this indicates an error was encountered. Instead, throw the
 * appropriate exception.
 *
 * @param runtime required
 * @param name required
 * @param classID optional
 * @return added or updated JavaClass, or exception thrown if invalid arguments passed.
 * @throws JCInvalidArgumentsException
 */
private JCJavaClass generateJavaClass(JCJavaRuntime runtime, String name, long classID) throws JCInvalidArgumentsException {
    if (name != null) {
        if (fAddressSpace.isValidAddressID(classID)) {
            JCJavaClass jClass = runtime.findJavaClass(classID);
            if (jClass == null) {
                jClass = runtime.findJavaClass(name);
                if (jClass != null) {
                    ImagePointer ip = jClass.getID();
                    if (ip == null) {
                        jClass.setID(classID);
                    } else {
                        jClass = new JCJavaClass(runtime, name);
                        jClass.setID(classID);
                    }
                } else {
                    jClass = new JCJavaClass(runtime, name);
                    jClass.setID(classID);
                }
            }
            return jClass;
        }
        JCJavaClass jClass = runtime.findJavaClass(name);
        if (jClass == null) {
            jClass = new JCJavaClass(runtime, name);
        }
        if (fAddressSpace.isValidAddressID(classID)) {
            jClass.setID(classID);
        }
        return jClass;
    } else {
        throw new JCInvalidArgumentsException("Failed to add class.  Null class name");
    }
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer) JCInvalidArgumentsException(com.ibm.dtfj.java.javacore.JCInvalidArgumentsException) JCJavaClass(com.ibm.dtfj.java.javacore.JCJavaClass)

Example 3 with JCInvalidArgumentsException

use of com.ibm.dtfj.java.javacore.JCInvalidArgumentsException in project openj9 by eclipse.

the class JavaRuntimeBuilder method addJavaStackFrame.

/**
 */
public JavaStackFrame addJavaStackFrame(JavaThread javaThread, String className, String classFileName, String methodName, String methodType, String compilationLevel, int lineNumber) throws BuilderFailureException {
    try {
        JCJavaThread jThread = (JCJavaThread) javaThread;
        JCJavaClass jclass = getJavaRuntime().findJavaClass(className);
        if (jclass == null) {
            jclass = new JCJavaClass(getJavaRuntime(), className);
        }
        JCJavaMethod method = new JCJavaMethod(methodName, jclass);
        JCJavaLocation location = new JCJavaLocation(method);
        location.setFilename(classFileName);
        location.setCompilation(compilationLevel);
        location.setLineNumber(lineNumber);
        JCJavaStackFrame stackFrame = new JCJavaStackFrame(jThread, location);
        if ("run".equals(methodName)) {
            /*
				 * Perhaps the type of the thread is the type of the last run() method.
				 * Not strictly accurate if the class was extended without overriding run(). 
				 * Add the object only if the object ID is valid.
				 */
            try {
                JavaObject jo = jThread.getObject();
                if (jo != null) {
                    ImagePointer tid = jo.getID();
                    if (fAddressSpace.isValidAddressID(tid.getAddress())) {
                        JCJavaObject jobject = new JCJavaObject(tid, jclass);
                        jThread.setObject(jobject);
                    }
                }
            } catch (CorruptDataException e) {
            // Ignore
            }
        }
        return stackFrame;
    } catch (JCInvalidArgumentsException e) {
        throw new BuilderFailureException(e);
    }
}
Also used : JCJavaObject(com.ibm.dtfj.java.javacore.JCJavaObject) ImagePointer(com.ibm.dtfj.image.ImagePointer) JCJavaMethod(com.ibm.dtfj.java.javacore.JCJavaMethod) JavaObject(com.ibm.dtfj.java.JavaObject) JCJavaObject(com.ibm.dtfj.java.javacore.JCJavaObject) BuilderFailureException(com.ibm.dtfj.javacore.builder.BuilderFailureException) JCJavaStackFrame(com.ibm.dtfj.java.javacore.JCJavaStackFrame) JCJavaLocation(com.ibm.dtfj.java.javacore.JCJavaLocation) JCInvalidArgumentsException(com.ibm.dtfj.java.javacore.JCInvalidArgumentsException) JCJavaClass(com.ibm.dtfj.java.javacore.JCJavaClass) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) JCJavaThread(com.ibm.dtfj.java.javacore.JCJavaThread)

Example 4 with JCInvalidArgumentsException

use of com.ibm.dtfj.java.javacore.JCInvalidArgumentsException in project openj9 by eclipse.

the class JavaRuntimeBuilder method addClassLoader.

/**
 * Must pass a valid class loader ID in order to generate a class loader object. Else exception
 * is thrown.
 *
 * @param classLoaderName optional
 * @param clID required, or else exception is throw and class loader is not created.
 * @param objectID optional (although generally this is the same as the clID for most javacores)
 * @return successfully created JavaClassLoader
 * @throws BuilderFailureException if class loader ID is invalid.
 */
public JavaClassLoader addClassLoader(String classLoaderName, long clID, long objectID) throws BuilderFailureException {
    try {
        JCJavaClassLoader classLoader = getJavaRuntime().findJavaClassLoader(clID);
        if (classLoader == null) {
            classLoader = new JCJavaClassLoader(getJavaRuntime(), clID);
        }
        JCJavaObject javaObject = classLoader.getInternalObject();
        if (javaObject == null) {
            JCJavaClass javaClass = getJavaRuntime().findJavaClass(classLoaderName);
            if (javaClass == null) {
                javaClass = new JCJavaClass(getJavaRuntime(), classLoaderName);
            }
            ImagePointer objectPointer = fAddressSpace.getPointer(objectID);
            javaObject = new JCJavaObject(objectPointer, javaClass);
            classLoader.setObject(javaObject);
        }
        return classLoader;
    } catch (JCInvalidArgumentsException e) {
        throw new BuilderFailureException(e);
    }
}
Also used : JCJavaObject(com.ibm.dtfj.java.javacore.JCJavaObject) ImagePointer(com.ibm.dtfj.image.ImagePointer) JCJavaClassLoader(com.ibm.dtfj.java.javacore.JCJavaClassLoader) BuilderFailureException(com.ibm.dtfj.javacore.builder.BuilderFailureException) JCInvalidArgumentsException(com.ibm.dtfj.java.javacore.JCInvalidArgumentsException) JCJavaClass(com.ibm.dtfj.java.javacore.JCJavaClass)

Example 5 with JCInvalidArgumentsException

use of com.ibm.dtfj.java.javacore.JCInvalidArgumentsException in project openj9 by eclipse.

the class ImageProcessBuilder method addImageThread.

/**
 * @param Properties with String key and String value
 */
public ImageThread addImageThread(long nativeThreadID, long systemThreadID, Properties properties) throws BuilderFailureException {
    try {
        ImagePointer pointer = fImageAddressSpace.getPointer(nativeThreadID);
        JCImageThread thread = fImageProcess.getImageThread(pointer);
        if (thread == null) {
            thread = new JCImageThread(pointer);
            if (registers != null) {
                // Add the registers to the first thread
                for (Iterator it = registers.entrySet().iterator(); it.hasNext(); ) {
                    Map.Entry me = (Map.Entry) it.next();
                    ImageRegister ir = new JCImageRegister((String) me.getKey(), (Number) me.getValue());
                    thread.addRegister(ir);
                }
                registers = null;
            }
            fImageProcess.addImageThread(thread);
        }
        for (Iterator it = properties.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry me = (Map.Entry) it.next();
            thread.addProperty(me.getKey(), me.getValue());
        }
        if (systemThreadID != IBuilderData.NOT_AVAILABLE) {
            pointer = fImageAddressSpace.getPointer(systemThreadID);
            thread.setSystemThreadID(pointer);
        }
        return thread;
    } catch (JCInvalidArgumentsException e) {
        throw new BuilderFailureException(e);
    }
}
Also used : JCImageThread(com.ibm.dtfj.image.javacore.JCImageThread) ImagePointer(com.ibm.dtfj.image.ImagePointer) ImageRegister(com.ibm.dtfj.image.ImageRegister) JCImageRegister(com.ibm.dtfj.image.javacore.JCImageRegister) BuilderFailureException(com.ibm.dtfj.javacore.builder.BuilderFailureException) JCImageRegister(com.ibm.dtfj.image.javacore.JCImageRegister) Iterator(java.util.Iterator) JCInvalidArgumentsException(com.ibm.dtfj.java.javacore.JCInvalidArgumentsException) Map(java.util.Map)

Aggregations

ImagePointer (com.ibm.dtfj.image.ImagePointer)8 JCInvalidArgumentsException (com.ibm.dtfj.java.javacore.JCInvalidArgumentsException)8 BuilderFailureException (com.ibm.dtfj.javacore.builder.BuilderFailureException)7 JCJavaClass (com.ibm.dtfj.java.javacore.JCJavaClass)6 JCJavaObject (com.ibm.dtfj.java.javacore.JCJavaObject)4 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 JCImageRegister (com.ibm.dtfj.image.javacore.JCImageRegister)1 JCImageThread (com.ibm.dtfj.image.javacore.JCImageThread)1 JavaObject (com.ibm.dtfj.java.JavaObject)1 JCJavaLocation (com.ibm.dtfj.java.javacore.JCJavaLocation)1 JCJavaMethod (com.ibm.dtfj.java.javacore.JCJavaMethod)1 JCJavaMonitor (com.ibm.dtfj.java.javacore.JCJavaMonitor)1 JCJavaStackFrame (com.ibm.dtfj.java.javacore.JCJavaStackFrame)1 JCJavaVMOption (com.ibm.dtfj.java.javacore.JCJavaVMOption)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1