Search in sources :

Example 36 with ImagePointer

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

the class JavaRuntimeBuilder method addVMOption.

/**
 * Adds an individual VM option to JavaVMInitArgs, with 'extra information' field
 */
public void addVMOption(String option, long extraInfo) throws BuilderFailureException {
    if (fJavaVMInitArgs == null) {
        throw new BuilderFailureException("JCJavaVMInitArgs must be created before options added");
    }
    try {
        ImagePointer pointer = fAddressSpace.getPointer(extraInfo);
        fJavaVMInitArgs.addOption(new JCJavaVMOption(option, pointer));
    } catch (JCInvalidArgumentsException e) {
        throw new BuilderFailureException(e);
    }
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer) JCJavaVMOption(com.ibm.dtfj.java.javacore.JCJavaVMOption) BuilderFailureException(com.ibm.dtfj.javacore.builder.BuilderFailureException) JCInvalidArgumentsException(com.ibm.dtfj.java.javacore.JCInvalidArgumentsException)

Example 37 with ImagePointer

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

the class JavaRuntimeBuilder method addWaitOnNotifyThread.

/**
 */
public void addWaitOnNotifyThread(JavaMonitor monitor, long threadID) throws BuilderFailureException {
    JCJavaMonitor jmonitor = (JCJavaMonitor) monitor;
    ImagePointer pointer = fAddressSpace.getPointer(threadID);
    jmonitor.addNotifyWaiter(pointer);
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer) JCJavaMonitor(com.ibm.dtfj.java.javacore.JCJavaMonitor)

Example 38 with ImagePointer

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

the class JavaRuntimeBuilder method addJavaMonitor.

/**
 * Required: monitor ID (throws exception if invalid)
 * <br>
 * Optional: object ID, class name, monitor name, owning thread
 * @return successfully created JavaMonitor
 * @throws BuilderFailureException if an invalid monitor ID is passed.
 */
public JavaMonitor addJavaMonitor(String monitorName, long monitorID, long objectID, String className, long owningThread) throws BuilderFailureException {
    try {
        JCJavaMonitor monitor = getJavaRuntime().findMonitor(monitorID);
        if (monitor == null) {
            ImagePointer pointerMonitorID = fAddressSpace.getPointer(monitorID);
            monitor = new JCJavaMonitor(getJavaRuntime(), pointerMonitorID, monitorName);
        }
        monitor.setOwner(owningThread);
        if (className != null) {
            JCJavaClass jClass = generateJavaClass(getJavaRuntime(), className, IBuilderData.NOT_AVAILABLE);
            /*
				 * Add the object only if the class is also present and object ID is valid.
				 */
            if (jClass != null && fAddressSpace.isValidAddressID(objectID)) {
                ImagePointer pointerObjectID = fAddressSpace.getPointer(objectID);
                JCJavaObject jobject = new JCJavaObject(pointerObjectID, jClass);
                monitor.setObject(jobject);
            }
        }
        return monitor;
    } catch (JCInvalidArgumentsException e) {
        throw new BuilderFailureException(e);
    }
}
Also used : JCJavaObject(com.ibm.dtfj.java.javacore.JCJavaObject) ImagePointer(com.ibm.dtfj.image.ImagePointer) BuilderFailureException(com.ibm.dtfj.javacore.builder.BuilderFailureException) JCInvalidArgumentsException(com.ibm.dtfj.java.javacore.JCInvalidArgumentsException) JCJavaMonitor(com.ibm.dtfj.java.javacore.JCJavaMonitor) JCJavaClass(com.ibm.dtfj.java.javacore.JCJavaClass)

Example 39 with ImagePointer

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

the class ImageProcessBuilder method addImageStackFrame.

public ImageStackFrame addImageStackFrame(long nativeThreadID, String name, long baseAddress, long procAddress) {
    ImagePointer pointer = fImageAddressSpace.getPointer(nativeThreadID);
    JCImageThread thread = fImageProcess.getImageThread(pointer);
    ImagePointer ip = procAddress != IBuilderData.NOT_AVAILABLE ? fImageAddressSpace.getPointer(procAddress) : null;
    JCImageStackFrame stackFrame = new JCImageStackFrame(name, null, ip);
    if (thread != null) {
        JCImageThread thrd = (JCImageThread) thread;
        thrd.addImageStackFrame(stackFrame);
    }
    return stackFrame;
}
Also used : JCImageThread(com.ibm.dtfj.image.javacore.JCImageThread) ImagePointer(com.ibm.dtfj.image.ImagePointer) JCImageStackFrame(com.ibm.dtfj.image.javacore.JCImageStackFrame)

Example 40 with ImagePointer

use of com.ibm.dtfj.image.ImagePointer 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)

Aggregations

ImagePointer (com.ibm.dtfj.image.ImagePointer)45 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)19 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)12 JavaClass (com.ibm.dtfj.java.JavaClass)9 JCInvalidArgumentsException (com.ibm.dtfj.java.javacore.JCInvalidArgumentsException)8 CorruptData (com.ibm.dtfj.image.j9.CorruptData)7 JavaObject (com.ibm.dtfj.java.JavaObject)7 BuilderFailureException (com.ibm.dtfj.javacore.builder.BuilderFailureException)7 Iterator (java.util.Iterator)7 JCJavaClass (com.ibm.dtfj.java.javacore.JCJavaClass)6 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)5 JCJavaObject (com.ibm.dtfj.java.javacore.JCJavaObject)4 ArrayList (java.util.ArrayList)4 Vector (java.util.Vector)4 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)3 ImageSection (com.ibm.dtfj.image.ImageSection)3 JCImageThread (com.ibm.dtfj.image.javacore.JCImageThread)3 JCJavaMonitor (com.ibm.dtfj.java.javacore.JCJavaMonitor)3 IOException (java.io.IOException)3 CorruptData (com.ibm.dtfj.image.CorruptData)2