Search in sources :

Example 1 with CorruptData

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

the class InfoThreadCommand method getMonitors.

@SuppressWarnings("rawtypes")
private void getMonitors(JavaRuntime jr) {
    int corruptThreadCount = 0;
    int corruptMonitorCount = 0;
    Iterator itMonitor = jr.getMonitors();
    while (itMonitor.hasNext()) {
        Object obj = itMonitor.next();
        if (obj instanceof CorruptData) {
            corruptMonitorCount++;
            continue;
        }
        JavaMonitor jm = (JavaMonitor) obj;
        Iterator itEnterWaiter = jm.getEnterWaiters();
        while (itEnterWaiter.hasNext()) {
            obj = itEnterWaiter.next();
            if (obj instanceof CorruptData) {
                corruptThreadCount++;
                continue;
            }
            JavaThread jt = (JavaThread) obj;
            monitors.put(jt, new MonitorState(jm, MonitorState.WAITING_TO_ENTER));
        }
        if (corruptThreadCount > 0) {
            String msg = String.format("Warning : %d corrupt thread(s) were found waiting to enter monitor %s", corruptThreadCount, getMonitorName(jm));
            logger.fine(msg);
        }
        corruptThreadCount = 0;
        Iterator itNotifyWaiter = jm.getNotifyWaiters();
        while (itNotifyWaiter.hasNext()) {
            obj = itNotifyWaiter.next();
            if (obj instanceof CorruptData) {
                corruptThreadCount++;
                continue;
            }
            JavaThread jt = (JavaThread) obj;
            monitors.put(jt, new MonitorState(jm, MonitorState.WAITING_TO_BE_NOTIFIED_ON));
        }
        if (corruptThreadCount > 0) {
            String msg = String.format("Warning : %d corrupt thread(s) were found waiting to be notified on monitor %s", corruptThreadCount, getMonitorName(jm));
            logger.fine(msg);
        }
    }
    if (corruptMonitorCount > 0) {
        String msg = String.format("Warning : %d corrupt monitor(s) were found", corruptMonitorCount);
        logger.fine(msg);
    }
}
Also used : MonitorState(com.ibm.jvm.dtfjview.commands.helpers.MonitorState) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) StateToString(com.ibm.jvm.dtfjview.commands.helpers.StateToString) JavaMonitor(com.ibm.dtfj.java.JavaMonitor)

Example 2 with CorruptData

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

the class InfoThreadCommand method printJavaStackFrameInfo.

private void printJavaStackFrameInfo(JavaThread jt) {
    Iterator itStackFrame;
    JavaStackFrame jsf;
    JavaLocation jl;
    itStackFrame = jt.getStackFrames();
    if (!itStackFrame.hasNext()) {
        out.print("<no frames to print>\n");
        return;
    } else {
        out.print("\n");
    }
    while (itStackFrame.hasNext()) {
        // this iterator can contain JavaStackFrame or CorruptData objects
        Object next = itStackFrame.next();
        if (next instanceof CorruptData) {
            out.print("     " + Exceptions.getCorruptDataExceptionString() + "\n");
            return;
        } else {
            jsf = (JavaStackFrame) next;
        }
        try {
            jl = jsf.getLocation();
        } catch (CorruptDataException e) {
            out.print("     " + Exceptions.getCorruptDataExceptionString() + "\n");
            logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
            return;
        }
        out.print("     bp: ");
        try {
            out.print(toAdjustedHex(jsf.getBasePointer().getAddress()));
        } catch (CorruptDataException e) {
            // jsf.getBasePointer() can't throw DataUnavailable, so we don't know if this is really
            // a corruption. Log the exception but revert to issuing a DataUnavailable message.
            out.print(Exceptions.getDataUnavailableString());
            logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
        }
        out.print("  method: ");
        try {
            String signature = null;
            try {
                signature = jl.getMethod().getSignature();
            } catch (CorruptDataException e) {
                // jl.getMethod() can't throw DataUnavailable, so we don't know if this is really a
                // corruption.  I don't think we need to be pedantic and insert 'not available' where
                // the return type and the parameter types would be. Just print class name and method.
                logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
            }
            if (signature == null) {
                out.print(jl.getMethod().getDeclaringClass().getName() + "." + jl.getMethod().getName());
            } else {
                out.print(Utils.getReturnValueName(signature) + " " + jl.getMethod().getDeclaringClass().getName() + "." + jl.getMethod().getName() + Utils.getMethodSignatureName(signature));
            }
        } 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);
        }
        // Assume the method is a java method in case of corrupt data.
        boolean isNative = false;
        try {
            isNative = Modifier.isNative(jl.getMethod().getModifiers());
        } catch (CorruptDataException e) {
            logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
        }
        if (!isNative) {
            out.print("  source: ");
            try {
                out.print(jl.getFilename());
            } catch (DataUnavailable d) {
                out.print(Exceptions.getDataUnavailableString());
                logger.log(Level.FINEST, Exceptions.getDataUnavailableString(), d);
            } catch (CorruptDataException e) {
                out.print(Exceptions.getCorruptDataExceptionString());
                logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
            }
            out.print(":");
            try {
                out.print(Integer.toString(jl.getLineNumber()));
            } catch (DataUnavailable d) {
                out.print(Exceptions.getDataUnavailableString());
                logger.log(Level.FINE, Exceptions.getDataUnavailableString(), d);
            } catch (CorruptDataException e) {
                out.print(Exceptions.getCorruptDataExceptionString());
                logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
            }
        } else {
            out.print("  (Native Method)");
        }
        out.print("\n      objects:");
        Iterator itObjectRefs = jsf.getHeapRoots();
        if (!itObjectRefs.hasNext()) {
            out.print(" <no objects in this frame>");
        }
        while (itObjectRefs.hasNext()) {
            Object nextRef = itObjectRefs.next();
            if (nextRef instanceof CorruptData) {
                out.print(Exceptions.getCorruptDataExceptionString() + "\n");
                // give up on this frame
                break;
            } else {
                JavaReference jr = (JavaReference) nextRef;
                try {
                    if (jr.isObjectReference()) {
                        JavaObject target = (JavaObject) (jr.getTarget());
                        out.print(" " + Utils.toHex(target.getID().getAddress()));
                    }
                } catch (DataUnavailable d) {
                    out.print(Exceptions.getDataUnavailableString());
                    logger.log(Level.FINEST, Exceptions.getDataUnavailableString(), d);
                } catch (CorruptDataException e) {
                    out.print(Exceptions.getCorruptDataExceptionString());
                    logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
                } catch (NullPointerException n) {
                    out.print(Exceptions.getDataUnavailableString());
                    logger.log(Level.FINEST, Exceptions.getDataUnavailableString(), n);
                }
            }
        }
        out.print("\n");
    }
}
Also used : JavaReference(com.ibm.dtfj.java.JavaReference) JavaLocation(com.ibm.dtfj.java.JavaLocation) JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) JavaStackFrame(com.ibm.dtfj.java.JavaStackFrame) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) StateToString(com.ibm.jvm.dtfjview.commands.helpers.StateToString)

Example 3 with CorruptData

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

the class InfoThreadCommand method getJavaThreads.

private Map getJavaThreads(String id) {
    Map threads = new HashMap();
    ManagedRuntime mr = ctx.getRuntime();
    if (mr instanceof JavaRuntime) {
        JavaRuntime jr = (JavaRuntime) mr;
        Iterator itThread = jr.getThreads();
        while (itThread.hasNext()) {
            Object next = itThread.next();
            // skip any corrupt threads
            if (next instanceof CorruptData)
                continue;
            JavaThread jt = (JavaThread) next;
            // Obtain the native thread ID for this thread, and for zOS also obtain the TCB
            String currentTID = null;
            String currentTCB = null;
            try {
                ImageThread it = jt.getImageThread();
                currentTID = it.getID();
                if (_is_zOS) {
                    currentTCB = it.getProperties().getProperty("TCB");
                }
            } catch (DTFJException e) {
            // Continue with what we have obtained so far
            }
            if (null == id) {
                // save all orphaned java threads in a list within the hashmap
                if (null == currentTID) {
                    if (threads.containsKey(null)) {
                        ArrayList ta = (ArrayList) threads.get(null);
                        ta.add(new ThreadData(jt, jr));
                    } else {
                        ArrayList ta = new ArrayList(1);
                        ta.add(new ThreadData(jt, jr));
                        threads.put(null, ta);
                    }
                } else {
                    threads.put(currentTID, new ThreadData(jt, jr));
                }
            } else if (id.equalsIgnoreCase(currentTID) || id.equalsIgnoreCase(currentTCB)) {
                // We just want the specific Java thread that matches the native thread ID or zOS TCB
                threads.put(currentTID, new ThreadData(jt, jr));
            }
        }
    }
    return threads;
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) HashMap(java.util.HashMap) DTFJException(com.ibm.dtfj.image.DTFJException) ArrayList(java.util.ArrayList) StateToString(com.ibm.jvm.dtfjview.commands.helpers.StateToString) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) ImageThread(com.ibm.dtfj.image.ImageThread) HashMap(java.util.HashMap) Map(java.util.Map) ManagedRuntime(com.ibm.dtfj.runtime.ManagedRuntime) ThreadData(com.ibm.jvm.dtfjview.commands.helpers.ThreadData)

Example 4 with CorruptData

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

the class XKCommand method printSymbol.

private boolean printSymbol(long pointer, long diff, int pointerSize) {
    ImageProcess ip = ctx.getProcess();
    Iterator itModule;
    try {
        itModule = ip.getLibraries();
    } catch (CorruptDataException e) {
        // FIXME
        itModule = null;
    } catch (DataUnavailable e) {
        // FIXME
        itModule = null;
    }
    while (null != itModule && itModule.hasNext()) {
        ImageModule im = (ImageModule) itModule.next();
        Iterator itImageSection = im.getSections();
        while (itImageSection.hasNext()) {
            ImageSection is = (ImageSection) itImageSection.next();
            long startAddr = is.getBaseAddress().getAddress();
            long endAddr = startAddr + is.getSize();
            if (pointer >= startAddr && pointer < endAddr) {
                /* can we find a matching symbol? */
                long maxDifference = pointer - startAddr;
                ImageSymbol bestSymbol = null;
                for (Iterator iter = im.getSymbols(); iter.hasNext(); ) {
                    Object next = iter.next();
                    if (next instanceof CorruptData)
                        continue;
                    ImageSymbol symbol = (ImageSymbol) next;
                    long symbolAddress = symbol.getAddress().getAddress();
                    if (symbolAddress <= pointer && pointer - symbolAddress < maxDifference) {
                        maxDifference = pointer - symbolAddress;
                        bestSymbol = symbol;
                    }
                }
                try {
                    out.print(im.getName());
                } catch (CorruptDataException e) {
                    out.print(Exceptions.getCorruptDataExceptionString());
                }
                out.print("::");
                if (bestSymbol == null) {
                    out.print(is.getName());
                } else {
                    out.print(bestSymbol.getName());
                }
                out.print("+");
                out.print(Long.toString(maxDifference));
                // trying to find it elsewhere in the address space
                return true;
            }
        }
    }
    return false;
}
Also used : ImageSymbol(com.ibm.dtfj.image.ImageSymbol) ImageProcess(com.ibm.dtfj.image.ImageProcess) Iterator(java.util.Iterator) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) ImageSection(com.ibm.dtfj.image.ImageSection) CorruptData(com.ibm.dtfj.image.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) ImageModule(com.ibm.dtfj.image.ImageModule)

Example 5 with CorruptData

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

the class InfoThreadCommand method printThreadSummary.

private void printThreadSummary(ImageProcess ip) {
    // Prints a summary list of native thread IDs
    int count = 0;
    Iterator itThread = ip.getThreads();
    while (itThread.hasNext()) {
        Object next = itThread.next();
        if (next instanceof CorruptData)
            continue;
        ImageThread it = (ImageThread) next;
        if (count % 8 == 0) {
            if (0 == count)
                out.print("\n\nNative thread IDs for current process:");
            out.print("\n ");
        }
        try {
            out.print(Utils.padWithSpaces(it.getID(), 8));
        } catch (CorruptDataException e) {
            out.print(Exceptions.getCorruptDataExceptionString());
        }
        count++;
    }
    out.print("\n");
}
Also used : Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) ImageThread(com.ibm.dtfj.image.ImageThread) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Aggregations

CorruptData (com.ibm.dtfj.image.CorruptData)68 JavaObject (com.ibm.dtfj.java.JavaObject)43 Iterator (java.util.Iterator)36 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)29 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)19 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)15 JavaClass (com.ibm.dtfj.java.JavaClass)11 JavaReference (com.ibm.dtfj.java.JavaReference)10 ImageProcess (com.ibm.dtfj.image.ImageProcess)9 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)7 LongListReferenceIterator (com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator)7 ReferenceIterator (com.ibm.jvm.dtfjview.heapdump.ReferenceIterator)7 ImageSection (com.ibm.dtfj.image.ImageSection)6 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)6 JavaHeap (com.ibm.dtfj.java.JavaHeap)6 J9Object (com.ibm.j9ddr.vm29.structure.J9Object)6 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)5 ImageThread (com.ibm.dtfj.image.ImageThread)5 JavaThread (com.ibm.dtfj.java.JavaThread)5 J9DDRImageSection (com.ibm.j9ddr.view.dtfj.image.J9DDRImageSection)5