Search in sources :

Example 31 with J9JavaVMPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer in project openj9 by eclipse.

the class MonitorsCommand method j9threadCommand.

/**
 * See {@link MonitorsCommand#helpCommand(String[], PrintStream)} for
 * function documentation
 *
 * @param args
 *            command args
 * @param out
 *            the output stream
 * @throws DDRInteractiveCommandException
 */
private void j9threadCommand(String[] args, PrintStream out) throws DDRInteractiveCommandException {
    if (args.length < 2) {
        out.println("This command takes one address argument: \"!monitors j9thread <address>\"");
        return;
    }
    try {
        long address = CommandUtils.parsePointer(args[1], J9BuildFlags.env_data64);
        VoidPointer ptr = VoidPointer.cast(address);
        J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
        J9VMThreadPointer mainThread = vm.mainThread();
        if (mainThread.isNull() || mainThread.osThread().isNull() || mainThread.osThread().library().isNull()) {
            throw new CorruptDataException("Cannot locate thread library");
        }
        J9ThreadLibraryPointer lib = mainThread.osThread().library();
        J9PoolPointer pool = lib.thread_pool();
        Pool<J9ThreadPointer> threadPool = Pool.fromJ9Pool(pool, J9ThreadPointer.class);
        SlotIterator<J9ThreadPointer> poolIterator = threadPool.iterator();
        J9ThreadPointer osThreadPtr = null;
        while (poolIterator.hasNext()) {
            if (ptr.equals(poolIterator.next())) {
                osThreadPtr = J9ThreadPointer.cast(ptr);
            }
        }
        if (null == osThreadPtr) {
            throw new DDRInteractiveCommandException(String.format("Could not find any j9thread at address %s\n", ptr.getHexAddress()));
        }
        // Is there an associated J9VMThread?
        J9VMThreadPointer vmThread = J9ThreadHelper.getVMThread(osThreadPtr);
        // Step 1: Print the general info for the VM and native threads:
        out.println(String.format("%s\t%s\t// %s", osThreadPtr.formatShortInteractive(), vmThread.notNull() ? vmThread.formatShortInteractive() : "<none>", vmThread.notNull() ? J9VMThreadHelper.getName(vmThread) : "[osthread]"));
        printMonitorsForJ9Thread(out, vm, osThreadPtr);
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : J9ThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer) J9PoolPointer(com.ibm.j9ddr.vm29.pointer.generated.J9PoolPointer) VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9ThreadLibraryPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadLibraryPointer)

Example 32 with J9JavaVMPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer in project openj9 by eclipse.

the class RamClassSummaryCommand method run.

public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    try {
        J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
        ClassSummaryHelper classSummaryHelper = new ClassSummaryHelper(preferredOrder);
        ClassSegmentIterator classSegmentIterator = new ClassSegmentIterator(vm.classMemorySegments());
        while (classSegmentIterator.hasNext()) {
            J9ClassPointer classPointer = (J9ClassPointer) classSegmentIterator.next();
            numberOfClasses++;
            ClassWalker classWalker = new RamClassWalker(classPointer, context);
            LinearDumper linearDumper = new LinearDumper();
            J9ClassRegionNode allRegionsNode = linearDumper.getAllRegions(classWalker);
            classSummaryHelper.addRegionsForClass(allRegionsNode);
        }
        classSummaryHelper.printStatistics(out);
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : ClassSegmentIterator(com.ibm.j9ddr.vm29.j9.walkers.ClassSegmentIterator) J9ClassRegionNode(com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper.J9ClassRegionNode) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) LinearDumper(com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) ClassSummaryHelper(com.ibm.j9ddr.vm29.tools.ddrinteractive.ClassSummaryHelper) ClassWalker(com.ibm.j9ddr.vm29.tools.ddrinteractive.ClassWalker) RamClassWalker(com.ibm.j9ddr.vm29.tools.ddrinteractive.RamClassWalker) RamClassWalker(com.ibm.j9ddr.vm29.tools.ddrinteractive.RamClassWalker) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 33 with J9JavaVMPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer in project openj9 by eclipse.

the class MonitorsCommand method printMonitorsForJ9VMThread.

private void printMonitorsForJ9VMThread(PrintStream out, J9JavaVMPointer vm, J9VMThreadPointer thread) throws CorruptDataException {
    FilterOptions defaultFilter = FilterOptions.defaultOption();
    MonitorIterator iterator = new MonitorIterator(vm);
    while (iterator.hasNext()) {
        Object current = iterator.next();
        if (current instanceof ObjectMonitor) {
            ObjectMonitor objMon = (ObjectMonitor) current;
            // Step 2: Print any monitors that the thread is the owner of:
            if (thread.equals(objMon.getOwner())) {
                out.print("Owns Object Monitor:\n\t");
                writeObjectMonitor(defaultFilter, objMon, out);
            }
            // Step 3: Print any monitors that the thread is blocking on::
            for (J9VMThreadPointer threadPtr : objMon.getBlockedThreads()) {
                if (threadPtr.equals(thread)) {
                    out.print(String.format("Blocking on (Enter Waiter):\n\t"));
                    writeObjectMonitor(defaultFilter, objMon, out);
                }
            }
            // Step 4: Print any monitors that the thread is waiting on:
            for (J9VMThreadPointer threadPtr : objMon.getWaitingThreads()) {
                if (threadPtr.equals(thread)) {
                    out.print(String.format("Waiting on (Notify Waiter):\n\t"));
                    writeObjectMonitor(defaultFilter, objMon, out);
                }
            }
        }
    }
}
Also used : MonitorIterator(com.ibm.j9ddr.vm29.j9.walkers.MonitorIterator) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) ObjectMonitor(com.ibm.j9ddr.vm29.j9.ObjectMonitor)

Example 34 with J9JavaVMPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer in project openj9 by eclipse.

the class MonitorsCommand method threadCommand.

/**
 * Dumps all monitors that are active for the specified J9Thread/J9VMThread/java.lang.Thread
 * @param args
 * @param out
 * @throws DDRInteractiveCommandException
 */
private void threadCommand(String[] args, PrintStream out) throws DDRInteractiveCommandException {
    if (args.length < 2) {
        out.println("This command takes one address argument: \"!monitors thread <address>\"");
        return;
    }
    try {
        long address = CommandUtils.parsePointer(args[1], J9BuildFlags.env_data64);
        VoidPointer ptr = VoidPointer.cast(address);
        J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
        J9VMThreadPointer mainThread = vm.mainThread();
        J9ThreadLibraryPointer lib = mainThread.osThread().library();
        J9PoolPointer pool = lib.thread_pool();
        Pool<J9ThreadPointer> threadPool = Pool.fromJ9Pool(pool, J9ThreadPointer.class);
        SlotIterator<J9ThreadPointer> poolIterator = threadPool.iterator();
        J9ThreadPointer osThreadPtr = null;
        while (poolIterator.hasNext()) {
            osThreadPtr = poolIterator.next();
            // Is there an associated J9VMThread?
            J9VMThreadPointer vmThread = J9ThreadHelper.getVMThread(osThreadPtr);
            J9ObjectPointer jlThread = null;
            if (vmThread.notNull()) {
                jlThread = vmThread.threadObject();
                if ((null != jlThread) && jlThread.equals(ptr)) {
                    out.println("Found java/lang/Thread @ " + ptr.getHexAddress());
                    printMonitorsForJ9VMThread(out, vm, vmThread);
                    return;
                } else if (vmThread.equals(ptr)) {
                    out.println("Found j9vmthread @ " + ptr.getHexAddress());
                    printMonitorsForJ9VMThread(out, vm, vmThread);
                    return;
                }
            }
            if (osThreadPtr.equals(ptr)) {
                out.println("Found j9thread @ " + ptr.getHexAddress());
                if (vmThread.notNull()) {
                    printMonitorsForJ9VMThread(out, vm, vmThread);
                }
                printMonitorsForJ9Thread(out, vm, osThreadPtr);
                return;
            }
        }
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : J9ThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer) J9PoolPointer(com.ibm.j9ddr.vm29.pointer.generated.J9PoolPointer) VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) J9ThreadLibraryPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadLibraryPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)

Example 35 with J9JavaVMPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer in project openj9 by eclipse.

the class MonitorsCommand method printMonitorsForJ9Thread.

private void printMonitorsForJ9Thread(PrintStream out, J9JavaVMPointer vm, J9ThreadPointer osThreadPtr) throws CorruptDataException {
    FilterOptions defaultFilter = FilterOptions.defaultOption();
    MonitorIterator iterator = new MonitorIterator(vm);
    while (iterator.hasNext()) {
        Object current = iterator.next();
        if (current instanceof J9ThreadMonitorPointer) {
            // System Monitor
            SystemMonitor monitor = SystemMonitor.fromJ9ThreadMonitor((J9ThreadMonitorPointer) current);
            List<J9ThreadPointer> threadList = null;
            // Step 2: Print any monitors that the thread is the owner of:
            J9ThreadPointer ownerPtr = monitor.getOwner();
            if (ownerPtr.notNull() && ownerPtr.equals(osThreadPtr)) {
                out.print("Owns System Monitor:\n\t");
                writeSystemMonitor(defaultFilter, monitor, out);
            }
            // Step 3: Print any monitors that the thread is blocking on:
            threadList = monitor.getBlockedThreads();
            for (J9ThreadPointer thread : threadList) {
                if (osThreadPtr.equals(thread)) {
                    out.print("Blocking on System Monitor (Enter Waiter):\n\t");
                    writeSystemMonitor(defaultFilter, monitor, out);
                }
            }
            // Step 4: Print any monitors that the thread is waiting on:
            threadList = monitor.getWaitingThreads();
            for (J9ThreadPointer thread : threadList) {
                if (osThreadPtr.equals(thread)) {
                    out.print("Waiting on System Monitor (Notify Waiter):\n\t");
                    writeSystemMonitor(defaultFilter, monitor, out);
                }
            }
        }
    }
}
Also used : J9ThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer) MonitorIterator(com.ibm.j9ddr.vm29.j9.walkers.MonitorIterator) SystemMonitor(com.ibm.j9ddr.vm29.j9.SystemMonitor) J9ThreadMonitorPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadMonitorPointer)

Aggregations

J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)57 CorruptDataException (com.ibm.j9ddr.CorruptDataException)49 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)39 J9ClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)23 J9VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)17 UDATA (com.ibm.j9ddr.vm29.types.UDATA)13 J9ROMClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer)10 ClassSegmentIterator (com.ibm.j9ddr.vm29.j9.walkers.ClassSegmentIterator)8 J9ObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)8 J9MemorySegmentPointer (com.ibm.j9ddr.vm29.pointer.generated.J9MemorySegmentPointer)6 PatternString (com.ibm.j9ddr.util.PatternString)5 MonitorIterator (com.ibm.j9ddr.vm29.j9.walkers.MonitorIterator)5 ROMClassesIterator (com.ibm.j9ddr.vm29.j9.walkers.ROMClassesIterator)5 U8Pointer (com.ibm.j9ddr.vm29.pointer.U8Pointer)5 J9ClassLoaderPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer)5 MM_HeapRegionManagerPointer (com.ibm.j9ddr.vm29.pointer.generated.MM_HeapRegionManagerPointer)5 Table (com.ibm.j9ddr.tools.ddrinteractive.Table)4 GCHeapRegionDescriptor (com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionDescriptor)4 J9MethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer)4 J9ThreadMonitorPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ThreadMonitorPointer)4