Search in sources :

Example 91 with CorruptDataException

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

the class PHDJavaClass method getReferences.

public Iterator<JavaReference> getReferences() {
    final JavaClass source = this;
    return new Iterator<JavaReference>() {

        int count;

        JavaClass sup;

        JavaObject load;

        {
            try {
                sup = getSuperclass();
                if (sup != null)
                    count = -1;
            } catch (CorruptDataException e) {
            }
            try {
                load = loader.getObject();
                if (load != null)
                    count = -2;
            } catch (CorruptDataException e) {
            }
        }

        public boolean hasNext() {
            if (count < 0) {
                return true;
            } else if (refs instanceof LongEnumeration) {
                LongEnumeration le = (LongEnumeration) refs;
                return le.hasMoreElements();
            } else if (refs instanceof long[]) {
                long[] arefs = (long[]) refs;
                return count < arefs.length;
            } else if (refs instanceof int[]) {
                int[] arefs = (int[]) refs;
                return count < arefs.length;
            } else {
                return false;
            }
        }

        public JavaReference next() {
            if (!hasNext())
                throw new NoSuchElementException("" + count++);
            long ref;
            int refType = PHDJavaReference.REFERENCE_UNKNOWN;
            Object cls = null;
            if (count == -2) {
                cls = load;
                ++count;
                // Skip over the superclass if not present
                if (sup == null)
                    ++count;
                ref = 0;
                refType = PHDJavaReference.REFERENCE_CLASS_LOADER;
            } else if (count == -1) {
                cls = sup;
                ++count;
                ref = 0;
                refType = PHDJavaReference.REFERENCE_SUPERCLASS;
            } else {
                if (refs instanceof LongEnumeration) {
                    LongEnumeration le = (LongEnumeration) refs;
                    ref = le.nextLong();
                    ++count;
                } else if (refs instanceof int[]) {
                    int[] arefs = (int[]) refs;
                    ref = runtime.expandAddress(arefs[count++]);
                } else {
                    long[] arefs = (long[]) refs;
                    ref = arefs[count++];
                }
                cls = runtime.findClass(ref);
            }
            if (cls != null) {
                return new PHDJavaReference(cls, source, PHDJavaReference.REACHABILITY_STRONG, refType, PHDJavaReference.HEAP_ROOT_UNKNOWN, "?");
            } else {
                return new PHDJavaReference(new PHDJavaObject.Builder((PHDJavaHeap) (runtime.getHeaps().next()), ref, null, PHDJavaObject.NO_HASHCODE, -1).build(), source, PHDJavaReference.REACHABILITY_STRONG, refType, PHDJavaReference.HEAP_ROOT_UNKNOWN, "?");
            }
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : CorruptDataException(com.ibm.dtfj.image.CorruptDataException) LongEnumeration(com.ibm.dtfj.phd.util.LongEnumeration) JavaClass(com.ibm.dtfj.java.JavaClass) JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) NoSuchElementException(java.util.NoSuchElementException)

Example 92 with CorruptDataException

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

the class PHDJavaClass method referencesClass.

/**
 * Is there a reference from one class to another?
 * E.g. from an array class to the component type? This would be an indication that they
 * are truly related.
 * @param from
 * @param to
 * @return
 */
static boolean referencesClass(JavaClass from, JavaClass to) {
    for (Iterator i1 = from.getReferences(); i1.hasNext(); ) {
        Object o = i1.next();
        if (o instanceof CorruptData)
            continue;
        JavaReference jr = (JavaReference) o;
        try {
            if (jr.isClassReference() && jr.getTarget().equals(to)) {
                return true;
            }
            if (jr.isObjectReference() && jr.getTarget().equals(to.getObject())) {
                return true;
            }
        } catch (DataUnavailable e) {
        } catch (CorruptDataException e) {
        }
    }
    return false;
}
Also used : JavaReference(com.ibm.dtfj.java.JavaReference) Iterator(java.util.Iterator) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 93 with CorruptDataException

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

the class PHDJavaClassLoader method processData.

private void processData(HeapdumpReader reader, final PHDImage parentImage, final ImageAddressSpace space, final PHDJavaRuntime runtime) throws IOException {
    final JavaClassLoader loader = this;
    final int adjustLen = reader.version() == 4 && reader.isJ9() ? 1 : 0;
    final int[] realClasses = new int[1];
    try {
        reader.parse(new PortableHeapDumpListener() {

            long prevAddress;

            PHDJavaClass prevObjClass;

            private void updateSizes(long address) {
                if (prevObjClass != null)
                    prevObjClass.updateSize(prevAddress, address);
                prevObjClass = null;
                prevAddress = address;
            }

            public void classDump(long address, long superAddress, String name, int size, int flags, int hashCode, LongEnumeration refs) throws Exception {
                updateSizes(address);
                classes.put(address, new PHDJavaClass.Builder(space, runtime, loader, address, superAddress, name).size(size).flags(flags).hashCode(hashCode).refs(refs).build());
                updateAddresses(address, size, name);
                ++realClasses[0];
            }

            public void objectArrayDump(long address, long classAddress, int flags, int hashCode, LongEnumeration refs, int length, long instanceSize) throws Exception {
                int refsLen = refs.numberOfElements();
                int adjustLen2 = Math.min(adjustLen, refsLen);
                updateSizes(address);
                updateAddresses(address, classAddress, length - adjustLen2);
                long classAddress2 = adjustLen2 == 1 ? refs.nextLong() : 0;
                genArrayClasses(space, runtime, loader, adjustLen2, classAddress, classAddress2);
            }

            public void objectDump(long address, long classAddress, int flags, int hashCode, LongEnumeration refs, long instanceSize) throws Exception {
                updateSizes(address);
                updateAddresses(address, classAddress, -1);
                genObjectClass(space, runtime, loader, classAddress, hashCode);
            }

            public void primitiveArrayDump(long address, int type, int length, int flags, int hashCode, long instanceSize) throws Exception {
                updateSizes(address);
                updateAddresses(address, type, length);
            }

            private void genObjectClass(final ImageAddressSpace space, final PHDJavaRuntime runtime, final JavaClassLoader loader, long classAddress, int hashCode) {
                if (!classes.containsKey(classAddress)) {
                    PHDJavaClass objClass = new PHDJavaClass.Builder(space, runtime, loader, classAddress, PHDJavaClass.UNKNOWN_SUPERCLASS, PHDJavaClass.UNKNOWN_NONARRAY).build();
                    classes.put(classAddress, objClass);
                    updateAddresses(classAddress, 100, null);
                }
                prevObjClass = (PHDJavaClass) findClass(classAddress);
            }

            private PHDJavaClass genArrayClass(final ImageAddressSpace space, final PHDJavaRuntime runtime, final JavaClassLoader loader, long classAddress, long sup, String name) {
                PHDJavaClass elemCls;
                int size = 100;
                elemCls = new PHDJavaClass.Builder(space, runtime, loader, classAddress, sup, name).build();
                classes.put(classAddress, elemCls);
                updateAddresses(classAddress, size, name);
                return elemCls;
            }

            private void genArrayClasses(final ImageAddressSpace space, final PHDJavaRuntime runtime, final JavaClassLoader loader, final int adjustLen, long classAddress, long classAddress2) {
                if (adjustLen == 1) {
                    // Java 5.0 arrays with type = base component type e.g. String
                    // First reference = actual array type e.g. [[Ljava.lang.String;
                    JavaClass arrayCls;
                    if (!classes.containsKey(classAddress2)) {
                        String name = PHDJavaClass.UNKNOWN_ARRAY;
                        arrayCls = genArrayClass(space, runtime, loader, classAddress2, jlo, name);
                    } else {
                        arrayCls = findClass(classAddress2);
                    }
                    arrayClasses.put(classAddress, arrayCls);
                    if (!classes.containsKey(classAddress)) {
                        String name = PHDJavaClass.UNKNOWN_NONARRAY;
                        genArrayClass(space, runtime, loader, classAddress, PHDJavaClass.UNKNOWN_SUPERCLASS, name);
                    }
                } else {
                    arrayClasses.put(classAddress, null);
                }
                return;
            }
        });
    } catch (EOFException e) {
        classes.put(runtime.nextDummyClassAddr(), new PHDCorruptJavaClass("Truncated dump found building class " + realClasses[0], null, e));
    } catch (IOException e) {
        classes.put(runtime.nextDummyClassAddr(), new PHDCorruptJavaClass("Corrupted dump found building class " + realClasses[0], null, e));
    } catch (Exception e) {
        classes.put(runtime.nextDummyClassAddr(), new PHDCorruptJavaClass("Building class " + realClasses[0], null, e));
    } finally {
        reader.close();
        reader = null;
    }
    jlo = 0;
    // Use an uncached search as the index hasn't been built.
    JavaClass jco = findClassUncached("java/lang/Object");
    if (jco != null) {
        ImagePointer ip = jco.getID();
        if (ip != null)
            jlo = ip.getAddress();
    } else {
        // If the dump is very corrupt it won't have java.lang.Object - so create one
        jco = new PHDJavaClass.Builder(space, runtime, loader, 0, 0, "java/lang/Object").build();
        jlo = runtime.nextDummyClassAddr();
        classes.put(jlo, jco);
    }
    // If the dump is very corrupt it won't have java.lang.Class - so create one
    JavaClass jcl = findClassUncached("java/lang/Class");
    if (jcl == null) {
        jcl = new PHDJavaClass.Builder(space, runtime, loader, 0, jlo, "java/lang/Class").build();
        classes.put(runtime.nextDummyClassAddr(), jcl);
    }
    // nor will it have primitive array classes
    for (int i = 0; i < PHDJavaRuntime.arrayTypeName.length; ++i) {
        JavaClass jc = findClassUncached(PHDJavaRuntime.arrayTypeName[i]);
        if (jc == null) {
            jc = new PHDJavaClass.Builder(space, runtime, loader, 0, jlo, PHDJavaRuntime.arrayTypeName[i]).build();
            classes.put(runtime.nextDummyClassAddr(), jc);
        }
    }
    // Bug in PHD dumps - some Java 6 types have the type of an array being the whole array, not the elements
    // Is the type of the array the whole array or the type of an element?
    boolean arrayTypeIsArray = true;
    for (Long id : arrayClasses.keySet()) {
        JavaClass cl1 = findClass(id);
        // Corrupt dump might not have the class!
        if (cl1 == null)
            continue;
        try {
            if (!cl1.isArray()) {
                arrayTypeIsArray = false;
            }
        } catch (CorruptDataException e) {
            // If we don't know the type then presume they are not arrays
            arrayTypeIsArray = false;
        }
    }
    // Create a mapping from the phd id of an array object to the type of the whole array
    for (Long id : arrayClasses.keySet()) {
        JavaClass cl1 = findClass(id);
        if (cl1 == null) {
            String name = arrayTypeIsArray ? PHDJavaClass.UNKNOWN_ARRAY : null;
            long sup = arrayTypeIsArray ? jlo : PHDJavaClass.UNKNOWN_SUPERCLASS;
            cl1 = new PHDJavaClass.Builder(space, runtime, loader, id, sup, name).build();
            classes.put(id, cl1);
        }
        JavaClass ar = arrayClasses.get(id);
        if (ar != null) {
            ImagePointer ip = ar.getID();
            if (ip != null) {
                JavaClass ar2 = findClass(ip.getAddress());
                if (ar2 != null) {
                    ar = ar2;
                }
            }
        // cl1 is not a component type for multidimensional arrays, but is the scalar type
        // ((PHDJavaClass)ar).setComponentType(cl1);
        }
        JavaClass cl2;
        if (arrayTypeIsArray) {
            cl2 = cl1;
        } else if (ar != null) {
            cl2 = ar;
        } else {
            try {
                String name = cl1.getName();
                String arrayName = arrayName(name);
                Set<JavaClass> s = findClasses(arrayName);
                if (s.size() == 0) {
                    // Array class doesn't exist, so create a dummy one
                    cl2 = new PHDJavaClass.Builder(space, runtime, loader, 0, jlo, arrayName).componentType(cl1).build();
                } else if (s.size() == 1) {
                    // Only one, so use it
                    cl2 = s.iterator().next();
                } else {
                    // Multiple classes, so if possible choose one
                    cl2 = null;
                    for (JavaClass cl3 : s) {
                        // If so then it is the one.
                        if (PHDJavaClass.referencesClass(cl3, cl1)) {
                            cl2 = cl3;
                            break;
                        }
                    }
                }
            } catch (CorruptDataException e) {
                // Array class doesn't exist, so create a dummy one
                cl2 = new PHDJavaClass.Builder(space, runtime, loader, 0, jlo, PHDJavaClass.UNKNOWN_ARRAY).componentType(cl1).build();
            }
            if (cl2 instanceof PHDJavaClass) {
                // We know the component type, so remember it for later
                ((PHDJavaClass) cl2).setComponentType(cl1);
            }
        }
        // Even if the array class is null (we couldn't decide), mark it so we know for later
        arrayClasses.put(id, cl2);
    }
    initCache();
}
Also used : PortableHeapDumpListener(com.ibm.dtfj.phd.parser.PortableHeapDumpListener) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) IOException(java.io.IOException) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) IOException(java.io.IOException) EOFException(java.io.EOFException) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) ImagePointer(com.ibm.dtfj.image.ImagePointer) LongEnumeration(com.ibm.dtfj.phd.util.LongEnumeration) JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaClass(com.ibm.dtfj.java.JavaClass) EOFException(java.io.EOFException)

Example 94 with CorruptDataException

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

the class PHDJavaHeap method getSections.

public Iterator<ImageSection> getSections() {
    List<ImageSection> c = new ArrayList<ImageSection>();
    // This is the start of the last object
    long last = runtime.maxAddress;
    if (runtime.minAddress <= runtime.maxAddress) {
        ImagePointer objPointer = space.getPointer(last);
        JavaObject lastObj = null;
        try {
            lastObj = getLastObject(objPointer, runtime.maxObjClass, runtime.maxObjLen);
        } catch (IOException e1) {
        // allow to fall through so that jo is null
        }
        try {
            // Find the end of the last object
            if (lastObj != null)
                last += lastObj.getSize();
            ImageSection s = new PHDImageSection(getName(), space.getPointer(runtime.minAddress), last - runtime.minAddress);
            c.add(s);
        } catch (CorruptDataException e) {
            ImageSection s = new PHDImageSection(getName(), space.getPointer(runtime.minAddress), last - runtime.minAddress);
            c.add(s);
            // The object will take some space
            s = new PHDCorruptImageSection("Corrupt " + getName(), objPointer, 8);
            c.add(s);
        }
    }
    if (runtime.minClassAddress <= runtime.maxClassAddress) {
        // Space in heap for class objects
        long last2 = runtime.maxClassAddress;
        ImagePointer objPointer = space.getPointer(last2);
        int insert = c.size();
        ImageSection s;
        try {
            JavaClass jc = runtime.findClass(last2);
            // Make sure the class takes up some room
            long size = 8;
            if (jc != null) {
                JavaObject lastObj = jc.getObject();
                if (lastObj != null && lastObj.getID().equals(jc.getID())) {
                    size = lastObj.getSize();
                }
            }
            last2 += size;
        } catch (CorruptDataException e) {
            s = new PHDCorruptImageSection("Corrupt " + getName(), objPointer, 8);
            c.add(s);
        }
        // Do the object and class object sections overlap, if so combine them
        if (last2 < runtime.minAddress || last < runtime.minClassAddress) {
            s = new PHDImageSection(getName(), space.getPointer(runtime.minClassAddress), last2 - runtime.minClassAddress);
            c.add(insert, s);
        } else {
            long minAddr = Math.min(runtime.minAddress, runtime.minClassAddress);
            long maxAddr = Math.max(last, last2);
            s = new PHDImageSection(getName(), space.getPointer(minAddr), maxAddr - minAddr);
            // Replace with a combined section
            c.set(0, s);
        }
    }
    return c.iterator();
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer) JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) ArrayList(java.util.ArrayList) ImageSection(com.ibm.dtfj.image.ImageSection) IOException(java.io.IOException) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 95 with CorruptDataException

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

the class PHDJavaLocation method toString.

/*
	 * Get a description of the frame in the same format as a stack trace 
	 */
public String toString() {
    StringBuilder sb = new StringBuilder();
    try {
        JavaMethod m = getMethod();
        sb.append(m.getDeclaringClass().getName().replace('/', '.'));
        sb.append('.');
        sb.append(m.getName());
    } catch (CorruptDataException e) {
        sb.append("corrupt");
    } catch (DataUnavailable e) {
        sb.append("data unavailable");
    }
    sb.append('(');
    boolean d = false;
    try {
        sb.append(getFilename());
        d = true;
        int line = getLineNumber();
        sb.append(':');
        sb.append(line);
    } catch (CorruptDataException e) {
        try {
            if (getCompilationLevel() > 0) {
                if (d)
                    sb.append('(');
                sb.append("Compiled Code");
                if (d)
                    sb.append(')');
            }
        } catch (CorruptDataException e2) {
        }
    } catch (DataUnavailable e) {
        try {
            if (getCompilationLevel() > 0) {
                if (d)
                    sb.append('(');
                sb.append("Compiled Code");
                if (d)
                    sb.append(')');
            }
        } catch (CorruptDataException e2) {
        }
    } finally {
        sb.append(')');
    }
    return sb.toString();
}
Also used : JavaMethod(com.ibm.dtfj.java.JavaMethod) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

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