Search in sources :

Example 16 with MemoryAccessException

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

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

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

Example 19 with MemoryAccessException

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

the class JavaHeapRegion method getObjectAtAddress.

public JavaObject getObjectAtAddress(ImagePointer address) throws CorruptDataException, IllegalArgumentException {
    JavaObject object = null;
    if ((null != address) && (0 != address.getAddress())) {
        // try the special objects cache first...
        JavaObject specialObject = _javaVM.getSpecialObject(address);
        if (null != specialObject) {
            return specialObject;
        }
        // CMVC 173262 - check alignment
        if ((address.getAddress() & (_objectAlignment - 1)) != 0) {
            throw new IllegalArgumentException("Invalid alignment for JavaObject should be " + _objectAlignment + " aligned. Address = " + address.toString());
        }
        long arrayletIdentificationBitmask = 0;
        long arrayletIdentificationResult = 0;
        int arrayletIdentificationWidth = 0;
        int arrayletIdentificationOffset = 0;
        int arrayletSpineSize = 0;
        long arrayletLeafSize = 0;
        arrayletIdentificationBitmask = _parentHeap.getArrayletIdentificationBitmask();
        arrayletIdentificationResult = _parentHeap.getArrayletIdentificationResult();
        arrayletIdentificationWidth = _parentHeap.getArrayletIdentificationWidth();
        arrayletIdentificationOffset = _parentHeap.getArrayletIdentificationOffset();
        arrayletSpineSize = getArrayletSpineSize();
        arrayletLeafSize = getArrayletLeafSize();
        boolean isArraylet = false;
        if (0 != arrayletIdentificationResult) {
            // note that this may be an arraylet so we need to do some extra work here
            long maskedFlags = 0;
            if (4 == arrayletIdentificationWidth) {
                try {
                    maskedFlags = 0xFFFFFFFFL & (long) (address.getIntAt(arrayletIdentificationOffset));
                } catch (MemoryAccessException e) {
                    throw new CorruptDataException(new CorruptData("unable to access object flags", address));
                }
            } else if (8 == arrayletIdentificationWidth) {
                try {
                    maskedFlags = address.getLongAt(arrayletIdentificationOffset);
                } catch (MemoryAccessException e) {
                    throw new CorruptDataException(new CorruptData("unable to access object flags", address));
                }
            } else {
                // this size cannot be read without exposing endian of the underlying core
                System.err.println("Arraylet identification width is invalid: " + arrayletIdentificationWidth + " (should be 4 or 8)");
            }
            isArraylet = arrayletIdentificationResult == (arrayletIdentificationBitmask & maskedFlags);
        }
        object = new com.ibm.dtfj.java.j9.JavaObject(_javaVM, address, _parentHeap, arrayletSpineSize, arrayletLeafSize, isArraylet, _objectAlignment);
    }
    return object;
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.j9.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 20 with MemoryAccessException

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

the class JavaObject method getPersistentHashcode.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaObject#getPersistentHashcode()
	 */
public long getPersistentHashcode() throws DataUnavailable, CorruptDataException {
    // this is a terrible way to do this since we know that it _will_ _break_ in the future.  It is, however, the best that we can do
    if (_javaVM.objectShouldInferHash()) {
        try {
            int flags = ((com.ibm.dtfj.java.j9.JavaAbstractClass) getJavaClass()).readFlagsFromInstance(this);
            // now mask out the non-hash bits, shift and return
            // high 15 bits, omitting most significant
            int twoBytes = flags & 0x7FFF0000;
            long hash = (twoBytes >> 16) | twoBytes;
            return hash;
        } catch (MemoryAccessException e) {
            // if we can't access the memory, the core must be corrupt
            throw new CorruptDataException(new CorruptData("Address in object header but unreadable", _basePointer));
        }
    } else {
        throw new DataUnavailable("Unknown hash strategy for this VM version");
    }
}
Also used : DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptData(com.ibm.dtfj.image.j9.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Aggregations

MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)25 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)24 JavaObject (com.ibm.dtfj.java.JavaObject)13 ImagePointer (com.ibm.dtfj.image.ImagePointer)11 CorruptData (com.ibm.dtfj.image.j9.CorruptData)9 JavaClass (com.ibm.dtfj.java.JavaClass)9 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)8 Iterator (java.util.Iterator)8 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)4 JavaThread (com.ibm.dtfj.java.JavaThread)4 JavaField (com.ibm.dtfj.java.JavaField)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Vector (java.util.Vector)3 CorruptData (com.ibm.dtfj.image.CorruptData)2 ImageThread (com.ibm.dtfj.image.ImageThread)2 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)2 HashMap (java.util.HashMap)2 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)1 JavaMethod (com.ibm.dtfj.java.JavaMethod)1