Search in sources :

Example 21 with JavaObject

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

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

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

the class InfoLockCommand method showJavaUtilConcurrentLocks.

private void showJavaUtilConcurrentLocks() {
    // A map of lock objects and their waiting threads.
    Map locksToThreads = new HashMap();
    JavaRuntime jr = ctx.getRuntime();
    Iterator itThread = jr.getThreads();
    while (itThread.hasNext()) {
        try {
            Object o = itThread.next();
            if (!(o instanceof JavaThread)) {
                continue;
            }
            JavaThread jt = (JavaThread) o;
            if ((jt.getState() & JavaThread.STATE_PARKED) != 0) {
                JavaObject lock = jt.getBlockingObject();
                if (lock != null) {
                    List parkedList = (List) locksToThreads.get(lock);
                    if (parkedList == null) {
                        parkedList = new LinkedList();
                        locksToThreads.put(lock, parkedList);
                    }
                    parkedList.add(jt);
                }
            }
        } catch (CorruptDataException cde) {
            out.println("\nwarning, corrupt data encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getCorruptDataExceptionString(), cde);
        } catch (DataUnavailable du) {
            out.println("\nwarning, data unavailable encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getDataUnavailableString(), du);
        }
    }
    out.println("\njava.util.concurrent locks in use...");
    if (locksToThreads.size() == 0) {
        out.println("\t...None.");
        out.println();
    }
    for (Object e : locksToThreads.entrySet()) {
        try {
            Map.Entry entry = (Map.Entry) e;
            JavaObject lock = (JavaObject) entry.getKey();
            List threads = (List) entry.getValue();
            String threadName = "<unowned>";
            JavaThread lockOwnerThread = Utils.getParkBlockerOwner(lock, ctx.getRuntime());
            if (lockOwnerThread != null) {
                threadName = lockOwnerThread.getName();
            } else {
                // If the owning thread has ended we won't find the JavaThread
                // We can still get the owning thread name from the java.lang.Thread object itself.
                JavaObject lockOwnerObj = Utils.getParkBlockerOwnerObject(lock, ctx.getRuntime());
                if (lockOwnerObj != null) {
                    threadName = Utils.getThreadNameFromObject(lockOwnerObj, ctx.getRuntime(), out);
                } else {
                    threadName = "<unknown>";
                }
            }
            if (threads != null && threads.size() > 0) {
                String lockID = Long.toHexString(lock.getID().getAddress());
                ImageThread imageThread = (lockOwnerThread != null ? lockOwnerThread.getImageThread() : null);
                out.println(lock.getJavaClass().getName() + "@0x" + lockID + "\n\tlocked by java thread id: " + ((imageThread != null) ? imageThread.getID() : "<null>") + " name: " + (threadName));
                for (Object t : threads) {
                    JavaThread waiter = (JavaThread) t;
                    out.println("\twaiting thread id: " + waiter.getImageThread().getID() + " name: " + waiter.getName());
                }
            }
        } catch (CorruptDataException cde) {
            out.println("\nwarning, corrupt data encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getCorruptDataExceptionString(), cde);
        } catch (MemoryAccessException ma) {
            out.println("\nwarning, memory access error encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getMemoryAccessExceptionString(), ma);
        } catch (DataUnavailable du) {
            out.println("\nwarning, data unavailable encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getDataUnavailableString(), du);
        }
    }
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) HashMap(java.util.HashMap) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) LinkedList(java.util.LinkedList) JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) JavaObject(com.ibm.dtfj.java.JavaObject) LinkedList(java.util.LinkedList) List(java.util.List) ImageThread(com.ibm.dtfj.image.ImageThread) HashMap(java.util.HashMap) Map(java.util.Map) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 24 with JavaObject

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

use of com.ibm.dtfj.java.JavaObject 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)

Aggregations

JavaObject (com.ibm.dtfj.java.JavaObject)70 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)47 Iterator (java.util.Iterator)35 JavaClass (com.ibm.dtfj.java.JavaClass)31 CorruptData (com.ibm.dtfj.image.CorruptData)19 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)17 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)14 JavaReference (com.ibm.dtfj.java.JavaReference)9 JavaThread (com.ibm.dtfj.java.JavaThread)9 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)8 JavaField (com.ibm.dtfj.java.JavaField)7 ImagePointer (com.ibm.dtfj.image.ImagePointer)6 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)6 J9Object (com.ibm.j9ddr.vm29.structure.J9Object)6 CorruptJavaObject (com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject)6 CorruptData (com.ibm.dtfj.image.j9.CorruptData)5 LongEnumeration (com.ibm.dtfj.phd.util.LongEnumeration)5 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)5 LongListReferenceIterator (com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator)5 ReferenceIterator (com.ibm.jvm.dtfjview.heapdump.ReferenceIterator)5