use of com.ibm.j9ddr.vm29.j9.ObjectMonitor in project openj9 by eclipse.
the class CheckMonitorTable method check.
@Override
public void check() {
try {
GCMonitorReferenceIterator monitorReferenceIterator = GCMonitorReferenceIterator.from();
while (monitorReferenceIterator.hasNext()) {
J9ObjectMonitorPointer objectMonitor = monitorReferenceIterator.next();
J9ThreadAbstractMonitorPointer monitor = J9ThreadAbstractMonitorPointer.cast(objectMonitor.monitor());
PointerPointer slot = PointerPointer.cast(monitor.userDataEA());
if (_engine.checkSlotPool(slot, VoidPointer.cast(monitorReferenceIterator.currentMonitorTable().getJ9HashTablePointer())) != J9MODRON_SLOT_ITERATOR_OK) {
return;
}
}
} catch (CorruptDataException e) {
// TODO: handle exception
}
}
use of com.ibm.j9ddr.vm29.j9.ObjectMonitor in project openj9 by eclipse.
the class J9VMThreadPointerUtil method getJ9State.
// Taken from thrinfo.c getVMThreadStateHelper
// Note that DDR has access to a wrapper for getting information about object monitors
// this should be used as the single point of access for obtaining this information rather
// than local copies of the functionality e.g. monitorPeekTable.
public static ThreadInfo getJ9State(J9VMThreadPointer targetThread) throws CorruptDataException {
final ThreadInfo thrinfo = new ThreadInfo();
if (targetThread.isNull()) {
thrinfo.state = new UDATA(J9VMTHREAD_STATE_UNKNOWN).longValue();
return thrinfo;
}
thrinfo.thread = targetThread;
long vmstate = J9VMTHREAD_STATE_RUNNING;
UDATA publicFlags = targetThread.publicFlags();
J9ThreadPointer j9self = targetThread.osThread();
/* j9self may be NULL if this function is used by RAS on a corrupt VM */
ThreadState j9state = new ThreadState(j9self);
if (publicFlags.anyBitsIn(J9_PUBLIC_FLAGS_THREAD_BLOCKED | J9_PUBLIC_FLAGS_THREAD_WAITING)) {
/* Assert_VMUtil_true(targetThread->blockingEnterObject != NULL); */
thrinfo.lockObject = targetThread.blockingEnterObject();
// use the DDR object monitor wrapper
ObjectMonitor monitor = ObjectMonitor.fromJ9Object(thrinfo.lockObject);
// isInflated
if (monitor.isInflated()) {
if (publicFlags.anyBitsIn(J9_PUBLIC_FLAGS_THREAD_BLOCKED)) {
if (monitor.getOwner().notNull() && !monitor.getOwner().equals(j9self)) {
/*
* The omrthread may be accessing other raw monitors, but
* the vmthread is blocked while the object monitor is
* owned by a competing thread.
*/
vmstate = J9VMTHREAD_STATE_BLOCKED;
thrinfo.rawLock = J9ThreadMonitorPointer.cast(monitor.getInflatedMonitor());
}
} else {
if (j9self.isNull()) {
if (publicFlags.anyBitsIn(J9_PUBLIC_FLAGS_THREAD_TIMED)) {
vmstate = J9VMTHREAD_STATE_WAITING_TIMED;
} else {
vmstate = J9VMTHREAD_STATE_WAITING;
}
thrinfo.rawLock = J9ThreadMonitorPointer.cast(monitor.getInflatedMonitor());
} else if (monitor.getInflatedMonitor().equals(j9state.blocker)) {
vmstate = getInflatedMonitorState(j9self, j9state, thrinfo);
}
/*
* If the omrthread is using a different monitor, it must be for vm access.
* So the vmthread is either not waiting yet or already awakened.
*/
}
} else {
if (monitor.getOwner().notNull() && (!monitor.getOwner().equals(targetThread))) {
/* count = J9_FLATLOCK_COUNT(lockWord); */
/* rawLock = (omrthread_monitor_t)monitorTablePeekMonitor(targetThread->javaVM, lockObject); */
vmstate = J9VMTHREAD_STATE_BLOCKED;
}
}
/*
* targetThread may be blocked attempting to reacquire VM access, after
* succeeding to acquire the object monitor. In this case, the returned
* vmstate depends on includeRawMonitors.
* includeRawMonitors == FALSE: the vmstate is RUNNING.
* includeRawMonitors == TRUE: the vmstate depends on the state of
* the omrthread. e.g. The omrthread may be blocked on publicFlagsMutex.
*/
} else if (publicFlags.anyBitsIn(J9_PUBLIC_FLAGS_THREAD_PARKED)) {
/* if the osthread is not parked, then the thread is runnable */
if (j9self.isNull() || (j9state.flags.anyBitsIn(J9THREAD_FLAG_PARKED))) {
thrinfo.lockObject = targetThread.blockingEnterObject();
if (publicFlags.anyBitsIn(J9_PUBLIC_FLAGS_THREAD_TIMED)) {
vmstate = J9VMTHREAD_STATE_PARKED_TIMED;
} else {
vmstate = J9VMTHREAD_STATE_PARKED;
}
}
} else if (publicFlags.anyBitsIn(J9_PUBLIC_FLAGS_THREAD_SLEEPING)) {
/* if the osthread is not sleeping, then the thread is runnable */
if (j9self.isNull() || (j9state.flags.anyBitsIn(J9THREAD_FLAG_SLEEPING))) {
vmstate = J9VMTHREAD_STATE_SLEEPING;
}
} else {
/* no vmthread flags apply, so go through the omrthread flags */
if (j9self.isNull()) {
vmstate = J9VMTHREAD_STATE_UNKNOWN;
} else if (j9state.flags.anyBitsIn(J9THREAD_FLAG_PARKED)) {
if (j9state.flags.anyBitsIn(J9THREAD_FLAG_TIMER_SET)) {
vmstate = J9VMTHREAD_STATE_PARKED_TIMED;
} else {
vmstate = J9VMTHREAD_STATE_PARKED;
}
} else if (j9state.flags.anyBitsIn(J9THREAD_FLAG_SLEEPING)) {
vmstate = J9VMTHREAD_STATE_SLEEPING;
} else if (j9state.flags.anyBitsIn(J9THREAD_FLAG_DEAD)) {
vmstate = J9VMTHREAD_STATE_DEAD;
}
}
if (J9VMTHREAD_STATE_RUNNING == vmstate) {
/* check if the omrthread is blocked/waiting on a raw monitor */
thrinfo.lockObject = null;
vmstate = getInflatedMonitorState(j9self, j9state, thrinfo);
}
if (thrinfo.rawLock != null) {
if (thrinfo.rawLock.flags().allBitsIn(J9THREAD_MONITOR_OBJECT)) {
thrinfo.lockObject = J9ObjectPointer.cast(thrinfo.rawLock.userData());
}
}
/* j9state was zeroed if j9self is NULL */
if (j9state.flags.anyBitsIn(J9THREAD_FLAG_INTERRUPTED)) {
vmstate |= J9VMTHREAD_STATE_INTERRUPTED;
}
if (j9state.flags.anyBitsIn(J9THREAD_FLAG_SUSPENDED)) {
vmstate |= J9VMTHREAD_STATE_SUSPENDED;
}
if (publicFlags.anyBitsIn(J9_PUBLIC_FLAGS_HALT_THREAD_JAVA_SUSPEND)) {
vmstate |= J9VMTHREAD_STATE_SUSPENDED;
}
thrinfo.state = new UDATA(vmstate).longValue();
return thrinfo;
}
use of com.ibm.j9ddr.vm29.j9.ObjectMonitor in project openj9 by eclipse.
the class HeapWalker method initializeFlatLockedMonitors.
private static void initializeFlatLockedMonitors() throws CorruptDataException {
J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
MM_GCExtensionsPointer gcext = GCExtensions.getGCExtensionsPointer();
MM_HeapRegionManagerPointer hrm = gcext.heapRegionManager();
flatLockedMonitors = new TreeSet<ObjectMonitor>();
GCHeapRegionIterator regions = GCHeapRegionIterator.fromMMHeapRegionManager(hrm, true, true);
while (regions.hasNext()) {
GCHeapRegionDescriptor region = regions.next();
if (!flatLockedMonitorsByRegion.containsKey(region)) {
runFlatLockMonitorRegionWalk(vm, region);
}
/* Running the walk should have populated the flatLockedMonitors map */
assert (flatLockedMonitorsByRegion.containsKey(region));
flatLockedMonitors.addAll(flatLockedMonitorsByRegion.get(region));
}
}
use of com.ibm.j9ddr.vm29.j9.ObjectMonitor in project openj9 by eclipse.
the class MonitorIterator method threadPoolHasNext.
private boolean threadPoolHasNext() throws CorruptDataException {
while ((current == null) && pool.notNull()) {
while (index < poolSize) {
J9ThreadMonitorPointer monitor = J9ThreadMonitorPointer.cast(poolEntries.add(index));
index++;
if (freeTag != monitor.count().longValue()) {
J9ThreadAbstractMonitorPointer lock = J9ThreadAbstractMonitorPointer.cast(monitor);
if (lock.flags().allBitsIn(J9ThreadAbstractMonitor.J9THREAD_MONITOR_OBJECT)) {
if (!lock.userData().eq(0)) {
// this is an object monitor in the system monitor table
J9ObjectPointer obj = J9ObjectPointer.cast(lock.userData());
ObjectMonitor objmon = ObjectAccessBarrier.getMonitor(obj);
// This check is to exclude flat object monitors. Flat object monitors are accounted for during the heap walk
if ((objmon == null) || !objmon.isInflated()) {
continue;
}
// return an object monitor
current = objmon;
}
} else {
// return a system monitor
current = monitor;
}
if (log.isLoggable(Level.FINE)) {
log.fine(String.format("Found monitor @ 0x%016x : %s", monitor.getAddress(), monitor.name().getCStringAtOffset(0)));
}
return true;
}
}
pool = pool.next();
if (pool.notNull()) {
index = 0;
poolEntries = pool.entriesEA();
}
}
return pool.notNull();
}
use of com.ibm.j9ddr.vm29.j9.ObjectMonitor in project openj9 by eclipse.
the class MonitorsCommand method writeObjectMonitorToBuffer.
/**
* Helper to write details for an object monitor to a buffer.
*
* @param objectMonitor
* @param out
* @throws CorruptDataException
*/
private void writeObjectMonitorToBuffer(FilterOptions filter, ObjectMonitor objMon, StringBuilder out) throws CorruptDataException {
if (filter.shouldPrint(objMon)) {
out.append(String.format("Object monitor for %s\t\n", objMon.getObject().formatShortInteractive()));
if (objMon.isInflated()) {
out.append("\tInflated\n");
} else {
if (objMon.isContended()) {
out.append("\tContended Flatlocked\n");
} else if (objMon.getLockword().isNull()) {
out.append("\tDeflated\n");
} else {
out.append("\tFlatlocked\n");
}
}
J9ObjectMonitorPointer j9ObjMonPtr = objMon.getJ9ObjectMonitorPointer();
if (j9ObjMonPtr.notNull()) {
out.append(String.format("\t%s %s\n", j9ObjMonPtr.formatShortInteractive(), j9ObjMonPtr.monitor().formatShortInteractive()));
}
J9VMThreadPointer ownerThreadPointer = objMon.getOwner();
if (ownerThreadPointer.notNull()) {
out.append(String.format("\tOwner:\t%s\t%s\n", ownerThreadPointer.formatShortInteractive(), J9VMThreadHelper.getName(ownerThreadPointer)));
}
if (!objMon.getBlockedThreads().isEmpty()) {
out.append(String.format("\t%s\t\n", "Blocking (Enter Waiter):"));
for (J9VMThreadPointer threadPtr : objMon.getBlockedThreads()) {
out.append(String.format("\t\t%s\t%s\n", threadPtr.formatShortInteractive(), J9VMThreadHelper.getName(threadPtr)));
}
}
if (!objMon.getWaitingThreads().isEmpty()) {
out.append(String.format("\t%s\t\n", "Waiting (Notify Waiter):"));
for (J9VMThreadPointer threadPtr : objMon.getWaitingThreads()) {
out.append(String.format("\t\t%s\t%s\n", threadPtr.formatShortInteractive(), J9VMThreadHelper.getName(threadPtr)));
}
}
out.append(nl);
}
}
Aggregations