Search in sources :

Example 1 with JavaField

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

the class DTFJJavaObject method getAssociatedClass.

private JavaClass getAssociatedClass() {
    // Retrieve the class loader for this class for using introspection to speed up
    // lookup when lots of classes are loaded by lots of class loaders.
    JavaObject targetClassLoaderObject = null;
    try {
        JavaClass javaLangClass = this.getJavaClass();
        Iterator<?> fields = javaLangClass.getDeclaredFields();
        while (fields.hasNext()) {
            Object o = fields.next();
            if (o instanceof JavaField) {
                JavaField field = (JavaField) o;
                if ("classLoader".equals(field.getName())) {
                    targetClassLoaderObject = (JavaObject) field.get(this);
                    break;
                }
            }
        }
    } catch (CorruptDataException e) {
    // This is only an optimisation to save us walking all class loaders. Continue
    } catch (MemoryAccessException e) {
    // This is only an optimisation to save us walking all class loaders. Continue
    }
    return getAssociatedClass(targetClassLoaderObject);
}
Also used : JavaField(com.ibm.dtfj.java.JavaField) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptJavaObject(com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject) 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) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 2 with JavaField

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

the class DTFJJavaField method equals.

public boolean equals(Object obj) {
    boolean isEqual = false;
    if (obj instanceof JavaField) {
        JavaField field = (JavaField) obj;
        boolean hasSameName;
        try {
            hasSameName = name.equals(field.getName());
        } catch (CorruptDataException cde) {
            hasSameName = false;
        }
        try {
            isEqual = hasSameName && (getClass().equals(field.getClass())) && clazz.equals(field.getDeclaringClass());
        } catch (Throwable t) {
            J9DDRDTFJUtils.handleAsCorruptDataException(DTFJContext.getProcess(), t);
        }
    }
    return isEqual;
}
Also used : JavaField(com.ibm.dtfj.java.JavaField) IDTFJJavaField(com.ibm.j9ddr.view.dtfj.java.IDTFJJavaField) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 3 with JavaField

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

the class InfoThreadCommand method printJavaThreadInfo.

private void printJavaThreadInfo(JavaThread jt, boolean idPrinted) {
    out.print("    name:          ");
    try {
        out.print(jt.getName());
    } catch (CorruptDataException e) {
        out.print(Exceptions.getCorruptDataExceptionString());
        logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
    }
    out.print("\n");
    if (!idPrinted) {
        try {
            if (jt.getImageThread() != null) {
                out.print("    id:            ");
                out.print(jt.getImageThread().getID());
            }
        } catch (CorruptDataException e) {
            out.print(Exceptions.getCorruptDataExceptionString());
            logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
        } catch (DataUnavailable e) {
            out.print(Exceptions.getDataUnavailableString());
            logger.log(Level.FINEST, Exceptions.getDataUnavailableString(), e);
        } finally {
            out.print("\n");
        }
    }
    out.print("    Thread object: ");
    try {
        JavaObject threadObj = jt.getObject();
        if (null == threadObj) {
            out.print("<no associated Thread object>");
        } else {
            String threadClassName = null;
            try {
                JavaClass threadClass = threadObj.getJavaClass();
                threadClassName = threadClass.getName();
                if (threadClassName != null) {
                    out.print(threadClassName + " @ ");
                }
                out.print(Utils.toHex(threadObj.getID().getAddress()));
                // Navigate to the parent java/lang.Thread class to get the 'tid' and 'isDaemon' fields
                while (!JAVA_LANG_THREAD_CLASS.equals(threadClass.getName()) && threadClass != null) {
                    threadClass = threadClass.getSuperclass();
                }
                if (threadClass != null) {
                    Iterator itField = threadClass.getDeclaredFields();
                    boolean foundThreadId = false;
                    while (itField.hasNext()) {
                        JavaField jf = (JavaField) itField.next();
                        /* "uniqueId" field in java.lang.Thread is renamed to "tid". The old field name is
							 * checked to preserve functionality of DDR command with old core files that reference
							 * the "uniqueId" field.
							 */
                        if (!foundThreadId && (jf.getName().equals("uniqueId") || jf.getName().equals("tid"))) {
                            foundThreadId = true;
                            out.print("\n    ID:            " + Utils.getVal(threadObj, jf));
                        } else if (jf.getName().equals("isDaemon")) {
                            out.print("\n    Daemon:        " + Utils.getVal(threadObj, jf));
                        }
                    }
                }
            } catch (CorruptDataException cde) {
                out.print(" <in-flight or corrupt data encountered>");
                logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), cde);
            }
        }
    } catch (CorruptDataException cde) {
        out.print(Exceptions.getCorruptDataExceptionString());
        logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), cde);
    }
    out.print("\n");
    out.print("    Priority:      ");
    try {
        Integer pri = new Integer(jt.getPriority());
        out.print(pri.toString());
    } catch (CorruptDataException e) {
        out.print(Exceptions.getCorruptDataExceptionString());
        logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
    }
    out.print("\n");
    out.print("    Thread.State:  ");
    try {
        out.print(StateToString.getThreadStateString(jt.getState()));
    } catch (CorruptDataException cde) {
        out.print(Exceptions.getCorruptDataExceptionString());
        logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), cde);
    }
    out.print("\n");
    out.print("    JVMTI state:   ");
    try {
        out.print(StateToString.getJVMTIStateString(jt.getState()));
    } catch (CorruptDataException cde) {
        out.print(Exceptions.getCorruptDataExceptionString());
        logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), cde);
    }
    out.print("\n");
    printThreadBlocker(jt);
    out.print("    Java stack frames: ");
    printJavaStackFrameInfo(jt);
    out.print("\n");
}
Also used : JavaField(com.ibm.dtfj.java.JavaField) JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) StateToString(com.ibm.jvm.dtfjview.commands.helpers.StateToString)

Example 4 with JavaField

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

the class Utils method getStringVal.

private static String getStringVal(JavaObject jo) {
    JavaClass jc;
    try {
        jc = jo.getJavaClass();
    } catch (CorruptDataException e) {
        return "<cannot get String class from String object (" + Exceptions.getCorruptDataExceptionString() + ")>";
    }
    Iterator itJavaField = jc.getDeclaredFields();
    JavaField jf = null;
    while (itJavaField.hasNext()) {
        jf = (JavaField) itJavaField.next();
        try {
            if (jf.getSignature().equals("[C") && !Modifier.isStatic(jf.getModifiers()))
                break;
        } catch (CorruptDataException e) {
        // if we have an exception, do nothing and go onto the next field
        }
    }
    if (jf == null) {
        // empty field iterator (occurs e.g. when reading PHD heapdumps), can't get the char array
        return "<cannot get char array out of String>";
    }
    JavaObject charArray = null;
    try {
        charArray = (JavaObject) jf.get(jo);
    } catch (CorruptDataException e) {
        return "<cannot get char array out of String (" + Exceptions.getCorruptDataExceptionString() + ")>";
    } catch (MemoryAccessException e) {
        return "<cannot get char array out of String (" + Exceptions.getMemoryAccessExceptionString() + ")>";
    }
    int arraySize;
    try {
        arraySize = charArray.getArraySize();
    } catch (CorruptDataException e) {
        return "<cannot determine the size of the array (" + Exceptions.getCorruptDataExceptionString() + ")>";
    }
    char[] dst = new char[arraySize];
    try {
        charArray.arraycopy(0, dst, 0, arraySize);
    } catch (CorruptDataException e) {
        return "<cannot copy data from the array (" + Exceptions.getCorruptDataExceptionString() + ")>";
    } catch (MemoryAccessException e) {
        return "<cannot copy data from the array (" + Exceptions.getMemoryAccessExceptionString() + ")>";
    }
    return "\"" + Utils.getPrintable(new String(dst)) + "\"";
}
Also used : JavaField(com.ibm.dtfj.java.JavaField) JavaClass(com.ibm.dtfj.java.JavaClass) JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 5 with JavaField

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

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