Search in sources :

Example 1 with ArtifactType

use of com.ibm.jvm.dtfjview.commands.BaseJdmpviewCommand.ArtifactType 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)

Aggregations

CorruptData (com.ibm.dtfj.image.CorruptData)1 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)1 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)1 ImagePointer (com.ibm.dtfj.image.ImagePointer)1 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)1 ArtifactType (com.ibm.jvm.dtfjview.commands.BaseJdmpviewCommand.ArtifactType)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1