Search in sources :

Example 6 with JavaField

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

the class ClassOutput method printNonStaticFields.

public static void printNonStaticFields(JavaClass jc, PrintStream out) {
    // if the class name refers to an array, return because there are no fields
    try {
        if (jc.isArray()) {
            return;
        }
    } catch (CorruptDataException cde) {
        out.print("\t  <can't determine if class is array; assuming it's not>\n\n");
    }
    String className;
    try {
        className = jc.getName();
    } catch (CorruptDataException cde) {
        className = null;
    }
    // we've found a class, so we'll print out its static fields
    boolean found = false;
    Iterator itField = jc.getDeclaredFields();
    while (itField.hasNext()) {
        JavaField jf = (JavaField) itField.next();
        boolean isStatic;
        try {
            isStatic = Modifier.isStatic(jf.getModifiers());
        } catch (CorruptDataException e) {
            out.print("\t   <error while getting modifier for field \"");
            try {
                out.print(jf.getName());
            } catch (CorruptDataException d) {
                out.print(Exceptions.getCorruptDataExceptionString());
            }
            out.print("\", " + Exceptions.getCorruptDataExceptionString() + ">");
            isStatic = false;
        }
        if (!isStatic) {
            if (!found) {
                out.print("\t  non-static fields for \"" + className + "\"\n");
            }
            found = true;
            printNonStaticFieldData(null, jf, out);
        }
    }
    if (found)
        out.print("\n");
    else
        out.print("\t  \"" + className + "\" has no non-static fields\n\n");
}
Also used : JavaField(com.ibm.dtfj.java.JavaField) Iterator(java.util.Iterator) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 7 with JavaField

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

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

the class DTFJJavaObject method addFieldReferences.

private void addFieldReferences(JavaClass jClass, int referentReachabilityType) throws CorruptDataException, MemoryAccessException {
    Iterator<?> fieldIt = jClass.getDeclaredFields();
    while (fieldIt.hasNext()) {
        Object fieldObj = fieldIt.next();
        if (fieldObj instanceof JavaField) {
            JavaField thisField = (JavaField) fieldObj;
            if ((thisField.getModifiers() & Modifier.STATIC) == 0) {
                String signature = thisField.getSignature();
                // From a reference point of view, only objects are interesting
                if (signature.startsWith("L") || signature.startsWith("[")) {
                    Object targetObj = thisField.get(this);
                    if (targetObj == null) {
                        continue;
                    }
                    if (targetObj instanceof JavaObject) {
                        String fieldName = thisField.getName();
                        String declaringClassName = null;
                        try {
                            declaringClassName = thisField.getDeclaringClass().getName();
                        } catch (DataUnavailable e) {
                        // declaringClassName will be null, we will add this as a strong ref.
                        }
                        String description = "Object Reference [field name:" + fieldName + "]";
                        // (Not any referent field declared in subclasses.)
                        if (fieldName.equals("referent") && "java/lang/ref/Reference".equals(declaringClassName)) {
                            references.add(new DTFJJavaReference(this, targetObj, description, JavaReference.REFERENCE_FIELD, JavaReference.HEAP_ROOT_UNKNOWN, referentReachabilityType));
                        } else {
                            references.add(new DTFJJavaReference(this, targetObj, description, JavaReference.REFERENCE_FIELD, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG));
                        }
                    } else if (targetObj instanceof CorruptData) {
                        references.add(targetObj);
                    } else {
                        references.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), "Unexpected type from field get: " + targetObj + ", class=" + targetObj.getClass().getName()));
                    }
                }
            }
        } else if (fieldObj instanceof CorruptData) {
            references.add(fieldObj);
        } else {
            references.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), "Unexpected type from field iteration: " + fieldObj + ", class=" + fieldObj.getClass().getName()));
        }
    }
}
Also used : JavaField(com.ibm.dtfj.java.JavaField) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptJavaObject(com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) JavaObject(com.ibm.dtfj.java.JavaObject) J9Object(com.ibm.j9ddr.vm29.structure.J9Object) CorruptJavaObject(com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) J9DDRCorruptData(com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)

Example 9 with JavaField

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

the class JavaFieldComparator method testEquals.

// getDeclaringClass()
// getModifiers()
// getName()
// getSignature
public void testEquals(Object ddrObject, Object jextractObject, int members) {
    JavaField ddrJavaField = (JavaField) ddrObject;
    JavaField jextractJavaField = (JavaField) jextractObject;
    // getDeclaringClass()
    if ((DECLARED_CLASS & members) != 0)
        new JavaClassComparator().testComparatorEquals(ddrJavaField, jextractJavaField, "getDeclaringClass");
    // getModifiers()
    if ((MODIFIERS & members) != 0)
        testJavaEquals(ddrJavaField, jextractJavaField, "getModifiers");
    // getName()
    if ((NAME & members) != 0)
        testJavaEquals(ddrJavaField, jextractJavaField, "getName");
    // getSignature()
    if ((SIGNATURE & members) != 0)
        testJavaEquals(ddrJavaField, jextractJavaField, "getSignature");
}
Also used : JavaField(com.ibm.dtfj.java.JavaField)

Example 10 with JavaField

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

the class ClassOutput method printFields.

public static void printFields(JavaObject jo, JavaClass jc, JavaRuntime jr, PrintStream out) {
    boolean array;
    try {
        array = jo.isArray();
    } catch (CorruptDataException e) {
        out.print("\t   <cannot determine if above object is array (" + Exceptions.getCorruptDataExceptionString() + "); " + "we will assume it is not an array>\n");
        array = false;
    }
    if (array) {
        String componentType;
        int arraySize;
        try {
            componentType = jc.getComponentType().getName();
        } catch (CorruptDataException e) {
            out.print("\t   <cannot determine what type of array this is (" + Exceptions.getCorruptDataExceptionString() + ")>\n");
            return;
        }
        try {
            arraySize = jo.getArraySize();
        } catch (CorruptDataException e) {
            out.print("\t   <cannot determine the size of the array (" + Exceptions.getCorruptDataExceptionString() + ")>\n");
            return;
        }
        Object dst = null;
        if (componentType.equals("boolean")) {
            dst = new boolean[arraySize];
        } else if (componentType.equals("byte")) {
            dst = new byte[arraySize];
        } else if (componentType.equals("char")) {
            dst = new char[arraySize];
        } else if (componentType.equals("short")) {
            dst = new short[arraySize];
        } else if (componentType.equals("int")) {
            dst = new int[arraySize];
        } else if (componentType.equals("long")) {
            dst = new long[arraySize];
        } else if (componentType.equals("float")) {
            dst = new float[arraySize];
        } else if (componentType.equals("double")) {
            dst = new double[arraySize];
        } else {
            dst = new JavaObject[arraySize];
        }
        try {
            jo.arraycopy(0, dst, 0, arraySize);
        } catch (CorruptDataException e) {
            out.print("\t   <cannot copy data from the array (" + Exceptions.getCorruptDataExceptionString() + ")>\n");
            return;
        } catch (MemoryAccessException e) {
            out.print("\t   <cannot copy data from the array (" + Exceptions.getMemoryAccessExceptionString() + ")>\n");
            return;
        } catch (UnsupportedOperationException e) {
            // Some artefacts e.g. phd do not support arraycopy so just put out what we can
            out.print("\t    This is an array of size " + arraySize + " elements\n");
            return;
        }
        for (int i = 0; i < arraySize; i++) {
            out.print("\t   " + i + ":\t");
            if (componentType.equals("boolean")) {
                out.print(Utils.getVal(new Boolean(((boolean[]) dst)[i])));
            } else if (componentType.equals("byte")) {
                out.print(Utils.getVal(new Byte(((byte[]) dst)[i])));
            } else if (componentType.equals("char")) {
                out.print(Utils.getVal(new Character(((char[]) dst)[i])));
            } else if (componentType.equals("short")) {
                out.print(Utils.getVal(new Short(((short[]) dst)[i])));
            } else if (componentType.equals("int")) {
                out.print(Utils.getVal(new Integer(((int[]) dst)[i])));
            } else if (componentType.equals("long")) {
                out.print(Utils.getVal(new Long(((long[]) dst)[i])));
            } else if (componentType.equals("float")) {
                out.print(Utils.getVal(new Float(((float[]) dst)[i])));
            } else if (componentType.equals("double")) {
                out.print(Utils.getVal(new Double(((double[]) dst)[i])));
            } else {
                out.print(Utils.getVal(((JavaObject[]) dst)[i]));
            }
            out.print("\n");
        }
    } else {
        JavaClass initialJC = jc;
        List<JavaClass> classList = new ArrayList<JavaClass>();
        while (jc != null) {
            classList.add(jc);
            try {
                jc = jc.getSuperclass();
            } catch (CorruptDataException d) {
                jc = null;
            }
        }
        for (int i = (classList.size() - 1); i >= 0; i--) {
            jc = classList.get(i);
            Iterator itField = jc.getDeclaredFields();
            if (itField.hasNext()) {
                if (jc.equals(initialJC)) {
                    out.print("\t   declared fields:\n");
                } else {
                    out.print("\t   fields inherited from \"");
                    try {
                        out.print(jc.getName() + "\":\n");
                    } catch (CorruptDataException d) {
                        out.print(Exceptions.getCorruptDataExceptionString());
                    }
                }
            }
            while (itField.hasNext()) {
                JavaField jf = (JavaField) itField.next();
                boolean isStatic;
                try {
                    isStatic = Modifier.isStatic(jf.getModifiers());
                } catch (CorruptDataException e) {
                    out.print("\t   <error while getting modifier for field \"");
                    try {
                        out.print(jf.getName());
                    } catch (CorruptDataException d) {
                        out.print(Exceptions.getCorruptDataExceptionString());
                    }
                    out.print("\", " + Exceptions.getCorruptDataExceptionString() + ">");
                    isStatic = true;
                }
                if (!isStatic) {
                    printNonStaticFieldData(jo, jf, out);
                }
            }
        }
    }
    out.print("\n");
}
Also used : ArrayList(java.util.ArrayList) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) JavaField(com.ibm.dtfj.java.JavaField) JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Aggregations

JavaField (com.ibm.dtfj.java.JavaField)11 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)7 JavaObject (com.ibm.dtfj.java.JavaObject)7 Iterator (java.util.Iterator)7 JavaClass (com.ibm.dtfj.java.JavaClass)5 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)3 CorruptData (com.ibm.dtfj.image.CorruptData)2 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)2 J9Object (com.ibm.j9ddr.vm29.structure.J9Object)2 CorruptJavaObject (com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject)2 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)1 IDTFJJavaField (com.ibm.j9ddr.view.dtfj.java.IDTFJJavaField)1 StateToString (com.ibm.jvm.dtfjview.commands.helpers.StateToString)1 LongListReferenceIterator (com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator)1 ReferenceIterator (com.ibm.jvm.dtfjview.heapdump.ReferenceIterator)1 ArrayList (java.util.ArrayList)1