Search in sources :

Example 1 with JavaObject

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

the class DTFJHeapUnitTest method generateXML.

@SuppressWarnings("unchecked")
public void generateXML(File path, JavaRuntime rt) throws Exception {
    createWriter(path);
    startTag("<heaps>\n");
    for (Iterator heaps = rt.getHeaps(); heaps.hasNext(); ) {
        JavaHeap heap = (JavaHeap) heaps.next();
        writeIndent();
        startTag("<heap name=\"" + heap.getName() + "\">\n");
        long count = 0;
        for (Iterator objects = heap.getObjects(); objects.hasNext(); count++) {
            try {
                JavaObject obj = (JavaObject) objects.next();
                if (((count % 100) == 0) || (obj.isArray())) {
                    writeObject(obj, count);
                }
            } catch (CorruptDataException e) {
                write("<!-- corrupt object @ " + e.getCorruptData().getAddress() + " -->");
            }
        }
        startTag("<objects count=\"" + count + "\">\n");
        endTag("</objects>\n");
        endTag("</heap>\n");
    }
    endTag("</heaps>\n");
    closeWriter();
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) JavaHeap(com.ibm.dtfj.java.JavaHeap) Iterator(java.util.Iterator) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 2 with JavaObject

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

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

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

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

the class DTFJJavaObject method arraycopy.

public void arraycopy(int srcStart, Object dst, int dstStart, int length) throws CorruptDataException, MemoryAccessException {
    fetchDeferredData();
    if (!objectIsArray) {
        throw new IllegalArgumentException("Object is not an array");
    }
    J9IndexableObjectPointer array = J9IndexableObjectPointer.cast(object);
    try {
        validateArrayCopyParameters(array, srcStart, dst, dstStart, length);
        // CMVC 171150 : use helper object to correctly get the class name
        String className = J9IndexableObjectHelper.getClassName(array);
        if ((null == className) || (className.length() < 2)) {
            J9DDRCorruptData cd = new J9DDRCorruptData(DTFJContext.getProcess(), "The class name for this object could not be determined", object.getAddress());
            throw new CorruptDataException(cd);
        }
        if (className.charAt(1) == 'L' || className.charAt(1) == '[') {
            // JExtract/DTFJ can cope with dst of either Object[] or JavaObject[] - but we need to detect other things
            if (!dst.getClass().equals(Object[].class) && !(dst instanceof JavaObject[])) {
                throw new IllegalArgumentException("Type of dst object (" + dst.getClass().getName() + ") incompatible with Object array. Should be JavaObject[] or Object[]");
            }
            J9ObjectPointer[] intermediateArray = new J9ObjectPointer[length];
            Object[] castedDst = (Object[]) dst;
            if (dstStart + (long) length > castedDst.length) {
                throw new ArrayIndexOutOfBoundsException("Supplied destination array too small. Requires: " + (dstStart + (long) length) + ", was " + castedDst.length);
            }
            J9IndexableObjectHelper.getData(array, intermediateArray, srcStart, length, 0);
            for (int i = 0; i < length; i++) {
                if (intermediateArray[i].isNull()) {
                    castedDst[dstStart + i] = null;
                } else {
                    castedDst[dstStart + i] = new DTFJJavaObject(intermediateArray[i]);
                }
            }
        } else {
            // For primitives we can pass through the client object. The type verification will be done in J9IndexableObjectPointer
            J9IndexableObjectHelper.getData(array, dst, srcStart, length, dstStart);
        }
    } catch (Throwable t) {
        throw J9DDRDTFJUtils.handleAllButMemAccExAsCorruptDataException(DTFJContext.getProcess(), t, whitelist);
    }
}
Also used : J9DDRCorruptData(com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData) J9IndexableObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9IndexableObjectPointer) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptJavaObject(com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject) JavaObject(com.ibm.dtfj.java.JavaObject) J9Object(com.ibm.j9ddr.vm29.structure.J9Object) CorruptJavaObject(com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject)

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