Search in sources :

Example 81 with CorruptDataException

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

the class JavaAbstractClass method addClassLoaderReference.

protected void addClassLoaderReference(Collection coll) {
    JavaReference jRef = null;
    try {
        JavaClassLoader classLoader = this.getClassLoader();
        if (null != classLoader) {
            JavaObject classLoaderObject = classLoader.getObject();
            if (null != classLoaderObject) {
                jRef = new JavaReference(_javaVM, this, classLoaderObject, "Classloader", JavaReference.REFERENCE_CLASS_LOADER, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
                coll.add(jRef);
            }
        }
    } catch (CorruptDataException e) {
        coll.add(e.getCorruptData());
    }
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 82 with CorruptDataException

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

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

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

the class JavaObject method getArrayReferences.

private List getArrayReferences(JavaArrayClass arrayClass) {
    List references = new ArrayList();
    try {
        String type = arrayClass.getComponentType().getName();
        if (type.equals("byte")) {
        // ignore byte arrays.
        } else if (type.equals("boolean")) {
        // ignore boolean arrays.
        } else if (type.equals("char")) {
        // ignore char arrays.
        } else if (type.equals("short")) {
        // ignore short arrays.
        } else if (type.equals("int")) {
        // ignore int arrays.
        } else if (type.equals("long")) {
        // ignore long arrays.
        } else if (type.equals("float")) {
        // ignore float arrays.
        } else if (type.equals("double")) {
        // ignore double arrays.
        } else {
            // must be Object array so handle it.
            Object[] dst = null;
            int arraySize = getArraySize();
            if (arraySize > 0) {
                // only deal with arrays that have space for Object references.
                dst = new Object[arraySize];
                try {
                    // copy the objects into our own array and then build the JavaReference
                    // objects from them.
                    arraycopy(0, dst, 0, arraySize);
                    for (int i = 0; i < dst.length; i++) {
                        if (null != dst[i]) {
                            String description = "Array Reference";
                            description = description + " [index:" + i + "]";
                            JavaReference jRef = new JavaReference(_javaVM, this, dst[i], description, JavaReference.REFERENCE_ARRAY_ELEMENT, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
                            references.add(jRef);
                        }
                    }
                } catch (MemoryAccessException e) {
                    // Memory access problems, so create a CorruptData object
                    // to describe the problem and add it to the container.
                    ImagePointer ptrInError = e.getPointer();
                    String message = e.getMessage();
                    references.add(new CorruptData(message, ptrInError));
                }
            }
        }
    } catch (CorruptDataException e) {
        // Corrupt data, so add it to the container.
        references.add(e.getCorruptData());
    }
    return references;
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CorruptData(com.ibm.dtfj.image.j9.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 85 with CorruptDataException

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

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