Search in sources :

Example 41 with JavaClass

use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.

the class JavaMethodTest method loadTestObjects.

protected void loadTestObjects(JavaRuntime ddrRuntime, List<Object> ddrObjects, JavaRuntime jextractRuntime, List<Object> jextractObjects) {
    List<Object> ddrClassLoaders = new ArrayList<Object>();
    List<Object> jextractClassLoaders = new ArrayList<Object>();
    fillLists(ddrClassLoaders, ddrRuntime.getJavaClassLoaders(), jextractClassLoaders, jextractRuntime.getJavaClassLoaders(), null);
    List<Object> ddrClasses = new ArrayList<Object>();
    List<Object> jextractClasses = new ArrayList<Object>();
    for (int i = 0; i < ddrClassLoaders.size(); i++) {
        JavaClassLoader ddrClassLoader = (JavaClassLoader) ddrClassLoaders.get(i);
        JavaClassLoader jextractClassLoader = (JavaClassLoader) jextractClassLoaders.get(i);
        fillLists(ddrClasses, ddrClassLoader.getDefinedClasses(), jextractClasses, jextractClassLoader.getDefinedClasses(), null);
    }
    for (int i = 0; i < ddrClasses.size(); i++) {
        JavaClass ddrClass = (JavaClass) ddrClasses.get(i);
        JavaClass jextractClass = (JavaClass) jextractClasses.get(i);
        fillLists(ddrObjects, ddrClass.getDeclaredMethods(), jextractObjects, jextractClass.getDeclaredMethods(), null);
    }
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaClass(com.ibm.dtfj.java.JavaClass) ArrayList(java.util.ArrayList)

Example 42 with JavaClass

use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.

the class JavaObject method getReferences.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaObject#getReferences()
	 */
public Iterator getReferences() {
    if (null == _references) {
        _references = new Vector();
        try {
            // find this object's class
            JavaClass jClass = getJavaClass();
            // add a reference to the object's class
            if (null != jClass) {
                JavaReference ref = new JavaReference(_javaVM, this, jClass, "Class", JavaReference.REFERENCE_CLASS, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
                _references.add(ref);
            }
            // walk through the super classes to this object.
            while (null != jClass) {
                List refs = null;
                if (jClass instanceof JavaArrayClass) {
                    JavaArrayClass arrayClass = (JavaArrayClass) jClass;
                    refs = getArrayReferences(arrayClass);
                } else if (jClass instanceof com.ibm.dtfj.java.j9.JavaClass) {
                    refs = getFieldReferences((com.ibm.dtfj.java.j9.JavaClass) jClass);
                }
                if (null != refs) {
                    _references.addAll(refs);
                }
                jClass = jClass.getSuperclass();
            }
        } catch (CorruptDataException e) {
            // Corrupt data, so add it to the container.
            _references.add(e.getCorruptData());
        }
        // Now add association-specific references
        if (isClassLoader()) {
            JavaClassLoader associatedClassLoader = getAssociatedClassLoader();
            for (Iterator classes = associatedClassLoader.getDefinedClasses(); classes.hasNext(); ) {
                Object potentialClass = classes.next();
                if (potentialClass instanceof JavaClass) {
                    JavaClass currentClass = (JavaClass) potentialClass;
                    JavaReference ref = new JavaReference(_javaVM, this, currentClass, "Loaded class", JavaReference.REFERENCE_LOADED_CLASS, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
                    _references.add(ref);
                }
            }
        }
        if (isMonitor()) {
        // need to figure out whether we need additional references here (for example to the owning thread)
        }
        if (isThread()) {
        // need to figure out whether we need additional references here
        }
        if (isClass()) {
            JavaClass associatedClass = getAssociatedClass();
            JavaReference ref = new JavaReference(_javaVM, this, associatedClass, "Associated class", JavaReference.REFERENCE_ASSOCIATED_CLASS, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
            _references.add(ref);
        }
    }
    return _references.iterator();
}
Also used : CorruptDataException(com.ibm.dtfj.image.CorruptDataException) JavaClass(com.ibm.dtfj.java.JavaClass) JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Vector(java.util.Vector)

Example 43 with JavaClass

use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.

the class JavaObject method arraycopy.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaObject#arraycopy(int, java.lang.Object, int, int)
	 */
public void arraycopy(int srcStart, Object dst, int dstStart, int length) throws CorruptDataException, MemoryAccessException {
    JavaClass javaClass = getJavaClass();
    if (javaClass instanceof JavaArrayClass) {
        JavaArrayClass isa = (JavaArrayClass) javaClass;
        String type = javaClass.getName();
        int elementCount = getArraySize();
        // do some rudimentary sanity checking before attempting the copy.
        if (null == dst) {
            // cannot copy to a null object, so raise an exception.
            throw new NullPointerException("dst is null");
        }
        if (length < 0) {
            // length cannot be negative, so raise an exception.
            throw new ArrayIndexOutOfBoundsException("length out of range: " + length);
        }
        if (dstStart < 0) {
            // array index cannot be negative, so raise an exception.
            throw new ArrayIndexOutOfBoundsException("dstStart out of range: " + dstStart);
        }
        if (srcStart < 0) {
            // array index cannot be negative, so raise an exception.
            throw new ArrayIndexOutOfBoundsException("srcStart out of range: " + srcStart);
        }
        if (srcStart + length > elementCount) {
            throw new ArrayIndexOutOfBoundsException("source array index out of range: " + (int) (srcStart + length));
        }
        // boolean
        if (type.equals(ARRAY_PREFIX_SIGNATURE + BYTE_SIGNATURE)) {
            if (dst instanceof byte[]) {
                byte[] target = (byte[]) dst;
                if (dstStart + length > target.length) {
                    throw new ArrayIndexOutOfBoundsException("destination array index out of range: " + (int) (dstStart + length));
                }
                for (int x = 0; x < length; x++) {
                    ImagePointer leafBase = leafBaseForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 1));
                    long leafIndex = leafIndexForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 1));
                    target[x + dstStart] = leafBase.getByteAt(leafIndex);
                }
            } else {
                throw new IllegalArgumentException("destination array type must be byte");
            }
        // boolean
        } else if (type.equals(ARRAY_PREFIX_SIGNATURE + BOOLEAN_SIGNATURE)) {
            if (dst instanceof boolean[]) {
                boolean[] target = (boolean[]) dst;
                if (dstStart + length > target.length) {
                    throw new ArrayIndexOutOfBoundsException("destination array index out of range: " + (int) (dstStart + length));
                }
                for (int x = 0; x < length; x++) {
                    ImagePointer leafBase = leafBaseForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 1));
                    long leafIndex = leafIndexForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 1));
                    target[x + dstStart] = (0 != leafBase.getByteAt(leafIndex));
                }
            } else {
                throw new IllegalArgumentException("destination array type must be boolean");
            }
        // char
        } else if (type.equals(ARRAY_PREFIX_SIGNATURE + CHAR_SIGNATURE)) {
            if (dst instanceof char[]) {
                char[] target = (char[]) dst;
                if (dstStart + length > target.length) {
                    throw new ArrayIndexOutOfBoundsException("destination array index out of range: " + (int) (dstStart + length));
                }
                for (int x = 0; x < length; x++) {
                    ImagePointer leafBase = leafBaseForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 2));
                    long leafIndex = leafIndexForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 2));
                    target[x + dstStart] = (char) (leafBase.getShortAt(leafIndex));
                }
            } else {
                throw new IllegalArgumentException("destination array type must be char");
            }
        // short
        } else if (type.equals(ARRAY_PREFIX_SIGNATURE + SHORT_SIGNATURE)) {
            if (dst instanceof short[]) {
                short[] target = (short[]) dst;
                if (dstStart + length > target.length) {
                    throw new ArrayIndexOutOfBoundsException("destination array index out of range: " + (int) (dstStart + length));
                }
                for (int x = 0; x < length; x++) {
                    ImagePointer leafBase = leafBaseForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 2));
                    long leafIndex = leafIndexForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 2));
                    target[x + dstStart] = leafBase.getShortAt(leafIndex);
                }
            } else {
                throw new IllegalArgumentException("destination array type must be short");
            }
        // int
        } else if (type.equals(ARRAY_PREFIX_SIGNATURE + INTEGER_SIGNATURE)) {
            if (dst instanceof int[]) {
                int[] target = (int[]) dst;
                if (dstStart + length > target.length) {
                    throw new ArrayIndexOutOfBoundsException("destination array index out of range: " + (int) (dstStart + length));
                }
                for (int x = 0; x < length; x++) {
                    ImagePointer leafBase = leafBaseForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 4));
                    long leafIndex = leafIndexForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 4));
                    target[x + dstStart] = leafBase.getIntAt(leafIndex);
                }
            } else {
                throw new IllegalArgumentException("destination array type must be int");
            }
        // long
        } else if (type.equals(ARRAY_PREFIX_SIGNATURE + LONG_SIGNATURE)) {
            if (dst instanceof long[]) {
                long[] target = (long[]) dst;
                if (dstStart + length > target.length) {
                    throw new ArrayIndexOutOfBoundsException("destination array index out of range: " + (int) (dstStart + length));
                }
                for (int x = 0; x < length; x++) {
                    ImagePointer leafBase = leafBaseForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 8));
                    long leafIndex = leafIndexForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 8));
                    target[x + dstStart] = leafBase.getLongAt(leafIndex);
                }
            } else {
                throw new IllegalArgumentException("destination array type must be long");
            }
        // float
        } else if (type.equals(ARRAY_PREFIX_SIGNATURE + FLOAT_SIGNATURE)) {
            if (dst instanceof float[]) {
                float[] target = (float[]) dst;
                if (dstStart + length > target.length) {
                    throw new ArrayIndexOutOfBoundsException("destination array index out of range: " + (int) (dstStart + length));
                }
                for (int x = 0; x < length; x++) {
                    ImagePointer leafBase = leafBaseForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 4));
                    long leafIndex = leafIndexForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 4));
                    target[x + dstStart] = leafBase.getFloatAt(leafIndex);
                }
            } else {
                throw new IllegalArgumentException("destination array type must be float");
            }
        // double
        } else if (type.equals(ARRAY_PREFIX_SIGNATURE + DOUBLE_SIGNATURE)) {
            if (dst instanceof double[]) {
                double[] target = (double[]) dst;
                if (dstStart + length > target.length) {
                    throw new ArrayIndexOutOfBoundsException("destination array index out of range: " + (int) (dstStart + length));
                }
                for (int x = 0; x < length; x++) {
                    ImagePointer leafBase = leafBaseForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 8));
                    long leafIndex = leafIndexForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 8));
                    target[x + dstStart] = leafBase.getDoubleAt(leafIndex);
                }
            } else {
                throw new IllegalArgumentException("destination array type must be double");
            }
        // object
        } else {
            // type must be Object
            if (!(dst instanceof Object[])) {
                throw new IllegalArgumentException("destination array type must be Object");
            }
            Object[] target = (Object[]) dst;
            if (dstStart + length > target.length) {
                throw new ArrayIndexOutOfBoundsException("destination array index out of range: " + (int) (dstStart + length));
            }
            // gather all the JavaObject refs into an intermediate array, throwing exceptions if we encounter an error
            Object[] intermediateArray = new Object[length];
            for (int x = 0; x < length; x++) {
                int fobjectSize = _containingHeap.getFObjectSize();
                ImagePointer leafBase = leafBaseForIndex(isa.getFirstElementOffset(), ((srcStart + x) * fobjectSize));
                long leafIndex = leafIndexForIndex(isa.getFirstElementOffset(), ((srcStart + x) * fobjectSize));
                ImagePointer pointer = _containingHeap.readFObjectAt(leafBase, leafIndex);
                try {
                    // an object.
                    if (pointer.getAddress() == 0) {
                        // CMVC 175864 : the getObjectAtAddress function enforces stricter address checking, so need to exclude uninitialised slots up front
                        intermediateArray[x] = null;
                    } else {
                        try {
                            intermediateArray[x] = _javaVM.getObjectAtAddress(pointer);
                        } catch (IllegalArgumentException e) {
                            // an IllegalArgumentException might be thrown if the address is not aligned
                            throw new CorruptDataException(new CorruptData(e.getMessage(), pointer));
                        }
                    }
                } catch (ArrayStoreException e) {
                    throw new IllegalArgumentException(e.getMessage());
                }
            }
            // if no exceptions were thrown, update the caller's array all in one go
            for (int i = 0; i < length; i++) {
                try {
                    target[dstStart + i] = intermediateArray[i];
                } catch (ArrayStoreException e) {
                    throw new IllegalArgumentException(e.getMessage());
                }
            }
        }
    } else {
        throw new IllegalArgumentException("this JavaObject instance is not an array");
    }
}
Also used : CorruptDataException(com.ibm.dtfj.image.CorruptDataException) ImagePointer(com.ibm.dtfj.image.ImagePointer) JavaClass(com.ibm.dtfj.java.JavaClass) CorruptData(com.ibm.dtfj.image.j9.CorruptData)

Example 44 with JavaClass

use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.

the class JavaObject method getFieldReference.

private JavaReference getFieldReference(JavaField jField) {
    JavaReference jRef = null;
    try {
        String sigPrefix = jField.getSignature();
        JavaClass jClass = getJavaClass();
        if (sigPrefix.startsWith(JavaField.OBJECT_PREFIX_SIGNATURE) || sigPrefix.startsWith(JavaField.ARRAY_PREFIX_SIGNATURE)) {
            // this is an object reference.
            try {
                JavaObject jObject = (JavaObject) jField.getReferenceType(this);
                if (null != jObject) {
                    // build a JavaReference type and add the reference to the container.
                    String fieldName = jField.getName();
                    String description = "Object Reference";
                    if (null != fieldName) {
                        description = description + " [field name:" + fieldName + "]";
                    }
                    // Now figure out the reachability of the new reference.
                    // This will normally be "strong", except for the referent field of a reference,
                    // for which reachability will be weak, soft or phantom, depending on the concrete reference type.
                    int reachability = JavaReference.REACHABILITY_STRONG;
                    if ("referent".equals(fieldName) && "java/lang/ref/Reference".equals(jField.getDeclaringClass().getName())) {
                        if (_javaVM._weakReferenceClass != null && _javaVM._weakReferenceClass.isAncestorOf(jClass)) {
                            reachability = JavaReference.REACHABILITY_WEAK;
                        } else if (_javaVM._softReferenceClass != null && _javaVM._softReferenceClass.isAncestorOf(jClass)) {
                            reachability = JavaReference.REACHABILITY_SOFT;
                        } else if (_javaVM._phantomReferenceClass != null && _javaVM._phantomReferenceClass.isAncestorOf(jClass)) {
                            reachability = JavaReference.REACHABILITY_PHANTOM;
                        }
                    }
                    jRef = new JavaReference(_javaVM, this, jObject, description, JavaReference.REFERENCE_FIELD, JavaReference.HEAP_ROOT_UNKNOWN, reachability);
                }
            } catch (CorruptDataException e) {
            }
        }
    } catch (CorruptDataException e) {
    } catch (MemoryAccessException e) {
    }
    return jRef;
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 45 with JavaClass

use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.

the class JavaThread method getName.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaThread#getName()
	 */
public String getName() throws CorruptDataException {
    JavaObject theObject = getObject();
    if (null != theObject) {
        JavaClass threadClass = _javaLangThreadSuperclass();
        Iterator fields = threadClass.getDeclaredFields();
        while (fields.hasNext()) {
            JavaField oneField = (JavaField) fields.next();
            if (oneField.getName().equals("name")) {
                try {
                    return oneField.getString(theObject);
                } catch (MemoryAccessException e) {
                    throw new CorruptDataException(new CorruptData("unable to read memory for 'name' field", null));
                }
            }
        }
        throw new CorruptDataException(new CorruptData("unable to find 'name' field", null));
    } else {
        return "vmthread @" + _jniEnv.getAddress();
    }
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) CorruptData(com.ibm.dtfj.image.j9.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Aggregations

JavaClass (com.ibm.dtfj.java.JavaClass)70 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)40 JavaObject (com.ibm.dtfj.java.JavaObject)39 Iterator (java.util.Iterator)33 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)23 CorruptData (com.ibm.dtfj.image.CorruptData)11 ArrayList (java.util.ArrayList)10 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)9 ImagePointer (com.ibm.dtfj.image.ImagePointer)9 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)9 CorruptData (com.ibm.dtfj.image.j9.CorruptData)8 JavaReference (com.ibm.dtfj.java.JavaReference)8 JavaField (com.ibm.dtfj.java.JavaField)6 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)6 LongEnumeration (com.ibm.dtfj.phd.util.LongEnumeration)5 JavaMethod (com.ibm.dtfj.java.JavaMethod)4 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)4 J9Object (com.ibm.j9ddr.vm29.structure.J9Object)4 LongListReferenceIterator (com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator)4 ReferenceIterator (com.ibm.jvm.dtfjview.heapdump.ReferenceIterator)4