Search in sources :

Example 36 with CorruptDataException

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

the class InfoClassCommand method countClassInstances.

private void countClassInstances() {
    JavaRuntime runtime = ctx.getRuntime();
    Map<JavaClass, ClassStatistics> thisRuntimeClasses = classInstanceCounts.get(runtime);
    final Collection<JavaClass> javaClasses = getRuntimeClasses(runtime);
    long corruptObjectCount = 0;
    long corruptClassCount = 0;
    long corruptClassNameCount = 0;
    Iterator itHeap = runtime.getHeaps();
    while (itHeap.hasNext()) {
        Object heap = itHeap.next();
        if (heap instanceof CorruptData) {
            out.println("[skipping corrupt heap]");
            continue;
        }
        JavaHeap jh = (JavaHeap) heap;
        Iterator itObject = jh.getObjects();
        // Walk through all objects in this heap, accumulating counts and total memory size by class
        while (itObject.hasNext()) {
            Object next = itObject.next();
            // JavaHeap, we don't attempt to count these as instances of known classes).
            if (next instanceof JavaObject) {
                JavaObject jo = (JavaObject) next;
                ClassStatistics stats = null;
                try {
                    // Check whether we found this class in the classloaders walk earlier
                    JavaClass jc = jo.getJavaClass();
                    if (javaClasses.contains(jc)) {
                        stats = thisRuntimeClasses.get(jc);
                    } else {
                        // Class not found in the classloaders, create a statistic for it now, and issue a warning message
                        stats = new ClassStatistics();
                        thisRuntimeClasses.put(jc, stats);
                        String classname;
                        try {
                            classname = jc.getName();
                            out.println("Warning, class: " + classname + " found when walking the heap was missing from classloader walk");
                        } catch (CorruptDataException cde) {
                            corruptClassNameCount++;
                        }
                    }
                    // Increment the statistic for objects of this class (accumulated count and size)
                    stats.incrementCount();
                    try {
                        stats.addToSize(jo.getSize());
                    } catch (CorruptDataException cde) {
                        // bad size, count object as corrupt
                        corruptObjectCount++;
                    }
                } catch (CorruptDataException cde) {
                    corruptClassCount++;
                }
            } else {
                corruptObjectCount++;
            }
        }
    }
    if (corruptObjectCount != 0) {
        out.println("Warning, found " + corruptObjectCount + " corrupt objects during heap walk");
    }
    if (corruptClassCount != 0) {
        out.println("Warning, found " + corruptClassCount + " corrupt class references during heap walk");
    }
    if (corruptClassNameCount != 0) {
        out.println("Warning, found " + corruptClassNameCount + " corrupt class names during heap walk");
    }
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) JavaHeap(com.ibm.dtfj.java.JavaHeap) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) JavaClass(com.ibm.dtfj.java.JavaClass) JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData)

Example 37 with CorruptDataException

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

the class InfoLockCommand method showJavaUtilConcurrentLocks.

private void showJavaUtilConcurrentLocks() {
    // A map of lock objects and their waiting threads.
    Map locksToThreads = new HashMap();
    JavaRuntime jr = ctx.getRuntime();
    Iterator itThread = jr.getThreads();
    while (itThread.hasNext()) {
        try {
            Object o = itThread.next();
            if (!(o instanceof JavaThread)) {
                continue;
            }
            JavaThread jt = (JavaThread) o;
            if ((jt.getState() & JavaThread.STATE_PARKED) != 0) {
                JavaObject lock = jt.getBlockingObject();
                if (lock != null) {
                    List parkedList = (List) locksToThreads.get(lock);
                    if (parkedList == null) {
                        parkedList = new LinkedList();
                        locksToThreads.put(lock, parkedList);
                    }
                    parkedList.add(jt);
                }
            }
        } catch (CorruptDataException cde) {
            out.println("\nwarning, corrupt data encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getCorruptDataExceptionString(), cde);
        } catch (DataUnavailable du) {
            out.println("\nwarning, data unavailable encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getDataUnavailableString(), du);
        }
    }
    out.println("\njava.util.concurrent locks in use...");
    if (locksToThreads.size() == 0) {
        out.println("\t...None.");
        out.println();
    }
    for (Object e : locksToThreads.entrySet()) {
        try {
            Map.Entry entry = (Map.Entry) e;
            JavaObject lock = (JavaObject) entry.getKey();
            List threads = (List) entry.getValue();
            String threadName = "<unowned>";
            JavaThread lockOwnerThread = Utils.getParkBlockerOwner(lock, ctx.getRuntime());
            if (lockOwnerThread != null) {
                threadName = lockOwnerThread.getName();
            } else {
                // If the owning thread has ended we won't find the JavaThread
                // We can still get the owning thread name from the java.lang.Thread object itself.
                JavaObject lockOwnerObj = Utils.getParkBlockerOwnerObject(lock, ctx.getRuntime());
                if (lockOwnerObj != null) {
                    threadName = Utils.getThreadNameFromObject(lockOwnerObj, ctx.getRuntime(), out);
                } else {
                    threadName = "<unknown>";
                }
            }
            if (threads != null && threads.size() > 0) {
                String lockID = Long.toHexString(lock.getID().getAddress());
                ImageThread imageThread = (lockOwnerThread != null ? lockOwnerThread.getImageThread() : null);
                out.println(lock.getJavaClass().getName() + "@0x" + lockID + "\n\tlocked by java thread id: " + ((imageThread != null) ? imageThread.getID() : "<null>") + " name: " + (threadName));
                for (Object t : threads) {
                    JavaThread waiter = (JavaThread) t;
                    out.println("\twaiting thread id: " + waiter.getImageThread().getID() + " name: " + waiter.getName());
                }
            }
        } catch (CorruptDataException cde) {
            out.println("\nwarning, corrupt data encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getCorruptDataExceptionString(), cde);
        } catch (MemoryAccessException ma) {
            out.println("\nwarning, memory access error encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getMemoryAccessExceptionString(), ma);
        } catch (DataUnavailable du) {
            out.println("\nwarning, data unavailable encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getDataUnavailableString(), du);
        }
    }
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) HashMap(java.util.HashMap) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) LinkedList(java.util.LinkedList) JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) JavaObject(com.ibm.dtfj.java.JavaObject) LinkedList(java.util.LinkedList) List(java.util.List) ImageThread(com.ibm.dtfj.image.ImageThread) HashMap(java.util.HashMap) Map(java.util.Map) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 38 with CorruptDataException

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

the class InfoSystemCommand method doCommand.

public void doCommand() {
    try {
        out.println("\nMachine OS:\t" + ctx.getImage().getSystemType());
    } catch (DataUnavailable exc) {
        out.println("\nMachine OS:\t" + "data unavailable");
    } catch (CorruptDataException exc) {
        out.println("\nMachine OS:\t" + "data corrupted");
    }
    Properties imageProperties = ctx.getImage().getProperties();
    if (imageProperties.containsKey("Hypervisor")) {
        out.println("Hypervisor:\t" + imageProperties.getProperty("Hypervisor"));
    }
    try {
        out.println("Machine name:\t" + ctx.getImage().getHostName());
    } catch (DataUnavailable exc) {
        out.println("Machine name:\t" + "data unavailable");
    } catch (CorruptDataException exc) {
        out.println("Machine name:\t" + "data corrupted");
    }
    out.println("Machine IP address(es):");
    try {
        Iterator<?> itIPAddresses = ctx.getImage().getIPAddresses();
        while (itIPAddresses.hasNext()) {
            Object addr = itIPAddresses.next();
            if (addr instanceof InetAddress) {
                out.println("\t\t" + ((InetAddress) addr).getHostAddress());
            } else if (addr instanceof CorruptData) {
                out.println("\t\tdata corrupted");
            }
        }
    } catch (DataUnavailable du) {
        out.println("\t\tdata unavailable");
    }
    try {
        out.println("System memory:\t" + ctx.getImage().getInstalledMemory());
    } catch (DataUnavailable exc) {
        out.println("System memory:\t" + "data unavailable");
    }
    try {
        long createTimeMillis = ctx.getImage().getCreationTime();
        if (createTimeMillis != 0) {
            DateFormat fmt = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS");
            String createTimeStr = fmt.format(new Date(createTimeMillis));
            out.println("\nDump creation time: " + createTimeStr);
        } else {
            out.println("\nDump creation time: data unavailable");
        }
    } catch (DataUnavailable d) {
        out.println("\nDump creation time: data unavailable");
    }
    // Dump creation time - nanotime - added in DTFJ 1.12
    try {
        long createTimeNanos = ctx.getImage().getCreationTimeNanos();
        if (createTimeNanos != 0) {
            out.println("Dump creation time (nanoseconds): " + createTimeNanos);
        } else {
            out.println("Dump creation time (nanoseconds): data unavailable");
        }
    } catch (DataUnavailable du) {
        out.println("Dump creation time (nanoseconds): data unavailable");
    } catch (CorruptDataException cde) {
        out.println("Dump creation time (nanoseconds): data corrupted");
    }
    out.println("\nJava version:");
    if (ctx.getRuntime() != null) {
        try {
            out.println(ctx.getRuntime().getVersion());
        } catch (CorruptDataException e) {
            out.println("version data corrupted");
        }
    } else {
        out.println("\tmissing, unknown or unsupported JRE");
    }
    // JVM start time - millisecond wall clock - added in DTFJ 1.12
    try {
        long startTimeMillis = ctx.getRuntime().getStartTime();
        if (startTimeMillis != 0) {
            DateFormat fmt = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS");
            String createTimeStr = fmt.format(new Date(startTimeMillis));
            out.println("\nJVM start time: " + createTimeStr);
        } else {
            out.println("\nJVM start time: data unavailable");
        }
    } catch (DataUnavailable d) {
        out.println("\nJVM start time: data unavailable");
    } catch (CorruptDataException cde) {
        out.println("\nJVM start time (nanoseconds): data corrupted");
    }
    // JVM start time - nanotime - added in DTFJ 1.12
    try {
        long startTimeNanos = ctx.getRuntime().getStartTimeNanos();
        if (startTimeNanos != 0) {
            out.println("JVM start time (nanoseconds): " + startTimeNanos);
        } else {
            out.println("JVM start time (nanoseconds): data unavailable");
        }
    } catch (DataUnavailable du) {
        out.println("JVM start time (nanoseconds): data unavailable");
    } catch (CorruptDataException cde) {
        out.println("JVM start time (nanoseconds): data corrupted");
    }
    boolean kernelSettingPrinted = false;
    for (String name : new String[] { "/proc/sys/kernel/sched_compat_yield", "/proc/sys/kernel/core_pattern", "/proc/sys/kernel/core_uses_pid" }) {
        if (imageProperties.containsKey(name)) {
            if (!kernelSettingPrinted) {
                out.println("\nLinux Kernel Settings:");
            }
            out.println(name + " = " + imageProperties.getProperty(name));
            kernelSettingPrinted = true;
        }
    }
    out.println();
}
Also used : CorruptDataException(com.ibm.dtfj.image.CorruptDataException) Properties(java.util.Properties) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptData(com.ibm.dtfj.image.CorruptData) InetAddress(java.net.InetAddress) SimpleDateFormat(java.text.SimpleDateFormat)

Example 39 with CorruptDataException

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

the class JavaRuntimeBuilder method addJavaStackFrame.

/**
 */
public JavaStackFrame addJavaStackFrame(JavaThread javaThread, String className, String classFileName, String methodName, String methodType, String compilationLevel, int lineNumber) throws BuilderFailureException {
    try {
        JCJavaThread jThread = (JCJavaThread) javaThread;
        JCJavaClass jclass = getJavaRuntime().findJavaClass(className);
        if (jclass == null) {
            jclass = new JCJavaClass(getJavaRuntime(), className);
        }
        JCJavaMethod method = new JCJavaMethod(methodName, jclass);
        JCJavaLocation location = new JCJavaLocation(method);
        location.setFilename(classFileName);
        location.setCompilation(compilationLevel);
        location.setLineNumber(lineNumber);
        JCJavaStackFrame stackFrame = new JCJavaStackFrame(jThread, location);
        if ("run".equals(methodName)) {
            /*
				 * Perhaps the type of the thread is the type of the last run() method.
				 * Not strictly accurate if the class was extended without overriding run(). 
				 * Add the object only if the object ID is valid.
				 */
            try {
                JavaObject jo = jThread.getObject();
                if (jo != null) {
                    ImagePointer tid = jo.getID();
                    if (fAddressSpace.isValidAddressID(tid.getAddress())) {
                        JCJavaObject jobject = new JCJavaObject(tid, jclass);
                        jThread.setObject(jobject);
                    }
                }
            } catch (CorruptDataException e) {
            // Ignore
            }
        }
        return stackFrame;
    } catch (JCInvalidArgumentsException e) {
        throw new BuilderFailureException(e);
    }
}
Also used : JCJavaObject(com.ibm.dtfj.java.javacore.JCJavaObject) ImagePointer(com.ibm.dtfj.image.ImagePointer) JCJavaMethod(com.ibm.dtfj.java.javacore.JCJavaMethod) JavaObject(com.ibm.dtfj.java.JavaObject) JCJavaObject(com.ibm.dtfj.java.javacore.JCJavaObject) BuilderFailureException(com.ibm.dtfj.javacore.builder.BuilderFailureException) JCJavaStackFrame(com.ibm.dtfj.java.javacore.JCJavaStackFrame) JCJavaLocation(com.ibm.dtfj.java.javacore.JCJavaLocation) JCInvalidArgumentsException(com.ibm.dtfj.java.javacore.JCInvalidArgumentsException) JCJavaClass(com.ibm.dtfj.java.javacore.JCJavaClass) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) JCJavaThread(com.ibm.dtfj.java.javacore.JCJavaThread)

Example 40 with CorruptDataException

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

the class JavaThread method getPriority.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaThread#getPriority()
	 */
public int getPriority() throws CorruptDataException {
    JavaObject theObject = getObject();
    if (null != theObject) {
        JavaClass threadClass = _javaLangThreadSuperclass();
        Iterator fields = threadClass.getDeclaredFields();
        while (fields.hasNext()) {
            JavaField oneField = (JavaField) fields.next();
            if (oneField.getName().equals("priority")) {
                try {
                    return oneField.getInt(theObject);
                } catch (MemoryAccessException e) {
                    throw new CorruptDataException(new CorruptData("unable to read memory for 'priority' field", null));
                }
            }
        }
        throw new CorruptDataException(new CorruptData("unable to find 'priority' field", null));
    } else {
        // TODO:  have a good exception for this sort of thing
        return -1;
    }
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) CorruptData(com.ibm.dtfj.image.j9.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

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