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");
}
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()));
}
}
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);
}
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;
}
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);
}
}
Aggregations