Search in sources :

Example 21 with JavaClass

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

the class Utils method getClassGivenName.

public static JavaClass[] getClassGivenName(String className, JavaRuntime jr, PrintStream out) {
    Iterator itJavaClassLoader = jr.getJavaClassLoaders();
    List classes = new ArrayList();
    while (itJavaClassLoader.hasNext()) {
        Object nextCl = itJavaClassLoader.next();
        if (!(nextCl instanceof JavaClassLoader)) {
            continue;
        }
        JavaClassLoader jcl = (JavaClassLoader) nextCl;
        Iterator itJavaClass = jcl.getDefinedClasses();
        while (itJavaClass.hasNext()) {
            Object next = itJavaClass.next();
            if (!(next instanceof JavaClass)) {
                continue;
            }
            JavaClass jc = (JavaClass) next;
            String currClassName;
            try {
                currClassName = jc.getName();
                if (currClassName.equals(className)) {
                    classes.add(jc);
                }
            } catch (CorruptDataException e) {
                out.print("\t  <error getting class name while traversing classes: ");
                out.print(Exceptions.getCorruptDataExceptionString());
                out.print(">\n");
                currClassName = null;
            }
        }
    }
    if (classes.size() > 0) {
        return (JavaClass[]) classes.toArray(new JavaClass[0]);
    } else {
        return null;
    }
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 22 with JavaClass

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

the class Utils method getVal.

public static String getVal(Object o, String str, JavaField jf) {
    String val = "";
    Long value = null;
    boolean object = false;
    if (null == o) {
        val += "null";
    } else {
        if (o instanceof Boolean) {
            val += ((Boolean) o).toString();
        } else if (o instanceof Byte) {
            byte b = ((Byte) o).byteValue();
            val += String.valueOf(b);
            value = new Long((new Byte(b)).longValue());
        } else if (o instanceof Character) {
            char c = ((Character) o).charValue();
            val += Utils.getPrintableWithQuotes(c);
            value = new Long((new Integer((int) c).longValue()));
        } else if (o instanceof Double) {
            double d = ((Double) o).doubleValue();
            val += String.valueOf(d);
            value = new Long(Double.doubleToRawLongBits(d));
        } else if (o instanceof Float) {
            float f = ((Float) o).floatValue();
            val += String.valueOf(f);
            value = new Long(Float.floatToRawIntBits(f));
        } else if (o instanceof Integer) {
            int i = ((Integer) o).intValue();
            val += String.valueOf(i);
            value = new Long((new Integer(i)).longValue());
        } else if (o instanceof Long) {
            long l = ((Long) o).longValue();
            val += String.valueOf(l);
            value = new Long(l);
        } else if (o instanceof Short) {
            short s = ((Short) o).shortValue();
            val += String.valueOf(s);
            value = new Long((new Short(s)).longValue());
        } else if (o instanceof String) {
            val += (String) o;
        } else if (o instanceof JavaObject) {
            if (Utils.isNull((JavaObject) o)) {
                val += "null";
            } else {
                object = true;
            }
        } else {
        // FIXME
        }
        // because we want control over the exceptions that are thrown
        if (object) {
            JavaObject joField = (JavaObject) o;
            JavaClass jcField;
            String jcName;
            try {
                jcField = joField.getJavaClass();
            } catch (CorruptDataException e) {
                jcField = null;
            }
            try {
                if (null != jcField) {
                    jcName = jcField.getName();
                } else {
                    jcName = null;
                }
            } catch (CorruptDataException e) {
                jcName = null;
            }
            if (null != jcName && jcName.equals("java/lang/String")) {
                if (null == str) {
                    val += getStringVal(joField);
                } else {
                    val += "\"" + Utils.getPrintable(str) + "\"";
                }
                val += " @ ";
                val += Utils.toHex(joField.getID().getAddress());
            } else {
                val += "<object>" + " @ " + Utils.toHex(joField.getID().getAddress());
            }
        }
    }
    if (null != value) {
        val += " (";
        val += Utils.toHex(value.longValue());
        val += ")";
    }
    return val;
}
Also used : CorruptDataException(com.ibm.dtfj.image.CorruptDataException) BigInteger(java.math.BigInteger) JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass)

Example 23 with JavaClass

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

the class Utils method getClassGivenAddress.

public static JavaClass getClassGivenAddress(long address, JavaRuntime jr) {
    Iterator itJavaClassLoader = jr.getJavaClassLoaders();
    while (itJavaClassLoader.hasNext()) {
        Object nextCl = itJavaClassLoader.next();
        if (!(nextCl instanceof JavaClassLoader)) {
            continue;
        }
        JavaClassLoader jcl = (JavaClassLoader) nextCl;
        Iterator itJavaClass = jcl.getDefinedClasses();
        while (itJavaClass.hasNext()) {
            Object next = itJavaClass.next();
            if (!(next instanceof JavaClass)) {
                continue;
            }
            if (next instanceof JavaClass) {
                JavaClass jc = (JavaClass) next;
                long currClassAddress = jc.getID().getAddress();
                if (currClassAddress == address) {
                    return jc;
                }
            }
        }
    }
    return null;
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject)

Example 24 with JavaClass

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

the class HeapdumpCommand method dumpHeap.

/**
 * Walks the supplied heap and passes the artifacts through the formatter
 */
private void dumpHeap(HeapDumpFormatter formatter, JavaHeap thisHeap) throws IOException {
    Iterator objectIterator = thisHeap.getObjects();
    while (objectIterator.hasNext()) {
        Object next = objectIterator.next();
        _numberOfObjects++;
        if (next instanceof CorruptData) {
            _numberOfErrors++;
            reportError("Corrupt object data found at " + ((CorruptData) next).getAddress() + " while walking heap " + thisHeap.getName(), null);
            continue;
        }
        try {
            JavaObject thisObject = (JavaObject) next;
            if (thisObject.getJavaClass().getName().equals("java/lang/Class")) {
                // heap classes are handled separately, in dumpClasses()
                continue;
            }
            JavaClass thisClass = thisObject.getJavaClass();
            JavaObject thisClassObject = thisClass.getObject();
            int hashcode = 0;
            if (_is32BitHash) {
                // JVMs from 2.6 on, optional 32-bit hashcodes, if object was hashed
                try {
                    hashcode = (int) thisObject.getPersistentHashcode();
                } catch (DataUnavailable ex) {
                // no persistent hashcode for this object, pass hashcode=0 to the heapdump formatter
                }
            } else {
                // JVMs prior to 2.6, all objects should have a 16-bit hashcode
                try {
                    hashcode = (int) thisObject.getHashcode();
                } catch (DataUnavailable ex) {
                    _numberOfErrors++;
                    reportError("Failed to get hashcode for object: " + thisObject.getID(), ex);
                }
            }
            if (thisObject.isArray()) {
                if (isPrimitive(thisClass.getComponentType())) {
                    formatter.addPrimitiveArray(thisObject.getID().getAddress(), thisClassObject.getID().getAddress(), getPrimitiveTypeCode(thisClass.getComponentType()), thisObject.getSize(), hashcode, thisObject.getArraySize());
                } else {
                    formatter.addObjectArray(thisObject.getID().getAddress(), thisClassObject.getID().getAddress(), thisClass.getName(), thisClass.getComponentType().getObject().getID().getAddress(), thisClass.getComponentType().getName(), thisObject.getSize(), thisObject.getArraySize(), hashcode, getObjectReferences(thisObject));
                }
            } else {
                formatter.addObject(thisObject.getID().getAddress(), thisClassObject.getID().getAddress(), thisClass.getName(), (int) thisObject.getSize(), hashcode, getObjectReferences(thisObject));
            }
        } catch (CorruptDataException ex) {
            _numberOfErrors++;
            reportError(null, ex);
            continue;
        }
    }
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) ReferenceIterator(com.ibm.jvm.dtfjview.heapdump.ReferenceIterator) Iterator(java.util.Iterator) LongListReferenceIterator(com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 25 with JavaClass

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

the class Utils method getThreadNameFromObject.

public static String getThreadNameFromObject(JavaObject lockOwnerObj, JavaRuntime rt, PrintStream out) throws CorruptDataException, MemoryAccessException {
    if (lockOwnerObj == null) {
        return null;
    }
    JavaClass[] threadClasses = Utils.getClassGivenName("java/lang/Thread", rt, out);
    // We might have got no classes or more than one. Both of which should be pretty hard to manage.
    if (threadClasses.length == 1) {
        Iterator fields = threadClasses[0].getDeclaredFields();
        while (fields.hasNext()) {
            Object o = fields.next();
            if (!(o instanceof JavaField)) {
                continue;
            }
            JavaField f = (JavaField) o;
            if ("name".equalsIgnoreCase(f.getName())) {
                return f.getString(lockOwnerObj);
            }
        }
    }
    return null;
}
Also used : JavaField(com.ibm.dtfj.java.JavaField) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject)

Aggregations

JavaClass (com.ibm.dtfj.java.JavaClass)70 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)40 JavaObject (com.ibm.dtfj.java.JavaObject)39 Iterator (java.util.Iterator)33 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)23 CorruptData (com.ibm.dtfj.image.CorruptData)11 ArrayList (java.util.ArrayList)10 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)9 ImagePointer (com.ibm.dtfj.image.ImagePointer)9 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)9 CorruptData (com.ibm.dtfj.image.j9.CorruptData)8 JavaReference (com.ibm.dtfj.java.JavaReference)8 JavaField (com.ibm.dtfj.java.JavaField)6 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)6 LongEnumeration (com.ibm.dtfj.phd.util.LongEnumeration)5 JavaMethod (com.ibm.dtfj.java.JavaMethod)4 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)4 J9Object (com.ibm.j9ddr.vm29.structure.J9Object)4 LongListReferenceIterator (com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator)4 ReferenceIterator (com.ibm.jvm.dtfjview.heapdump.ReferenceIterator)4