Search in sources :

Example 61 with JavaClass

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

the class ClassOutput method printFields.

public static void printFields(JavaObject jo, JavaClass jc, JavaRuntime jr, PrintStream out) {
    boolean array;
    try {
        array = jo.isArray();
    } catch (CorruptDataException e) {
        out.print("\t   <cannot determine if above object is array (" + Exceptions.getCorruptDataExceptionString() + "); " + "we will assume it is not an array>\n");
        array = false;
    }
    if (array) {
        String componentType;
        int arraySize;
        try {
            componentType = jc.getComponentType().getName();
        } catch (CorruptDataException e) {
            out.print("\t   <cannot determine what type of array this is (" + Exceptions.getCorruptDataExceptionString() + ")>\n");
            return;
        }
        try {
            arraySize = jo.getArraySize();
        } catch (CorruptDataException e) {
            out.print("\t   <cannot determine the size of the array (" + Exceptions.getCorruptDataExceptionString() + ")>\n");
            return;
        }
        Object dst = null;
        if (componentType.equals("boolean")) {
            dst = new boolean[arraySize];
        } else if (componentType.equals("byte")) {
            dst = new byte[arraySize];
        } else if (componentType.equals("char")) {
            dst = new char[arraySize];
        } else if (componentType.equals("short")) {
            dst = new short[arraySize];
        } else if (componentType.equals("int")) {
            dst = new int[arraySize];
        } else if (componentType.equals("long")) {
            dst = new long[arraySize];
        } else if (componentType.equals("float")) {
            dst = new float[arraySize];
        } else if (componentType.equals("double")) {
            dst = new double[arraySize];
        } else {
            dst = new JavaObject[arraySize];
        }
        try {
            jo.arraycopy(0, dst, 0, arraySize);
        } catch (CorruptDataException e) {
            out.print("\t   <cannot copy data from the array (" + Exceptions.getCorruptDataExceptionString() + ")>\n");
            return;
        } catch (MemoryAccessException e) {
            out.print("\t   <cannot copy data from the array (" + Exceptions.getMemoryAccessExceptionString() + ")>\n");
            return;
        } catch (UnsupportedOperationException e) {
            // Some artefacts e.g. phd do not support arraycopy so just put out what we can
            out.print("\t    This is an array of size " + arraySize + " elements\n");
            return;
        }
        for (int i = 0; i < arraySize; i++) {
            out.print("\t   " + i + ":\t");
            if (componentType.equals("boolean")) {
                out.print(Utils.getVal(new Boolean(((boolean[]) dst)[i])));
            } else if (componentType.equals("byte")) {
                out.print(Utils.getVal(new Byte(((byte[]) dst)[i])));
            } else if (componentType.equals("char")) {
                out.print(Utils.getVal(new Character(((char[]) dst)[i])));
            } else if (componentType.equals("short")) {
                out.print(Utils.getVal(new Short(((short[]) dst)[i])));
            } else if (componentType.equals("int")) {
                out.print(Utils.getVal(new Integer(((int[]) dst)[i])));
            } else if (componentType.equals("long")) {
                out.print(Utils.getVal(new Long(((long[]) dst)[i])));
            } else if (componentType.equals("float")) {
                out.print(Utils.getVal(new Float(((float[]) dst)[i])));
            } else if (componentType.equals("double")) {
                out.print(Utils.getVal(new Double(((double[]) dst)[i])));
            } else {
                out.print(Utils.getVal(((JavaObject[]) dst)[i]));
            }
            out.print("\n");
        }
    } else {
        JavaClass initialJC = jc;
        List<JavaClass> classList = new ArrayList<JavaClass>();
        while (jc != null) {
            classList.add(jc);
            try {
                jc = jc.getSuperclass();
            } catch (CorruptDataException d) {
                jc = null;
            }
        }
        for (int i = (classList.size() - 1); i >= 0; i--) {
            jc = classList.get(i);
            Iterator itField = jc.getDeclaredFields();
            if (itField.hasNext()) {
                if (jc.equals(initialJC)) {
                    out.print("\t   declared fields:\n");
                } else {
                    out.print("\t   fields inherited from \"");
                    try {
                        out.print(jc.getName() + "\":\n");
                    } catch (CorruptDataException d) {
                        out.print(Exceptions.getCorruptDataExceptionString());
                    }
                }
            }
            while (itField.hasNext()) {
                JavaField jf = (JavaField) itField.next();
                boolean isStatic;
                try {
                    isStatic = Modifier.isStatic(jf.getModifiers());
                } catch (CorruptDataException e) {
                    out.print("\t   <error while getting modifier for field \"");
                    try {
                        out.print(jf.getName());
                    } catch (CorruptDataException d) {
                        out.print(Exceptions.getCorruptDataExceptionString());
                    }
                    out.print("\", " + Exceptions.getCorruptDataExceptionString() + ">");
                    isStatic = true;
                }
                if (!isStatic) {
                    printNonStaticFieldData(jo, jf, out);
                }
            }
        }
    }
    out.print("\n");
}
Also used : ArrayList(java.util.ArrayList) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) JavaField(com.ibm.dtfj.java.JavaField) JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 62 with JavaClass

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

the class InfoClassCommand method printAllRuntimeClasses.

private void printAllRuntimeClasses(Comparator<JavaClass> sortOrder) {
    JavaRuntime jr = ctx.getRuntime();
    Collection<JavaClass> javaClasses = getRuntimeClasses(jr);
    long objCount = 0;
    long totalSize = 0;
    Iterator<JavaClass> itClass;
    if (sortOrder == null) {
        itClass = javaClasses.iterator();
    } else {
        List<JavaClass> sortedList = new LinkedList<JavaClass>();
        Iterator<JavaClass> itr = javaClasses.iterator();
        while (itr.hasNext()) {
            sortedList.add(itr.next());
        }
        Collections.sort(sortedList, sortOrder);
        itClass = sortedList.iterator();
    }
    if (itClass.hasNext()) {
        printClassListHeader();
    } else {
        out.print("\n\t No information found for loaded classes\n");
    }
    while (itClass.hasNext()) {
        JavaClass jc = itClass.next();
        ClassStatistics d = getClassStatisticsFor(jr, jc);
        totalSize += d.getSize();
        objCount += d.getCount();
        printOneClass(jc, d);
    }
    out.print("\n");
    out.print("\t Total number of objects: " + objCount + "\n");
    out.print("\t Total size of objects: " + totalSize + "\n");
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) JavaClass(com.ibm.dtfj.java.JavaClass) LinkedList(java.util.LinkedList)

Example 63 with JavaClass

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

the class InfoClassCommand method cacheRuntimeClasses.

/**
 * Pre-populates the classInstanceCounts map with just classes, and empty ClassStatistics objects.
 * The key-set of classInstanceCounts.get(someRuntime) can be then treated as a cache of all classes for that runtime,
 * eliminating the need to iterate over all class loaders (see getRuntimeClasses()).
 * @param jr
 * @param errOut
 * @return
 */
private void cacheRuntimeClasses() {
    classInstanceCounts = new HashMap<JavaRuntime, Map<JavaClass, ClassStatistics>>();
    long corruptClassCount = 0;
    Map<JavaClass, ClassStatistics> classesOfThisRuntime = new HashMap<JavaClass, ClassStatistics>();
    JavaRuntime runtime = ctx.getRuntime();
    classInstanceCounts.put(runtime, classesOfThisRuntime);
    Iterator itClassLoader = runtime.getJavaClassLoaders();
    while (itClassLoader.hasNext()) {
        JavaClassLoader jcl = (JavaClassLoader) itClassLoader.next();
        Iterator itClass = jcl.getDefinedClasses();
        while (itClass.hasNext()) {
            Object obj = itClass.next();
            if (obj instanceof JavaClass) {
                // check that a cast can be made to JavaClass
                classesOfThisRuntime.put((JavaClass) obj, new ClassStatistics());
            } else {
                corruptClassCount++;
            }
        }
    }
    if (corruptClassCount > 0) {
        out.print("Warning, found " + corruptClassCount + " corrupt classes during classloader walk\n");
    }
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) JavaClass(com.ibm.dtfj.java.JavaClass) JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) HashMap(java.util.HashMap) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 64 with JavaClass

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

the class InfoClassCommand method printSingleRuntimeClassInfo.

private void printSingleRuntimeClassInfo(String className) {
    JavaRuntime jr = ctx.getRuntime();
    Long objAddress = Utils.longFromStringWithPrefix(className);
    JavaClass[] classes = null;
    if (objAddress != null) {
        JavaClass jc = Utils.getClassGivenAddress(objAddress.longValue(), jr);
        if (jc != null) {
            classes = new JavaClass[1];
            classes[0] = jc;
        }
    } else {
        classes = Utils.getClassGivenName(className, jr, out);
    }
    // still be an array type or it might not exist
    if (null == classes || classes.length == 0) {
        out.print("\t  could not find class with name \"" + className + "\"\n\n");
    } else if (classes.length == 1) {
        JavaClass jc = classes[0];
        printClassDetails(jr, className, jc);
    } else {
        out.println("name = " + className + " found " + classes.length + " on different class loaders");
        for (int i = 0; i < classes.length; i++) {
            JavaClass jc = classes[i];
            ClassOutput.printRuntimeClassAndLoader(jc, out);
        }
        out.println("Use info class with the class ID to print out information on a specific class.");
        out.println("For example: info class 0x" + Long.toHexString(classes[0].getID().getAddress()));
    }
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) JavaClass(com.ibm.dtfj.java.JavaClass)

Example 65 with JavaClass

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

the class WhatisCommand method checkMethodInRange.

private void checkMethodInRange(Iterator objects, long address) {
    while (objects.hasNext()) {
        JavaObject jObject = (JavaObject) objects.next();
        JavaClass jClass;
        try {
            jClass = jObject.getJavaClass();
        } catch (CorruptDataException cde) {
            // go to the next iteration
            continue;
        }
        Iterator methods = jClass.getDeclaredMethods();
        while (methods.hasNext()) {
            JavaMethod jMethod = (JavaMethod) methods.next();
            Iterator bytecodeSections = jMethod.getBytecodeSections();
            Iterator compiledSections = jMethod.getCompiledSections();
            if (isWithinImageSections(bytecodeSections, jMethod, false, address)) {
                // found it, we are done
                return;
            }
            if (isWithinImageSections(compiledSections, jMethod, true, address)) {
                // found it, we are done
                return;
            }
        }
    }
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) JavaMethod(com.ibm.dtfj.java.JavaMethod) 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