Search in sources :

Example 56 with CorruptDataException

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

the class JavaArrayClass method getName.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaClass#getName()
	 */
public String getName() throws CorruptDataException {
    String name = "";
    // Note that validation in JavaObject.arraycopy is dependent on type name constructed here
    for (int x = 0; x < _dimension; x++) {
        name += JavaObject.ARRAY_PREFIX_SIGNATURE;
    }
    JavaClass leafClass = getLeafClass();
    if (null == leafClass) {
        CorruptData data = new CorruptData("unable to retrieve leaf class", null);
        throw new CorruptDataException(data);
    }
    String elementClassName = leafClass.getName();
    if (elementClassName.equals("boolean")) {
        name += JavaObject.BOOLEAN_SIGNATURE;
    } else if (elementClassName.equals("byte")) {
        name += JavaObject.BYTE_SIGNATURE;
    } else if (elementClassName.equals("char")) {
        name += JavaObject.CHAR_SIGNATURE;
    } else if (elementClassName.equals("short")) {
        name += JavaObject.SHORT_SIGNATURE;
    } else if (elementClassName.equals("int")) {
        name += JavaObject.INTEGER_SIGNATURE;
    } else if (elementClassName.equals("long")) {
        name += JavaObject.LONG_SIGNATURE;
    } else if (elementClassName.equals("float")) {
        name += JavaObject.FLOAT_SIGNATURE;
    } else if (elementClassName.equals("double")) {
        name += JavaObject.DOUBLE_SIGNATURE;
    } else {
        // reference type
        name += JavaObject.OBJECT_PREFIX_SIGNATURE;
        name += elementClassName;
        name += ';';
    }
    return name;
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) CorruptData(com.ibm.dtfj.image.j9.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 57 with CorruptDataException

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

the class JavaClass method getConstantPoolReferences.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaClass#getConstantPoolReferences()
	 */
public Iterator getConstantPoolReferences() {
    // first look up all the class IDs and translate them into classes then add the objects
    Iterator ids = _constantPoolClassRefs.iterator();
    Vector allRefs = new Vector();
    while (ids.hasNext()) {
        long oneID = ((Long) ids.next()).longValue();
        Object toBeAdded = null;
        com.ibm.dtfj.java.JavaClass oneClass = _javaVM.getClassForID(oneID);
        if (oneClass == null) {
            toBeAdded = new CorruptData("Unknown class in constant pool " + oneID, null);
        } else {
            try {
                toBeAdded = oneClass.getObject();
            } catch (CorruptDataException e) {
                toBeAdded = e.getCorruptData();
            } catch (Exception e) {
                toBeAdded = new CorruptData(e.getMessage());
            }
        }
        allRefs.add(toBeAdded);
    }
    // Loop through the list of constant pool objects, instantiating them and adding them to the list
    for (int i = 0; i < _constantPoolObjects.size(); i++) {
        try {
            long objectId = ((Long) (_constantPoolObjects.get(i))).longValue();
            if (objectId != 0) {
                ImagePointer pointer = _javaVM.pointerInAddressSpace(objectId);
                try {
                    JavaObject instance = _javaVM.getObjectAtAddress(pointer);
                    allRefs.add(instance);
                } catch (IllegalArgumentException e) {
                    // getObjectAtAddress may throw an IllegalArgumentException if the address is not aligned
                    allRefs.add(new CorruptData(e.getMessage(), pointer));
                }
            }
        } catch (CorruptDataException e) {
            allRefs.add(e.getCorruptData());
        }
    }
    return allRefs.iterator();
}
Also used : CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) ImagePointer(com.ibm.dtfj.image.ImagePointer) JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.j9.CorruptData) Vector(java.util.Vector)

Example 58 with CorruptDataException

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

the class JavaObject method getSections.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaObject#getSections()
	 */
public Iterator getSections() {
    // (not initialized so that code paths will be compiler-validated)
    List sections;
    // arraylets have a more complicated scheme so handle them differently
    if (isArraylet()) {
        try {
            JavaArrayClass arrayForm = (JavaArrayClass) getJavaClass();
            // the first element comes immediately after the header so the offset to it is the size of the header
            // NOTE:  this header size does NOT count arraylet leaves
            int objectHeaderSize = arrayForm.getFirstElementOffset();
            // we require the pointer size in order to walk the leaf pointers in the spine
            int bytesPerPointer = _javaVM.bytesPerPointer();
            try {
                int instanceSize = arrayForm.getInstanceSize(this);
                // the instance size will include the header and the actual data inside the array so seperate them
                long contentDataSize = (long) (instanceSize - objectHeaderSize);
                // get the number of leaves, excluding the tail leaf (the tail leaf is the final leaf which points back into the spine).  There won't be one if there is isn't a remainder in this calculation since it would be empty
                int fullSizeLeaves = (int) (contentDataSize / _arrayletLeafSize);
                // find out how big the tail leaf would be
                long tailLeafSize = contentDataSize % _arrayletLeafSize;
                // if it is non-zero, we know that there must be one (bear in mind the fact that all arraylets have at least 1 leaf pointer - consider empty arrays)
                int totalLeafCount = (0 == tailLeafSize) ? fullSizeLeaves : (fullSizeLeaves + 1);
                // CMVC 153943 : DTFJ fix for zero-length arraylets - remove code to add 1 to the leaf count in the event that it is 0.
                // by always assuming there is a leaf means that when the image sections are determined it will cause an error as there
                // is no space allocated in this instace beyond the size of the spine.
                String nestedType = arrayForm.getLeafClass().getName();
                // 4-byte object alignment in realtime requires the long and double arraylets have padding which may need to be placed before the array data or after, depending on if the alignment succeeded at a natural boundary or not
                boolean alignmentCandidate = (4 == _objectAlignment) && ("double".equals(nestedType) || "long".equals(nestedType));
                // we will need a size for the section which includes the spine (and potentially the tail leaf or even all the leaves (in immortal))
                // start with the object header and the leaves
                long headerAndLeafPointers = objectHeaderSize + (totalLeafCount * bytesPerPointer);
                long spineSectionSize = headerAndLeafPointers;
                // we will now walk the leaves to see if this is an inline arraylet
                // first off, see if we would need padding to align the first inline data element
                long nextExpectedInteriorLeafAddress = _basePointer.getAddress() + headerAndLeafPointers;
                boolean doesHaveTailPadding = false;
                if (alignmentCandidate && (totalLeafCount > 0)) {
                    // alignment candidates need to have at least 1 leaf otherwise there is nothing to align
                    if (0 == (nextExpectedInteriorLeafAddress % 8)) {
                        // no need to add extra space here so the extra slot will be at the tail
                        doesHaveTailPadding = true;
                    } else {
                        // we need to bump up our expected location for alignment
                        nextExpectedInteriorLeafAddress += 4;
                        spineSectionSize += 4;
                        if (0 != (nextExpectedInteriorLeafAddress % 8)) {
                            // this can't happen so the core is corrupt
                            throw new CorruptDataException(new CorruptData("Arraylet leaf pointer misaligned for object", _basePointer));
                        }
                    }
                }
                Vector externalSections = null;
                for (int i = 0; i < totalLeafCount; i++) {
                    ImagePointer leafPointer = _basePointer.getPointerAt(objectHeaderSize + (i * bytesPerPointer));
                    if (leafPointer.getAddress() == nextExpectedInteriorLeafAddress) {
                        // this pointer is interior so add it to the spine section
                        long internalLeafSize = _arrayletLeafSize;
                        if (fullSizeLeaves == i) {
                            // this is the last leaf so get the tail leaf size
                            internalLeafSize = tailLeafSize;
                        }
                        spineSectionSize += internalLeafSize;
                        nextExpectedInteriorLeafAddress += internalLeafSize;
                    } else {
                        // this pointer is exterior so make it its own section
                        if (null == externalSections) {
                            externalSections = new Vector();
                        }
                        externalSections.add(new JavaObjectImageSection(leafPointer, _arrayletLeafSize));
                    }
                }
                if (doesHaveTailPadding) {
                    // now, add the extra 4 bytes to the end
                    spineSectionSize += 4;
                }
                // ensure that we are at least the minimum object size
                spineSectionSize = Math.max(spineSectionSize, _arrayletSpineSize);
                JavaObjectImageSection spineSection = new JavaObjectImageSection(_basePointer, spineSectionSize);
                if (null == externalSections) {
                    // create the section list, with the spine first (other parts of our implementation use the knowledge that the spine is first to reduce logic duplication)
                    sections = Collections.singletonList(spineSection);
                } else {
                    sections = new Vector();
                    sections.add(spineSection);
                    sections.addAll(externalSections);
                }
            } catch (MemoryAccessException e) {
                // if we had a memory access exception, the spine must be corrupt, or something
                sections = Collections.singletonList(new CorruptData("failed to walk arraylet spine", e.getPointer()));
            }
        } catch (CorruptDataException e) {
            sections = Collections.singletonList(e.getCorruptData());
        }
    } else {
        // currently J9 objects are atomic extents of memory but that changes with metronome and that will probably extend to other VM configurations, as well
        long size = 0;
        try {
            size = ((com.ibm.dtfj.java.j9.JavaAbstractClass) getJavaClass()).getInstanceSize(this);
            JavaObjectImageSection section = new JavaObjectImageSection(_basePointer, size);
            sections = Collections.singletonList(section);
        } catch (CorruptDataException e) {
            sections = Collections.singletonList(e.getCorruptData());
        }
    // XXX - handle the case of this corrupt data better (may require API change)
    }
    return sections.iterator();
}
Also used : CorruptDataException(com.ibm.dtfj.image.CorruptDataException) ImagePointer(com.ibm.dtfj.image.ImagePointer) ArrayList(java.util.ArrayList) List(java.util.List) CorruptData(com.ibm.dtfj.image.j9.CorruptData) Vector(java.util.Vector) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 59 with CorruptDataException

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

the class JavaReference method getTarget.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaReference#getTarget()
	 */
public Object getTarget() throws DataUnavailable, CorruptDataException {
    if (null == _target) {
        if (0 == _address) {
            // we have no way of determining the target so it is unresolved.
            _resolution = ResolutionType_UNRESOLVED;
            return null;
        }
        if (JavaReference.HEAP_ROOT_SYSTEM_CLASS == _roottype || JavaReference.REFERENCE_CLASS == _referencetype || JavaReference.REFERENCE_SUPERCLASS == _referencetype || JavaReference.REFERENCE_LOADED_CLASS == _referencetype || JavaReference.REFERENCE_ASSOCIATED_CLASS == _referencetype) {
            // this is a class reference, so create a class to represent the target.
            _target = _javaVM.getClassForID(_address);
            if (null == _target) {
                ImagePointer pointer = _javaVM.pointerInAddressSpace(_address);
                _resolution = ResolutionType_BROKEN;
                throw new CorruptDataException(new CorruptData("Unknown class ID", pointer));
            }
            _resolution = ResolutionType_CLASS;
        } else if ((JavaReference.HEAP_ROOT_JNI_GLOBAL == _roottype) || (JavaReference.HEAP_ROOT_JNI_LOCAL == _roottype) || (JavaReference.HEAP_ROOT_MONITOR == _roottype) || (JavaReference.HEAP_ROOT_OTHER == _roottype) || (JavaReference.HEAP_ROOT_STACK_LOCAL == _roottype) || (JavaReference.HEAP_ROOT_THREAD == _roottype) || (JavaReference.HEAP_ROOT_FINALIZABLE_OBJ == _roottype) || (JavaReference.HEAP_ROOT_UNFINALIZED_OBJ == _roottype) || (JavaReference.HEAP_ROOT_CLASSLOADER == _roottype) || (JavaReference.HEAP_ROOT_STRINGTABLE == _roottype) || (JavaReference.REFERENCE_ARRAY_ELEMENT == _referencetype) || (JavaReference.REFERENCE_CLASS_LOADER == _referencetype) || (JavaReference.REFERENCE_CONSTANT_POOL == _referencetype) || (JavaReference.REFERENCE_FIELD == _referencetype) || (JavaReference.REFERENCE_INTERFACE == _referencetype) || (JavaReference.REFERENCE_PROTECTION_DOMAIN == _referencetype) || (JavaReference.REFERENCE_SIGNERS == _referencetype) || (JavaReference.REFERENCE_STATIC_FIELD == _referencetype) || (JavaReference.REFERENCE_CLASS_OBJECT == _referencetype)) {
            // this is an object reference, so create a object to represent the target.
            ImagePointer pointer = _javaVM.pointerInAddressSpace(_address);
            try {
                _target = _javaVM.getObjectAtAddress(pointer);
            } catch (IllegalArgumentException e) {
                // getObjectAtAddress can throw an IllegalArgumentException if the address is not aligned
                _resolution = ResolutionType_BROKEN;
                throw new CorruptDataException(new com.ibm.dtfj.image.j9.CorruptData(e.getMessage(), pointer));
            }
            if (_target == null) {
                _resolution = ResolutionType_BROKEN;
                throw new CorruptDataException(new CorruptData("Unknown object ID", pointer));
            }
            _resolution = ResolutionType_OBJECT;
        } else {
            // we have no way of determining the target so it is unresolved.
            _resolution = ResolutionType_UNRESOLVED;
            return null;
        }
    }
    return _target;
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer) CorruptData(com.ibm.dtfj.image.j9.CorruptData) CorruptData(com.ibm.dtfj.image.j9.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 60 with CorruptDataException

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

the class JavaInstanceField method getReferenceType.

public Object getReferenceType(JavaObject object) throws CorruptDataException, MemoryAccessException {
    // sanity check
    if (_isSafeToAccess(object)) {
        checkDeclaringClass(object);
        String sigPrefix = getSignature();
        if (sigPrefix.startsWith(OBJECT_PREFIX_SIGNATURE) || sigPrefix.startsWith(ARRAY_PREFIX_SIGNATURE)) {
            ImagePointer value = ((com.ibm.dtfj.java.j9.JavaObject) object).getFObjectAtOffset(_offset);
            // CMVC 173262 - return null if the reference object is null
            if (0 == value.getAddress()) {
                // points to a null reference
                return null;
            }
            try {
                return _javaVM.getObjectAtAddress(value);
            } catch (IllegalArgumentException e) {
                // getObjectAtAddress can throw an IllegalArgumentException if the address is not aligned
                throw new CorruptDataException(new com.ibm.dtfj.image.j9.CorruptData(e.getMessage(), value));
            }
        } else {
            throw new IllegalArgumentException();
        }
    } else {
        throw new NullPointerException();
    }
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer) JavaObject(com.ibm.dtfj.java.JavaObject) 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