Search in sources :

Example 41 with CorruptDataException

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

the class PHDJavaRuntime method prepClassLoaders.

/**
 * Remember objects associated with class loaders
 * Performance optimization - we can then find these objects on a scan through the heap
 * and remember them, saving a fruitless search of the heap if they only exist in a javacore.
 */
private void prepClassLoaders() {
    if (metaJavaRuntime != null) {
        final PHDJavaClassLoader boot = loaders.get(null);
        for (Iterator it = metaJavaRuntime.getJavaClassLoaders(); it.hasNext(); ) {
            Object next = it.next();
            if (next instanceof CorruptData)
                continue;
            JavaClassLoader load = (JavaClassLoader) next;
            try {
                JavaObject jo = load.getObject();
                saveExtraObject(boot, jo);
            } catch (CorruptDataException e) {
            }
        }
    }
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 42 with CorruptDataException

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

the class PHDJavaRuntime method saveExtraObject.

private void saveExtraObject(final PHDJavaClassLoader boot, JavaObject jo) {
    if (jo != null) {
        long addr = jo.getID().getAddress();
        JavaClass cls;
        try {
            cls = boot.findClassUnique(jo.getJavaClass().getName());
        } catch (CorruptDataException e) {
            cls = null;
        }
        // Construct a dummy object with little information in case the object is not in the heap
        JavaObject jo2 = new PHDJavaObject.Builder(heaps.get(0), addr, cls, PHDJavaObject.NO_HASHCODE, -1).refsAsArray(NOREFS, 0).length(PHDJavaObject.UNKNOWN_TYPE).build();
        extraObjectsCache.put(addr, jo2);
    }
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 43 with CorruptDataException

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

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

the class Utils method getVal.

// note: this method lets you pass in a null JavaObject, but it _will_ throw a
// NullPointerException if the JavaField is not a static field when you pass it
// a null JavaObject; this is the behavior of jf.get() and jf.getString()
public static String getVal(JavaObject jo, JavaField jf) {
    Object o;
    String s;
    if (null == jf) {
        o = jo;
        s = null;
    } else {
        try {
            o = jf.get(jo);
        } catch (CorruptDataException e) {
            return "<corrupt data>";
        } catch (MemoryAccessException d) {
            return "<invalid memory address>";
        } catch (NumberFormatException nfe) {
            return "<invalid number>";
        }
        try {
            s = jf.getString(jo);
        } catch (CorruptDataException e) {
            s = null;
        } catch (MemoryAccessException e) {
            s = null;
        } catch (IllegalArgumentException e) {
            s = null;
        }
    }
    return getVal(o, s, jf);
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 45 with CorruptDataException

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

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