equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
38 import javax.management.remote.JMXConnector; |
38 import javax.management.remote.JMXConnector; |
39 import java.lang.management.RuntimeMXBean; |
39 import java.lang.management.RuntimeMXBean; |
40 import static java.lang.management.ManagementFactory.*; |
40 import static java.lang.management.ManagementFactory.*; |
41 import java.net.Socket; |
41 import java.net.Socket; |
42 import java.net.InetSocketAddress; |
42 import java.net.InetSocketAddress; |
43 import java.io.File; |
|
44 import java.io.IOException; |
43 import java.io.IOException; |
45 |
44 |
46 // Sun specific |
45 // Sun specific |
47 import com.sun.tools.attach.VirtualMachine; |
46 import com.sun.tools.attach.VirtualMachine; |
48 |
47 |
53 |
52 |
54 /* |
53 /* |
55 * Starts the management agent in the target VM |
54 * Starts the management agent in the target VM |
56 */ |
55 */ |
57 private static void startManagementAgent(String pid) throws IOException { |
56 private static void startManagementAgent(String pid) throws IOException { |
58 /* |
|
59 * JAR file normally in ${java.home}/jre/lib but may be in ${java.home}/lib |
|
60 * with development/non-images builds |
|
61 */ |
|
62 String home = System.getProperty("java.home"); |
|
63 String agent = home + File.separator + "jre" + File.separator + "lib" |
|
64 + File.separator + "management-agent.jar"; |
|
65 File f = new File(agent); |
|
66 if (!f.exists()) { |
|
67 agent = home + File.separator + "lib" + File.separator + |
|
68 "management-agent.jar"; |
|
69 f = new File(agent); |
|
70 if (!f.exists()) { |
|
71 throw new RuntimeException("management-agent.jar missing"); |
|
72 } |
|
73 } |
|
74 agent = f.getCanonicalPath(); |
|
75 |
|
76 System.out.println("Loading " + agent + " into target VM ..."); |
|
77 |
|
78 try { |
57 try { |
79 VirtualMachine.attach(pid).loadAgent(agent); |
58 VirtualMachine.attach(pid).startLocalManagementAgent(); |
80 } catch (Exception x) { |
59 } catch (Exception x) { |
81 throw new IOException(x.getMessage()); |
60 throw new IOException(x.getMessage()); |
82 } |
61 } |
83 } |
62 } |
84 |
63 |
120 String jvmstatLocalConnectorAddress = |
99 String jvmstatLocalConnectorAddress = |
121 ConnectorAddressLink.importFrom(vmid); |
100 ConnectorAddressLink.importFrom(vmid); |
122 |
101 |
123 if (agentPropLocalConnectorAddress == null && |
102 if (agentPropLocalConnectorAddress == null && |
124 jvmstatLocalConnectorAddress == null) { |
103 jvmstatLocalConnectorAddress == null) { |
125 // No JMX Connector address so attach to VM, and load |
104 // No JMX Connector address so attach to VM, and start local agent |
126 // management-agent.jar |
|
127 startManagementAgent(pid); |
105 startManagementAgent(pid); |
128 agentPropLocalConnectorAddress = (String) |
106 agentPropLocalConnectorAddress = (String) |
129 vm.getAgentProperties().get(LOCAL_CONNECTOR_ADDRESS_PROP); |
107 vm.getAgentProperties().get(LOCAL_CONNECTOR_ADDRESS_PROP); |
130 jvmstatLocalConnectorAddress = |
108 jvmstatLocalConnectorAddress = |
131 ConnectorAddressLink.importFrom(vmid); |
109 ConnectorAddressLink.importFrom(vmid); |