Search in sources :

Example 1 with JavaLocation

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

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

the class JavaLocationComparator method testEquals.

// getAddress()
// getCompilationLevel()
// getFileName()
// getLineNumber()
// getMethod()
public void testEquals(Object ddrObject, Object jextractObject, int members) {
    JavaLocation ddrJavaLocation = (JavaLocation) ddrObject;
    JavaLocation jextractJavaLocation = (JavaLocation) jextractObject;
    // getAddress()
    if ((ADDRESS & members) != 0)
        new ImagePointerComparator().testComparatorEquals(ddrJavaLocation, jextractJavaLocation, "getAddress");
    // getCompilationLevel()
    if ((COMPILATION_LEVEL & members) != 0)
        testJavaEquals(ddrJavaLocation, jextractJavaLocation, "getCompilationLevel");
    // getFileName()
    if ((FILE_NAME & members) != 0)
        testJavaEquals(ddrJavaLocation, jextractJavaLocation, "getFilename");
    // getLineNumber
    if ((LINE_NUMBER & members) != 0)
        testJavaEquals(ddrJavaLocation, jextractJavaLocation, "getLineNumber");
    // getMethod
    if ((METHOD & members) != 0)
        new JavaMethodComparator().testComparatorEquals(ddrJavaLocation, jextractJavaLocation, "getMethod");
}
Also used : JavaLocation(com.ibm.dtfj.java.JavaLocation)

Example 3 with JavaLocation

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

the class JavaStackFrameTest method printStackTrace.

private void printStackTrace(JavaThread thread) throws CorruptDataException {
    Iterator<?> frames = thread.getStackFrames();
    int count = 0;
    while (frames.hasNext()) {
        Object o = frames.next();
        System.err.print(count + ":");
        if (o instanceof JavaStackFrame) {
            JavaStackFrame frame = (JavaStackFrame) o;
            JavaLocation location = frame.getLocation();
            int lineNumber = -1;
            String fileName = "<unknown>";
            try {
                lineNumber = location.getLineNumber();
            } catch (DataUnavailable e) {
            // deliberately do nothing
            }
            try {
                fileName = location.getFilename();
            } catch (DataUnavailable e) {
            // Deliberately do nothing
            }
            System.err.println(location.getMethod().getClass().getName() + "." + location.getMethod().getName() + "(" + fileName + ":" + lineNumber + ")");
        } else if (o instanceof CorruptData) {
            System.err.println("<Corrupt Data: " + o + " >");
        } else {
            System.err.println("<Unexpected type: " + o.getClass().getName() + ":  " + o + " >");
        }
        count++;
    }
}
Also used : JavaLocation(com.ibm.dtfj.java.JavaLocation) JavaStackFrame(com.ibm.dtfj.java.JavaStackFrame) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptData(com.ibm.dtfj.image.CorruptData)

Aggregations

JavaLocation (com.ibm.dtfj.java.JavaLocation)3 CorruptData (com.ibm.dtfj.image.CorruptData)2 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)2 JavaStackFrame (com.ibm.dtfj.java.JavaStackFrame)2 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)1 JavaObject (com.ibm.dtfj.java.JavaObject)1 JavaReference (com.ibm.dtfj.java.JavaReference)1 StateToString (com.ibm.jvm.dtfjview.commands.helpers.StateToString)1 Iterator (java.util.Iterator)1