Mercurial > hg > graal-compiler
annotate agent/src/share/classes/sun/jvm/hotspot/tools/Tool.java @ 14223:de6a9e811145
8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
Summary: Copyright year updated for files modified during 2013
Reviewed-by: twisti, iveresov
author | mikael |
---|---|
date | Tue, 24 Dec 2013 11:48:39 -0800 |
parents | 5280822ddfcd |
children | 4ca6dc0799b6 |
rev | line source |
---|---|
0 | 1 /* |
14223
de6a9e811145
8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents:
13388
diff
changeset
|
2 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.tools; | |
26 | |
27 import java.io.PrintStream; | |
12932
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
28 |
13388
5280822ddfcd
6626412: jstack using SA prints some info messages into err stream
sla
parents:
12932
diff
changeset
|
29 import sun.jvm.hotspot.HotSpotAgent; |
5280822ddfcd
6626412: jstack using SA prints some info messages into err stream
sla
parents:
12932
diff
changeset
|
30 import sun.jvm.hotspot.debugger.DebuggerException; |
5280822ddfcd
6626412: jstack using SA prints some info messages into err stream
sla
parents:
12932
diff
changeset
|
31 import sun.jvm.hotspot.debugger.JVMDebugger; |
5280822ddfcd
6626412: jstack using SA prints some info messages into err stream
sla
parents:
12932
diff
changeset
|
32 import sun.jvm.hotspot.runtime.VM; |
0 | 33 |
34 // generic command line or GUI tool. | |
35 // override run & code main as shown below. | |
36 | |
37 public abstract class Tool implements Runnable { | |
8103 | 38 private HotSpotAgent agent; |
11054
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
39 private JVMDebugger jvmDebugger; |
0 | 40 private int debugeeType; |
41 | |
42 // debugeeType is one of constants below | |
43 protected static final int DEBUGEE_PID = 0; | |
44 protected static final int DEBUGEE_CORE = 1; | |
45 protected static final int DEBUGEE_REMOTE = 2; | |
46 | |
11054
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
47 public Tool() { |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
48 } |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
49 |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
50 public Tool(JVMDebugger d) { |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
51 jvmDebugger = d; |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
52 } |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
53 |
0 | 54 public String getName() { |
55 return getClass().getName(); | |
56 } | |
57 | |
58 protected boolean needsJavaPrefix() { | |
59 return true; | |
60 } | |
61 | |
8103 | 62 protected void setAgent(HotSpotAgent a) { |
0 | 63 agent = a; |
64 } | |
65 | |
66 protected void setDebugeeType(int dt) { | |
67 debugeeType = dt; | |
68 } | |
69 | |
8103 | 70 protected HotSpotAgent getAgent() { |
0 | 71 return agent; |
72 } | |
73 | |
74 protected int getDebugeeType() { | |
75 return debugeeType; | |
76 } | |
77 | |
78 protected void printUsage() { | |
79 String name = null; | |
80 if (needsJavaPrefix()) { | |
81 name = "java " + getName(); | |
82 } else { | |
83 name = getName(); | |
84 } | |
85 System.out.println("Usage: " + name + " [option] <pid>"); | |
86 System.out.println("\t\t(to connect to a live java process)"); | |
87 System.out.println(" or " + name + " [option] <executable> <core>"); | |
88 System.out.println("\t\t(to connect to a core file)"); | |
89 System.out.println(" or " + name + " [option] [server_id@]<remote server IP or hostname>"); | |
90 System.out.println("\t\t(to connect to a remote debug server)"); | |
91 System.out.println(); | |
92 System.out.println("where option must be one of:"); | |
93 printFlagsUsage(); | |
94 } | |
95 | |
96 protected void printFlagsUsage() { | |
97 System.out.println(" -h | -help\tto print this help message"); | |
98 } | |
99 | |
100 protected void usage() { | |
101 printUsage(); | |
102 } | |
103 | |
104 /* | |
105 Derived class main should be of the following form: | |
106 | |
107 public static void main(String[] args) { | |
108 <derived class> obj = new <derived class>; | |
12932
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
109 obj.execute(args); |
0 | 110 } |
111 | |
112 */ | |
113 | |
12932
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
114 protected void execute(String[] args) { |
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
115 int returnStatus = 1; |
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
116 |
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
117 try { |
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
118 returnStatus = start(args); |
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
119 } finally { |
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
120 stop(); |
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
121 } |
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
122 |
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
123 // Exit with 0 or 1 |
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
124 System.exit(returnStatus); |
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
125 } |
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
126 |
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
127 public void stop() { |
0 | 128 if (agent != null) { |
129 agent.detach(); | |
130 } | |
131 } | |
132 | |
12932
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
133 private int start(String[] args) { |
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
134 |
0 | 135 if ((args.length < 1) || (args.length > 2)) { |
136 usage(); | |
12932
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
137 return 1; |
0 | 138 } |
139 | |
140 // Attempt to handle -h or -help or some invalid flag | |
12932
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
141 if (args[0].startsWith("-h")) { |
0 | 142 usage(); |
12932
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
143 return 0; |
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
144 } else if (args[0].startsWith("-")) { |
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
145 usage(); |
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
146 return 1; |
0 | 147 } |
148 | |
149 PrintStream err = System.err; | |
13388
5280822ddfcd
6626412: jstack using SA prints some info messages into err stream
sla
parents:
12932
diff
changeset
|
150 PrintStream out = System.out; |
0 | 151 |
152 int pid = 0; | |
153 String coreFileName = null; | |
154 String executableName = null; | |
155 String remoteServer = null; | |
156 | |
157 switch (args.length) { | |
158 case 1: | |
159 try { | |
160 pid = Integer.parseInt(args[0]); | |
161 debugeeType = DEBUGEE_PID; | |
162 } catch (NumberFormatException e) { | |
163 // try remote server | |
164 remoteServer = args[0]; | |
165 debugeeType = DEBUGEE_REMOTE; | |
166 } | |
167 break; | |
168 | |
169 case 2: | |
170 executableName = args[0]; | |
171 coreFileName = args[1]; | |
172 debugeeType = DEBUGEE_CORE; | |
173 break; | |
174 | |
175 default: | |
176 usage(); | |
12932
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
177 return 1; |
0 | 178 } |
179 | |
8103 | 180 agent = new HotSpotAgent(); |
0 | 181 try { |
182 switch (debugeeType) { | |
183 case DEBUGEE_PID: | |
13388
5280822ddfcd
6626412: jstack using SA prints some info messages into err stream
sla
parents:
12932
diff
changeset
|
184 out.println("Attaching to process ID " + pid + ", please wait..."); |
0 | 185 agent.attach(pid); |
186 break; | |
187 | |
188 case DEBUGEE_CORE: | |
13388
5280822ddfcd
6626412: jstack using SA prints some info messages into err stream
sla
parents:
12932
diff
changeset
|
189 out.println("Attaching to core " + coreFileName + |
0 | 190 " from executable " + executableName + ", please wait..."); |
191 agent.attach(executableName, coreFileName); | |
192 break; | |
193 | |
194 case DEBUGEE_REMOTE: | |
13388
5280822ddfcd
6626412: jstack using SA prints some info messages into err stream
sla
parents:
12932
diff
changeset
|
195 out.println("Attaching to remote server " + remoteServer + ", please wait..."); |
0 | 196 agent.attach(remoteServer); |
197 break; | |
198 } | |
199 } | |
200 catch (DebuggerException e) { | |
201 switch (debugeeType) { | |
202 case DEBUGEE_PID: | |
203 err.print("Error attaching to process: "); | |
204 break; | |
205 | |
206 case DEBUGEE_CORE: | |
207 err.print("Error attaching to core file: "); | |
208 break; | |
209 | |
210 case DEBUGEE_REMOTE: | |
211 err.print("Error attaching to remote server: "); | |
212 break; | |
213 } | |
214 if (e.getMessage() != null) { | |
12932
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
215 err.println(e.getMessage()); |
11054
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
216 e.printStackTrace(); |
0 | 217 } |
218 err.println(); | |
12932
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
219 return 1; |
0 | 220 } |
221 | |
13388
5280822ddfcd
6626412: jstack using SA prints some info messages into err stream
sla
parents:
12932
diff
changeset
|
222 out.println("Debugger attached successfully."); |
11054
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
223 startInternal(); |
12932
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
224 return 0; |
11054
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
225 } |
0 | 226 |
11054
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
227 // When using an existing JVMDebugger. |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
228 public void start() { |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
229 |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
230 if (jvmDebugger == null) { |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
231 throw new RuntimeException("Tool.start() called with no JVMDebugger set."); |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
232 } |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
233 agent = new HotSpotAgent(); |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
234 agent.attach(jvmDebugger); |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
235 startInternal(); |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
236 } |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
237 |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
238 // Remains of the start mechanism, common to both start methods. |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
239 private void startInternal() { |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8103
diff
changeset
|
240 |
13388
5280822ddfcd
6626412: jstack using SA prints some info messages into err stream
sla
parents:
12932
diff
changeset
|
241 PrintStream out = System.out; |
8103 | 242 VM vm = VM.getVM(); |
243 if (vm.isCore()) { | |
13388
5280822ddfcd
6626412: jstack using SA prints some info messages into err stream
sla
parents:
12932
diff
changeset
|
244 out.println("Core build detected."); |
8103 | 245 } else if (vm.isClientCompiler()) { |
13388
5280822ddfcd
6626412: jstack using SA prints some info messages into err stream
sla
parents:
12932
diff
changeset
|
246 out.println("Client compiler detected."); |
8103 | 247 } else if (vm.isServerCompiler()) { |
13388
5280822ddfcd
6626412: jstack using SA prints some info messages into err stream
sla
parents:
12932
diff
changeset
|
248 out.println("Server compiler detected."); |
8103 | 249 } else { |
250 throw new RuntimeException("Fatal error: " | |
251 + "should have been able to detect core/C1/C2 build"); | |
252 } | |
0 | 253 |
8103 | 254 String version = vm.getVMRelease(); |
255 if (version != null) { | |
13388
5280822ddfcd
6626412: jstack using SA prints some info messages into err stream
sla
parents:
12932
diff
changeset
|
256 out.print("JVM version is "); |
5280822ddfcd
6626412: jstack using SA prints some info messages into err stream
sla
parents:
12932
diff
changeset
|
257 out.println(version); |
8103 | 258 } |
0 | 259 |
8103 | 260 run(); |
0 | 261 } |
262 } |