Search in sources :

Example 1 with Argument

use of com.sun.jdi.connect.Connector.Argument in project HotswapAgent by HotswapProjects.

the class JDIRedefiner method connect.

private VirtualMachine connect(int port) throws IOException {
    VirtualMachineManager manager = Bootstrap.virtualMachineManager();
    // Find appropiate connector
    List<AttachingConnector> connectors = manager.attachingConnectors();
    AttachingConnector chosenConnector = null;
    for (AttachingConnector c : connectors) {
        if (c.transport().name().equals(TRANSPORT_NAME)) {
            chosenConnector = c;
            break;
        }
    }
    if (chosenConnector == null) {
        throw new IllegalStateException("Could not find socket connector");
    }
    // Set port argument
    AttachingConnector connector = chosenConnector;
    Map<String, Argument> defaults = connector.defaultArguments();
    Argument arg = defaults.get(PORT_ARGUMENT_NAME);
    if (arg == null) {
        throw new IllegalStateException("Could not find port argument");
    }
    arg.setValue(Integer.toString(port));
    // Attach
    try {
        System.out.println("Connector arguments: " + defaults);
        return connector.attach(defaults);
    } catch (IllegalConnectorArgumentsException e) {
        throw new IllegalArgumentException("Illegal connector arguments", e);
    }
}
Also used : IllegalConnectorArgumentsException(com.sun.jdi.connect.IllegalConnectorArgumentsException) Argument(com.sun.jdi.connect.Connector.Argument) AttachingConnector(com.sun.jdi.connect.AttachingConnector) VirtualMachineManager(com.sun.jdi.VirtualMachineManager)

Example 2 with Argument

use of com.sun.jdi.connect.Connector.Argument in project ceylon by eclipse.

the class TracerImpl method start.

public void start() throws Exception {
    VirtualMachineManager vmm = com.sun.jdi.Bootstrap.virtualMachineManager();
    LaunchingConnector conn = vmm.defaultConnector();
    Map<String, Argument> defaultArguments = conn.defaultArguments();
    defaultArguments.get("main").setValue(mainClass);
    defaultArguments.get("options").setValue("-cp " + classPath);
    System.out.println(defaultArguments);
    vm = conn.launch(defaultArguments);
    err = vm.process().getErrorStream();
    out = vm.process().getInputStream();
    eq = vm.eventQueue();
    rm = vm.eventRequestManager();
    outer: while (true) {
        echo(err, System.err);
        echo(out, System.out);
        events = eq.remove();
        for (Event event : events) {
            if (event instanceof VMStartEvent) {
                System.out.println(event);
                break outer;
            } else if (event instanceof VMDisconnectEvent || event instanceof VMDeathEvent) {
                System.out.println(event);
                vm = null;
                rm = null;
                eq = null;
                break outer;
            }
        }
        events.resume();
    }
    echo(err, System.err);
    echo(out, System.out);
}
Also used : VMDisconnectEvent(com.sun.jdi.event.VMDisconnectEvent) Argument(com.sun.jdi.connect.Connector.Argument) VMDeathEvent(com.sun.jdi.event.VMDeathEvent) LaunchingConnector(com.sun.jdi.connect.LaunchingConnector) VMStartEvent(com.sun.jdi.event.VMStartEvent) MethodEntryEvent(com.sun.jdi.event.MethodEntryEvent) Event(com.sun.jdi.event.Event) VMDisconnectEvent(com.sun.jdi.event.VMDisconnectEvent) VMDeathEvent(com.sun.jdi.event.VMDeathEvent) StepEvent(com.sun.jdi.event.StepEvent) VMStartEvent(com.sun.jdi.event.VMStartEvent) MethodExitEvent(com.sun.jdi.event.MethodExitEvent) VirtualMachineManager(com.sun.jdi.VirtualMachineManager)

Example 3 with Argument

use of com.sun.jdi.connect.Connector.Argument in project processing by processing.

the class Runner method launchVirtualMachine.

public boolean launchVirtualMachine(boolean present, String[] args) {
    StringList vmParams = getMachineParams();
    StringList sketchParams = getSketchParams(present, args);
    //    PApplet.printArray(sketchParams);
    int port = 8000 + (int) (Math.random() * 1000);
    String portStr = String.valueOf(port);
    // Added 'quiet=y' for 3.0.2 to prevent command line parsing problems
    // https://github.com/processing/processing/issues/4098
    String jdwpArg = "-agentlib:jdwp=transport=dt_socket,address=" + portStr + ",server=y,suspend=y,quiet=y";
    // Everyone works the same under Java 7 (also on OS X)
    StringList commandArgs = new StringList();
    commandArgs.append(Platform.getJavaPath());
    commandArgs.append(jdwpArg);
    commandArgs.append(vmParams);
    commandArgs.append(sketchParams);
    // the next chance to cancel will be after connecting to the VM
    if (cancelled) {
        return false;
    }
    launchJava(commandArgs.array());
    AttachingConnector connector = (AttachingConnector) findConnector("com.sun.jdi.SocketAttach");
    //PApplet.println(connector);  // gets the defaults
    Map<String, Argument> arguments = connector.defaultArguments();
    //  Connector.Argument addressArg =
    //    (Connector.Argument)arguments.get("address");
    //  addressArg.setValue(addr);
    Connector.Argument portArg = arguments.get("port");
    portArg.setValue(portStr);
    try {
        //      while (!available) {
        while (true) {
            try {
                Messages.log(getClass().getName() + " attempting to attach to VM");
                synchronized (cancelLock) {
                    vm = connector.attach(arguments);
                    if (cancelled && vm != null) {
                        // cancelled and connected to the VM, handle closing now
                        Messages.log(getClass().getName() + " aborting, launch cancelled");
                        close();
                        return false;
                    }
                }
                //          vm = connector.attach(arguments);
                if (vm != null) {
                    Messages.log(getClass().getName() + " attached to the VM");
                    //            available = true;
                    return true;
                }
            } catch (ConnectException ce) {
                // This will fire ConnectException (socket not available) until
                // the VM finishes starting up and opens its socket for us.
                Messages.log(getClass().getName() + " socket for VM not ready");
                //          e.printStackTrace();
                try {
                    Thread.sleep(100);
                } catch (InterruptedException ie) {
                    Messages.loge(getClass().getName() + " interrupted", ie);
                //            ie.printStackTrace(sketchErr);
                }
            } catch (IOException e) {
                Messages.loge(getClass().getName() + " while attaching to VM", e);
            }
        }
    //    } catch (IOException exc) {
    //      throw new Error("Unable to launch target VM: " + exc);
    } catch (IllegalConnectorArgumentsException exc) {
        throw new Error("Internal error: " + exc);
    }
}
Also used : Argument(com.sun.jdi.connect.Connector.Argument) StringList(processing.data.StringList) Argument(com.sun.jdi.connect.Connector.Argument) Point(java.awt.Point) ConnectException(java.net.ConnectException)

Example 4 with Argument

use of com.sun.jdi.connect.Connector.Argument in project ceylon-compiler by ceylon.

the class TracerImpl method start.

public void start() throws Exception {
    VirtualMachineManager vmm = com.sun.jdi.Bootstrap.virtualMachineManager();
    LaunchingConnector conn = vmm.defaultConnector();
    Map<String, Argument> defaultArguments = conn.defaultArguments();
    defaultArguments.get("main").setValue(mainClass);
    defaultArguments.get("options").setValue("-cp " + classPath);
    System.out.println(defaultArguments);
    vm = conn.launch(defaultArguments);
    err = vm.process().getErrorStream();
    out = vm.process().getInputStream();
    eq = vm.eventQueue();
    rm = vm.eventRequestManager();
    outer: while (true) {
        echo(err, System.err);
        echo(out, System.out);
        events = eq.remove();
        for (Event event : events) {
            if (event instanceof VMStartEvent) {
                System.out.println(event);
                break outer;
            } else if (event instanceof VMDisconnectEvent || event instanceof VMDeathEvent) {
                System.out.println(event);
                vm = null;
                rm = null;
                eq = null;
                break outer;
            }
        }
        events.resume();
    }
    echo(err, System.err);
    echo(out, System.out);
}
Also used : VMDisconnectEvent(com.sun.jdi.event.VMDisconnectEvent) Argument(com.sun.jdi.connect.Connector.Argument) VMDeathEvent(com.sun.jdi.event.VMDeathEvent) LaunchingConnector(com.sun.jdi.connect.LaunchingConnector) VMStartEvent(com.sun.jdi.event.VMStartEvent) MethodEntryEvent(com.sun.jdi.event.MethodEntryEvent) Event(com.sun.jdi.event.Event) VMDisconnectEvent(com.sun.jdi.event.VMDisconnectEvent) VMDeathEvent(com.sun.jdi.event.VMDeathEvent) StepEvent(com.sun.jdi.event.StepEvent) VMStartEvent(com.sun.jdi.event.VMStartEvent) MethodExitEvent(com.sun.jdi.event.MethodExitEvent) VirtualMachineManager(com.sun.jdi.VirtualMachineManager)

Aggregations

Argument (com.sun.jdi.connect.Connector.Argument)4 VirtualMachineManager (com.sun.jdi.VirtualMachineManager)3 LaunchingConnector (com.sun.jdi.connect.LaunchingConnector)2 Event (com.sun.jdi.event.Event)2 MethodEntryEvent (com.sun.jdi.event.MethodEntryEvent)2 MethodExitEvent (com.sun.jdi.event.MethodExitEvent)2 StepEvent (com.sun.jdi.event.StepEvent)2 VMDeathEvent (com.sun.jdi.event.VMDeathEvent)2 VMDisconnectEvent (com.sun.jdi.event.VMDisconnectEvent)2 VMStartEvent (com.sun.jdi.event.VMStartEvent)2 AttachingConnector (com.sun.jdi.connect.AttachingConnector)1 IllegalConnectorArgumentsException (com.sun.jdi.connect.IllegalConnectorArgumentsException)1 Point (java.awt.Point)1 ConnectException (java.net.ConnectException)1 StringList (processing.data.StringList)1