Search in sources :

Example 31 with CorruptDataException

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

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

the class InfoProcCommand method printJITOptions.

private void printJITOptions() {
    try {
        if (ctx.getRuntime().isJITEnabled()) {
            out.println("\t JIT was enabled for this runtime");
            Properties props = ctx.getRuntime().getJITProperties();
            StringBuilder options = new StringBuilder("\t ");
            for (Object key : props.keySet()) {
                options.append(" " + key + " " + props.get(key) + ",");
            }
            out.println(options.substring(0, options.length() - 1));
        } else {
            out.println("\t JIT was disabled for this runtime");
        }
    } catch (CorruptDataException e) {
        out.println("\t JIT options\n");
    } catch (DataUnavailable e) {
        out.println("\t JIT options not supported by this implementation of DTFJ");
    }
}
Also used : DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) Properties(java.util.Properties)

Example 33 with CorruptDataException

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

the class InfoProcCommand method printEnvironmentVariables.

private void printEnvironmentVariables() {
    ImageProcess ip = ctx.getProcess();
    out.print("\t Environment variables:");
    out.print("\n");
    Properties variables;
    try {
        variables = ip.getEnvironment();
    } catch (CorruptDataException e) {
        out.print("\t  " + Exceptions.getCorruptDataExceptionString() + "\n");
        return;
    } catch (DataUnavailable e) {
        out.print("\t  " + Exceptions.getDataUnavailableString() + "\n");
        return;
    }
    Enumeration<?> keys = variables.propertyNames();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        printVariableInfo(key, variables.getProperty(key));
    }
}
Also used : ImageProcess(com.ibm.dtfj.image.ImageProcess) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) Properties(java.util.Properties)

Example 34 with CorruptDataException

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

the class InfoSymCommand method listModules.

private void listModules(String moduleName) {
    ImageProcess ip = ctx.getProcess();
    try {
        Object e = ip.getExecutable();
        if (e instanceof ImageModule) {
            ImageModule exe = (ImageModule) e;
            if (moduleName != null) {
                if (checkModuleName(exe.getName(), moduleName)) {
                    printModule(exe, true);
                }
            } else {
                printModule(exe, false);
            }
        } else if (e instanceof CorruptData) {
            CorruptData corruptObj = (CorruptData) e;
            // warn the user that this image library is corrupt
            out.print("\t  <corrupt executable encountered: " + corruptObj.toString() + ">\n\n");
        }
    } catch (DataUnavailable e) {
        out.println(Exceptions.getDataUnavailableString());
    } catch (CorruptDataException e) {
        out.println(Exceptions.getCorruptDataExceptionString());
    }
    Iterator iLibs;
    try {
        iLibs = ip.getLibraries();
    } catch (DataUnavailable du) {
        iLibs = null;
        out.println(Exceptions.getDataUnavailableString());
    } catch (CorruptDataException cde) {
        iLibs = null;
        out.println(Exceptions.getCorruptDataExceptionString());
    }
    // iterate through the libraries
    while (null != iLibs && iLibs.hasNext()) {
        Object next = iLibs.next();
        if (next instanceof ImageModule) {
            ImageModule mod = (ImageModule) next;
            String currentName = null;
            try {
                currentName = mod.getName();
            } catch (CorruptDataException e) {
                out.print("\t  <corrupt library name: " + mod.toString() + ">\n\n");
            }
            if (moduleName != null) {
                if (checkModuleName(currentName, moduleName)) {
                    printModule(mod, true);
                }
            } else {
                printModule(mod, false);
            }
        } else if (next instanceof CorruptData) {
            CorruptData corruptObj = (CorruptData) next;
            // warn the user that this image library is corrupt
            out.print("\t  <corrupt library encountered: " + corruptObj.toString() + ">\n\n");
        } else {
            // unexpected type in iterator
            out.print("\t  <corrupt library encountered>\n\n");
        }
    }
}
Also used : ImageProcess(com.ibm.dtfj.image.ImageProcess) Iterator(java.util.Iterator) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptData(com.ibm.dtfj.image.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) ImageModule(com.ibm.dtfj.image.ImageModule)

Example 35 with CorruptDataException

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

the class InfoClassCommand method printClassDetails.

private void printClassDetails(JavaRuntime jr, String className, JavaClass jc) {
    String spaces = "    ";
    String cdeInfo = "N/A (CorruptDataException occurred)";
    try {
        out.print("name = " + jc.getName());
    } catch (CorruptDataException dce) {
        out.print("name = " + cdeInfo);
    }
    out.print("\n\n\t");
    out.print("ID = " + Utils.toHex(jc.getID()));
    String superClassId;
    try {
        JavaClass superClass = jc.getSuperclass();
        if (null == superClass) {
            superClassId = "<no superclass>";
        } else {
            superClassId = Utils.toHex(superClass.getID());
        }
    } catch (CorruptDataException dce) {
        superClassId = cdeInfo;
    }
    out.print(spaces);
    out.print("superID = " + superClassId);
    // Omitting size of class because that might differ between instances (i.e. arrays)
    String classLoaderId;
    try {
        JavaClassLoader jClassLoader = jc.getClassLoader();
        JavaObject jo = jClassLoader.getObject();
        if (jo != null) {
            classLoaderId = Utils.toHex(jo.getID());
        } else {
            classLoaderId = "<data unavailable>";
        }
    } catch (CorruptDataException cde) {
        classLoaderId = cdeInfo;
    }
    out.print(spaces);
    out.print("\n\t");
    out.print("classLoader = " + classLoaderId);
    String modifiersInfo;
    try {
        modifiersInfo = Utils.getClassModifierString(jc);
    } catch (CorruptDataException cde) {
        modifiersInfo = cdeInfo;
    }
    out.print(spaces);
    out.print("modifiers: " + modifiersInfo);
    out.print("\n\n");
    ClassStatistics d = getClassStatisticsFor(jr, jc);
    out.print("\tnumber of instances:     " + d.getCount() + "\n");
    out.print("\ttotal size of instances on the heap: " + d.getSize() + " bytes");
    out.print("\n\n");
    printClassHierarchy(jc);
    out.print("\n");
    printFields(jc);
    out.print("\n");
    printMethods(jc);
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

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