Search in sources :

Example 36 with JavaObject

use of com.ibm.dtfj.java.JavaObject 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 37 with JavaObject

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

the class HeapdumpCommand method addStaticReferences.

/**
 * Extracts static references from class
 * @param thisClass Class being examined
 * @param references List to add references to
 */
private void addStaticReferences(JavaClass thisClass, List references) throws CorruptDataException, MemoryAccessException {
    Iterator fieldsIt = thisClass.getDeclaredFields();
    while (fieldsIt.hasNext()) {
        Object potential = fieldsIt.next();
        if (potential instanceof CorruptData) {
            reportError("Corrupt field found in class " + thisClass.getName() + "(" + thisClass.getID() + ") at " + ((CorruptData) potential).getAddress(), null);
            _numberOfErrors++;
            continue;
        }
        JavaField field = (JavaField) potential;
        if (!Modifier.isStatic(field.getModifiers())) {
            continue;
        }
        Object referent = field.get(thisClass.getObject());
        if (referent instanceof CorruptData) {
            _numberOfErrors++;
            reportError("Corrupt referent found in class " + thisClass.getName() + "(" + thisClass.getID() + ") from field " + field.getName() + " at address " + ((CorruptData) potential).getAddress(), null);
        } else if (referent instanceof JavaObject) {
            JavaObject referredObject = (JavaObject) referent;
            references.add(new Long(referredObject.getID().getAddress()));
        } else if (referent == null) {
            references.add(new Long(0));
        } else if (referent instanceof Number || referent instanceof Boolean || referent instanceof Character) {
        // Ignore
        } else {
            reportError("Unexpected type: " + referent.getClass().getName() + " returned from field " + field.getName() + " from class " + thisClass.getName() + "(" + thisClass.getID() + ")", null);
            _numberOfErrors++;
        }
    }
}
Also used : JavaField(com.ibm.dtfj.java.JavaField) JavaObject(com.ibm.dtfj.java.JavaObject) ReferenceIterator(com.ibm.jvm.dtfjview.heapdump.ReferenceIterator) Iterator(java.util.Iterator) LongListReferenceIterator(com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData)

Example 38 with JavaObject

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

the class DTFJJavaClass method addStaticFieldReferences.

@SuppressWarnings("rawtypes")
private void addStaticFieldReferences(List<Object> references) {
    JavaReference jRef;
    Iterator declaredFieldIt = getDeclaredFields();
    // can get corrupt data returned through the field iterator as it's coming from DTFJ
    Object obj = null;
    while ((declaredFieldIt.hasNext() && (obj = declaredFieldIt.next()) instanceof DTFJJavaField)) {
        DTFJJavaField jField = (DTFJJavaField) obj;
        if (jField instanceof DTFJJavaFieldStatic) {
            JavaObject jObject;
            try {
                char type = jField.getSignature().charAt(0);
                if (type == DTFJConstants.OBJECT_PREFIX_SIGNATURE || type == DTFJConstants.ARRAY_PREFIX_SIGNATURE) {
                    jObject = (JavaObject) jField.get(null);
                    if (jObject != null) {
                        // build a JavaReference type and add the reference to the container.
                        String fieldName = jField.getName();
                        String description = "Static field";
                        if (null != fieldName) {
                            description = description + " [field name:" + fieldName + "]";
                        }
                        jRef = new DTFJJavaReference(this, jObject, description, JavaReference.REFERENCE_STATIC_FIELD, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
                        references.add(jRef);
                    }
                }
            } catch (Throwable t) {
                CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
                references.add(cd);
            }
        }
    }
}
Also used : JavaReference(com.ibm.dtfj.java.JavaReference) JavaObject(com.ibm.dtfj.java.JavaObject) J9ObjectFieldOffsetIterator(com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffsetIterator) DTFJConstantPoolIterator(com.ibm.j9ddr.vm29.view.dtfj.java.j9.DTFJConstantPoolIterator) J9DDRDTFJUtils.corruptIterator(com.ibm.j9ddr.view.dtfj.J9DDRDTFJUtils.corruptIterator) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) J9Object(com.ibm.j9ddr.vm29.structure.J9Object) CorruptData(com.ibm.dtfj.image.CorruptData) J9DDRCorruptData(com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)

Example 39 with JavaObject

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

the class DTFJJavaObject method getAssociatedClass.

private JavaClass getAssociatedClass(JavaObject targetClassLoaderObject) {
    Iterator<?> classloaderIt = DTFJContext.getRuntime().getJavaClassLoaders();
    while (classloaderIt.hasNext()) {
        Object clObj = classloaderIt.next();
        if (clObj instanceof JavaClassLoader) {
            JavaClassLoader loader = (JavaClassLoader) clObj;
            try {
                if (targetClassLoaderObject != null && !loader.getObject().equals(targetClassLoaderObject)) {
                    continue;
                }
            } catch (CorruptDataException e1) {
            // This is an optimisation so if it fails, continue.
            }
            Iterator<?> classesIt = loader.getDefinedClasses();
            while (classesIt.hasNext()) {
                Object classObj = classesIt.next();
                if (classObj instanceof JavaClass) {
                    JavaClass clazz = (JavaClass) classObj;
                    try {
                        if (clazz.getObject().equals(this)) {
                            return clazz;
                        }
                    } catch (CorruptDataException e) {
                    // Deliberately do nothing. If this is the class we're interesting in, we'll
                    // insert a CorruptData object later when it isn't found. If it's not the class
                    // we want, we don't need to worry
                    }
                }
            }
        }
    }
    return null;
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaClass(com.ibm.dtfj.java.JavaClass) JavaObject(com.ibm.dtfj.java.JavaObject) J9Object(com.ibm.j9ddr.vm29.structure.J9Object) CorruptJavaObject(com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 40 with JavaObject

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

the class DTFJJavaObject method addObjectArrayReferencesWithLimitCheck.

/**
 * If the array is corrupt, it can report having some huge number of elements. This can lead to OOM (see defect 181042).
 * To avoid that, try getting the first safetyLimit references - if they're all valid, then this is just a large object,
 * so carry on. Otherwise, throw CorruptDataException.
 * @param safetyLimit
 * @throws CorruptDataException
 * @throws MemoryAccessException
 */
private void addObjectArrayReferencesWithLimitCheck(final int safetyLimit) throws CorruptDataException, MemoryAccessException {
    JavaObject[] elements = new JavaObject[arraySize];
    JavaObject[] limitedElements = new JavaObject[safetyLimit];
    // also checks references are valid
    this.arraycopy(0, limitedElements, 0, safetyLimit);
    elements = new JavaObject[this.getArraySize() - safetyLimit];
    this.arraycopy(safetyLimit, elements, 0, this.getArraySize() - safetyLimit);
    // all went fine (no exception from arraycopy), so copy the results into the list
    for (int i = 0; i != limitedElements.length; i++) {
        JavaObject thisObj = limitedElements[i];
        if (thisObj != null) {
            references.add(new DTFJJavaReference(this, thisObj, "Array Reference [" + i + "]", JavaReference.REFERENCE_ARRAY_ELEMENT, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG));
        }
    }
    for (int i = 0; i != elements.length; i++) {
        JavaObject thisObj = elements[i];
        if (thisObj != null) {
            references.add(new DTFJJavaReference(this, thisObj, "Array Reference [" + i + "]", JavaReference.REFERENCE_ARRAY_ELEMENT, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG));
        }
    }
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) CorruptJavaObject(com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject)

Aggregations

JavaObject (com.ibm.dtfj.java.JavaObject)70 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)47 Iterator (java.util.Iterator)35 JavaClass (com.ibm.dtfj.java.JavaClass)31 CorruptData (com.ibm.dtfj.image.CorruptData)19 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)17 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)14 JavaReference (com.ibm.dtfj.java.JavaReference)9 JavaThread (com.ibm.dtfj.java.JavaThread)9 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)8 JavaField (com.ibm.dtfj.java.JavaField)7 ImagePointer (com.ibm.dtfj.image.ImagePointer)6 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)6 J9Object (com.ibm.j9ddr.vm29.structure.J9Object)6 CorruptJavaObject (com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject)6 CorruptData (com.ibm.dtfj.image.j9.CorruptData)5 LongEnumeration (com.ibm.dtfj.phd.util.LongEnumeration)5 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)5 LongListReferenceIterator (com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator)5 ReferenceIterator (com.ibm.jvm.dtfjview.heapdump.ReferenceIterator)5