VirtualMachineManager
Java Code Examples for com.sun.jdi.VirtualMachineManager
https://www.programcreek.com/java-api-examples/index.php?api=com.sun.jdi.VirtualMachineManager
The following are top voted examples for showing how to use com.sun.jdi.VirtualMachineManager. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.
| Project: fiji File: StartDebugging.java View source code | 6 votes | ![]() ![]() |
private VirtualMachine launchVirtualMachine() {
VirtualMachineManager vmm = Bootstrap.virtualMachineManager();
LaunchingConnector defConnector = vmm.defaultConnector();
Transport transport = defConnector.transport();
List<LaunchingConnector> list = vmm.launchingConnectors();
for (LaunchingConnector conn: list)
System.out.println(conn.name());
Map<String, Connector.Argument> arguments = defConnector.defaultArguments();
Set<String> s = arguments.keySet();
for (String string: s)
System.out.println(string);
Connector.Argument mainarg = arguments.get("main");
String s1 = System.getProperty("java.class.path");
mainarg.setValue("-classpath \"" + s1 + "\" fiji.MainClassForDebugging " + plugInName);
try {
return defConnector.launch(arguments);
} catch (IOException exc) {
throw new Error("Unable to launch target VM: " + exc);
} catch (IllegalConnectorArgumentsException exc) {
IJ.handleException(exc);
} catch (VMStartException exc) {
throw new Error("Target VM failed to initialize: " +
exc.getMessage());
}
return null;
}
| Project: proxyhotswap File: JDIRedefiner.java View source code | 6 votes | ![]() ![]() |
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);
}
}
| Project: robovm-eclipse File: AbstractLaunchConfigurationDelegate.java View source code | 6 votes | ![]() ![]() |
private VirtualMachine attachToVm(IProgressMonitor monitor, int port) throws CoreException {
VirtualMachineManager manager = Bootstrap.virtualMachineManager();
AttachingConnector connector = null;
for (Iterator<?> it = manager.attachingConnectors().iterator(); it.hasNext();) {
AttachingConnector con = (AttachingConnector) it.next();
if ("dt_socket".equalsIgnoreCase(con.transport().name())) {
connector = con;
break;
}
}
if (connector == null) {
throw new CoreException(new Status(IStatus.ERROR, RoboVMPlugin.PLUGIN_ID, "Couldn't find socket transport"));
}
Map<String, Argument> defaultArguments = connector.defaultArguments();
defaultArguments.get("hostname").setValue("localhost");
defaultArguments.get("port").setValue("" + port);
int retries = 60;
CoreException exception = null;
while (retries > 0) {
try {
return connector.attach(defaultArguments);
} catch (Exception e) {
exception = new CoreException(new Status(IStatus.ERROR, RoboVMPlugin.PLUGIN_ID,
"Couldn't connect to JDWP server at localhost:" + port, e));
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
if (monitor.isCanceled()) {
return null;
}
retries--;
}
throw exception;
}
| Project: openjdk File: SACoreAttachingConnector.java View source code | 6 votes | ![]() ![]() |
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)
});
}
| Project: eclipse.jdt.debug File: JDIDebugPlugin.java View source code | 6 votes | ![]() ![]() |
/**
* Returns the detected version of JDI support. This is intended to
* distinguish between clients that support JDI 1.4 methods like hot code
* replace.
*
* @return an array of version numbers, major followed by minor
* @since 2.1
*/
public static int[] getJDIVersion() {
if (fJDIVersion == null) {
fJDIVersion = new int[2];
VirtualMachineManager mgr = Bootstrap.virtualMachineManager();
fJDIVersion[0] = mgr.majorInterfaceVersion();
fJDIVersion[1] = mgr.minorInterfaceVersion();
}
return fJDIVersion;
}
| Project: Sorbet File: Main.java View source code | 6 votes | ![]() ![]() |
public static VirtualMachine createVirtualMachine(String main, String args) {
VirtualMachineManager manager = Bootstrap.virtualMachineManager();
LaunchingConnector connector = manager.defaultConnector();
Map<String, Connector.Argument> arguments = connector.defaultArguments();
arguments.get("main").setValue(main);
if (args != null) {
arguments.get("options").setValue(args);
}
try {
VirtualMachine vm = connector.launch(arguments);
// Forward standard out and standard error
new StreamTunnel(vm.process().getInputStream(), System.out);
new StreamTunnel(vm.process().getErrorStream(), System.err);
return vm;
} catch (IOException e) {
throw new Error("Error: Could not launch target VM: " + e.getMessage());
} catch (IllegalConnectorArgumentsException e) {
StringBuffer illegalArguments = new StringBuffer();
for (String arg : e.argumentNames()) {
illegalArguments.append(arg);
}
throw new Error("Error: Could not launch target VM because of illegal arguments: " + illegalArguments.toString());
} catch (VMStartException e) {
throw new Error("Error: Could not launch target VM: " + e.getMessage());
}
}
| Project: HotswapAgent File: JDIRedefiner.java View source code | 6 votes | ![]() ![]() |
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);
}
}
| Project: gravel File: VMAcquirer.java View source code | 6 votes | ![]() ![]() |
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();
}
| Project: ceylon-compiler File: TracerImpl.java View source code | 6 votes | ![]() ![]() |
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);
}
| Project: j File: VMConnection.java View source code | 6 votes | ![]() ![]() |
public static VMConnection getConnection(Jdb jdb)
{
VirtualMachineManager vmm = Bootstrap.virtualMachineManager();
LaunchingConnector connector = vmm.defaultConnector();
Map map = connector.defaultArguments();
String javaHome = jdb.getJavaHome();
((Connector.Argument)map.get("home")).setValue(javaHome);
String javaExecutable = jdb.getJavaExecutable();
((Connector.Argument)map.get("vmexec")).setValue(javaExecutable); // Command line.
FastStringBuffer sb = new FastStringBuffer(jdb.getMainClass());
String mainClassArgs = jdb.getMainClassArgs();
if (mainClassArgs != null && mainClassArgs.length() > 0) {
sb.append(' ');
sb.append(mainClassArgs);
}
((Connector.Argument)map.get("main")).setValue(sb.toString()); // CLASSPATH and VM options.
sb.setLength(0);
String vmArgs = jdb.getVMArgs();
if (vmArgs != null) {
vmArgs = vmArgs.trim();
if (vmArgs.length() > 0) {
sb.append(vmArgs);
sb.append(' ');
}
}
String classPath = jdb.getClassPath();
if (classPath != null) {
classPath = classPath.trim();
if (classPath.length() > 0) {
sb.append("-classpath ");
sb.append(classPath);
}
}
((Connector.Argument)map.get("options")).setValue(sb.toString()); ((Connector.Argument)map.get("suspend")).setValue("true");
return new VMConnection(connector, map);
}
| Project: eclipse.jdt.ui File: InvocationCountPerformanceMeter.java View source code | 6 votes | ![]() ![]() |
private void attach(String host, int port) throws IOException, IllegalConnectorArgumentsException {
VirtualMachineManager manager= Bootstrap.virtualMachineManager();
List<AttachingConnector> connectors= manager.attachingConnectors();
AttachingConnector connector= connectors.get(0);
Map<String, Connector.Argument> args= connector.defaultArguments();
args.get("port").setValue(String.valueOf(port)); //$NON-NLS-1$
args.get("hostname").setValue(host); //$NON-NLS-1$
fVM= connector.attach(args);
}
| Project: dcevm File: JDIRedefiner.java View source code | 6 votes | ![]() ![]() |
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);
}
}
| Project: visage-compiler File: VisageBootstrap.java View source code | 6 votes | ![]() ![]() |
public static VirtualMachineManager virtualMachineManager() {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
JDIPermission vmmPermission =
new JDIPermission("virtualMachineManager");
sm.checkPermission(vmmPermission);
}
synchronized (lock) {
if (vmm == null) {
vmm = new VisageVirtualMachineManager();
}
}
return vmm;
}
| Project: XRobot File: LaunchEV3ConfigDelegate.java View source code | 5 votes | ![]() ![]() |
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
LeJOSEV3Util.message("Starting debugger ...");
// Find the socket attach connector
VirtualMachineManager mgr=Bootstrap.virtualMachineManager();
List<?> connectors = mgr.attachingConnectors();
AttachingConnector chosen=null;
for (Iterator<?> iterator = connectors.iterator(); iterator
.hasNext();) {
AttachingConnector conn = (AttachingConnector) iterator.next();
if(conn.name().contains("SocketAttach")) {
chosen=conn;
break;
}
}
if(chosen == null) {
LeJOSEV3Util.error("No suitable connector");
} else {
Map<String, Argument> connectorArgs = chosen.defaultArguments();
Connector.IntegerArgument portArg = (IntegerArgument) connectorArgs.get("port");
Connector.StringArgument hostArg = (StringArgument) connectorArgs.get("hostname");
portArg.setValue(8000);
//LeJOSEV3Util.message("hostArg is " + hostArg);
hostArg.setValue(brickName);
VirtualMachine vm;
int retries = 10;
while (true) {
try {
vm = chosen.attach(connectorArgs);
break;
} catch (Exception e) {
if (--retries == 0) {
LeJOSEV3Util.message("Failed to attach to the debugger: " + e);
return;
}
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
}
}
}
LeJOSEV3Util.message("Connection established");
JDIDebugModel.newDebugTarget(launch, vm, simpleName, null, true, true, true);
}
}
| Project: eclipse.jdt.core File: DebugEvaluationSetup.java View source code | 5 votes | ![]() ![]() |
protected void setUp() {
if (this.context == null) {
// Launch VM in evaluation mode
int debugPort = Util.getFreePort();
int evalPort = Util.getFreePort();
LocalVMLauncher launcher;
try {
launcher = LocalVMLauncher.getLauncher();
launcher.setVMArguments(new String[]{"-verify"});
launcher.setVMPath(JRE_PATH);
launcher.setEvalPort(evalPort);
launcher.setEvalTargetPath(EVAL_DIRECTORY);
launcher.setDebugPort(debugPort);
this.launchedVM = launcher.launch();
} catch (TargetException e) {
throw new Error(e.getMessage());
}
// Thread that read the stout of the VM so that the VM doesn't block
try {
startReader("VM's stdout reader", this.launchedVM.getInputStream(), System.out);
} catch (TargetException e) {
}
// Thread that read the sterr of the VM so that the VM doesn't block
try {
startReader("VM's sterr reader", this.launchedVM.getErrorStream(), System.err);
} catch (TargetException e) {
}
// Start JDI connection (try 10 times)
for (int i = 0; i < 10; i++) {
try {
VirtualMachineManager manager = org.eclipse.jdi.Bootstrap.virtualMachineManager();
List connectors = manager.attachingConnectors();
if (connectors.size() == 0)
break;
AttachingConnector connector = (AttachingConnector)connectors.get(0);
Map args = connector.defaultArguments();
Connector.Argument argument = (Connector.Argument)args.get("port");
if (argument != null) {
argument.setValue(String.valueOf(debugPort));
}
argument = (Connector.Argument)args.get("hostname");
if (argument != null) {
argument.setValue(launcher.getTargetAddress());
}
argument = (Connector.Argument)args.get("timeout");
if (argument != null) {
argument.setValue("10000");
}
this.vm = connector.attach(args);
// workaround pb with some VMs
this.vm.resume();
break;
} catch (IllegalConnectorArgumentsException e) {
e.printStackTrace();
try {
System.out.println("Could not contact the VM at " + launcher.getTargetAddress() + ":" + debugPort + ". Retrying...");
Thread.sleep(100);
} catch (InterruptedException e2) {
}
} catch (IOException e) {
e.printStackTrace();
try {
System.out.println("Could not contact the VM at " + launcher.getTargetAddress() +":"+ debugPort +". Retrying...");Thread.sleep(100);}catch(InterruptedException e2){}}}if(this.vm ==null){if(this.launchedVM !=null){// If the VM is not running, output error streamtry{if(!this.launchedVM.isRunning()){InputStreamin=this.launchedVM.getErrorStream();int read;do{
read =in.read();if(read !=-1)System.out.print((char)read);}while(read !=-1);}}catch(TargetException e){}catch(IOException e){}// Shut it downtry{if(this.target !=null){this.target.disconnect();// Close the socket first so that the OS resource has a chance to be freed.}intretry=0;while(this.launchedVM.isRunning()&&(++retry<20)){try{Thread.sleep(retry*100);}catch(InterruptedException e){}}if(this.launchedVM.isRunning()){this.launchedVM.shutDown();}}catch(TargetException e){}}System.err.println("Could not contact the VM");return;}// Create contextthis.context =newEvaluationContext();// Create targetthis.target =newTargetInterface();this.target.connect("localhost", evalPort,30000);// allow 30s max to connect (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=188127)// Create name environmentthis.env =newFileSystem(Util.getJavaClassLibs(),newString[0],null);}super.setUp();}
| Project: jnode File: Hotswap.java View source code | 5 votes | ![]() ![]() |
private void connect(String host, String port, String name) throws Exception {
// connect to JVM
boolean useSocket = (port != null);
VirtualMachineManager manager = Bootstrap.virtualMachineManager();
List<AttachingConnector> connectors = manager.attachingConnectors();
AttachingConnector connector = null;
// System.err.println("Connectors available");
for (int i = 0; i < connectors.size(); i++) {
AttachingConnector tmp = connectors.get(i);
// System.err.println("conn "+i+" name="+tmp.name()+" transport="+tmp.transport().name()+
// " description="+tmp.description());
if (!useSocket && tmp.transport().name().equals("dt_shmem")) {
connector = tmp;
break;
}
if (useSocket && tmp.transport().name().equals("dt_socket")) {
connector = tmp;
break;
}
}
if (connector == null) {
throw new IllegalStateException("Cannot find shared memory connector");
}
Map<String, Argument> args = connector.defaultArguments();
// Iterator iter = args.keySet().iterator();
// while (iter.hasNext()) {
// Object key = iter.next();
// Object val = args.get(key);
// System.err.println("key:"+key.toString()+" = "+val.toString());
// }
Connector.Argument arg;
// use name if using dt_shmem
if (!useSocket) {
arg = (Connector.Argument) args.get("name");
arg.setValue(name);
} else {
// use port if using dt_socket
arg = (Connector.Argument) args.get("port");
arg.setValue(port);
if (host != null) {
arg = (Connector.Argument) args.get("hostname");
arg.setValue(host);
}
}
vm = connector.attach(args);
// query capabilities
if (!vm.canRedefineClasses()) {
throw new Exception("JVM doesn't support class replacement");
}
// if (!vm.canAddMethod()) {
// throw new Exception("JVM doesn't support adding method");
// }
// System.err.println("attached!");
}
| Project: Greenfoot File: VMReference.java View source code | 5 votes | ![]() ![]() |
/**
* Launch a remote debug VM using a TCP/IP socket.
*
* @param initDir
* the directory to have as a current directory in the remote VM
* @param mgr
* the virtual machine manager
* @return an instance of a VirtualMachine or null if there was an error
*/
public VirtualMachine localhostSocketLaunch(File initDir, DebuggerTerminal term, VirtualMachineManager mgr)
{
final int CONNECT_TRIES = 5; // try to connect max of 5 times
final int CONNECT_WAIT = 500; // wait half a sec between each connect int portNumber;
String [] launchParams; // launch the VM using the runtime classpath.
Boot boot = Boot.getInstance();
File [] filesPath = BPClassLoader.toFiles(boot.getRuntimeUserClassPath());
String allClassPath = BPClassLoader.toClasspathString(filesPath); ArrayList<String> paramList = new ArrayList<String>(10);
paramList.add(Config.getJDKExecutablePath(null, "java")); //check if any vm args are specified in Config, at the moment these
//are only Locale options: user.language and user.country paramList.addAll(Config.getDebugVMArgs()); paramList.add("-classpath");
paramList.add(allClassPath);
paramList.add("-Xdebug");
paramList.add("-Xnoagent");
if (Config.isMacOS()) {
paramList.add("-Xdock:icon=" + Config.getBlueJIconPath() + "/" + Config.getVMIconsName());
paramList.add("-Xdock:name=" + Config.getVMDockName());
}
paramList.add("-Xrunjdwp:transport=dt_socket,server=y"); // set index of memory transport, this may be used later if socket launch
// will not work
transportIndex = paramList.size() - 1;
paramList.add(SERVER_CLASSNAME); // set output encoding if specified, default is to use system default
// this gets passed to ExecServer's main as an arg which can then be
// used to specify encoding
streamEncoding = Config.getPropString("bluej.terminal.encoding", null);
isDefaultEncoding = (streamEncoding == null);
if(!isDefaultEncoding) {
paramList.add(streamEncoding);
} launchParams = (String[]) paramList.toArray(new String[0]); String transport = Config.getPropString("bluej.vm.transport"); AttachingConnector tcpipConnector = null;
AttachingConnector shmemConnector = null; Throwable tcpipFailureReason = null;
Throwable shmemFailureReason = null; // Attempt to connect via TCP/IP transport List connectors = mgr.attachingConnectors();
AttachingConnector connector = null; // find the known connectors
Iterator it = connectors.iterator();
while (it.hasNext()) {
AttachingConnector c = (AttachingConnector) it.next(); if (c.transport().name().equals("dt_socket")) {
tcpipConnector = c;
}
else if (c.transport().name().equals("dt_shmem")) {
shmemConnector = c;
}
} connector = tcpipConnector; // If the transport has been explicitly set the shmem in bluej.defs,
// try to use the dt_shmem connector first.
if (transport.equals("dt_shmem") && shmemConnector != null)
connector = null; for (int i = 0; i < CONNECT_TRIES; i++) { if (connector != null) {
try {
final StringBuffer listenMessage = new StringBuffer();
remoteVMprocess = launchVM(initDir, launchParams, listenMessage, term); portNumber = extractPortNumber(listenMessage.toString());if(portNumber ==-1){
closeIO();
remoteVMprocess.destroy();
remoteVMprocess =null;thrownewException(){publicvoid printStackTrace(){Debug.message("Could not find port number to connect to debugger");Debug.message("Line received from debugger was: "+ listenMessage);}};}Map arguments = connector.defaultArguments();Connector.Argument hostnameArg =(Connector.Argument) arguments.get("hostname");Connector.Argument portArg =(Connector.Argument) arguments.get("port");Connector.Argument timeoutArg =(Connector.Argument) arguments.get("timeout");if(hostnameArg ==null|| portArg ==null){thrownewException(){publicvoid printStackTrace(){Debug.message("incompatible JPDA socket launch connector");}};} hostnameArg.setValue("127.0.0.1");
portArg.setValue(Integer.toString(portNumber));if(timeoutArg !=null){// The timeout appears to be in milliseconds.// The default is apparently no timeout.
timeoutArg.setValue("1000");}VirtualMachine m =null;try{
m = connector.attach(arguments);}catch(Throwable t){// failed to connect.
closeIO();
remoteVMprocess.destroy();
remoteVMprocess =null;throw t;}Debug.log("Connected to debug VM via dt_socket transport...");
machine = m;
setupEventHandling();
waitForStartup();Debug.log("Communication with debug VM fully established.");return m;}catch(Throwable t){
tcpipFailureReason = t;}}// Attempt launch using shared memory transport, if available connector = shmemConnector;if(connector !=null){try{Map arguments = connector.defaultArguments();Connector.Argument addressArg =(Connector.Argument) arguments.get("name");if(addressArg ==null){thrownewException(){publicvoid printStackTrace(){Debug.message("Shared memory connector is incompatible - no 'name' argument");}};}else{String shmName ="bluej"+ shmCount++;
addressArg.setValue(shmName); launchParams[transportIndex]="-Xrunjdwp:transport=dt_shmem,address="+ shmName +",server=y,suspend=y";StringBuffer listenMessage =newStringBuffer();
remoteVMprocess = launchVM(initDir, launchParams, listenMessage,term);VirtualMachine m =null;try{
m = connector.attach(arguments);}catch(Throwable t){// failed to connect.
closeIO();
remoteVMprocess.destroy();
remoteVMprocess =null;throw t;}Debug.log("Connected to debug VM via dt_shmem transport...");
machine = m;
setupEventHandling();
waitForStartup();Debug.log("Communication with debug VM fully established.");return m;}}catch(Throwable t){
shmemFailureReason = t;}}// Do a small wait between connection attemptstry{if(i != CONNECT_TRIES -1)Thread.sleep(CONNECT_WAIT);}catch(InterruptedException ie){break;}
connector = tcpipConnector;}// failed to connectDebug.message("Failed to connect to debug VM. Reasons follow:");if(tcpipConnector !=null&& tcpipFailureReason !=null){Debug.message("dt_socket transport:");
tcpipFailureReason.printStackTrace();}if(shmemConnector !=null&& shmemFailureReason !=null){Debug.message("dt_shmem transport:");
tcpipFailureReason.printStackTrace();}if(shmemConnector ==null&& tcpipConnector ==null){Debug.message(" No suitable transports available.");}returnnull;}
| Project: classlib6 File: Hotswap.java View source code | 5 votes | ![]() ![]() |
private void connect(String host, String port, String name) throws Exception {
// connect to JVM
boolean useSocket = (port != null);
VirtualMachineManager manager = Bootstrap.virtualMachineManager();
List connectors = manager.attachingConnectors();
AttachingConnector connector = null;
// System.err.println("Connectors available");
for (int i = 0; i < connectors.size(); i++) {
AttachingConnector tmp = (AttachingConnector) connectors.get(i);
// System.err.println("conn "+i+" name="+tmp.name()+" transport="+tmp.transport().name()+
// " description="+tmp.description());
if (!useSocket && tmp.transport().name().equals("dt_shmem")) {
connector = tmp;
break;
}
if (useSocket && tmp.transport().name().equals("dt_socket")) {
connector = tmp;
break;
}
}
if (connector == null) {
throw new IllegalStateException("Cannot find shared memory connector");
}
Map args = connector.defaultArguments();
// Iterator iter = args.keySet().iterator();
// while (iter.hasNext()) {
// Object key = iter.next();
// Object val = args.get(key);
// System.err.println("key:"+key.toString()+" = "+val.toString());
// }
Connector.Argument arg;
// use name if using dt_shmem
if (!useSocket) {
arg = (Connector.Argument) args.get("name");
arg.setValue(name);
} else {
// use port if using dt_socket
arg = (Connector.Argument) args.get("port");
arg.setValue(port);
if (host != null) {
arg = (Connector.Argument) args.get("hostname");
arg.setValue(host);
}
}
vm = connector.attach(args);
// query capabilities
if (!vm.canRedefineClasses()) {
throw new Exception("JVM doesn't support class replacement");
}
// if (!vm.canAddMethod()) {
// throw new Exception("JVM doesn't support adding method");
// }
// System.err.println("attached!");
}
VirtualMachineManager的更多相关文章
- 新建VM_Script
在Hyper-V群集中,不需要设置VM的自启动,当宿主机意外关机重新启动后,上面的VM会自动转移到另一台主机:如果另一台主机处于关机状态,则宿主机重新启动后,其VM也会自启动(如果其VM在宿主机关机前 ...
- opennebula 编译日志
[root@localhost opennebula-]# scons mysql=yes scons: Reading SConscript files ... Testing recipe: xm ...
- JVM核心知识体系(转http://www.cnblogs.com/wxdlut/p/10670871.html)
1.问题 1.如何理解类文件结构布局? 2.如何应用类加载器的工作原理进行将应用辗转腾挪? 3.热部署与热替换有何区别,如何隔离类冲突? 4.JVM如何管理内存,有何内存淘汰机制? 5.JVM执行引擎 ...
- Java调试那点事[转]
转自云栖社区:https://yq.aliyun.com/articles/56?spm=5176.100239.blogcont59193.11.jOh3ZG# 摘要: 该文章来自于阿里巴巴技术协会 ...
- scvmm sdk之ddtkh(二)
ddtkh,dynamic datacenter toolkit for hosters,原先发布在codeplex开源社区,后来被微软归档到开发者社区中,从本质上来说它是一个企业级应用的套件,集成了 ...
- scvmm sdk之powershell(一)
shell表示计算机操作系统中的壳层,与之相对的是内核,内核不能与用户直接交互,而是通过shell为用户提供操作界面,shell分为两类,一种提供命令行界面,一种提供图形界面.windows powe ...
- Asp.net使用powershell管理hyper-v
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- C#调PowerShell在SCVMM中创建虚拟机时,实时显示创建进度
关于c#调用PowerShell来控制SCVMM,网上有很多例子,也比较简单,但创建虚拟机的过程,是一个很漫长的时间,所以一般来说,创建的时候都希望可以实时的显示当前虚拟机的创建进度.当时这个问题困扰 ...
- 自己动手实现java断点/单步调试(一)
又是好长时间没有写博客了,今天我们就来谈一下java程序的断点调试.写这篇主题的主要原因是身边的公司或者个人都执着于做apaas平台,简单来说apaas平台就是一个零代码或者低代码的配置平台,通过配置 ...
随机推荐
- 常用的HTTP方法有哪些?
GET: 用于请求访问已经被URI(统一资源标识符)识别的资源,可以通过URL传参给服务器POST:用于传输数据给服务器,主要功能与GET方法类似,但一般推荐使用POST方式.PUT: 传输数据,报文 ...
- TCP/IP 协议分层
协议分层 可能大家对OSI七层模型并不陌生,它将网络协议很细致地从逻辑上分为了7层.但是实际运用中并不是按七层模型,一般大家都只使用5层模型.如下: 物理层:一般包括物理媒介,电信号,光信号等,主要对 ...
- CAD交互绘制样条线(com接口)
在CAD设计时,需要绘制样条线,用户可以设置样条线线重及颜色等属性. 主要用到函数说明: _DMxDrawX::SendStringToExecuteFun 把命令当着函数执行,可以传参数.详细说明如 ...
- vue 常用功能和命令
1. vue-cli 构建项目 # 全局安装 vue-cli $ npm install --global vue-clif # 创建一个基于 webpack 模板的新项目 $ vue init we ...
- SpringMVC+ajax返回JSON串
一.引言 本文使用springMVC和ajax做的一个小小的demo,实现将JSON对象返回到页面,没有什么技术含量,纯粹是因为最近项目中引入了springMVC框架. 二.入门例子 ①. 建立工程, ...
- 原生javascript实现call、apply和bind的方法
var context = {id: 12}; function fun (name, age) { console.log(this.id, name, age) } bind bind() 方法会 ...
- HNOI 2010 物品调度 并查集 置换
题意: 题意有点细,暂不概括.请仔细审题. 分析: 我们先要把c生成出来. 记得颜神讲这道题,首先表明,这道题有两个问题需要处理. 第一个是要先定位,第二个是要求最小移动步数. 定位时对于每一个物品i ...
- 色码表 Color code table
最近打算更新设计博客页面,需要用到CSS色码表,查了一些资料现转载此处以备以后使用,点击此处查看原文,另外还发现了几个不错的网站: color-hex HTML颜色代码 色碼表 色碼表英文為 Colo ...
- UvaLive 4917 Abstract Extract (模拟)
题意: 给定一篇文章, 文章中有段落, 段落中有句子. 句子只会以'!' , '.' , '?' 结尾, 求出每段中含有与他下面同样是该段落中相同单词数最多的句子, 注意, 单词忽略大小写, 重复的单 ...
- Uva 12657 移动盒子(双向链表)
题意: 你有一行盒子,从左到右依次编号为1, 2, 3,…, n.可以执行以下4种指令:1 X Y表示把盒子X移动到盒子Y左边(如果X已经在Y的左边则忽略此指令).2 X Y表示把盒子X移动到盒子Y右 ...

