Search in sources :

Example 16 with JavaClass

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

the class Utils method getStringVal.

private static String getStringVal(JavaObject jo) {
    JavaClass jc;
    try {
        jc = jo.getJavaClass();
    } catch (CorruptDataException e) {
        return "<cannot get String class from String object (" + Exceptions.getCorruptDataExceptionString() + ")>";
    }
    Iterator itJavaField = jc.getDeclaredFields();
    JavaField jf = null;
    while (itJavaField.hasNext()) {
        jf = (JavaField) itJavaField.next();
        try {
            if (jf.getSignature().equals("[C") && !Modifier.isStatic(jf.getModifiers()))
                break;
        } catch (CorruptDataException e) {
        // if we have an exception, do nothing and go onto the next field
        }
    }
    if (jf == null) {
        // empty field iterator (occurs e.g. when reading PHD heapdumps), can't get the char array
        return "<cannot get char array out of String>";
    }
    JavaObject charArray = null;
    try {
        charArray = (JavaObject) jf.get(jo);
    } catch (CorruptDataException e) {
        return "<cannot get char array out of String (" + Exceptions.getCorruptDataExceptionString() + ")>";
    } catch (MemoryAccessException e) {
        return "<cannot get char array out of String (" + Exceptions.getMemoryAccessExceptionString() + ")>";
    }
    int arraySize;
    try {
        arraySize = charArray.getArraySize();
    } catch (CorruptDataException e) {
        return "<cannot determine the size of the array (" + Exceptions.getCorruptDataExceptionString() + ")>";
    }
    char[] dst = new char[arraySize];
    try {
        charArray.arraycopy(0, dst, 0, arraySize);
    } catch (CorruptDataException e) {
        return "<cannot copy data from the array (" + Exceptions.getCorruptDataExceptionString() + ")>";
    } catch (MemoryAccessException e) {
        return "<cannot copy data from the array (" + Exceptions.getMemoryAccessExceptionString() + ")>";
    }
    return "\"" + Utils.getPrintable(new String(dst)) + "\"";
}
Also used : JavaField(com.ibm.dtfj.java.JavaField) JavaClass(com.ibm.dtfj.java.JavaClass) JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 17 with JavaClass

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

the class InfoClassCommand method printClassDetails.

private void printClassDetails(JavaRuntime jr, String className, JavaClass jc) {
    String spaces = "    ";
    String cdeInfo = "N/A (CorruptDataException occurred)";
    try {
        out.print("name = " + jc.getName());
    } catch (CorruptDataException dce) {
        out.print("name = " + cdeInfo);
    }
    out.print("\n\n\t");
    out.print("ID = " + Utils.toHex(jc.getID()));
    String superClassId;
    try {
        JavaClass superClass = jc.getSuperclass();
        if (null == superClass) {
            superClassId = "<no superclass>";
        } else {
            superClassId = Utils.toHex(superClass.getID());
        }
    } catch (CorruptDataException dce) {
        superClassId = cdeInfo;
    }
    out.print(spaces);
    out.print("superID = " + superClassId);
    // Omitting size of class because that might differ between instances (i.e. arrays)
    String classLoaderId;
    try {
        JavaClassLoader jClassLoader = jc.getClassLoader();
        JavaObject jo = jClassLoader.getObject();
        if (jo != null) {
            classLoaderId = Utils.toHex(jo.getID());
        } else {
            classLoaderId = "<data unavailable>";
        }
    } catch (CorruptDataException cde) {
        classLoaderId = cdeInfo;
    }
    out.print(spaces);
    out.print("\n\t");
    out.print("classLoader = " + classLoaderId);
    String modifiersInfo;
    try {
        modifiersInfo = Utils.getClassModifierString(jc);
    } catch (CorruptDataException cde) {
        modifiersInfo = cdeInfo;
    }
    out.print(spaces);
    out.print("modifiers: " + modifiersInfo);
    out.print("\n\n");
    ClassStatistics d = getClassStatisticsFor(jr, jc);
    out.print("\tnumber of instances:     " + d.getCount() + "\n");
    out.print("\ttotal size of instances on the heap: " + d.getSize() + " bytes");
    out.print("\n\n");
    printClassHierarchy(jc);
    out.print("\n");
    printFields(jc);
    out.print("\n");
    printMethods(jc);
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 18 with JavaClass

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

the class InfoClassCommand method countClassInstances.

private void countClassInstances() {
    JavaRuntime runtime = ctx.getRuntime();
    Map<JavaClass, ClassStatistics> thisRuntimeClasses = classInstanceCounts.get(runtime);
    final Collection<JavaClass> javaClasses = getRuntimeClasses(runtime);
    long corruptObjectCount = 0;
    long corruptClassCount = 0;
    long corruptClassNameCount = 0;
    Iterator itHeap = runtime.getHeaps();
    while (itHeap.hasNext()) {
        Object heap = itHeap.next();
        if (heap instanceof CorruptData) {
            out.println("[skipping corrupt heap]");
            continue;
        }
        JavaHeap jh = (JavaHeap) heap;
        Iterator itObject = jh.getObjects();
        // Walk through all objects in this heap, accumulating counts and total memory size by class
        while (itObject.hasNext()) {
            Object next = itObject.next();
            // JavaHeap, we don't attempt to count these as instances of known classes).
            if (next instanceof JavaObject) {
                JavaObject jo = (JavaObject) next;
                ClassStatistics stats = null;
                try {
                    // Check whether we found this class in the classloaders walk earlier
                    JavaClass jc = jo.getJavaClass();
                    if (javaClasses.contains(jc)) {
                        stats = thisRuntimeClasses.get(jc);
                    } else {
                        // Class not found in the classloaders, create a statistic for it now, and issue a warning message
                        stats = new ClassStatistics();
                        thisRuntimeClasses.put(jc, stats);
                        String classname;
                        try {
                            classname = jc.getName();
                            out.println("Warning, class: " + classname + " found when walking the heap was missing from classloader walk");
                        } catch (CorruptDataException cde) {
                            corruptClassNameCount++;
                        }
                    }
                    // Increment the statistic for objects of this class (accumulated count and size)
                    stats.incrementCount();
                    try {
                        stats.addToSize(jo.getSize());
                    } catch (CorruptDataException cde) {
                        // bad size, count object as corrupt
                        corruptObjectCount++;
                    }
                } catch (CorruptDataException cde) {
                    corruptClassCount++;
                }
            } else {
                corruptObjectCount++;
            }
        }
    }
    if (corruptObjectCount != 0) {
        out.println("Warning, found " + corruptObjectCount + " corrupt objects during heap walk");
    }
    if (corruptClassCount != 0) {
        out.println("Warning, found " + corruptClassCount + " corrupt class references during heap walk");
    }
    if (corruptClassNameCount != 0) {
        out.println("Warning, found " + corruptClassNameCount + " corrupt class names during heap walk");
    }
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) JavaHeap(com.ibm.dtfj.java.JavaHeap) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) JavaClass(com.ibm.dtfj.java.JavaClass) JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData)

Example 19 with JavaClass

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

the class JavaThread method getPriority.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaThread#getPriority()
	 */
public int getPriority() throws CorruptDataException {
    JavaObject theObject = getObject();
    if (null != theObject) {
        JavaClass threadClass = _javaLangThreadSuperclass();
        Iterator fields = threadClass.getDeclaredFields();
        while (fields.hasNext()) {
            JavaField oneField = (JavaField) fields.next();
            if (oneField.getName().equals("priority")) {
                try {
                    return oneField.getInt(theObject);
                } catch (MemoryAccessException e) {
                    throw new CorruptDataException(new CorruptData("unable to read memory for 'priority' field", null));
                }
            }
        }
        throw new CorruptDataException(new CorruptData("unable to find 'priority' field", null));
    } else {
        // TODO:  have a good exception for this sort of thing
        return -1;
    }
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) CorruptData(com.ibm.dtfj.image.j9.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 20 with JavaClass

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

the class PHDJavaRuntime method saveExtraObject.

private void saveExtraObject(final PHDJavaClassLoader boot, JavaObject jo) {
    if (jo != null) {
        long addr = jo.getID().getAddress();
        JavaClass cls;
        try {
            cls = boot.findClassUnique(jo.getJavaClass().getName());
        } catch (CorruptDataException e) {
            cls = null;
        }
        // Construct a dummy object with little information in case the object is not in the heap
        JavaObject jo2 = new PHDJavaObject.Builder(heaps.get(0), addr, cls, PHDJavaObject.NO_HASHCODE, -1).refsAsArray(NOREFS, 0).length(PHDJavaObject.UNKNOWN_TYPE).build();
        extraObjectsCache.put(addr, jo2);
    }
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

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