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

The following examples show how to use com.sun.jdi.VirtualMachine#resume() . 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: HelloWorld.java    From java-svc with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void main(String[] args) throws AttachException, IOException, IllegalConnectorArgumentsException {
	if (args.length != 2) {
		System.out.println("Must provide host and port!");
		System.exit(2);
	}
	String host = args[0];
	String port = args[1];
	VirtualMachine vm = null;
	try {
		vm = connect(host, port);
		vm.resume();
		System.out.println("The process at " + JdiUtils.prettyPrint(host, port) + " is running " + vm.name()
				+ " version " + vm.version());
		System.out.println("Press <enter> to quit, and to terminate the application connected to.");
		System.in.read();
		vm.exit(0);
	} catch (Exception e) {
		e.printStackTrace();
		System.out.println("Could not connect to " + JdiUtils.prettyPrint(host, port));
		System.out.println("Message was: " + e.getMessage() + "\nExiting...");
	}
}
 
Example 2
Source File: ExclusiveBind.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the first debuggee
    Process process1 = launch(address, true, "HelloWorld");

    // give first debuggee time to suspend
    Thread.currentThread().sleep(5000);

    // launch a second debuggee with the same address
    Process process2 = launch(address, false, "HelloWorld");

    // get exit status from second debuggee
    int exitCode = process2.waitFor();

    // clean-up - attach to first debuggee and resume it
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);
    vm.resume();

    // if the second debuggee ran to completion then we've got a problem
    if (exitCode == 0) {
        throw new RuntimeException("Test failed - second debuggee didn't fail to bind");
    } else {
        System.out.println("Test passed - second debuggee correctly failed to bind");
    }
}
 
Example 3
Source File: ExclusiveBind.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the first debuggee
    Process process1 = launch(address, true, "HelloWorld");

    // give first debuggee time to suspend
    Thread.currentThread().sleep(5000);

    // launch a second debuggee with the same address
    Process process2 = launch(address, false, "HelloWorld");

    // get exit status from second debuggee
    int exitCode = process2.waitFor();

    // clean-up - attach to first debuggee and resume it
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);
    vm.resume();

    // if the second debuggee ran to completion then we've got a problem
    if (exitCode == 0) {
        throw new RuntimeException("Test failed - second debuggee didn't fail to bind");
    } else {
        System.out.println("Test passed - second debuggee correctly failed to bind");
    }
}
 
Example 4
Source File: RunToExit.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the server debuggee
    Process process = launch(address, "Exit0");

    // wait for the debugge to be ready
    while (!ready) {
        try {
            Thread.sleep(1000);
        } catch(Exception ee) {
            throw ee;
        }
    }

    // attach to server debuggee and resume it so it can exit
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);

    // The first event is always a VMStartEvent, and it is always in
    // an EventSet by itself.  Wait for it.
    EventSet evtSet = vm.eventQueue().remove();
    for (Event event: evtSet) {
        if (event instanceof VMStartEvent) {
            break;
        }
        throw new RuntimeException("Test failed - debuggee did not start properly");
    }
    vm.eventRequestManager().deleteAllBreakpoints();
    vm.resume();

    int exitCode = process.waitFor();

    // if the server debuggee ran cleanly, we assume we were clean
    if (exitCode == 0 && error_seen == 0) {
        System.out.println("Test passed - server debuggee cleanly terminated");
    } else {
        throw new RuntimeException("Test failed - server debuggee generated an error when it terminated");
    }
}
 
Example 5
Source File: RunToExit.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the server debuggee
    Process process = launch(address, "Exit0");

    // wait for the debugge to be ready
    while (!ready) {
        try {
            Thread.sleep(1000);
        } catch(Exception ee) {
            throw ee;
        }
    }

    // attach to server debuggee and resume it so it can exit
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);

    // The first event is always a VMStartEvent, and it is always in
    // an EventSet by itself.  Wait for it.
    EventSet evtSet = vm.eventQueue().remove();
    for (Event event: evtSet) {
        if (event instanceof VMStartEvent) {
            break;
        }
        throw new RuntimeException("Test failed - debuggee did not start properly");
    }
    vm.eventRequestManager().deleteAllBreakpoints();
    vm.resume();

    int exitCode = process.waitFor();

    // if the server debuggee ran cleanly, we assume we were clean
    if (exitCode == 0 && error_seen == 0) {
        System.out.println("Test passed - server debuggee cleanly terminated");
    } else {
        throw new RuntimeException("Test failed - server debuggee generated an error when it terminated");
    }
}
 
Example 6
Source File: RunToExit.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the server debuggee
    Process process = launch(address, "Exit0");

    // wait for the debugge to be ready
    while (!ready) {
        try {
            Thread.sleep(1000);
        } catch(Exception ee) {
            throw ee;
        }
    }

    // attach to server debuggee and resume it so it can exit
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);

    // The first event is always a VMStartEvent, and it is always in
    // an EventSet by itself.  Wait for it.
    EventSet evtSet = vm.eventQueue().remove();
    for (Event event: evtSet) {
        if (event instanceof VMStartEvent) {
            break;
        }
        throw new RuntimeException("Test failed - debuggee did not start properly");
    }
    vm.eventRequestManager().deleteAllBreakpoints();
    vm.resume();

    int exitCode = process.waitFor();

    // if the server debuggee ran cleanly, we assume we were clean
    if (exitCode == 0 && error_seen == 0) {
        System.out.println("Test passed - server debuggee cleanly terminated");
    } else {
        throw new RuntimeException("Test failed - server debuggee generated an error when it terminated");
    }
}
 
Example 7
Source File: ExclusiveBind.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the first debuggee
    ProcessBuilder process1 = prepareLauncher(address, true, "HelloWorld");
    // start the debuggee and wait for the "ready" message
    Process p = ProcessTools.startProcess(
            "process1",
            process1,
            line -> line.equals("Listening for transport dt_socket at address: " + address),
            Math.round(5000 * Utils.TIMEOUT_FACTOR),
            TimeUnit.MILLISECONDS
    );

    // launch a second debuggee with the same address
    ProcessBuilder process2 = prepareLauncher(address, false, "HelloWorld");

    // get exit status from second debuggee
    int exitCode = ProcessTools.startProcess("process2", process2).waitFor();

    // clean-up - attach to first debuggee and resume it
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);
    vm.resume();

    // if the second debuggee ran to completion then we've got a problem
    if (exitCode == 0) {
        throw new RuntimeException("Test failed - second debuggee didn't fail to bind");
    } else {
        System.out.println("Test passed - second debuggee correctly failed to bind");
    }
}
 
Example 8
Source File: RunToExit.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the server debuggee
    Process process = launch(address, "Exit0");

    // wait for the debugge to be ready
    while (!ready) {
        try {
            Thread.sleep(1000);
        } catch(Exception ee) {
            throw ee;
        }
    }

    // attach to server debuggee and resume it so it can exit
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);

    // The first event is always a VMStartEvent, and it is always in
    // an EventSet by itself.  Wait for it.
    EventSet evtSet = vm.eventQueue().remove();
    for (Event event: evtSet) {
        if (event instanceof VMStartEvent) {
            break;
        }
        throw new RuntimeException("Test failed - debuggee did not start properly");
    }
    vm.eventRequestManager().deleteAllBreakpoints();
    vm.resume();

    int exitCode = process.waitFor();

    // if the server debuggee ran cleanly, we assume we were clean
    if (exitCode == 0 && error_seen == 0) {
        System.out.println("Test passed - server debuggee cleanly terminated");
    } else {
        throw new RuntimeException("Test failed - server debuggee generated an error when it terminated");
    }
}
 
Example 9
Source File: RunToExit.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the server debuggee
    Process process = launch(address, "Exit0");

    // wait for the debugge to be ready
    while (!ready) {
        try {
            Thread.sleep(1000);
        } catch(Exception ee) {
            throw ee;
        }
    }

    // attach to server debuggee and resume it so it can exit
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);

    // The first event is always a VMStartEvent, and it is always in
    // an EventSet by itself.  Wait for it.
    EventSet evtSet = vm.eventQueue().remove();
    for (Event event: evtSet) {
        if (event instanceof VMStartEvent) {
            break;
        }
        throw new RuntimeException("Test failed - debuggee did not start properly");
    }
    vm.eventRequestManager().deleteAllBreakpoints();
    vm.resume();

    int exitCode = process.waitFor();

    // if the server debuggee ran cleanly, we assume we were clean
    if (exitCode == 0 && error_seen == 0) {
        System.out.println("Test passed - server debuggee cleanly terminated");
    } else {
        throw new RuntimeException("Test failed - server debuggee generated an error when it terminated");
    }
}
 
Example 10
Source File: RunToExit.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the server debuggee
    Process process = launch(address, "Exit0");

    // attach to server debuggee and resume it so it can exit
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);

    System.out.println("Connection arguments: " + conn_args);

    VirtualMachine vm = null;
    while (vm == null) {
        try {
            vm = conn.attach(conn_args);
        } catch (ConnectException e) {
            e.printStackTrace(System.out);
            System.out.println("--- Debugee not ready. Retrying in 500ms. ---");
            Thread.sleep(500);
        }
    }

    // The first event is always a VMStartEvent, and it is always in
    // an EventSet by itself.  Wait for it.
    EventSet evtSet = vm.eventQueue().remove();
    for (Event event: evtSet) {
        if (event instanceof VMStartEvent) {
            break;
        }
        throw new RuntimeException("Test failed - debuggee did not start properly");
    }
    vm.eventRequestManager().deleteAllBreakpoints();
    vm.resume();

    int exitCode = process.waitFor();

    // if the server debuggee ran cleanly, we assume we were clean
    if (exitCode == 0 && error_seen == 0) {
        System.out.println("Test passed - server debuggee cleanly terminated");
    } else {
        throw new RuntimeException("Test failed - server debuggee generated an error when it terminated, " +
            "exit code was " + exitCode + ", " + error_seen + " error(s) seen in debugee output.");
    }
}
 
Example 11
Source File: ExclusiveBind.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the first debuggee
    ProcessBuilder process1 = prepareLauncher(address, true, "HelloWorld");
    // start the debuggee and wait for the "ready" message
    Process p = ProcessTools.startProcess(
            "process1",
            process1,
            line -> line.equals("Listening for transport dt_socket at address: " + address),
            Math.round(5000 * Utils.TIMEOUT_FACTOR),
            TimeUnit.MILLISECONDS
    );

    // launch a second debuggee with the same address
    ProcessBuilder process2 = prepareLauncher(address, false, "HelloWorld");

    // get exit status from second debuggee
    int exitCode = ProcessTools.startProcess("process2", process2).waitFor();

    // clean-up - attach to first debuggee and resume it
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);
    vm.resume();

    // if the second debuggee ran to completion then we've got a problem
    if (exitCode == 0) {
        throw new RuntimeException("Test failed - second debuggee didn't fail to bind");
    } else {
        System.out.println("Test passed - second debuggee correctly failed to bind");
    }
}
 
Example 12
Source File: RunToExit.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the server debuggee
    Process process = launch(address, "Exit0");

    // wait for the debugge to be ready
    while (!ready) {
        try {
            Thread.sleep(1000);
        } catch(Exception ee) {
            throw ee;
        }
    }

    // attach to server debuggee and resume it so it can exit
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);

    // The first event is always a VMStartEvent, and it is always in
    // an EventSet by itself.  Wait for it.
    EventSet evtSet = vm.eventQueue().remove();
    for (Event event: evtSet) {
        if (event instanceof VMStartEvent) {
            break;
        }
        throw new RuntimeException("Test failed - debuggee did not start properly");
    }
    vm.eventRequestManager().deleteAllBreakpoints();
    vm.resume();

    int exitCode = process.waitFor();

    // if the server debuggee ran cleanly, we assume we were clean
    if (exitCode == 0 && error_seen == 0) {
        System.out.println("Test passed - server debuggee cleanly terminated");
    } else {
        throw new RuntimeException("Test failed - server debuggee generated an error when it terminated");
    }
}
 
Example 13
Source File: ExclusiveBind.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the first debuggee
    ProcessBuilder process1 = prepareLauncher(address, true, "HelloWorld");
    // start the debuggee and wait for the "ready" message
    Process p = ProcessTools.startProcess(
            "process1",
            process1,
            line -> line.equals("Listening for transport dt_socket at address: " + address),
            Math.round(5000 * Utils.TIMEOUT_FACTOR),
            TimeUnit.MILLISECONDS
    );

    // launch a second debuggee with the same address
    ProcessBuilder process2 = prepareLauncher(address, false, "HelloWorld");

    // get exit status from second debuggee
    int exitCode = ProcessTools.startProcess("process2", process2).waitFor();

    // clean-up - attach to first debuggee and resume it
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);
    vm.resume();

    // if the second debuggee ran to completion then we've got a problem
    if (exitCode == 0) {
        throw new RuntimeException("Test failed - second debuggee didn't fail to bind");
    } else {
        System.out.println("Test passed - second debuggee correctly failed to bind");
    }
}
 
Example 14
Source File: ExclusiveBind.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the first debuggee
    ProcessBuilder process1 = prepareLauncher(address, true, "HelloWorld");
    // start the debuggee and wait for the "ready" message
    Process p = ProcessTools.startProcess(
            "process1",
            process1,
            line -> line.equals("Listening for transport dt_socket at address: " + address),
            Math.round(5000 * Utils.TIMEOUT_FACTOR),
            TimeUnit.MILLISECONDS
    );

    // launch a second debuggee with the same address
    ProcessBuilder process2 = prepareLauncher(address, false, "HelloWorld");

    // get exit status from second debuggee
    int exitCode = ProcessTools.startProcess("process2", process2).waitFor();

    // clean-up - attach to first debuggee and resume it
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);
    vm.resume();

    // if the second debuggee ran to completion then we've got a problem
    if (exitCode == 0) {
        throw new RuntimeException("Test failed - second debuggee didn't fail to bind");
    } else {
        System.out.println("Test passed - second debuggee correctly failed to bind");
    }
}
 
Example 15
Source File: RunToExit.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the server debuggee
    Process process = launch(address, "Exit0");

    // wait for the debugge to be ready
    while (!ready) {
        try {
            Thread.sleep(1000);
        } catch(Exception ee) {
            throw ee;
        }
    }

    // attach to server debuggee and resume it so it can exit
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);

    // The first event is always a VMStartEvent, and it is always in
    // an EventSet by itself.  Wait for it.
    EventSet evtSet = vm.eventQueue().remove();
    for (Event event: evtSet) {
        if (event instanceof VMStartEvent) {
            break;
        }
        throw new RuntimeException("Test failed - debuggee did not start properly");
    }
    vm.eventRequestManager().deleteAllBreakpoints();
    vm.resume();

    int exitCode = process.waitFor();

    // if the server debuggee ran cleanly, we assume we were clean
    if (exitCode == 0 && error_seen == 0) {
        System.out.println("Test passed - server debuggee cleanly terminated");
    } else {
        throw new RuntimeException("Test failed - server debuggee generated an error when it terminated");
    }
}
 
Example 16
Source File: ExclusiveBind.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the first debuggee
    ProcessBuilder process1 = prepareLauncher(address, true, "HelloWorld");
    // start the debuggee and wait for the "ready" message
    Process p = ProcessTools.startProcess(
            "process1",
            process1,
            line -> line.equals("Listening for transport dt_socket at address: " + address),
            Math.round(5000 * Utils.TIMEOUT_FACTOR),
            TimeUnit.MILLISECONDS
    );

    // launch a second debuggee with the same address
    ProcessBuilder process2 = prepareLauncher(address, false, "HelloWorld");

    // get exit status from second debuggee
    int exitCode = ProcessTools.startProcess("process2", process2).waitFor();

    // clean-up - attach to first debuggee and resume it
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);
    vm.resume();

    // if the second debuggee ran to completion then we've got a problem
    if (exitCode == 0) {
        throw new RuntimeException("Test failed - second debuggee didn't fail to bind");
    } else {
        System.out.println("Test passed - second debuggee correctly failed to bind");
    }
}
 
Example 17
Source File: RunToExit.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the server debuggee
    Process process = launch(address, "Exit0");

    // wait for the debugge to be ready
    while (!ready) {
        try {
            Thread.sleep(1000);
        } catch(Exception ee) {
            throw ee;
        }
    }

    // attach to server debuggee and resume it so it can exit
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);

    // The first event is always a VMStartEvent, and it is always in
    // an EventSet by itself.  Wait for it.
    EventSet evtSet = vm.eventQueue().remove();
    for (Event event: evtSet) {
        if (event instanceof VMStartEvent) {
            break;
        }
        throw new RuntimeException("Test failed - debuggee did not start properly");
    }
    vm.eventRequestManager().deleteAllBreakpoints();
    vm.resume();

    int exitCode = process.waitFor();

    // if the server debuggee ran cleanly, we assume we were clean
    if (exitCode == 0 && error_seen == 0) {
        System.out.println("Test passed - server debuggee cleanly terminated");
    } else {
        throw new RuntimeException("Test failed - server debuggee generated an error when it terminated");
    }
}
 
Example 18
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();
	}
}
 
Example 19
Source File: RunToExit.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the server debuggee
    Process process = launch(address, "Exit0");

    // wait for the debugge to be ready
    while (!ready) {
        try {
            Thread.sleep(1000);
        } catch(Exception ee) {
            throw ee;
        }
    }

    // attach to server debuggee and resume it so it can exit
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);

    // The first event is always a VMStartEvent, and it is always in
    // an EventSet by itself.  Wait for it.
    EventSet evtSet = vm.eventQueue().remove();
    for (Event event: evtSet) {
        if (event instanceof VMStartEvent) {
            break;
        }
        throw new RuntimeException("Test failed - debuggee did not start properly");
    }
    vm.eventRequestManager().deleteAllBreakpoints();
    vm.resume();

    int exitCode = process.waitFor();

    // if the server debuggee ran cleanly, we assume we were clean
    if (exitCode == 0 && error_seen == 0) {
        System.out.println("Test passed - server debuggee cleanly terminated");
    } else {
        throw new RuntimeException("Test failed - server debuggee generated an error when it terminated");
    }
}
 
Example 20
Source File: RunToExit.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();

    String address = String.valueOf(port);

    // launch the server debuggee
    Process process = launch(address, "Exit0");

    // wait for the debugge to be ready
    while (!ready) {
        try {
            Thread.sleep(1000);
        } catch(Exception ee) {
            throw ee;
        }
    }

    // attach to server debuggee and resume it so it can exit
    AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
    Map conn_args = conn.defaultArguments();
    Connector.IntegerArgument port_arg =
        (Connector.IntegerArgument)conn_args.get("port");
    port_arg.setValue(port);
    VirtualMachine vm = conn.attach(conn_args);

    // The first event is always a VMStartEvent, and it is always in
    // an EventSet by itself.  Wait for it.
    EventSet evtSet = vm.eventQueue().remove();
    for (Event event: evtSet) {
        if (event instanceof VMStartEvent) {
            break;
        }
        throw new RuntimeException("Test failed - debuggee did not start properly");
    }
    vm.eventRequestManager().deleteAllBreakpoints();
    vm.resume();

    int exitCode = process.waitFor();

    // if the server debuggee ran cleanly, we assume we were clean
    if (exitCode == 0 && error_seen == 0) {
        System.out.println("Test passed - server debuggee cleanly terminated");
    } else {
        throw new RuntimeException("Test failed - server debuggee generated an error when it terminated");
    }
}