Search in sources :

Example 21 with ImagePointer

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

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

the class JavaObject method leafBaseForIndex.

private ImagePointer leafBaseForIndex(int firstElementOffset, long index) throws CorruptDataException, MemoryAccessException {
    ImagePointer ret = null;
    if (isArraylet()) {
        int fobjectSize = _containingHeap.getFObjectSize();
        long pointerIndex = index / _arrayletLeafSize;
        long pointerAddress = firstElementOffset + (fobjectSize * pointerIndex);
        ret = _containingHeap.readFObjectAt(_basePointer, pointerAddress);
    } else {
        ret = _basePointer;
    }
    return ret;
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer)

Example 23 with ImagePointer

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

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

Example 25 with ImagePointer

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

the class DTFJMethod method handleException.

/**
 * Handle an exception thrown by the DTFJ API.
 *
 * @param cmd the command current executing the API. This is required to provide access to context information.
 * @param cause exception to be handled
 * @return textual data to be written out
 */
public static String handleException(BaseJdmpviewCommand cmd, Throwable cause) {
    ctx = cmd.ctx;
    StringBuffer sb = new StringBuffer();
    // Try and determine the artifact type
    StackTraceElement[] myStack = cause.getStackTrace();
    ArtifactType artifactType = cmd.getArtifactType();
    String artifactTypeName = null;
    switch(artifactType) {
        case core:
            artifactTypeName = "core";
            break;
        case javacore:
            artifactTypeName = "javacore";
            break;
        case phd:
            artifactTypeName = "phd";
            break;
        default:
            artifactTypeName = "Unknown artifact type";
            break;
    }
    // Let's find out which DTFJ Class/Method was being used
    DTFJMethod dMethod = getDTFJMethod(myStack, cmd);
    if (cause instanceof DataUnavailable) {
        if (dMethod == null) {
            sb.append("Could not determine DTFJ class/method that caused this exception: ");
            sb.append(cause.getLocalizedMessage());
        } else if (dMethod.isSupported(artifactType) == WORKS) {
            sb.append(dMethod.getClassName());
            sb.append(".");
            sb.append(dMethod.getMethodname());
            sb.append(" should have worked for a ");
            sb.append(artifactTypeName);
            sb.append(" but returned: ");
            sb.append(cause.getLocalizedMessage());
        } else if (dMethod.isSupported(artifactType) == CAN_FAIL) {
            sb.append(dMethod.getClassName());
            sb.append(".");
            sb.append(dMethod.getMethodname());
            sb.append(" can fail for a ");
            sb.append(artifactTypeName);
            sb.append(" which is why it returned: ");
            sb.append(cause.getLocalizedMessage());
        } else if (dMethod.isSupported(artifactType) == FAILS) {
            sb.append(dMethod.getClassName());
            sb.append(".");
            sb.append(dMethod.getMethodname());
            sb.append(" is not supported for a ");
            sb.append(artifactTypeName);
            String s = cause.getLocalizedMessage();
            if (s != null) {
                sb.append(" causing: ");
                sb.append(s);
            }
        }
    } else if (cause instanceof CorruptDataException) {
        CorruptData corruptData = ((CorruptDataException) cause).getCorruptData();
        ImagePointer ip = corruptData.getAddress();
        if (ip == null) {
            sb.append("CorruptData found in dump at unknown address executing ");
            if (dMethod == null) {
                sb.append("an unknown class/method that caused this exception: ");
                sb.append(cause.getLocalizedMessage());
            } else {
                sb.append(dMethod.getClassName());
                sb.append(".");
                sb.append(dMethod.getMethodname());
            }
        } else {
            String addr = cmd.toHexStringAddr(ip.getAddress());
            sb.append("CorruptData found in dump at address: ");
            sb.append(addr);
            sb.append(" causing: ");
            sb.append(cause.getLocalizedMessage());
            if (dMethod != null) {
                sb.append(" executing ");
                sb.append(dMethod.getClassName());
                sb.append(".");
                sb.append(dMethod.getMethodname());
            }
        }
    } else if (cause instanceof MemoryAccessException) {
        sb.append(cause.getLocalizedMessage());
    } else if (cause instanceof IllegalArgumentException) {
        sb.append(cause.getLocalizedMessage());
    } else {
        // If we are here then something bad has really happened
        // This is just debug code to help determine other problems this
        // method has to deal with
        sb.append("==========> Unexpected exception " + cause.getClass().getName() + " thrown: " + cause.getLocalizedMessage());
        StringWriter st = new StringWriter();
        cause.printStackTrace(new PrintWriter(st));
        sb.append(st.toString());
    }
    return sb.toString();
}
Also used : CorruptDataException(com.ibm.dtfj.image.CorruptDataException) ImagePointer(com.ibm.dtfj.image.ImagePointer) StringWriter(java.io.StringWriter) ArtifactType(com.ibm.jvm.dtfjview.commands.BaseJdmpviewCommand.ArtifactType) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptData(com.ibm.dtfj.image.CorruptData) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException) PrintWriter(java.io.PrintWriter)

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