Search in sources :

Example 11 with JavaClass

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

the class PHDJavaRuntime method findArrayOfClass.

JavaClass findArrayOfClass(long id) {
    JavaClass cl1 = findClass(id);
    if (cl1 != null) {
        try {
            // Try the class loader of the component type first
            JavaClassLoader jcl = cl1.getClassLoader();
            if (jcl instanceof PHDJavaClassLoader) {
                PHDJavaClassLoader ldr = (PHDJavaClassLoader) jcl;
                JavaClass cls = ldr.findArrayOfClass(id);
                if (cls != null) {
                    return cls;
                }
            }
        } catch (CorruptDataException e) {
        }
    }
    return findArrayOfClass2(id);
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 12 with JavaClass

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

the class PHDJavaClassLoader method setArrayType.

/**
 * The class has been moved from one loader to this one.
 * Does the array type need to be set up? It could be that there was a choice of arrays with the same name
 * but now the arrays are in different class loaders there is only one to choose.
 * @param runtime
 * @param from
 * @param cl1
 * @return
 */
JavaClass setArrayType(PHDJavaRuntime runtime, PHDJavaClassLoader from, JavaClass cl1) {
    boolean lookInBootLoader = false;
    JavaClass cl2 = null;
    ImagePointer ip = cl1.getID();
    if (ip != null) {
        long addr = ip.getAddress();
        if (arrayClasses.containsKey(addr)) {
            cl2 = arrayClasses.get(addr);
            if (cl2 == null) {
                // Need an array type, but it hasn't yet been found
                try {
                    String name = cl1.getName();
                    String arrayName = arrayName(name);
                    Set<JavaClass> s = findClasses(arrayName);
                    // Does the array class exist in this loader?
                    lookInBootLoader = s.size() == 0;
                    if (lookInBootLoader) {
                        // Try the boot loader instead
                        s = from.findClasses(arrayName);
                    }
                    if (s.size() == 0) {
                        // Array class doesn't exist, so create a dummy one.
                        // Unlikely to happen as a dummy array has been built earlier.
                        // May happen if the class is loader by multiple loaders, but only some loaders have the array
                        cl2 = new PHDJavaClass.Builder(cl1.getID().getAddressSpace(), runtime, this, 0, jlo, arrayName).componentType(cl1).build();
                    } else if (s.size() == 1) {
                        // Only one class, so use it
                        cl2 = s.iterator().next();
                    } else {
                        for (JavaClass cl3 : s) {
                            // Default - first class found
                            if (cl2 == null)
                                cl2 = cl3;
                            // See if this class is unused as an array type
                            if (cl3 instanceof PHDJavaClass) {
                                // Choose one array class not already set as an array of another class
                                if (((PHDJavaClass) cl3).setComponentType(null) == null) {
                                    cl2 = cl3;
                                    break;
                                }
                            }
                        }
                    }
                } catch (CorruptDataException e) {
                    cl2 = new PHDJavaClass.Builder(cl1.getID().getAddressSpace(), runtime, this, 0, jlo, PHDJavaClass.UNKNOWN_ARRAY).componentType(cl1).build();
                }
                if (cl2 instanceof PHDJavaClass) {
                    // We know the component type, so remember it for later
                    JavaClass c1 = ((PHDJavaClass) cl2).setComponentType(cl1);
                }
                arrayClasses.put(addr, cl2);
            }
        }
    }
    // If the class was found in the boot loader, return it so that it can be removed.
    return lookInBootLoader ? cl2 : null;
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer) JavaClass(com.ibm.dtfj.java.JavaClass) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 13 with JavaClass

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

the class PHDJavaHeap method getLastObject.

/**
 * Attempt to get the last object without rereading the entire heap.
 * @param address
 * @param classAddress
 * @param length
 * @return a JavaObject with sufficient information to determine its length
 * @throws IOException
 */
JavaObject getLastObject(ImagePointer address, long classAddress, int length) throws IOException {
    JavaObject jo = getCachedObjectAtAddress(address, false);
    if (jo != null)
        return jo;
    long addr = address.getAddress();
    if (classAddress < 8) {
        JavaClass jc = runtime.findArrayOfType((int) classAddress);
        jo = new PHDJavaObject.Builder(this, addr, jc, PHDJavaObject.NO_HASHCODE, -1).length(length).refsAsArray(NOREFS, 0).build();
    } else if (length >= 0) {
        if (isJ9V4)
            length--;
        JavaClass jc = runtime.findArrayOfClass(classAddress);
        jo = new PHDJavaObject.Builder(this, addr, jc, PHDJavaObject.NO_HASHCODE, -1).length(length).build();
    } else {
        JavaClass jc = runtime.findClass(classAddress);
        jo = new PHDJavaObject.Builder(this, addr, jc, PHDJavaObject.NO_HASHCODE, -1).length(PHDJavaObject.SIMPLE_OBJECT).build();
    }
    return jo;
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass)

Example 14 with JavaClass

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

the class PHDJavaClassLoader method prepareToMove.

/**
 * Get reader to move a class from one loader to another, including the array refs.
 * @param from
 * @param j1
 */
void prepareToMove(PHDJavaClassLoader from, JavaClass j1) {
    setLoader(j1);
    ImagePointer ip = j1.getID();
    if (ip != null) {
        long address = ip.getAddress();
        JavaClass j2 = from.arrayClasses.get(address);
        if (j2 != null)
            setLoader(j2);
    }
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer) JavaClass(com.ibm.dtfj.java.JavaClass)

Example 15 with JavaClass

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

the class InfoThreadCommand method printJavaThreadInfo.

private void printJavaThreadInfo(JavaThread jt, boolean idPrinted) {
    out.print("    name:          ");
    try {
        out.print(jt.getName());
    } catch (CorruptDataException e) {
        out.print(Exceptions.getCorruptDataExceptionString());
        logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
    }
    out.print("\n");
    if (!idPrinted) {
        try {
            if (jt.getImageThread() != null) {
                out.print("    id:            ");
                out.print(jt.getImageThread().getID());
            }
        } catch (CorruptDataException e) {
            out.print(Exceptions.getCorruptDataExceptionString());
            logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
        } catch (DataUnavailable e) {
            out.print(Exceptions.getDataUnavailableString());
            logger.log(Level.FINEST, Exceptions.getDataUnavailableString(), e);
        } finally {
            out.print("\n");
        }
    }
    out.print("    Thread object: ");
    try {
        JavaObject threadObj = jt.getObject();
        if (null == threadObj) {
            out.print("<no associated Thread object>");
        } else {
            String threadClassName = null;
            try {
                JavaClass threadClass = threadObj.getJavaClass();
                threadClassName = threadClass.getName();
                if (threadClassName != null) {
                    out.print(threadClassName + " @ ");
                }
                out.print(Utils.toHex(threadObj.getID().getAddress()));
                // Navigate to the parent java/lang.Thread class to get the 'tid' and 'isDaemon' fields
                while (!JAVA_LANG_THREAD_CLASS.equals(threadClass.getName()) && threadClass != null) {
                    threadClass = threadClass.getSuperclass();
                }
                if (threadClass != null) {
                    Iterator itField = threadClass.getDeclaredFields();
                    boolean foundThreadId = false;
                    while (itField.hasNext()) {
                        JavaField jf = (JavaField) itField.next();
                        /* "uniqueId" field in java.lang.Thread is renamed to "tid". The old field name is
							 * checked to preserve functionality of DDR command with old core files that reference
							 * the "uniqueId" field.
							 */
                        if (!foundThreadId && (jf.getName().equals("uniqueId") || jf.getName().equals("tid"))) {
                            foundThreadId = true;
                            out.print("\n    ID:            " + Utils.getVal(threadObj, jf));
                        } else if (jf.getName().equals("isDaemon")) {
                            out.print("\n    Daemon:        " + Utils.getVal(threadObj, jf));
                        }
                    }
                }
            } catch (CorruptDataException cde) {
                out.print(" <in-flight or corrupt data encountered>");
                logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), cde);
            }
        }
    } catch (CorruptDataException cde) {
        out.print(Exceptions.getCorruptDataExceptionString());
        logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), cde);
    }
    out.print("\n");
    out.print("    Priority:      ");
    try {
        Integer pri = new Integer(jt.getPriority());
        out.print(pri.toString());
    } catch (CorruptDataException e) {
        out.print(Exceptions.getCorruptDataExceptionString());
        logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
    }
    out.print("\n");
    out.print("    Thread.State:  ");
    try {
        out.print(StateToString.getThreadStateString(jt.getState()));
    } catch (CorruptDataException cde) {
        out.print(Exceptions.getCorruptDataExceptionString());
        logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), cde);
    }
    out.print("\n");
    out.print("    JVMTI state:   ");
    try {
        out.print(StateToString.getJVMTIStateString(jt.getState()));
    } catch (CorruptDataException cde) {
        out.print(Exceptions.getCorruptDataExceptionString());
        logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), cde);
    }
    out.print("\n");
    printThreadBlocker(jt);
    out.print("    Java stack frames: ");
    printJavaStackFrameInfo(jt);
    out.print("\n");
}
Also used : JavaField(com.ibm.dtfj.java.JavaField) JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) StateToString(com.ibm.jvm.dtfjview.commands.helpers.StateToString)

Aggregations

JavaClass (com.ibm.dtfj.java.JavaClass)70 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)40 JavaObject (com.ibm.dtfj.java.JavaObject)39 Iterator (java.util.Iterator)33 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)23 CorruptData (com.ibm.dtfj.image.CorruptData)11 ArrayList (java.util.ArrayList)10 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)9 ImagePointer (com.ibm.dtfj.image.ImagePointer)9 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)9 CorruptData (com.ibm.dtfj.image.j9.CorruptData)8 JavaReference (com.ibm.dtfj.java.JavaReference)8 JavaField (com.ibm.dtfj.java.JavaField)6 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)6 LongEnumeration (com.ibm.dtfj.phd.util.LongEnumeration)5 JavaMethod (com.ibm.dtfj.java.JavaMethod)4 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)4 J9Object (com.ibm.j9ddr.vm29.structure.J9Object)4 LongListReferenceIterator (com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator)4 ReferenceIterator (com.ibm.jvm.dtfjview.heapdump.ReferenceIterator)4