Search in sources :

Example 16 with JavaObject

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

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

Example 18 with JavaObject

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

the class InfoThreadCommand method printThreadBlocker.

private void printThreadBlocker(JavaThread jt) {
    try {
        if ((jt.getState() & JavaThread.STATE_PARKED) != 0) {
            out.print("      parked on: ");
            // java.util.concurrent locks
            if (jt.getBlockingObject() == null) {
                out.print("<unknown>");
            } else {
                JavaObject jo = jt.getBlockingObject();
                String lockID = Long.toHexString(jo.getID().getAddress());
                out.print(jo.getJavaClass().getName() + "@0x" + lockID);
                String ownerThreadName = "<unknown>";
                String ownerThreadID = "<null>";
                out.print(" owner name: ");
                JavaThread lockOwnerThread = Utils.getParkBlockerOwner(jo, ctx.getRuntime());
                if (lockOwnerThread != null) {
                    ownerThreadName = lockOwnerThread.getName();
                    if (lockOwnerThread.getImageThread() != null) {
                        ownerThreadID = lockOwnerThread.getImageThread().getID();
                    }
                } 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.
                    // We won't get a thread id.
                    JavaObject lockOwnerObj = Utils.getParkBlockerOwnerObject(jo, ctx.getRuntime());
                    if (lockOwnerObj != null) {
                        ownerThreadName = Utils.getThreadNameFromObject(lockOwnerObj, ctx.getRuntime(), out);
                    }
                }
                out.print("\"" + ownerThreadName + "\"");
                out.print(" owner id: " + ownerThreadID);
            }
            out.print("\n");
        } else if ((jt.getState() & JavaThread.STATE_IN_OBJECT_WAIT) != 0) {
            out.print("      waiting to be notified on: ");
        } else if ((jt.getState() & JavaThread.STATE_BLOCKED_ON_MONITOR_ENTER) != 0) {
            out.print("      waiting to enter: ");
        }
        if ((jt.getState() & JavaThread.STATE_IN_OBJECT_WAIT) != 0 || (jt.getState() & JavaThread.STATE_BLOCKED_ON_MONITOR_ENTER) != 0) {
            // java monitors
            MonitorState ms = (MonitorState) monitors.get(jt);
            if (ms == null) {
                out.println("<monitor information not available>");
            } else {
                JavaObject jo = ms.getMonitor().getObject();
                if (null == jo) {
                    // working with a raw monitor
                    String name = ms.getMonitor().getName();
                    if (name.equals("")) {
                        name = "<unnamed>";
                    }
                    out.print("\"" + name + "\"");
                    out.print(" with ID ");
                    out.print(Utils.toHex(ms.getMonitor().getID().getAddress()));
                } else {
                    // working with a Java monitor
                    String lockID = Long.toHexString(jo.getID().getAddress());
                    out.print(jo.getJavaClass().getName() + "@0x" + lockID);
                }
                out.print(" owner name: ");
                if (ms.getMonitor().getOwner() != null) {
                    out.print("\"" + ms.getMonitor().getOwner().getName() + "\"");
                    if (ms.getMonitor().getOwner().getImageThread() != null) {
                        out.print(" owner id: " + ms.getMonitor().getOwner().getImageThread().getID());
                    }
                } else {
                    out.print("<unowned>");
                }
                out.print("\n");
            }
        }
    } catch (CorruptDataException cde) {
        out.print(Exceptions.getCorruptDataExceptionString());
        logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), cde);
    } catch (DataUnavailable e) {
        out.print(Exceptions.getDataUnavailableString());
        logger.log(Level.FINEST, Exceptions.getDataUnavailableString(), e);
    } catch (MemoryAccessException e) {
        out.print(Exceptions.getMemoryAccessExceptionString());
        logger.log(Level.FINEST, Exceptions.getMemoryAccessExceptionString(), e);
    }
}
Also used : MonitorState(com.ibm.jvm.dtfjview.commands.helpers.MonitorState) JavaObject(com.ibm.dtfj.java.JavaObject) JavaThread(com.ibm.dtfj.java.JavaThread) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) StateToString(com.ibm.jvm.dtfjview.commands.helpers.StateToString) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 19 with JavaObject

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

the class Utils method getParkBlockerOwner.

/* Find the JavaThread that owns a blocking object by finding the java/lang/Thread
	 * JavaObject of the owner and then looking through the list of JavaThreads to
	 * see who that belongs to. 
	 */
public static JavaThread getParkBlockerOwner(JavaObject blocker, JavaRuntime r) throws CorruptDataException, MemoryAccessException {
    JavaObject ownerObj = getParkBlockerOwnerObject(blocker, r);
    if (ownerObj == null) {
        return null;
    }
    Iterator threads = r.getThreads();
    while (threads.hasNext()) {
        Object lObj = threads.next();
        if (lObj instanceof JavaThread) {
            JavaThread thread = (JavaThread) lObj;
            if (ownerObj.equals(thread.getObject())) {
                return thread;
            }
        }
    }
    return null;
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) JavaObject(com.ibm.dtfj.java.JavaObject)

Example 20 with JavaObject

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

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