Java Code Examples for com.sun.jdi.VirtualMachine#allThreads()

The following examples show how to use com.sun.jdi.VirtualMachine#allThreads() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GetObjectLockCount.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static int getLockRecursions(VirtualMachine vm) {
    List <ThreadReference> threads = vm.allThreads();
    for (ThreadReference thread : threads) {
        if (thread.name().equals("main")) {

            System.out.println("Found main thread.");
            try{
                StackFrame frame = thread.frame(3);
                return frame.thisObject().entryCount();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        System.out.println("Main thread not found!");
    }
    return -1;
}
 
Example 2
Source File: ProcessAttachDebugger.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example 3
Source File: ProcessAttachDebugger.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example 4
Source File: ProcessAttachDebugger.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example 5
Source File: ProcessAttachDebugger.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example 6
Source File: Operator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void dumpThreadsStatus(VirtualMachine vm, Level l) {
    logger.log(l, "DUMP of threads:\n");
    List<ThreadReference> allThreads = vm.allThreads();
    for (ThreadReference t : allThreads) {
        logger.log(l, "   "+t+" "+JPDAThreadImpl.getThreadStateLog(t));
    }
    logger.log(l, "DUMP DONE.");
}
 
Example 7
Source File: ProcessAttachDebugger.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example 8
Source File: ProcessAttachDebugger.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example 9
Source File: ProcessAttachDebugger.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example 10
Source File: ProcessAttachDebugger.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example 11
Source File: ProcessAttachDebugger.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example 12
Source File: ProcessAttachDebugger.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example 13
Source File: ProcessAttachDebugger.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example 14
Source File: ProcessAttachDebugger.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String main_args[]) throws Exception {
    String pid = main_args[0];

    // find ProcessAttachingConnector

    List<AttachingConnector> l =
        Bootstrap.virtualMachineManager().attachingConnectors();
    AttachingConnector ac = null;
    for (AttachingConnector c: l) {
        if (c.name().equals("com.sun.jdi.ProcessAttach")) {
            ac = c;
            break;
        }
    }
    if (ac == null) {
        throw new RuntimeException("Unable to locate ProcessAttachingConnector");
    }

    Map<String,Connector.Argument> args = ac.defaultArguments();
    Connector.StringArgument arg = (Connector.StringArgument)args.get("pid");
    arg.setValue(pid);

    System.out.println("Debugger is attaching to: " + pid + " ...");

    VirtualMachine vm = ac.attach(args);

    System.out.println("Attached! Now listing threads ...");

    // list all threads

    for (ThreadReference thr: vm.allThreads()) {
        System.out.println(thr);
    }

    System.out.println("Debugger done.");
}
 
Example 15
Source File: VMTargetStarter.java    From gravel with Apache License 2.0 4 votes vote down vote up
public VMRemoteTarget createJVM() throws IOException, InterruptedException,
		IncompatibleThreadStateException {
	Process process = startSecondJVM(VMLocalTarget.class);
	sleep(90);
	// connect
	VirtualMachine vm = new VMAcquirer().connect(debugPort);

	ClassPrepareRequest createClassPrepareRequest = vm
			.eventRequestManager().createClassPrepareRequest();
	createClassPrepareRequest.addClassFilter(VMLocalTarget.class.getName());
	createClassPrepareRequest.enable();
	
	vm.resume();

	List<ThreadReference> allThreads = vm.allThreads();
	for (ThreadReference threadReference : allThreads) {
		System.out.println(threadReference+" isSuspended: "+threadReference.isSuspended()+" suspendCount: "+threadReference.suspendCount());
	}

	// process events
	EventQueue eventQueue = vm.eventQueue();
	while (true) {
		EventSet eventSet = eventQueue.remove();
		for (Event event : eventSet) {
			if (event instanceof ClassPrepareEvent) {
				event.request().disable();
				installHaltPoint(vm);
			}
			if (event instanceof VMDeathEvent
					|| event instanceof VMDisconnectEvent) {
				return null;
			}
			if (event instanceof BreakpointEvent) {
				event.request().disable();
				ThreadReference thread = ((BreakpointEvent) event).thread();
				return new VMRemoteTarget(process, vm, thread, debugPort);
			}
		}
		eventSet.resume();
	}
}