private static String getJavaHome(BTraceTask btt) { try { VirtualMachine vm = VirtualMachine.attach(String.valueOf(btt.getPid())); return vm.getSystemProperties().getProperty("java.home"); } catch (AttachNotSupportedException e) { LOGGER.log(Level.SEVERE, null, e); } catch (IOException e) { LOGGER.log(Level.SEVERE, null, e); } return null; } }
VirtualMachine vm = null; try { vm = VirtualMachine.attach(String.valueOf(pid)); HotSpotVirtualMachine hvm = (HotSpotVirtualMachine) vm; try (InputStream in = hvm.executeJCmd("GC.run");) {
String name = String.valueOf(vmid); try { vm = VirtualMachine.attach(name); } catch (AttachNotSupportedException x) { throw new IOException(x.getMessage(), x);
private void attachAgent(final String targetJvmPid, final String agentJarPath, final String cfg) throws Exception { VirtualMachine vmObj = null; try { vmObj = VirtualMachine.attach(targetJvmPid); if (vmObj != null) { vmObj.loadAgent(agentJarPath, cfg); } } finally { if (null != vmObj) { vmObj.detach(); } } }
@Override public int getTaskPort(BTraceTask task) { VirtualMachine vm = null; try { vm = VirtualMachine.attach(String.valueOf(task.getPid())); String portStr = vm.getSystemProperties().getProperty(PORT_PROPERTY); return portStr != null ? Integer.parseInt(portStr) : findFreePort(); } catch (AttachNotSupportedException ex) { Logger.getLogger(PortLocatorImpl.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PortLocatorImpl.class.getName()).log(Level.SEVERE, null, ex); } finally { if (vm != null) { try { vm.detach(); } catch (IOException e) { LOGGER.log(Level.SEVERE, null, e); } } } return findFreePort(); }
vm = VirtualMachine.attach(pid);
public static JMXServiceURL extractJMXServiceURLFromPid(String pid) throws IOException { try { VirtualMachine vm = VirtualMachine.attach(pid); try { String connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS); if (connectorAddress == null) { String agent = vm.getSystemProperties().getProperty("java.home") + File.separator + "lib" + File.separator + "management-agent.jar"; vm.loadAgent(agent); connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS); } return new JMXServiceURL(connectorAddress); } finally { vm.detach(); } } catch(Exception e) { throw new IOException(e); } }
vm = VirtualMachine.attach(pid); } catch (AttachNotSupportedException x) { IOException ioe = new IOException(x.getMessage());
VirtualMachine vm = VirtualMachine.attach(pid); vm.loadAgent(agentJar.getAbsolutePath(), null); vm.detach();
VirtualMachine vm = VirtualMachine.attach(pid); vm.loadAgent(agentJar.getAbsolutePath(), null); vm.detach();
vm = VirtualMachine.attach( String.valueOf( pid ) );
VirtualMachine vm = VirtualMachine.attach(String.valueOf(pid)); try { Properties agentProps = vm.getAgentProperties();
public static LocalVirtualMachine getLocalVirtualMachine(int vmid) throws Exception { Map<Integer, LocalVirtualMachine> map = getAllVirtualMachines(); LocalVirtualMachine lvm = map.get(vmid); if (lvm == null) { // Check if the VM is attachable but not included in the list // if it's running with a different security context. // For example, Windows services running // local SYSTEM account are attachable if you have Adminstrator // privileges. boolean attachable = false; String address = null; String name = String.valueOf(vmid); // default display name to pid VirtualMachine vm = VirtualMachine.attach(name); attachable = true; Properties agentProps = vm.getAgentProperties(); address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP); vm.detach(); lvm = new LocalVirtualMachine(vmid, name, attachable, address); } return lvm; }
@Test public void attachToSelfIsOk() throws Exception { String nameOfRunningVM = ManagementFactory.getRuntimeMXBean().getName(); int p = nameOfRunningVM.indexOf('@'); String pid = nameOfRunningVM.substring(0, p); VirtualMachine vm = VirtualMachine.attach(pid); vm.detach(); } }
try vm = VirtualMachine.attach(name);
try VirtualMachine vm = VirtualMachine.attach(vmd); attachable = true; Properties agentProps = vm.getAgentProperties();
debugPrint("attaching to " + pid); vm = VirtualMachine.attach(pid); if (debug) { debugPrint("checking port availability: " + port);
String name = String.valueOf(vmid); try { vm = VirtualMachine.attach(name); } catch (AttachNotSupportedException x) { throw new IOException(x.getMessage(), x);
String options = sb.toString(); Integer pid = pids.get(0); final VirtualMachine vm = VirtualMachine.attach("" + pid); log.log(Level.INFO, "Loading agent with command " + options + " as agent " + agentFile.getCanonicalPath()); vm.loadAgent(agentFile.getCanonicalPath(), options); for (Integer pid : pids) { log.log(Level.INFO, "Attaching to remote process " + pid); VirtualMachine vm = VirtualMachine.attach("" + pid); String options = sb.toString(); log.log(Level.INFO, "Loading agent with command " + options + " as agent " + agentFile.getCanonicalPath());
private VirtualMachine attachToThisVM() { try { return VirtualMachine.attach(pid); } catch (AttachNotSupportedException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }