Search in sources :

Example 26 with CorruptDataException

use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.

the class PHDJavaObject method getSections.

public Iterator<ImageSection> getSections() {
    List<ImageSection> c = new ArrayList<ImageSection>();
    ImageSection s;
    try {
        s = new PHDImageSection("Object section", getID(), getSize());
    } catch (CorruptDataException e) {
        s = new PHDCorruptImageSection("Corrupt object section", getID());
    }
    c.add(s);
    return c.iterator();
}
Also used : ArrayList(java.util.ArrayList) ImageSection(com.ibm.dtfj.image.ImageSection) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 27 with CorruptDataException

use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.

the class InfoMemoryCommand method printAllMemoryCategories.

/**
 * Print out the memory categories in nice ASCII art tree similar to the ones in javacore.
 * @param out the PrintStream to write to.
 * @param memoryCategories the memory categories to write
 */
private void printAllMemoryCategories(PrintStream out, Iterator memoryCategories) {
    try {
        while (memoryCategories.hasNext()) {
            Object obj = memoryCategories.next();
            if (obj instanceof JavaRuntimeMemoryCategory) {
                JavaRuntimeMemoryCategory category = (JavaRuntimeMemoryCategory) obj;
                LinkedList<Integer> stack = new LinkedList<Integer>();
                int childCount = countPrintableChildren(category);
                stack.addLast(childCount);
                printCategory(category, stack, out);
            }
        }
    } catch (CorruptDataException cde) {
        out.println("Corrupt Data encountered walking memory categories");
        logger.log(Level.FINE, Exceptions.getCorruptDataExceptionString(), cde);
    }
}
Also used : JavaRuntimeMemoryCategory(com.ibm.dtfj.java.JavaRuntimeMemoryCategory) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) LinkedList(java.util.LinkedList)

Example 28 with CorruptDataException

use of com.ibm.dtfj.image.CorruptDataException 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 29 with CorruptDataException

use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.

the class InfoThreadCommand method printThreadInfo.

private boolean printThreadInfo(String id, Map threads) {
    Iterator itThread;
    ImageThread it;
    boolean found = false;
    itThread = ctx.getProcess().getThreads();
    while (itThread.hasNext()) {
        Object next = itThread.next();
        if (next instanceof CorruptData) {
            out.print("\n  <corrupt data>");
            continue;
        }
        it = (ImageThread) next;
        // Obtain the native thread ID for this thread, and for zOS also obtain the TCB
        String currentTID = null;
        String currentTCB = null;
        try {
            currentTID = it.getID();
            if (_is_zOS) {
                currentTCB = it.getProperties().getProperty("TCB");
            }
        } catch (CorruptDataException e) {
        // Continue with what we have obtained so far
        }
        // the requested native thread ID or zOS TCB, then go ahead and print out this thread.
        if (null == id || id.equalsIgnoreCase(currentTID) || id.equalsIgnoreCase(currentTCB)) {
            out.print("  thread id: ");
            out.print(currentTID);
            out.print("\n");
            printRegisters(it);
            out.print("   native stack sections:");
            out.print("\n");
            Iterator itStackSection = it.getStackSections();
            while (itStackSection.hasNext()) {
                Object nextStackSection = itStackSection.next();
                if (nextStackSection instanceof CorruptData) {
                    out.print("    " + Exceptions.getCorruptDataExceptionString() + "\n");
                    continue;
                }
                ImageSection is = (ImageSection) nextStackSection;
                printStackSection(is);
            }
            printStackFrameInfo(it);
            out.print("   properties:");
            out.print("\n");
            printProperties(it);
            out.print("   associated Java thread: ");
            ThreadData td = (ThreadData) threads.remove(currentTID);
            if (null != td) {
                out.print("\n");
                printJavaThreadInfo(td.getThread(), true);
            } else {
                out.print("<no associated Java thread>\n");
            }
            out.print("\n");
            found = true;
        }
    }
    return found;
}
Also used : Iterator(java.util.Iterator) ImageSection(com.ibm.dtfj.image.ImageSection) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) ImageThread(com.ibm.dtfj.image.ImageThread) StateToString(com.ibm.jvm.dtfjview.commands.helpers.StateToString) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) ThreadData(com.ibm.jvm.dtfjview.commands.helpers.ThreadData)

Example 30 with CorruptDataException

use of com.ibm.dtfj.image.CorruptDataException 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)

Aggregations

CorruptDataException (com.ibm.dtfj.image.CorruptDataException)124 JavaObject (com.ibm.dtfj.java.JavaObject)55 Iterator (java.util.Iterator)49 JavaClass (com.ibm.dtfj.java.JavaClass)41 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)39 CorruptData (com.ibm.dtfj.image.CorruptData)26 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)25 ImagePointer (com.ibm.dtfj.image.ImagePointer)19 CorruptData (com.ibm.dtfj.image.j9.CorruptData)17 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)14 ImageSection (com.ibm.dtfj.image.ImageSection)12 ImageThread (com.ibm.dtfj.image.ImageThread)12 JavaThread (com.ibm.dtfj.java.JavaThread)12 ArrayList (java.util.ArrayList)11 ImageProcess (com.ibm.dtfj.image.ImageProcess)9 JavaField (com.ibm.dtfj.java.JavaField)8 JavaReference (com.ibm.dtfj.java.JavaReference)8 LinkedList (java.util.LinkedList)8 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)7 JavaMethod (com.ibm.dtfj.java.JavaMethod)7