Search in sources :

Example 66 with CorruptDataException

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

the class J9DDRImageProcess method getEnvironment.

/**
 * This method gets the environment variables.
 * First it tries to extract it from RAS structure.
 * If not, it tries to get it from loaded modules.
 * @return Properties instance of environment variables.
 * @throws DataUnavailable
 * @throws CorruptDataException
 */
public Properties getEnvironment() throws DataUnavailable, CorruptDataException {
    try {
        checkFailureInfo();
        if (j9rasProcessData != null) {
            try {
                Properties properties;
                long environ = j9rasProcessData.getEnvironment();
                if (process.getPlatform() == Platform.WINDOWS && j9rasProcessData.version() > 4) {
                    // Get the env vars from an environment strings block instead of the environ global
                    properties = EnvironmentUtils.readEnvironmentStrings(process, environ);
                } else {
                    long stringPointer = process.getPointerAt(environ);
                    properties = EnvironmentUtils.readEnvironment(process, stringPointer);
                }
                if ((null == properties) || (0 == properties.size())) {
                    /* In the case of env vars is null or empty, 
						 * throw exception so that it tries to get env vars from modules 
						 */
                    throw new com.ibm.j9ddr.CorruptDataException("");
                }
                return properties;
            } catch (com.ibm.j9ddr.CorruptDataException e1) {
                /* Seems like RAS structure is corrupted. Try to get it from modules. */
                return process.getEnvironmentVariables();
            }
        } else {
            /* We don't have a J9RAS structure to work with. Try to get it from modules. */
            return process.getEnvironmentVariables();
        }
    } catch (com.ibm.j9ddr.CorruptDataException e) {
        throw new DTFJCorruptDataException(process, e);
    } catch (DataUnavailableException e) {
        throw new DataUnavailable(e.getMessage());
    }
}
Also used : DataUnavailableException(com.ibm.j9ddr.DataUnavailableException) DTFJCorruptDataException(com.ibm.j9ddr.view.dtfj.DTFJCorruptDataException) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) DTFJCorruptDataException(com.ibm.j9ddr.view.dtfj.DTFJCorruptDataException) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) Properties(java.util.Properties)

Example 67 with CorruptDataException

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

the class DTFJJavaRuntimeHelper method getTotalHeapSize.

@SuppressWarnings("rawtypes")
public static long getTotalHeapSize(JavaRuntime runtime, IProcess process) throws CorruptDataException {
    if (totalSizeOfAllHeaps > 0) {
        // already calculated, never changes
        return totalSizeOfAllHeaps;
    }
    if (runtime == null) {
        throw new com.ibm.dtfj.image.CorruptDataException(J9DDRDTFJUtils.newCorruptData(process, "No Java Runtime present"));
    }
    Iterator heaps = runtime.getHeaps();
    while (heaps.hasNext()) {
        Object nextHeap = heaps.next();
        Iterator sections;
        if (nextHeap instanceof JavaHeap) {
            sections = ((JavaHeap) nextHeap).getSections();
        } else {
            // CorruptData?
            throw new com.ibm.dtfj.image.CorruptDataException(J9DDRDTFJUtils.newCorruptData(process, "Corrupt heap encountered whilst calculating total heap size"));
        }
        while (sections.hasNext()) {
            Object nextSection = sections.next();
            if (nextSection instanceof ImageSection) {
                long sectionSize = ((ImageSection) nextSection).getSize();
                if (Long.MAX_VALUE - sectionSize > totalSizeOfAllHeaps) {
                    totalSizeOfAllHeaps += sectionSize;
                } else {
                    // no point adding further, the cap is on Long.MAX_VALUE
                    return Long.MAX_VALUE;
                }
            } else {
                // CorruptData?
                throw new com.ibm.dtfj.image.CorruptDataException(J9DDRDTFJUtils.newCorruptData(process, "Corrupt section encountered whilst calculating total heap size"));
            }
        }
    }
    return totalSizeOfAllHeaps;
}
Also used : JavaHeap(com.ibm.dtfj.java.JavaHeap) Iterator(java.util.Iterator) ImageSection(com.ibm.dtfj.image.ImageSection) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 68 with CorruptDataException

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

the class DTFJJavaObject method getHeap.

public JavaHeap getHeap() throws CorruptDataException, DataUnavailable {
    try {
        if (heap == null) {
            DTFJJavaRuntime runtime = DTFJContext.getRuntime();
            heap = runtime.getHeapFromAddress(DTFJContext.getImagePointer(object.getAddress()));
            if (heap == null) {
                throw new CorruptDataException(new CorruptJavaObject(null, object));
            }
        }
        return heap;
    } catch (Throwable t) {
        throw J9DDRDTFJUtils.handleAsCorruptDataException(DTFJContext.getProcess(), t);
    }
}
Also used : CorruptJavaObject(com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 69 with CorruptDataException

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

the class DTFJJavaObject method getAssociatedClass.

private JavaClass getAssociatedClass(JavaObject targetClassLoaderObject) {
    Iterator<?> classloaderIt = DTFJContext.getRuntime().getJavaClassLoaders();
    while (classloaderIt.hasNext()) {
        Object clObj = classloaderIt.next();
        if (clObj instanceof JavaClassLoader) {
            JavaClassLoader loader = (JavaClassLoader) clObj;
            try {
                if (targetClassLoaderObject != null && !loader.getObject().equals(targetClassLoaderObject)) {
                    continue;
                }
            } catch (CorruptDataException e1) {
            // This is an optimisation so if it fails, continue.
            }
            Iterator<?> classesIt = loader.getDefinedClasses();
            while (classesIt.hasNext()) {
                Object classObj = classesIt.next();
                if (classObj instanceof JavaClass) {
                    JavaClass clazz = (JavaClass) classObj;
                    try {
                        if (clazz.getObject().equals(this)) {
                            return clazz;
                        }
                    } catch (CorruptDataException e) {
                    // Deliberately do nothing. If this is the class we're interesting in, we'll
                    // insert a CorruptData object later when it isn't found. If it's not the class
                    // we want, we don't need to worry
                    }
                }
            }
        }
    }
    return null;
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaClass(com.ibm.dtfj.java.JavaClass) JavaObject(com.ibm.dtfj.java.JavaObject) J9Object(com.ibm.j9ddr.vm29.structure.J9Object) CorruptJavaObject(com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 70 with CorruptDataException

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

the class DTFJJavaObject method getSections.

public Iterator getSections() {
    try {
        fetchDeferredData();
        LinkedList<ImageSection> sections = new LinkedList<ImageSection>();
        long mainSectionSize = ObjectModel.getConsumedSizeInBytesWithHeader(object).longValue();
        String name = getSectionName(mainSectionSize);
        J9DDRImageSection section = DTFJContext.getImageSection(object.getAddress(), name);
        section.setSize(mainSectionSize);
        sections.add(section);
        return sections.iterator();
    } catch (CorruptDataException e) {
        return corruptIterator(e.getCorruptData());
    } catch (Throwable t) {
        CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
        return corruptIterator(cd);
    }
}
Also used : J9DDRImageSection(com.ibm.j9ddr.view.dtfj.image.J9DDRImageSection) ImageSection(com.ibm.dtfj.image.ImageSection) CorruptData(com.ibm.dtfj.image.CorruptData) J9DDRCorruptData(com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) LinkedList(java.util.LinkedList) J9DDRImageSection(com.ibm.j9ddr.view.dtfj.image.J9DDRImageSection)

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