Search in sources :

Example 1 with JavaReference

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

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

the class XJCommand method printReferences.

/**
 * Print the references from the given object. Omit the first reference: this is always a reference to the
 * object's class.
 */
public static void printReferences(JavaObject jo, PrintStream out) {
    Iterator<?> references = jo.getReferences();
    if (references.hasNext()) {
        // reference to the class, ignore this one
        references.next();
    }
    if (!references.hasNext()) {
        out.print("\t    references: <none>\n ");
        out.print("\t     ");
    } else {
        out.print("\t    references:\n ");
        out.print("\t     ");
        while (references.hasNext()) {
            Object potential_reference = references.next();
            if (potential_reference instanceof JavaReference) {
                JavaReference reference = (JavaReference) potential_reference;
                try {
                    Object target = reference.getTarget();
                    if (target instanceof JavaObject) {
                        out.print(" 0x" + Long.toHexString(((JavaObject) target).getID().getAddress()));
                    } else if (target instanceof JavaClass) {
                        out.print(" 0x" + Long.toHexString(((JavaClass) target).getID().getAddress()));
                    }
                } catch (DataUnavailable e) {
                // don't print anything
                } catch (CorruptDataException e) {
                    out.print(Exceptions.getCorruptDataExceptionString());
                }
            }
        }
    }
    out.print("\n\n");
}
Also used : JavaReference(com.ibm.dtfj.java.JavaReference) JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 3 with JavaReference

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

the class DTFJJavaClass method addClassLoaderReference.

private void addClassLoaderReference(List<Object> coll) {
    JavaReference jRef = null;
    try {
        JavaClassLoader classLoader = this.getClassLoader();
        if (null != classLoader) {
            JavaObject classLoaderObject = classLoader.getObject();
            if (null != classLoaderObject) {
                jRef = new DTFJJavaReference(this, classLoaderObject, "Classloader", JavaReference.REFERENCE_CLASS_LOADER, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
                coll.add(jRef);
            }
        }
    } catch (Throwable t) {
        CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
        coll.add(cd);
    }
}
Also used : JavaReference(com.ibm.dtfj.java.JavaReference) JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) J9DDRCorruptData(com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)

Example 4 with JavaReference

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

the class DTFJJavaClass method addSuperclassReference.

private void addSuperclassReference(List<Object> coll) {
    JavaReference jRef = null;
    try {
        JavaClass superClass = this.getSuperclass();
        if (null != superClass) {
            jRef = new DTFJJavaReference(this, superClass, "Superclass", JavaReference.REFERENCE_SUPERCLASS, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
            coll.add(jRef);
        }
    } catch (Throwable t) {
        CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
        coll.add(cd);
    }
}
Also used : JavaReference(com.ibm.dtfj.java.JavaReference) JavaClass(com.ibm.dtfj.java.JavaClass) CorruptData(com.ibm.dtfj.image.CorruptData) J9DDRCorruptData(com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)

Example 5 with JavaReference

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

the class DTFJJavaClass method addConstantPoolReferences.

@SuppressWarnings("rawtypes")
private JavaReference addConstantPoolReferences(List<Object> references) {
    // get the Constant Pool references from this class.
    JavaReference jRef = null;
    Iterator constantPoolIt = getConstantPoolReferences();
    try {
        while (constantPoolIt.hasNext()) {
            // get each reference in turn, note that the iterator can return JavaClass
            // JavaObject and CorruptData. The CorruptData objects are ignored.
            Object cpObject = constantPoolIt.next();
            if (cpObject instanceof JavaObject) {
                // add the reference to the container.
                jRef = new DTFJJavaReference(this, cpObject, "Constant Pool Object", JavaReference.REFERENCE_CONSTANT_POOL, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
            } else if (cpObject instanceof JavaClass) {
                // add the reference to the container.
                jRef = new DTFJJavaReference(this, cpObject, "Constant Pool Class", JavaReference.REFERENCE_CONSTANT_POOL, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
            }
            if (null != jRef) {
                references.add(jRef);
            }
        }
    } catch (Throwable t) {
        CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
        references.add(cd);
    }
    return jRef;
}
Also used : JavaReference(com.ibm.dtfj.java.JavaReference) JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) J9ObjectFieldOffsetIterator(com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffsetIterator) DTFJConstantPoolIterator(com.ibm.j9ddr.vm29.view.dtfj.java.j9.DTFJConstantPoolIterator) J9DDRDTFJUtils.corruptIterator(com.ibm.j9ddr.view.dtfj.J9DDRDTFJUtils.corruptIterator) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) J9Object(com.ibm.j9ddr.vm29.structure.J9Object) CorruptData(com.ibm.dtfj.image.CorruptData) J9DDRCorruptData(com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)

Aggregations

JavaReference (com.ibm.dtfj.java.JavaReference)13 JavaObject (com.ibm.dtfj.java.JavaObject)11 CorruptData (com.ibm.dtfj.image.CorruptData)10 Iterator (java.util.Iterator)8 JavaClass (com.ibm.dtfj.java.JavaClass)7 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)6 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)6 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)6 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)3 J9DDRDTFJUtils.corruptIterator (com.ibm.j9ddr.view.dtfj.J9DDRDTFJUtils.corruptIterator)3 J9Object (com.ibm.j9ddr.vm29.structure.J9Object)3 J9ObjectFieldOffsetIterator (com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffsetIterator)2 DTFJConstantPoolIterator (com.ibm.j9ddr.vm29.view.dtfj.java.j9.DTFJConstantPoolIterator)2 HashMap (java.util.HashMap)2 ImagePointer (com.ibm.dtfj.image.ImagePointer)1 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)1 JavaLocation (com.ibm.dtfj.java.JavaLocation)1 JavaMethod (com.ibm.dtfj.java.JavaMethod)1 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)1 JavaStackFrame (com.ibm.dtfj.java.JavaStackFrame)1