Search in sources :

Example 86 with J9ObjectPointer

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

the class CheckEngine method checkSlotPool.

public int checkSlotPool(PointerPointer objectIndirect, VoidPointer objectIndirectBase) {
    J9ObjectPointer object;
    try {
        object = J9ObjectPointer.cast(objectIndirect.at(0));
        int result = checkObjectIndirect(object);
        if (J9MODRON_GCCHK_RC_OK != result) {
            CheckError error = new CheckError(objectIndirectBase, objectIndirect, _cycle, _currentCheck, result, _cycle.nextErrorCount(), CheckError.check_type_other);
            _reporter.report(error);
        }
    } catch (CorruptDataException e) {
        // TODO : cde should be part of the error
        CheckError error = new CheckError(objectIndirectBase, objectIndirect, _cycle, _currentCheck, J9MODRON_GCCHK_RC_CORRUPT_DATA_EXCEPTION, _cycle.nextErrorCount(), CheckError.check_type_other);
        _reporter.report(error);
    }
    return J9MODRON_SLOT_ITERATOR_OK;
}
Also used : CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)

Example 87 with J9ObjectPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer 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 88 with J9ObjectPointer

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

the class DeadlockUtils method findThreadCycle.

/**
 * @param vmThread
 * @param map
 * @throws CorruptDataException
 */
public static void findThreadCycle(J9ThreadPointer aThread, HashMap<Integer, NativeDeadlockGraphNode> deadlocks, HashMap<J9ObjectPointer, Object> objectMonitorsMap) throws CorruptDataException {
    // Based on JavaCoreDumpWriter::findThreadCycle()
    // Can't stack allocate or (safely) re-purpose an object in Java,
    // so we create a new one on each iteration, this is slightly
    // different from what is done in javadump.cpp
    NativeDeadlockGraphNode node = null;
    NativeDeadlockGraphNode prev = null;
    do {
        // Is there an associated J9VMThread?
        J9VMThreadPointer vmThread = J9ThreadHelper.getVMThread(aThread);
        boolean isJavaThread = (null != vmThread) && vmThread.notNull();
        // Enter waiter (blocked) or notify waiter.
        boolean isJavaWaiter = false;
        if (isJavaThread) {
            // There is, so grab all the J9VMThread related information.
            JavaDeadlockGraphNode javaNode = new JavaDeadlockGraphNode();
            javaNode.javaThread = vmThread;
            J9VMThreadPointer owner = null;
            J9ObjectPointer lockObject = null;
            J9ThreadAbstractMonitorPointer lock = null;
            // Functionally equivalent to getVMThreadStateHelper(...) in thrinfo.c
            lockObject = vmThread.blockingEnterObject();
            if ((null != lockObject) && lockObject.notNull()) {
                // This condition hitting means we are in one of the desired states:
                // J9VMTHREAD_STATE_BLOCKED
                // J9VMTHREAD_STATE_WAITING, J9VMTHREAD_STATE_WAITING_TIMED
                // J9VMTHREAD_STATE_PARKED, J9VMTHREAD_STATE_PARKED_TIMED
                isJavaWaiter = true;
                // The original native relies on getVMThreadStateHelper(...)
                // from thrinfo.c to obtain this information, which is analogous
                // to J9VMThreadPointerUtil.getJ9State(...), but we don't actually
                // need all that information.
                Object current = objectMonitorsMap.get(lockObject);
                if (current instanceof ObjectMonitor) {
                    ObjectMonitor mon = (ObjectMonitor) current;
                    owner = mon.getOwner();
                    lock = mon.getInflatedMonitor();
                } else if (current instanceof J9ThreadMonitorPointer) {
                    // System Monitor
                    J9ThreadMonitorPointer mon = (J9ThreadMonitorPointer) current;
                    J9ThreadPointer sysThread = mon.owner();
                    lock = J9ThreadAbstractMonitorPointer.cast(mon);
                    if (sysThread.notNull()) {
                        owner = J9ThreadHelper.getVMThread(sysThread);
                    }
                }
                if ((null == owner) || owner.isNull() || (owner.equals(vmThread))) {
                    // See JAZZ103 63676: There are cases where even if we know there is no
                    // Java deadlock, we should still check for a system deadlock.
                    // We simply deal with this node as a native one from this point on.
                    isJavaWaiter = false;
                } else {
                    // N.B. In the native there are comparisons with J9VMTHREAD_STATE_*
                    // constants as returned by the helper, but here we don't actually need them.
                    javaNode.javaLock = lock;
                    javaNode.lockObject = lockObject;
                    javaNode.cycle = 0;
                    /* Record current thread and update last node */
                    javaNode.nativeThread = vmThread.osThread();
                    deadlocks.put(javaNode.hashCode(), javaNode);
                    if (null != prev) {
                        prev.next = javaNode;
                    }
                    /* Move around the graph */
                    prev = javaNode;
                    /* Peek ahead to see if we're in a possible cycle */
                    prev.next = deadlocks.get(owner.osThread().hashCode());
                    aThread = owner.osThread();
                }
            }
            // Have to keep going for the case of Java thread blocking on system monitor.
            // We have to write the J9Thread info as well.
            node = javaNode;
        }
        if (false == isJavaThread) {
            node = new NativeDeadlockGraphNode();
        }
        // Now get all of the J9Thread fields (even when we are working with a Java thread).
        node.nativeThread = aThread;
        J9ThreadMonitorPointer nativeLock = aThread.monitor();
        J9ThreadPointer owner = null;
        if ((null == nativeLock) || nativeLock.isNull()) {
            if (false == isJavaThread) {
                return;
            }
        } else {
            node.nativeLock = nativeLock;
            owner = nativeLock.owner();
        }
        // to change the pointers, otherwise we have to set them up.
        if (false == isJavaWaiter) {
            deadlocks.put(node.hashCode(), node);
            if (null != prev) {
                prev.next = node;
            }
            if ((null == owner) || owner.isNull() || (owner.equals(aThread))) {
                return;
            } else {
                /* Move around the graph */
                prev = node;
                /* Peek ahead to see if we're in a possible cycle */
                prev.next = deadlocks.get(owner.hashCode());
                aThread = owner;
            }
        }
    } while (// Quit as soon as possible (first node we've already visited).
    null == prev.next);
// The rest of the cycles will be found by multiple calls to findThreadCycle(...)
}
Also used : J9ThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) 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 89 with J9ObjectPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer 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)

Example 90 with J9ObjectPointer

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

the class CheckReporterTTY method reportObjectHeader.

@Override
public void reportObjectHeader(CheckError error, J9ObjectPointer object, String prefix) {
    String prefixString = prefix == null ? "" : prefix;
    if (!shouldReport(error)) {
        return;
    }
    boolean isValid = false;
    boolean isHole = false;
    boolean isIndexable = false;
    try {
        isHole = ObjectModel.isDeadObject(object);
        if (!isHole) {
            isIndexable = ObjectModel.isIndexable(object);
        }
        isValid = true;
    } catch (CorruptDataException cde) {
    }
    if (isValid) {
        if (isIndexable) {
            out.print(String.format("  <gc check (%d): %sIObject %x header:", error._errorNumber, prefixString, object.getAddress()));
        } else {
            String elementName = isHole ? "Hole" : "Object";
            out.print(String.format("  <gc check (%d): %s%s %x header:", error._errorNumber, prefixString, elementName, object.getAddress()));
        }
    } else {
        out.print(String.format("  <gc check (%d): %s%s %x header:", error._errorNumber, prefixString, "Corrupt", object.getAddress()));
    }
    int headerSize = (int) J9Object.SIZEOF;
    if (isHole) {
        headerSize = (int) MM_HeapLinkedFreeHeader.SIZEOF;
    } else {
        try {
            headerSize = ObjectModel.getHeaderSize(object).intValue();
        } catch (CorruptDataException cde) {
        }
    }
    try {
        U32Pointer data = U32Pointer.cast(object);
        for (int i = 0; i < headerSize / U32.SIZEOF; i++) {
            out.print(String.format(" %08X", data.at(i).longValue()));
        }
    } catch (CorruptDataException cde) {
    }
    out.println(">");
}
Also used : CorruptDataException(com.ibm.j9ddr.CorruptDataException) U32Pointer(com.ibm.j9ddr.vm29.pointer.U32Pointer)

Aggregations

J9ObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)76 CorruptDataException (com.ibm.j9ddr.CorruptDataException)48 UDATA (com.ibm.j9ddr.vm29.types.UDATA)22 NoSuchElementException (java.util.NoSuchElementException)18 J9ClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)17 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)16 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)12 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)7 PointerPointer (com.ibm.j9ddr.vm29.pointer.PointerPointer)6 ObjectMonitor (com.ibm.j9ddr.vm29.j9.ObjectMonitor)5 MarkedObject (com.ibm.j9ddr.vm29.j9.gc.GCHeapMap.MarkedObject)5 GCHeapRegionDescriptor (com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionDescriptor)5 J9VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)5 GCObjectHeapIterator (com.ibm.j9ddr.vm29.j9.gc.GCObjectHeapIterator)4 GCObjectIterator (com.ibm.j9ddr.vm29.j9.gc.GCObjectIterator)4 UDATAPointer (com.ibm.j9ddr.vm29.pointer.UDATAPointer)4 ArrayList (java.util.ArrayList)4 J9ObjectFieldOffset (com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset)3 GCHeapRegionIterator (com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionIterator)3 U32Pointer (com.ibm.j9ddr.vm29.pointer.U32Pointer)3