Search in sources :

Example 21 with JavaRuntime

use of com.ibm.dtfj.java.JavaRuntime 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 22 with JavaRuntime

use of com.ibm.dtfj.java.JavaRuntime 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 23 with JavaRuntime

use of com.ibm.dtfj.java.JavaRuntime 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 24 with JavaRuntime

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

the class InfoJitmCommand method showJITdMethods.

private void showJITdMethods() {
    JavaRuntime jr = ctx.getRuntime();
    Iterator itJavaClassLoader = jr.getJavaClassLoaders();
    while (itJavaClassLoader.hasNext()) {
        JavaClassLoader jcl = (JavaClassLoader) itJavaClassLoader.next();
        Iterator itJavaClass = jcl.getDefinedClasses();
        while (itJavaClass.hasNext()) {
            JavaClass jc = (JavaClass) itJavaClass.next();
            Iterator itJavaMethod = jc.getDeclaredMethods();
            String jcName;
            try {
                jcName = jc.getName();
            } catch (CorruptDataException e) {
                jcName = Exceptions.getCorruptDataExceptionString();
            }
            while (itJavaMethod.hasNext()) {
                JavaMethod jm = (JavaMethod) itJavaMethod.next();
                String name;
                String sig;
                try {
                    name = jm.getName();
                } catch (CorruptDataException e) {
                    name = Exceptions.getCorruptDataExceptionString();
                }
                try {
                    sig = jm.getSignature();
                } catch (CorruptDataException e) {
                    sig = Exceptions.getCorruptDataExceptionString();
                }
                if (jm.getCompiledSections().hasNext()) {
                    Iterator itImageSection = jm.getCompiledSections();
                    while (itImageSection.hasNext()) {
                        ImageSection is = (ImageSection) itImageSection.next();
                        long startAddr = is.getBaseAddress().getAddress();
                        long size = is.getSize();
                        long endAddr = startAddr + size;
                        out.print("\n\t" + "start=" + Utils.toHex(startAddr) + "  " + "end=" + Utils.toHex(endAddr) + "   " + jcName + "::" + name + sig);
                    }
                }
            }
        }
    }
    out.print("\n");
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) JavaMethod(com.ibm.dtfj.java.JavaMethod) ImageSection(com.ibm.dtfj.image.ImageSection) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 25 with JavaRuntime

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

the class InfoLockCommand method showSystemLocks.

private void showSystemLocks() {
    Vector vMonitorsWithLockedObjects = new Vector();
    JavaRuntime jRuntime = ctx.getRuntime();
    Iterator monitors = jRuntime.getMonitors();
    out.println("\nSystem locks...");
    while (monitors.hasNext()) {
        JavaMonitor jMonitor = (JavaMonitor) monitors.next();
        JavaObject jObject = jMonitor.getObject();
        try {
            String monitorName = jMonitor.getName().trim();
            if (monitorName.equalsIgnoreCase("")) {
                monitorName = "<un-named monitor>";
            }
            out.println("id: 0x" + jMonitor.getID() + " name: " + jMonitor.getName());
            JavaThread owner = jMonitor.getOwner();
            if (null != owner) {
                try {
                    out.println("\towner thread id: " + owner.getImageThread().getID() + " name: " + owner.getName());
                } catch (DataUnavailable e) {
                    out.println("\towner thread id: " + Exceptions.getDataUnavailableString());
                    logger.log(Level.FINE, Exceptions.getDataUnavailableString(), e);
                }
            }
            showWaiters(jMonitor);
        } catch (CorruptDataException cde) {
            out.println("\nwarning, corrupt data encountered during scan for system locks...");
        }
        if (null != jObject) {
            // Remember object monitors (flat or inflated) for later
            vMonitorsWithLockedObjects.add(jMonitor);
        }
    }
    showLockedObjects(vMonitorsWithLockedObjects);
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) Vector(java.util.Vector) JavaMonitor(com.ibm.dtfj.java.JavaMonitor)

Aggregations

JavaRuntime (com.ibm.dtfj.java.JavaRuntime)27 Iterator (java.util.Iterator)13 JavaObject (com.ibm.dtfj.java.JavaObject)10 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)8 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)8 ImageProcess (com.ibm.dtfj.image.ImageProcess)8 CorruptData (com.ibm.dtfj.image.CorruptData)7 JavaClass (com.ibm.dtfj.java.JavaClass)6 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)5 Image (com.ibm.dtfj.image.Image)5 JavaHeap (com.ibm.dtfj.java.JavaHeap)5 JavaThread (com.ibm.dtfj.java.JavaThread)5 File (java.io.File)4 HashMap (java.util.HashMap)4 ImageFactory (com.ibm.dtfj.image.ImageFactory)3 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)3 JavaMonitor (com.ibm.dtfj.java.JavaMonitor)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ImageSection (com.ibm.dtfj.image.ImageSection)2