Search in sources :

Example 6 with JavaRuntime

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

the class PHDImageAddressSpace method getImageSections.

public Iterator<ImageSection> getImageSections() {
    List<ImageSection> list = new ArrayList<ImageSection>();
    for (Iterator<ImageProcess> ip = getProcesses(); ip.hasNext(); ) {
        ImageProcess p = ip.next();
        if (p instanceof CorruptData)
            continue;
        for (Iterator<ManagedRuntime> jr = p.getRuntimes(); jr.hasNext(); ) {
            ManagedRuntime mr = jr.next();
            if (mr instanceof CorruptData)
                continue;
            if (mr instanceof JavaRuntime) {
                for (Iterator<JavaHeap> jh = ((JavaRuntime) mr).getHeaps(); jh.hasNext(); ) {
                    JavaHeap hp = jh.next();
                    if (hp instanceof CorruptData)
                        continue;
                    for (Iterator<ImageSection> is = hp.getSections(); is.hasNext(); ) {
                        // Add the corrupt sections too
                        list.add(is.next());
                    }
                }
            }
        }
    }
    if (metaImageAddressSpace != null) {
        for (Iterator it = metaImageAddressSpace.getImageSections(); it.hasNext(); ) {
            Object next = it.next();
            if (next instanceof ImageSection) {
                ImageSection section = (ImageSection) next;
                ImageSection newSection = new PHDImageSection(section.getName(), getPointer(section.getBaseAddress().getAddress()), section.getSize());
                list.add(newSection);
            }
        }
    }
    return list.iterator();
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) JavaHeap(com.ibm.dtfj.java.JavaHeap) ArrayList(java.util.ArrayList) ImageSection(com.ibm.dtfj.image.ImageSection) ImageProcess(com.ibm.dtfj.image.ImageProcess) Iterator(java.util.Iterator) CorruptData(com.ibm.dtfj.image.CorruptData) ManagedRuntime(com.ibm.dtfj.runtime.ManagedRuntime)

Example 7 with JavaRuntime

use of com.ibm.dtfj.java.JavaRuntime 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 8 with JavaRuntime

use of com.ibm.dtfj.java.JavaRuntime 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 9 with JavaRuntime

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

the class OpenCommand method createContexts.

private void createContexts(Image loadedImage, String coreFilePath) {
    if (loadedImage == null) {
        // cannot create any contexts as an image has not been obtained
        return;
    }
    boolean hasContexts = false;
    Iterator<?> spaces = loadedImage.getAddressSpaces();
    while (spaces.hasNext()) {
        Object o = spaces.next();
        if (o instanceof ImageAddressSpace) {
            ImageAddressSpace space = (ImageAddressSpace) o;
            Iterator<?> procs = space.getProcesses();
            if (procs.hasNext()) {
                while (procs.hasNext()) {
                    o = procs.next();
                    if (o instanceof ImageProcess) {
                        ImageProcess proc = (ImageProcess) o;
                        Iterator<?> runtimes = proc.getRuntimes();
                        if (runtimes.hasNext()) {
                            while (runtimes.hasNext()) {
                                o = runtimes.next();
                                if (o instanceof JavaRuntime) {
                                    createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, (JavaRuntime) o, coreFilePath);
                                    hasContexts = true;
                                } else if (o instanceof CorruptData) {
                                    logger.fine("CorruptData encountered in ImageProcess.getRuntimes(): " + ((CorruptData) o).toString());
                                    createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, null, coreFilePath);
                                    hasContexts = true;
                                } else {
                                    logger.fine("Unexpected class encountered in ImageProcess.getRuntimes()");
                                    createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, null, coreFilePath);
                                    hasContexts = true;
                                }
                            }
                        } else {
                            // there are no runtimes so create a context for this process
                            createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, null, coreFilePath);
                            hasContexts = true;
                        }
                    }
                }
            } else {
                // context with only an address space
                createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, null, null, coreFilePath);
                hasContexts = true;
            }
        } else {
            // need a representation of a corrupt context
            logger.fine("Skipping corrupt ImageAddress space");
        }
    }
    if (!hasContexts) {
        if (ctx.hasPropertyBeenSet(VERBOSE_MODE_PROPERTY)) {
            out.println("Warning : no contexts were found, is this a valid core file ?");
        }
    }
}
Also used : ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) JavaRuntime(com.ibm.dtfj.java.JavaRuntime) ImageProcess(com.ibm.dtfj.image.ImageProcess) CorruptData(com.ibm.dtfj.image.CorruptData)

Example 10 with JavaRuntime

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

the class J9DDRImageProcess method getExecutablePathFromSystemProperties.

private String getExecutablePathFromSystemProperties() {
    Iterator<?> runtimeIt = getRuntimes();
    while (runtimeIt.hasNext()) {
        Object o = runtimeIt.next();
        if (o instanceof JavaRuntime) {
            JavaRuntime runtime = (JavaRuntime) o;
            try {
                JavaVMInitArgs args = runtime.getJavaVMInitArgs();
                Iterator<?> optionsIt = args.getOptions();
                Pattern javaHomePattern = Pattern.compile("-Djava.home=(.*)");
                while (optionsIt.hasNext()) {
                    Object optionObj = optionsIt.next();
                    if (optionObj instanceof JavaVMOption) {
                        JavaVMOption option = (JavaVMOption) optionObj;
                        Matcher m = javaHomePattern.matcher(option.getOptionString());
                        if (m.find()) {
                            String javaHome = m.group(1);
                            // Note this method not used on Windows - don't have to worry about .exe or \
                            return javaHome + "/bin/java";
                        }
                    }
                }
            } catch (Exception e) {
            // Ignore
            }
        }
    }
    return null;
}
Also used : JavaVMOption(com.ibm.dtfj.java.JavaVMOption) JavaRuntime(com.ibm.dtfj.java.JavaRuntime) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) JavaVMInitArgs(com.ibm.dtfj.java.JavaVMInitArgs) DataUnavailableException(com.ibm.j9ddr.DataUnavailableException) DTFJCorruptDataException(com.ibm.j9ddr.view.dtfj.DTFJCorruptDataException) IOException(java.io.IOException) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Aggregations

JavaRuntime (com.ibm.dtfj.java.JavaRuntime)27 Iterator (java.util.Iterator)13 JavaObject (com.ibm.dtfj.java.JavaObject)10 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)8 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)8 ImageProcess (com.ibm.dtfj.image.ImageProcess)8 CorruptData (com.ibm.dtfj.image.CorruptData)7 JavaClass (com.ibm.dtfj.java.JavaClass)6 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)5 Image (com.ibm.dtfj.image.Image)5 JavaHeap (com.ibm.dtfj.java.JavaHeap)5 JavaThread (com.ibm.dtfj.java.JavaThread)5 File (java.io.File)4 HashMap (java.util.HashMap)4 ImageFactory (com.ibm.dtfj.image.ImageFactory)3 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)3 JavaMonitor (com.ibm.dtfj.java.JavaMonitor)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ImageSection (com.ibm.dtfj.image.ImageSection)2