Search in sources :

Example 81 with J9JavaVMPointer

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

the class SetVMCommand method run.

/**
 * Runs the !setvm command.
 * 1. Checks whether correct number of args passed which is 1.
 * 2. If condition 1 is successful, checks whether the passed arg is a valid integer, decimal or hexadecimal.
 * 3. If condition 2 is successful, checks whether the address (only arg) is a valid J9JavaVM address.
 * 4. If condition 3 is unsuccessful, checks whether the address is a valid J9VMThread address.
 *
 * If any of the condition 3 or 4 succeeds, then cachedVM is set to new address.
 * Otherwise, it prints error msg.
 *
 * @param command DDR extension command which is setVM for this extension.
 * @param args arguments passed with the command
 * @param context current context that DDR is running on.
 * @param  out	PrintStream to print the user messages.
 * @return void
 */
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    if (1 != args.length) {
        printHelp(out);
        return;
    }
    long address = CommandUtils.parsePointer(args[0], J9BuildFlags.env_data64);
    J9JavaVMPointer vmPtr = J9JavaVMPointer.cast(address);
    if (testJavaVMPtr(vmPtr)) {
        J9RASHelper.setCachedVM(vmPtr);
        out.println("VM set to " + vmPtr.getHexAddress());
        return;
    } else {
        /* hmm. It's not a J9JavaVM. Maybe it's a vmThread? */
        /* try to read the VM slot */
        J9VMThreadPointer threadPtr = J9VMThreadPointer.cast(address);
        try {
            vmPtr = threadPtr.javaVM();
            if (testJavaVMPtr(vmPtr)) {
                J9RASHelper.setCachedVM(vmPtr);
                out.println("VM set to " + vmPtr.getHexAddress());
                return;
            }
        } catch (CorruptDataException e) {
        /* Do Nothing */
        }
    }
    out.println("Error: Specified value (=" + address + ") is not a javaVM or vmThread pointer, VM not set");
}
Also used : J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 82 with J9JavaVMPointer

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

the class VmCheckCommand method verifyAddressInSegment.

private void verifyAddressInSegment(PrintStream out, J9JavaVMPointer vm, J9MemorySegmentPointer segment, long address, String description) throws CorruptDataException {
    U8Pointer heapBase = segment.heapBase();
    U8Pointer heapAlloc = segment.heapAlloc();
    if (address < heapBase.getAddress() || (address >= heapAlloc.getAddress())) {
        reportError(out, "address 0x%s (%s) not in segment [heapBase=0x%s, heapAlloc=0x%s]", address, description, Long.toHexString(heapBase.getAddress()), Long.toHexString(heapAlloc.getAddress()));
    }
}
Also used : U8Pointer(com.ibm.j9ddr.vm29.pointer.U8Pointer)

Example 83 with J9JavaVMPointer

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

the class VmCheckCommand method checkJ9VMThreadSanity.

/*
	 *  Based on vmchk/checkthreads.c r1.5
	 *
	 *	J9VMThread sanity:
	 *		Valid VM check:
	 *			J9VMThread->javaVM->javaVM == J9VMThread->javaVM.
	 *
	 *		Exclusive access check:
	 *			If any J9VMThread has exclusive access, ensure no other thread has exclusive or vm access.
	 */
private void checkJ9VMThreadSanity(J9JavaVMPointer javaVM, PrintStream out) throws CorruptDataException {
    GCVMThreadListIterator gcvmThreadListIterator = GCVMThreadListIterator.from();
    int count = 0;
    int numberOfThreadsWithVMAccess = 0;
    boolean exclusiveVMAccess = javaVM.exclusiveAccessState().eq(J9_XACCESS_EXCLUSIVE);
    reportMessage(out, "Checking threads");
    while (gcvmThreadListIterator.hasNext()) {
        J9VMThreadPointer thread = gcvmThreadListIterator.next();
        verifyJ9VMThread(out, thread, javaVM);
        if (thread.publicFlags().allBitsIn(J9Consts.J9_PUBLIC_FLAGS_VM_ACCESS)) {
            numberOfThreadsWithVMAccess++;
        }
        count++;
    }
    if (exclusiveVMAccess && numberOfThreadsWithVMAccess > 1) {
        reportError(out, "numberOfThreadsWithVMAccess (%d) > 1 with vm->exclusiveAccessState == J9_XACCESS_EXCLUSIVE", numberOfThreadsWithVMAccess);
    }
    reportMessage(out, "Checking %d threads done", count);
}
Also used : GCVMThreadListIterator(com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)

Example 84 with J9JavaVMPointer

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

the class DeadlockUtils method readObjectMonitors.

/**
 * Returns a hash map of Object Pointers to their respective mutex (Object Monitor or System Monitor)
 * @param vm
 * @return
 * @throws CorruptDataException
 */
public static HashMap<J9ObjectPointer, Object> readObjectMonitors(J9JavaVMPointer vm) throws CorruptDataException {
    HashMap<J9ObjectPointer, Object> objectMonitorsMap = new HashMap<J9ObjectPointer, Object>();
    MonitorIterator iterator = new MonitorIterator(vm);
    while (iterator.hasNext()) {
        Object current = iterator.next();
        if (current instanceof ObjectMonitor) {
            ObjectMonitor mon = (ObjectMonitor) current;
            J9ObjectPointer object = mon.getObject();
            objectMonitorsMap.put(object, mon);
        } else if (current instanceof J9ThreadMonitorPointer) {
            // System Monitor
            J9ThreadMonitorPointer mon = (J9ThreadMonitorPointer) current;
            J9ThreadAbstractMonitorPointer lock = J9ThreadAbstractMonitorPointer.cast(mon);
            if (false == lock.userData().eq(0)) {
                // this is an object monitor in the system monitor table
                J9ObjectPointer object = J9ObjectPointer.cast(lock.userData());
                objectMonitorsMap.put(object, mon);
            }
        }
    }
    return objectMonitorsMap;
}
Also used : MonitorIterator(com.ibm.j9ddr.vm29.j9.walkers.MonitorIterator) HashMap(java.util.HashMap) J9ThreadMonitorPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadMonitorPointer) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer) J9ThreadAbstractMonitorPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadAbstractMonitorPointer) ObjectMonitor(com.ibm.j9ddr.vm29.j9.ObjectMonitor)

Example 85 with J9JavaVMPointer

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

the class DeadlockDetector method findDeadlocks.

/**
 * @param out
 * @throws DDRInteractiveCommandException
 */
public static void findDeadlocks(PrintStream out) throws DDRInteractiveCommandException {
    // Based on JavaCoreDumpWriter::writeDeadLocks()
    // Modified to work for both J9VMThreads and J9Threads.
    HashMap<Integer, NativeDeadlockGraphNode> map = new HashMap<Integer, NativeDeadlockGraphNode>();
    try {
        J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
        HashMap<J9ObjectPointer, Object> objectMonitorsMap = DeadlockUtils.readObjectMonitors(vm);
        J9ThreadLibraryPointer lib = vm.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();
            DeadlockUtils.findThreadCycle(osThreadPtr, map, objectMonitorsMap);
            // Is there an associated J9VMThread?
            J9VMThreadPointer vmThread = J9ThreadHelper.getVMThread(osThreadPtr);
            if ((null != vmThread) && (vmThread.notNull()) && vmThread.publicFlags().allBitsIn(J9Consts.J9_PUBLIC_FLAGS_HALT_THREAD_INSPECTION)) {
                break;
            }
        }
        // Identifier for each (independent) cycle.
        int cycle = 0;
        Iterator<Map.Entry<Integer, NativeDeadlockGraphNode>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            NativeDeadlockGraphNode node = iterator.next().getValue();
            cycle++;
            while (null != node) {
                if (node.cycle > 0) {
                    // it means we've looped around!
                    if (node.cycle == cycle) {
                        // Output header for each deadlock:
                        out.println("Deadlock Detected !!!");
                        out.println("---------------------");
                        out.println();
                        NativeDeadlockGraphNode head = node;
                        boolean isCycleRoot = true;
                        do {
                            DeadlockUtils.writeDeadlockNode(node, isCycleRoot, objectMonitorsMap, out);
                            node = node.next;
                            isCycleRoot = false;
                        } while (node != head);
                        out.println(node.toString());
                    }
                    // Skip already visited nodes
                    break;
                } else {
                    node.cycle = cycle;
                }
                node = node.next;
            }
        }
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : J9ThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer) HashMap(java.util.HashMap) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer) J9PoolPointer(com.ibm.j9ddr.vm29.pointer.generated.J9PoolPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) J9ThreadLibraryPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadLibraryPointer)

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