use of com.sun.tools.attach.VirtualMachine in project ACS by ACS-Community.
the class RemoteThreadsClient method getServiceURL.
private void getServiceURL(int pid) throws IOException, AgentLoadException, RemoteThreadsException, AttachNotSupportedException, AgentInitializationException {
// attach to the target application
final VirtualMachine vm = VirtualMachine.attach(String.valueOf(pid));
// get the connector address
String connectorAddress = vm.getAgentProperties().getProperty(LOCAL_CONNECTOR_ADDRESS);
// no connector address, so we start the JMX agent
if (connectorAddress == null) {
String agent = vm.getSystemProperties().getProperty("java.home") + File.separator + "lib" + File.separator + "management-agent.jar";
vm.loadAgent(agent);
// agent is started, get the connector address
connectorAddress = vm.getAgentProperties().getProperty(LOCAL_CONNECTOR_ADDRESS);
if (connectorAddress == null)
throw new RemoteThreadsException("Can't get the remote JVM connector address");
}
remoteURL = new JMXServiceURL(connectorAddress);
}
use of com.sun.tools.attach.VirtualMachine in project jdk8u_jdk by JetBrains.
the class JCmd method executeCommandForPid.
private static void executeCommandForPid(String pid, String command) throws AttachNotSupportedException, IOException, UnsupportedEncodingException {
VirtualMachine vm = VirtualMachine.attach(pid);
// Cast to HotSpotVirtualMachine as this is an
// implementation specific method.
HotSpotVirtualMachine hvm = (HotSpotVirtualMachine) vm;
String[] lines = command.split("\\n");
for (String line : lines) {
if (line.trim().equals("stop")) {
break;
}
try (InputStream in = hvm.executeJCmd(line)) {
// read to EOF and just print output
byte[] b = new byte[256];
int n;
boolean messagePrinted = false;
do {
n = in.read(b);
if (n > 0) {
String s = new String(b, 0, n, "UTF-8");
System.out.print(s);
messagePrinted = true;
}
} while (n > 0);
if (!messagePrinted) {
System.out.println("Command executed successfully");
}
}
}
vm.detach();
}
use of com.sun.tools.attach.VirtualMachine in project jdk8u_jdk by JetBrains.
the class JMap method histo.
private static void histo(String pid, boolean live) throws IOException {
VirtualMachine vm = attach(pid);
InputStream in = ((HotSpotVirtualMachine) vm).heapHisto(live ? LIVE_OBJECTS_OPTION : ALL_OBJECTS_OPTION);
drain(vm, in);
}
use of com.sun.tools.attach.VirtualMachine in project jdk8u_jdk by JetBrains.
the class JMap method dump.
private static void dump(String pid, String options) throws IOException {
// parse the options to get the dump filename
String filename = parseDumpOptions(options);
if (filename == null) {
// invalid options or no filename
usage(1);
}
// get the canonical path - important to avoid just passing
// a "heap.bin" and having the dump created in the target VM
// working directory rather than the directory where jmap
// is executed.
filename = new File(filename).getCanonicalPath();
// dump live objects only or not
boolean live = isDumpLiveObjects(options);
VirtualMachine vm = attach(pid);
System.out.println("Dumping heap to " + filename + " ...");
InputStream in = ((HotSpotVirtualMachine) vm).dumpHeap((Object) filename, (live ? LIVE_OBJECTS_OPTION : ALL_OBJECTS_OPTION));
drain(vm, in);
}
use of com.sun.tools.attach.VirtualMachine in project jdk8u_jdk by JetBrains.
the class JInfo method flag.
private static void flag(String pid, String option) throws IOException {
VirtualMachine vm = attach(pid);
String flag;
InputStream in;
int index = option.indexOf('=');
if (index != -1) {
flag = option.substring(0, index);
String value = option.substring(index + 1);
in = ((HotSpotVirtualMachine) vm).setFlag(flag, value);
} else {
char c = option.charAt(0);
switch(c) {
case '+':
flag = option.substring(1);
in = ((HotSpotVirtualMachine) vm).setFlag(flag, "1");
break;
case '-':
flag = option.substring(1);
in = ((HotSpotVirtualMachine) vm).setFlag(flag, "0");
break;
default:
flag = option;
in = ((HotSpotVirtualMachine) vm).printFlag(flag);
break;
}
}
drain(vm, in);
}
Aggregations