com.sun.jdi.VirtualMachineManager Java Examples

The following examples show how to use com.sun.jdi.VirtualMachineManager. 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: SADebugServerAttachingConnector.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String debugServerName)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByServerMethod =
                        vmImplClass.getMethod(
                               "createVirtualMachineForServer",
                               new Class[] {
                                   VirtualMachineManager.class,
                                   String.class,
                                   Integer.TYPE
                               });
    return (VirtualMachine) connectByServerMethod.invoke(null,
                               new Object[] {
                                   Bootstrap.virtualMachineManager(),
                                   debugServerName,
                                   new Integer(0)
                               });
}
 
Example #2
Source File: SACoreAttachingConnector.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String javaExec, String corefile)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByCoreMethod = vmImplClass.getMethod(
                             "createVirtualMachineForCorefile",
                              new Class[] {
                                  VirtualMachineManager.class,
                                  String.class, String.class,
                                  Integer.TYPE
                              });
    return (VirtualMachine) connectByCoreMethod.invoke(null,
                              new Object[] {
                                  Bootstrap.virtualMachineManager(),
                                  javaExec,
                                  corefile,
                                  new Integer(0)
                              });
}
 
Example #3
Source File: SADebugServerAttachingConnector.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String debugServerName)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByServerMethod =
                        vmImplClass.getMethod(
                               "createVirtualMachineForServer",
                               new Class[] {
                                   VirtualMachineManager.class,
                                   String.class,
                                   Integer.TYPE
                               });
    return (VirtualMachine) connectByServerMethod.invoke(null,
                               new Object[] {
                                   Bootstrap.virtualMachineManager(),
                                   debugServerName,
                                   new Integer(0)
                               });
}
 
Example #4
Source File: SACoreAttachingConnector.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String javaExec, String corefile)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByCoreMethod = vmImplClass.getMethod(
                             "createVirtualMachineForCorefile",
                              new Class[] {
                                  VirtualMachineManager.class,
                                  String.class, String.class,
                                  Integer.TYPE
                              });
    return (VirtualMachine) connectByCoreMethod.invoke(null,
                              new Object[] {
                                  Bootstrap.virtualMachineManager(),
                                  javaExec,
                                  corefile,
                                  new Integer(0)
                              });
}
 
Example #5
Source File: SADebugServerAttachingConnector.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String debugServerName)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByServerMethod =
                        vmImplClass.getMethod(
                               "createVirtualMachineForServer",
                               new Class[] {
                                   VirtualMachineManager.class,
                                   String.class,
                                   Integer.TYPE
                               });
    return (VirtualMachine) connectByServerMethod.invoke(null,
                               new Object[] {
                                   Bootstrap.virtualMachineManager(),
                                   debugServerName,
                                   new Integer(0)
                               });
}
 
Example #6
Source File: SADebugServerAttachingConnector.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String debugServerName)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByServerMethod =
                        vmImplClass.getMethod(
                               "createVirtualMachineForServer",
                               new Class[] {
                                   VirtualMachineManager.class,
                                   String.class,
                                   Integer.TYPE
                               });
    return (VirtualMachine) connectByServerMethod.invoke(null,
                               new Object[] {
                                   Bootstrap.virtualMachineManager(),
                                   debugServerName,
                                   new Integer(0)
                               });
}
 
Example #7
Source File: DebugUtility.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Attach to an existing debuggee VM.
 * @param vmManager
 *               the virtual machine manager
 * @param hostName
 *               the machine where the debuggee VM is launched on
 * @param port
 *               the debug port that the debuggee VM exposed
 * @param attachTimeout
 *               the timeout when attaching to the debuggee VM
 * @return an instance of IDebugSession
 * @throws IOException
 *               when unable to attach.
 * @throws IllegalConnectorArgumentsException
 *               when one of the connector arguments is invalid.
 */
public static IDebugSession attach(VirtualMachineManager vmManager, String hostName, int port, int attachTimeout)
        throws IOException, IllegalConnectorArgumentsException {
    List<AttachingConnector> connectors = vmManager.attachingConnectors();
    AttachingConnector connector = connectors.get(0);
    // in JDK 10, the first AttachingConnector is not the one we want
    final String SUN_ATTACH_CONNECTOR = "com.sun.tools.jdi.SocketAttachingConnector";
    for (AttachingConnector con : connectors) {
        if (con.getClass().getName().equals(SUN_ATTACH_CONNECTOR)) {
            connector = con;
            break;
        }
    }
    Map<String, Argument> arguments = connector.defaultArguments();
    arguments.get(HOSTNAME).setValue(hostName);
    arguments.get(PORT).setValue(String.valueOf(port));
    arguments.get(TIMEOUT).setValue(String.valueOf(attachTimeout));
    return new DebugSession(connector.attach(arguments));
}
 
Example #8
Source File: SACoreAttachingConnector.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String javaExec, String corefile)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByCoreMethod = vmImplClass.getMethod(
                             "createVirtualMachineForCorefile",
                              new Class[] {
                                  VirtualMachineManager.class,
                                  String.class, String.class,
                                  Integer.TYPE
                              });
    return (VirtualMachine) connectByCoreMethod.invoke(null,
                              new Object[] {
                                  Bootstrap.virtualMachineManager(),
                                  javaExec,
                                  corefile,
                                  new Integer(0)
                              });
}
 
Example #9
Source File: DebugUtility.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Launch a debuggee in suspend mode.
 * @see #launch(VirtualMachineManager, String, String, String, String, String, String, String[], String)
 */
public static IDebugSession launch(VirtualMachineManager vmManager,
        String mainClass,
        String programArguments,
        String vmArguments,
        List<String> modulePaths,
        List<String> classPaths,
        String cwd,
        String[] envVars,
        String javaExec)
        throws IOException, IllegalConnectorArgumentsException, VMStartException {
    return DebugUtility.launch(vmManager,
            mainClass,
            programArguments,
            vmArguments,
            String.join(File.pathSeparator, modulePaths),
            String.join(File.pathSeparator, classPaths),
            cwd,
            envVars,
            javaExec);
}
 
Example #10
Source File: DebugUtility.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Launch a debuggee in suspend mode.
 * @see #launch(VirtualMachineManager, String, String, String, String, String, String, String[])
 */
public static IDebugSession launch(VirtualMachineManager vmManager,
        String mainClass,
        String programArguments,
        String vmArguments,
        List<String> modulePaths,
        List<String> classPaths,
        String cwd,
        String[] envVars)
        throws IOException, IllegalConnectorArgumentsException, VMStartException {
    return DebugUtility.launch(vmManager,
            mainClass,
            programArguments,
            vmArguments,
            String.join(File.pathSeparator, modulePaths),
            String.join(File.pathSeparator, classPaths),
            cwd,
            envVars);
}
 
Example #11
Source File: SACoreAttachingConnector.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String javaExec, String corefile)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByCoreMethod = vmImplClass.getMethod(
                             "createVirtualMachineForCorefile",
                              new Class[] {
                                  VirtualMachineManager.class,
                                  String.class, String.class,
                                  Integer.TYPE
                              });
    return (VirtualMachine) connectByCoreMethod.invoke(null,
                              new Object[] {
                                  Bootstrap.virtualMachineManager(),
                                  javaExec,
                                  corefile,
                                  new Integer(0)
                              });
}
 
Example #12
Source File: SADebugServerAttachingConnector.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String debugServerName)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByServerMethod =
                        vmImplClass.getMethod(
                               "createVirtualMachineForServer",
                               new Class[] {
                                   VirtualMachineManager.class,
                                   String.class,
                                   Integer.TYPE
                               });
    return (VirtualMachine) connectByServerMethod.invoke(null,
                               new Object[] {
                                   Bootstrap.virtualMachineManager(),
                                   debugServerName,
                                   new Integer(0)
                               });
}
 
Example #13
Source File: SACoreAttachingConnector.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String javaExec, String corefile)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByCoreMethod = vmImplClass.getMethod(
                             "createVirtualMachineForCorefile",
                              new Class[] {
                                  VirtualMachineManager.class,
                                  String.class, String.class,
                                  Integer.TYPE
                              });
    return (VirtualMachine) connectByCoreMethod.invoke(null,
                              new Object[] {
                                  Bootstrap.virtualMachineManager(),
                                  javaExec,
                                  corefile,
                                  new Integer(0)
                              });
}
 
Example #14
Source File: SADebugServerAttachingConnector.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String debugServerName)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByServerMethod =
                        vmImplClass.getMethod(
                               "createVirtualMachineForServer",
                               new Class[] {
                                   VirtualMachineManager.class,
                                   String.class,
                                   Integer.TYPE
                               });
    return (VirtualMachine) connectByServerMethod.invoke(null,
                               new Object[] {
                                   Bootstrap.virtualMachineManager(),
                                   debugServerName,
                                   new Integer(0)
                               });
}
 
Example #15
Source File: SACoreAttachingConnector.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String javaExec, String corefile)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByCoreMethod = vmImplClass.getMethod(
                             "createVirtualMachineForCorefile",
                              new Class[] {
                                  VirtualMachineManager.class,
                                  String.class, String.class,
                                  Integer.TYPE
                              });
    return (VirtualMachine) connectByCoreMethod.invoke(null,
                              new Object[] {
                                  Bootstrap.virtualMachineManager(),
                                  javaExec,
                                  corefile,
                                  new Integer(0)
                              });
}
 
Example #16
Source File: SADebugServerAttachingConnector.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String debugServerName)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByServerMethod =
                        vmImplClass.getMethod(
                               "createVirtualMachineForServer",
                               new Class[] {
                                   VirtualMachineManager.class,
                                   String.class,
                                   Integer.TYPE
                               });
    return (VirtualMachine) connectByServerMethod.invoke(null,
                               new Object[] {
                                   Bootstrap.virtualMachineManager(),
                                   debugServerName,
                                   new Integer(0)
                               });
}
 
Example #17
Source File: SACoreAttachingConnector.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private VirtualMachine createVirtualMachine(Class vmImplClass,
                                            String javaExec, String corefile)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method connectByCoreMethod = vmImplClass.getMethod(
                             "createVirtualMachineForCorefile",
                              new Class[] {
                                  VirtualMachineManager.class,
                                  String.class, String.class,
                                  Integer.TYPE
                              });
    return (VirtualMachine) connectByCoreMethod.invoke(null,
                              new Object[] {
                                  Bootstrap.virtualMachineManager(),
                                  javaExec,
                                  corefile,
                                  new Integer(0)
                              });
}
 
Example #18
Source File: LocalVirtualMachineTemplateTest.java    From confucius-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    VirtualMachineManager virtualMachineManager = Bootstrap.virtualMachineManager();
    List<Connector> allConnectors = virtualMachineManager.allConnectors();
    List<VirtualMachine> connectedVirtualMachines = virtualMachineManager.connectedVirtualMachines();
    System.out.println(allConnectors);
    System.out.println(connectedVirtualMachines);


}
 
Example #19
Source File: VMAcquirer.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
private AttachingConnector getConnector() {
    VirtualMachineManager vmManager = Bootstrap.virtualMachineManager();
    for (Connector connector : vmManager.attachingConnectors()) {
        if ("com.sun.jdi.SocketAttach".equals(connector.name())) {
            return (AttachingConnector) connector;
        }
    }
    throw new IllegalStateException();
}
 
Example #20
Source File: JDIRedefiner.java    From HotswapAgent with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example #21
Source File: SAPIDAttachingConnector.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private VirtualMachine createVirtualMachine(Class virtualMachineImplClass, int pid)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method createByPIDMethod
              = virtualMachineImplClass.getMethod("createVirtualMachineForPID",
                 new Class[] {
                     VirtualMachineManager.class,
                     Integer.TYPE, Integer.TYPE
                 });
    return (VirtualMachine) createByPIDMethod.invoke(null,
                 new Object[] {
                     Bootstrap.virtualMachineManager(),
                     new Integer(pid),
                     new Integer(0)
                 });
}
 
Example #22
Source File: VMAcquirer.java    From gravel with Apache License 2.0 5 votes vote down vote up
private AttachingConnector getConnector() {
  VirtualMachineManager vmManager = Bootstrap
      .virtualMachineManager();
  for (AttachingConnector connector : vmManager
      .attachingConnectors()) {
    if ("com.sun.jdi.SocketAttach".equals(connector
        .name())) {
      return (AttachingConnector) connector;
    }
  }
  throw new IllegalStateException();
}
 
Example #23
Source File: SAPIDAttachingConnector.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private VirtualMachine createVirtualMachine(Class virtualMachineImplClass, int pid)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method createByPIDMethod
              = virtualMachineImplClass.getMethod("createVirtualMachineForPID",
                 new Class[] {
                     VirtualMachineManager.class,
                     Integer.TYPE, Integer.TYPE
                 });
    return (VirtualMachine) createByPIDMethod.invoke(null,
                 new Object[] {
                     Bootstrap.virtualMachineManager(),
                     new Integer(pid),
                     new Integer(0)
                 });
}
 
Example #24
Source File: SAPIDAttachingConnector.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private VirtualMachine createVirtualMachine(Class virtualMachineImplClass, int pid)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method createByPIDMethod
              = virtualMachineImplClass.getMethod("createVirtualMachineForPID",
                 new Class[] {
                     VirtualMachineManager.class,
                     Integer.TYPE, Integer.TYPE
                 });
    return (VirtualMachine) createByPIDMethod.invoke(null,
                 new Object[] {
                     Bootstrap.virtualMachineManager(),
                     new Integer(pid),
                     new Integer(0)
                 });
}
 
Example #25
Source File: SAPIDAttachingConnector.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private VirtualMachine createVirtualMachine(Class virtualMachineImplClass, int pid)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method createByPIDMethod
              = virtualMachineImplClass.getMethod("createVirtualMachineForPID",
                 new Class[] {
                     VirtualMachineManager.class,
                     Integer.TYPE, Integer.TYPE
                 });
    return (VirtualMachine) createByPIDMethod.invoke(null,
                 new Object[] {
                     Bootstrap.virtualMachineManager(),
                     new Integer(pid),
                     new Integer(0)
                 });
}
 
Example #26
Source File: JdtVirtualMachineManagerProvider.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public synchronized VirtualMachineManager getVirtualMachineManager() {
    if (vmManager == null) {
        vmManager = new AdvancedVirtualMachineManager();
    }
    return vmManager;
}
 
Example #27
Source File: SAPIDAttachingConnector.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private VirtualMachine createVirtualMachine(Class virtualMachineImplClass, int pid)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method createByPIDMethod
              = virtualMachineImplClass.getMethod("createVirtualMachineForPID",
                 new Class[] {
                     VirtualMachineManager.class,
                     Integer.TYPE, Integer.TYPE
                 });
    return (VirtualMachine) createByPIDMethod.invoke(null,
                 new Object[] {
                     Bootstrap.virtualMachineManager(),
                     new Integer(pid),
                     new Integer(0)
                 });
}
 
Example #28
Source File: JPDASupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static JPDASupport attach (String mainClass, String[] args, File[] classPath) throws IOException,
DebuggerStartException {
    Process process = launchVM (mainClass, args, classPath, "", true);
    String line = readLine (process.getInputStream ());
    int port = Integer.parseInt (line.substring (line.lastIndexOf (':') + 1).trim ());
    ProcessIO pio = new ProcessIO (process);
    pio.go ();

    VirtualMachineManager vmm = Bootstrap.virtualMachineManager();
    List aconnectors = vmm.attachingConnectors();
    AttachingConnector connector = null;
    for (Iterator i = aconnectors.iterator(); i.hasNext();) {
        AttachingConnector ac = (AttachingConnector) i.next();
        Transport t = ac.transport ();
        if (t != null && t.name().equals("dt_socket")) {
            connector = ac;
            break;
        }
    }
    if (connector == null) 
        throw new RuntimeException
            ("No attaching socket connector available");

    JPDADebugger jpdaDebugger = JPDADebugger.attach (
        "localhost", 
        port, 
        createServices ()
    );
    return new JPDASupport (jpdaDebugger);
}
 
Example #29
Source File: SAPIDAttachingConnector.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private VirtualMachine createVirtualMachine(Class virtualMachineImplClass, int pid)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method createByPIDMethod
              = virtualMachineImplClass.getMethod("createVirtualMachineForPID",
                 new Class[] {
                     VirtualMachineManager.class,
                     Integer.TYPE, Integer.TYPE
                 });
    return (VirtualMachine) createByPIDMethod.invoke(null,
                 new Object[] {
                     Bootstrap.virtualMachineManager(),
                     new Integer(pid),
                     new Integer(0)
                 });
}
 
Example #30
Source File: SAPIDAttachingConnector.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private VirtualMachine createVirtualMachine(Class virtualMachineImplClass, int pid)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    java.lang.reflect.Method createByPIDMethod
              = virtualMachineImplClass.getMethod("createVirtualMachineForPID",
                 new Class[] {
                     VirtualMachineManager.class,
                     Integer.TYPE, Integer.TYPE
                 });
    return (VirtualMachine) createByPIDMethod.invoke(null,
                 new Object[] {
                     Bootstrap.virtualMachineManager(),
                     new Integer(pid),
                     new Integer(0)
                 });
}