Search in sources :

Example 61 with CorruptDataException

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

the class JavaClassLoader method getDefinedClasses.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaClassLoader#getDefinedClasses()
	 */
public Iterator getDefinedClasses() {
    if (null == _defined) {
        // Loop through the list of all classes building a list of this loader's defined classes.
        // A defined class is a class whose class loader is this loader
        Iterator cached = _javaVM.getClasses();
        long thisID = _id.getAddress();
        _defined = new ArrayList();
        while (cached.hasNext()) {
            Object next = cached.next();
            // corrupt entries by looking at the cached classes via getCachedClasses()
            if (next instanceof CorruptData) {
                continue;
            }
            // Extract the current class
            JavaClass currentClass = (JavaClass) next;
            try {
                // Extract the current class's class loader
                JavaClassLoader currentClassLoader = (JavaClassLoader) currentClass.getClassLoader();
                // old versions of jextract
                if ((currentClassLoader != null) && (currentClassLoader._id.getAddress() == thisID)) {
                    _defined.add(currentClass);
                }
            } catch (CorruptDataException e) {
            // Ignore this one
            }
        }
    }
    return _defined.iterator();
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.j9.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 62 with CorruptDataException

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

the class JavaAbstractClass method addClassObjectReference.

protected void addClassObjectReference(Collection coll) {
    JavaReference jRef = null;
    try {
        com.ibm.dtfj.java.JavaObject classObject = this.getObject();
        if (null != classObject) {
            jRef = new JavaReference(_javaVM, this, classObject, "Class object", JavaReference.REFERENCE_CLASS_OBJECT, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
            coll.add(jRef);
        }
    } catch (CorruptDataException e) {
        coll.add(e.getCorruptData());
    }
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 63 with CorruptDataException

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

the class PHDCorruptData method newCorruptDataException.

static CorruptDataException newCorruptDataException(PHDCorruptData cd) {
    CorruptDataException e = new CorruptDataException(cd);
    cd.initCause(e);
    return e;
}
Also used : CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 64 with CorruptDataException

use of com.ibm.dtfj.image.CorruptDataException 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 65 with CorruptDataException

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

the class DDRLibraryAdapter method constructLibraryList.

/**
 * Constructs the list of libraries required using the DDR implementation of the DTFJ Image* API.
 * This ensures that the correct classloading is used for determining which libraries to collect.
 * @param coreFile core file to process
 */
@SuppressWarnings({ "unchecked" })
private void constructLibraryList(final File coreFile) {
    moduleNames = new ArrayList<String>();
    ImageFactory factory = new J9DDRImageFactory();
    final Image image;
    final boolean isAIX;
    try {
        image = factory.getImage(coreFile);
        isAIX = image.getSystemType().toLowerCase().startsWith("aix");
    } catch (IOException e) {
        logger.log(SEVERE, "Could not open core file", e);
        errorMessages.add(e.getMessage());
        return;
    } catch (CorruptDataException e) {
        logger.log(SEVERE, "Could not determine system type", e);
        errorMessages.add(e.getMessage());
        return;
    } catch (DataUnavailable e) {
        logger.log(SEVERE, "Could not determine system type", e);
        errorMessages.add(e.getMessage());
        return;
    }
    for (Iterator spaces = image.getAddressSpaces(); spaces.hasNext(); ) {
        ImageAddressSpace space = (ImageAddressSpace) spaces.next();
        for (Iterator procs = space.getProcesses(); procs.hasNext(); ) {
            ImageProcess proc = (ImageProcess) procs.next();
            try {
                // add the executable to the list of libraries to be collected
                ImageModule exe = proc.getExecutable();
                moduleNames.add(exe.getName());
                for (Iterator libraries = proc.getLibraries(); libraries.hasNext(); ) {
                    ImageModule module = (ImageModule) libraries.next();
                    String key = null;
                    try {
                        // handle CDE thrown by getName(), as this is required further on this call needs to succeed
                        if (isAIX) {
                            key = module.getName();
                            // check on AIX if module is the .a file or library
                            int pos = key.indexOf(".a(");
                            if ((pos != -1) && (key.lastIndexOf(')') == key.length() - 1)) {
                                key = key.substring(0, pos + 2);
                            }
                        } else {
                            key = module.getName();
                        }
                        logger.fine("Module : " + key);
                        if (!moduleNames.contains(key)) {
                            // don't store duplicate libraries
                            moduleNames.add(key);
                        }
                    } catch (Exception e) {
                        logger.log(WARNING, "Error getting module name", e);
                    }
                }
            } catch (DataUnavailable e) {
                logger.log(WARNING, "Error getting library list", e);
                errorMessages.add(e.getMessage());
            } catch (com.ibm.dtfj.image.CorruptDataException e) {
                logger.log(WARNING, "Error getting library list", e);
                errorMessages.add(e.getMessage());
            }
        }
    }
}
Also used : IOException(java.io.IOException) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) Image(com.ibm.dtfj.image.Image) ImageModule(com.ibm.dtfj.image.ImageModule) IOException(java.io.IOException) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) J9DDRImageFactory(com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory) J9DDRImageFactory(com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory) ImageFactory(com.ibm.dtfj.image.ImageFactory) ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) ImageProcess(com.ibm.dtfj.image.ImageProcess) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) Iterator(java.util.Iterator) DataUnavailable(com.ibm.dtfj.image.DataUnavailable)

Aggregations

CorruptDataException (com.ibm.dtfj.image.CorruptDataException)124 JavaObject (com.ibm.dtfj.java.JavaObject)55 Iterator (java.util.Iterator)49 JavaClass (com.ibm.dtfj.java.JavaClass)41 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)39 CorruptData (com.ibm.dtfj.image.CorruptData)26 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)25 ImagePointer (com.ibm.dtfj.image.ImagePointer)19 CorruptData (com.ibm.dtfj.image.j9.CorruptData)17 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)14 ImageSection (com.ibm.dtfj.image.ImageSection)12 ImageThread (com.ibm.dtfj.image.ImageThread)12 JavaThread (com.ibm.dtfj.java.JavaThread)12 ArrayList (java.util.ArrayList)11 ImageProcess (com.ibm.dtfj.image.ImageProcess)9 JavaField (com.ibm.dtfj.java.JavaField)8 JavaReference (com.ibm.dtfj.java.JavaReference)8 LinkedList (java.util.LinkedList)8 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)7 JavaMethod (com.ibm.dtfj.java.JavaMethod)7