Search in sources :

Example 36 with CorruptData

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

the class DTFJMethod method handleException.

/**
 * Handle an exception thrown by the DTFJ API.
 *
 * @param cmd the command current executing the API. This is required to provide access to context information.
 * @param cause exception to be handled
 * @return textual data to be written out
 */
public static String handleException(BaseJdmpviewCommand cmd, Throwable cause) {
    ctx = cmd.ctx;
    StringBuffer sb = new StringBuffer();
    // Try and determine the artifact type
    StackTraceElement[] myStack = cause.getStackTrace();
    ArtifactType artifactType = cmd.getArtifactType();
    String artifactTypeName = null;
    switch(artifactType) {
        case core:
            artifactTypeName = "core";
            break;
        case javacore:
            artifactTypeName = "javacore";
            break;
        case phd:
            artifactTypeName = "phd";
            break;
        default:
            artifactTypeName = "Unknown artifact type";
            break;
    }
    // Let's find out which DTFJ Class/Method was being used
    DTFJMethod dMethod = getDTFJMethod(myStack, cmd);
    if (cause instanceof DataUnavailable) {
        if (dMethod == null) {
            sb.append("Could not determine DTFJ class/method that caused this exception: ");
            sb.append(cause.getLocalizedMessage());
        } else if (dMethod.isSupported(artifactType) == WORKS) {
            sb.append(dMethod.getClassName());
            sb.append(".");
            sb.append(dMethod.getMethodname());
            sb.append(" should have worked for a ");
            sb.append(artifactTypeName);
            sb.append(" but returned: ");
            sb.append(cause.getLocalizedMessage());
        } else if (dMethod.isSupported(artifactType) == CAN_FAIL) {
            sb.append(dMethod.getClassName());
            sb.append(".");
            sb.append(dMethod.getMethodname());
            sb.append(" can fail for a ");
            sb.append(artifactTypeName);
            sb.append(" which is why it returned: ");
            sb.append(cause.getLocalizedMessage());
        } else if (dMethod.isSupported(artifactType) == FAILS) {
            sb.append(dMethod.getClassName());
            sb.append(".");
            sb.append(dMethod.getMethodname());
            sb.append(" is not supported for a ");
            sb.append(artifactTypeName);
            String s = cause.getLocalizedMessage();
            if (s != null) {
                sb.append(" causing: ");
                sb.append(s);
            }
        }
    } else if (cause instanceof CorruptDataException) {
        CorruptData corruptData = ((CorruptDataException) cause).getCorruptData();
        ImagePointer ip = corruptData.getAddress();
        if (ip == null) {
            sb.append("CorruptData found in dump at unknown address executing ");
            if (dMethod == null) {
                sb.append("an unknown class/method that caused this exception: ");
                sb.append(cause.getLocalizedMessage());
            } else {
                sb.append(dMethod.getClassName());
                sb.append(".");
                sb.append(dMethod.getMethodname());
            }
        } else {
            String addr = cmd.toHexStringAddr(ip.getAddress());
            sb.append("CorruptData found in dump at address: ");
            sb.append(addr);
            sb.append(" causing: ");
            sb.append(cause.getLocalizedMessage());
            if (dMethod != null) {
                sb.append(" executing ");
                sb.append(dMethod.getClassName());
                sb.append(".");
                sb.append(dMethod.getMethodname());
            }
        }
    } else if (cause instanceof MemoryAccessException) {
        sb.append(cause.getLocalizedMessage());
    } else if (cause instanceof IllegalArgumentException) {
        sb.append(cause.getLocalizedMessage());
    } else {
        // If we are here then something bad has really happened
        // This is just debug code to help determine other problems this
        // method has to deal with
        sb.append("==========> Unexpected exception " + cause.getClass().getName() + " thrown: " + cause.getLocalizedMessage());
        StringWriter st = new StringWriter();
        cause.printStackTrace(new PrintWriter(st));
        sb.append(st.toString());
    }
    return sb.toString();
}
Also used : CorruptDataException(com.ibm.dtfj.image.CorruptDataException) ImagePointer(com.ibm.dtfj.image.ImagePointer) StringWriter(java.io.StringWriter) ArtifactType(com.ibm.jvm.dtfjview.commands.BaseJdmpviewCommand.ArtifactType) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptData(com.ibm.dtfj.image.CorruptData) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException) PrintWriter(java.io.PrintWriter)

Example 37 with CorruptData

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

the class J9DDRDTFJUtils method handleAsCorruptData.

/**
 * Convert the supplied error condition into a CorruptData object and return
 * it, typically for insertion into an iterator,
 * or re-throw it if it is an instance of Error that we do not want to
 * intercept.
 *
 * @param p the process from the dtfj context
 * @param t the error condition to handle
 * @return the error expressed as corrupt data
 */
public static CorruptData handleAsCorruptData(IProcess p, Throwable t) {
    if (isErrorNotToBeIntercepted(t)) {
        if (t instanceof Error) {
            // re-throw unhandled errors
            throw (Error) t;
        }
        // should not hit this as we handle run time exceptions
        throw new RuntimeException(t);
    }
    if (t instanceof com.ibm.j9ddr.CorruptDataException) {
        com.ibm.j9ddr.CorruptDataException cde = (com.ibm.j9ddr.CorruptDataException) t;
        logger.log(Level.FINE, "Corrupt data encountered", t);
        return newCorruptData(p, cde);
    }
    String message = logError(t);
    CorruptData cd = newCorruptData(p, message);
    return cd;
}
Also used : J9DDRCorruptData(com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData) CorruptData(com.ibm.dtfj.image.CorruptData) CorruptDataException(com.ibm.j9ddr.CorruptDataException) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 38 with CorruptData

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

the class DTFJJavaClass method getDeclaredMethods.

@SuppressWarnings("rawtypes")
public Iterator getDeclaredMethods() {
    ArrayList<Object> methods;
    J9MethodPointer ramMethod;
    long methodCount;
    try {
        ramMethod = j9class.ramMethods();
        methodCount = j9class.romClass().romMethodCount().longValue();
        if (methodCount > MAX_CLASS_METHODS) {
            CorruptData cd = J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), "Corrupt class, maximum number of methods exceeded");
            return corruptIterator(cd);
        }
        methods = new ArrayList<Object>((int) methodCount);
    } catch (Throwable t) {
        CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
        return corruptIterator(cd);
    }
    for (int i = 0; i < methodCount; i++) {
        try {
            DTFJJavaMethod jmethod = new DTFJJavaMethod(this, ramMethod.add(i));
            methods.add(jmethod);
        } catch (Throwable t) {
            CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
            methods.add(cd);
        }
    }
    return methods.iterator();
}
Also used : J9MethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer) 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)

Example 39 with CorruptData

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

the class DTFJJavaClass method addStaticFieldReferences.

@SuppressWarnings("rawtypes")
private void addStaticFieldReferences(List<Object> references) {
    JavaReference jRef;
    Iterator declaredFieldIt = getDeclaredFields();
    // can get corrupt data returned through the field iterator as it's coming from DTFJ
    Object obj = null;
    while ((declaredFieldIt.hasNext() && (obj = declaredFieldIt.next()) instanceof DTFJJavaField)) {
        DTFJJavaField jField = (DTFJJavaField) obj;
        if (jField instanceof DTFJJavaFieldStatic) {
            JavaObject jObject;
            try {
                char type = jField.getSignature().charAt(0);
                if (type == DTFJConstants.OBJECT_PREFIX_SIGNATURE || type == DTFJConstants.ARRAY_PREFIX_SIGNATURE) {
                    jObject = (JavaObject) jField.get(null);
                    if (jObject != null) {
                        // build a JavaReference type and add the reference to the container.
                        String fieldName = jField.getName();
                        String description = "Static field";
                        if (null != fieldName) {
                            description = description + " [field name:" + fieldName + "]";
                        }
                        jRef = new DTFJJavaReference(this, jObject, description, JavaReference.REFERENCE_STATIC_FIELD, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
                        references.add(jRef);
                    }
                }
            } catch (Throwable t) {
                CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
                references.add(cd);
            }
        }
    }
}
Also used : JavaReference(com.ibm.dtfj.java.JavaReference) JavaObject(com.ibm.dtfj.java.JavaObject) 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)

Example 40 with CorruptData

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

the class DTFJJavaClass method addClassObjectReference.

private void addClassObjectReference(List<Object> coll) {
    JavaReference jRef = null;
    try {
        com.ibm.dtfj.java.JavaObject classObject = this.getObject();
        if (null != classObject) {
            jRef = new DTFJJavaReference(this, classObject, "Class object", JavaReference.REFERENCE_CLASS_OBJECT, 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) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) J9DDRCorruptData(com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)

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