author | ysuenaga |
Wed, 29 May 2019 13:50:33 +0900 | |
changeset 55073 | f4702c8c9b3f |
parent 54917 | 81852d53e585 |
child 55650 | 56e8c0a3fe9a |
child 58678 | 9cf78a70fa4f |
permissions | -rw-r--r-- |
31978 | 1 |
/* |
54917
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
31978 | 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 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
package sun.jvm.hotspot; |
|
26 |
||
27 |
import java.util.ArrayList; |
|
28 |
import java.util.Arrays; |
|
29 |
||
30 |
import sun.jvm.hotspot.tools.JStack; |
|
31 |
import sun.jvm.hotspot.tools.JMap; |
|
32 |
import sun.jvm.hotspot.tools.JInfo; |
|
37090 | 33 |
import sun.jvm.hotspot.tools.JSnap; |
31978 | 34 |
|
35 |
public class SALauncher { |
|
36 |
||
37 |
private static boolean launcherHelp() { |
|
38 |
System.out.println(" clhsdb \tcommand line debugger"); |
|
39 |
System.out.println(" hsdb \tui debugger"); |
|
54917
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
40 |
System.out.println(" debugd --help\tto get more information"); |
31978 | 41 |
System.out.println(" jstack --help\tto get more information"); |
42 |
System.out.println(" jmap --help\tto get more information"); |
|
43 |
System.out.println(" jinfo --help\tto get more information"); |
|
37090 | 44 |
System.out.println(" jsnap --help\tto get more information"); |
31978 | 45 |
return false; |
46 |
} |
|
47 |
||
55073
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
48 |
private static boolean commonHelp(String mode) { |
31978 | 49 |
// --pid <pid> |
50 |
// --exe <exe> |
|
51 |
// --core <core> |
|
55073
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
52 |
System.out.println(" --pid <pid> \tTo attach to and operate on the given live process."); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
53 |
System.out.println(" --core <corefile>\tTo operate on the given core file."); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
54 |
System.out.println(" --exe <executable for corefile>"); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
55 |
System.out.println(); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
56 |
System.out.println(" The --core and --exe options must be set together to give the core"); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
57 |
System.out.println(" file, and associated executable, to operate on. Otherwise the --pid"); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
58 |
System.out.println(" option can be set to operate on a live process."); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
59 |
System.out.println(" The arguments for --exe and --core can use absolute or relative paths."); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
60 |
System.out.println(); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
61 |
System.out.println(" Examples: jhsdb " + mode + " --pid 1234"); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
62 |
System.out.println(" or jhsdb " + mode + " --core ./core.1234 --exe ./myexe"); |
31978 | 63 |
return false; |
64 |
} |
|
65 |
||
40101 | 66 |
private static boolean debugdHelp() { |
67 |
// [options] <pid> [server-id] |
|
68 |
// [options] <executable> <core> [server-id] |
|
55073
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
69 |
System.out.println(" --serverid <id> \tA unique identifier for this debug server."); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
70 |
return commonHelp("debugd"); |
40101 | 71 |
} |
72 |
||
31978 | 73 |
private static boolean jinfoHelp() { |
74 |
// --flags -> -flags |
|
75 |
// --sysprops -> -sysprops |
|
55073
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
76 |
System.out.println(" --flags \tTo print VM flags."); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
77 |
System.out.println(" --sysprops \tTo print Java System properties."); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
78 |
System.out.println(" <no option> \tTo print both of the above."); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
79 |
return commonHelp("jinfo"); |
31978 | 80 |
} |
81 |
||
82 |
private static boolean jmapHelp() { |
|
83 |
// --heap -> -heap |
|
84 |
// --binaryheap -> -heap:format=b |
|
85 |
// --histo -> -histo |
|
86 |
// --clstats -> -clstats |
|
87 |
// --finalizerinfo -> -finalizerinfo |
|
88 |
||
55073
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
89 |
System.out.println(" <no option> \tTo print same info as Solaris pmap."); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
90 |
System.out.println(" --heap \tTo print java heap summary."); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
91 |
System.out.println(" --binaryheap \tTo dump java heap in hprof binary format."); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
92 |
System.out.println(" --dumpfile <name>\tThe name of the dump file."); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
93 |
System.out.println(" --histo \tTo print histogram of java object heap."); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
94 |
System.out.println(" --clstats \tTo print class loader statistics."); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
95 |
System.out.println(" --finalizerinfo \tTo print information on objects awaiting finalization."); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
96 |
return commonHelp("jmap"); |
31978 | 97 |
} |
98 |
||
99 |
private static boolean jstackHelp() { |
|
100 |
// --locks -> -l |
|
101 |
// --mixed -> -m |
|
55073
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
102 |
System.out.println(" --locks \tTo print java.util.concurrent locks."); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
103 |
System.out.println(" --mixed \tTo print both Java and native frames (mixed mode)."); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
104 |
return commonHelp("jstack"); |
31978 | 105 |
} |
106 |
||
37090 | 107 |
private static boolean jsnapHelp() { |
55073
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
108 |
System.out.println(" --all \tTo print all performance counters."); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
109 |
return commonHelp("jsnap"); |
37090 | 110 |
} |
111 |
||
31978 | 112 |
private static boolean toolHelp(String toolName) { |
113 |
if (toolName.equals("jstack")) { |
|
114 |
return jstackHelp(); |
|
115 |
} |
|
116 |
if (toolName.equals("jinfo")) { |
|
117 |
return jinfoHelp(); |
|
118 |
} |
|
119 |
if (toolName.equals("jmap")) { |
|
120 |
return jmapHelp(); |
|
121 |
} |
|
37090 | 122 |
if (toolName.equals("jsnap")) { |
123 |
return jsnapHelp(); |
|
124 |
} |
|
40101 | 125 |
if (toolName.equals("debugd")) { |
126 |
return debugdHelp(); |
|
127 |
} |
|
55073
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
128 |
if (toolName.equals("hsdb")) { |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
129 |
return commonHelp("hsdb"); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
130 |
} |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
131 |
if (toolName.equals("clhsdb")) { |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
132 |
return commonHelp("clhsdb"); |
31978 | 133 |
} |
134 |
return launcherHelp(); |
|
135 |
} |
|
136 |
||
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
137 |
private static void buildAttachArgs(ArrayList<String> newArgs, String pid, |
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
138 |
String exe, String core, boolean allowEmpty) { |
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
139 |
if (!allowEmpty && (pid == null) && (exe == null)) { |
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
140 |
throw new SAGetoptException("You have to set --pid or --exe."); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
141 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
142 |
|
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
143 |
if (pid != null) { // Attach to live process |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
144 |
if (exe != null) { |
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
145 |
throw new SAGetoptException("Unnecessary argument: --exe"); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
146 |
} else if (core != null) { |
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
147 |
throw new SAGetoptException("Unnecessary argument: --core"); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
148 |
} else if (!pid.matches("^\\d+$")) { |
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
149 |
throw new SAGetoptException("Invalid pid: " + pid); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
150 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
151 |
|
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
152 |
newArgs.add(pid); |
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
153 |
} else if (exe != null) { |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
154 |
if (exe.length() == 0) { |
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
155 |
throw new SAGetoptException("You have to set --exe."); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
156 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
157 |
|
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
158 |
newArgs.add(exe); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
159 |
|
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
160 |
if ((core == null) || (core.length() == 0)) { |
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
161 |
throw new SAGetoptException("You have to set --core."); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
162 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
163 |
|
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
164 |
newArgs.add(core); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
165 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
166 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
167 |
|
31978 | 168 |
private static void runCLHSDB(String[] oldArgs) { |
169 |
SAGetopt sg = new SAGetopt(oldArgs); |
|
170 |
String[] longOpts = {"exe=", "core=", "pid="}; |
|
171 |
||
172 |
ArrayList<String> newArgs = new ArrayList(); |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
173 |
String pid = null; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
174 |
String exe = null; |
31978 | 175 |
String core = null; |
176 |
String s = null; |
|
177 |
||
178 |
while((s = sg.next(null, longOpts)) != null) { |
|
179 |
if (s.equals("exe")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
180 |
exe = sg.getOptarg(); |
31978 | 181 |
continue; |
182 |
} |
|
183 |
if (s.equals("core")) { |
|
184 |
core = sg.getOptarg(); |
|
185 |
continue; |
|
186 |
} |
|
187 |
if (s.equals("pid")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
188 |
pid = sg.getOptarg(); |
31978 | 189 |
continue; |
190 |
} |
|
191 |
} |
|
192 |
||
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
193 |
buildAttachArgs(newArgs, pid, exe, core, true); |
31978 | 194 |
CLHSDB.main(newArgs.toArray(new String[newArgs.size()])); |
195 |
} |
|
196 |
||
197 |
private static void runHSDB(String[] oldArgs) { |
|
198 |
SAGetopt sg = new SAGetopt(oldArgs); |
|
199 |
String[] longOpts = {"exe=", "core=", "pid="}; |
|
200 |
||
201 |
ArrayList<String> newArgs = new ArrayList(); |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
202 |
String pid = null; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
203 |
String exe = null; |
31978 | 204 |
String core = null; |
205 |
String s = null; |
|
206 |
||
207 |
while((s = sg.next(null, longOpts)) != null) { |
|
208 |
if (s.equals("exe")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
209 |
exe = sg.getOptarg(); |
31978 | 210 |
continue; |
211 |
} |
|
212 |
if (s.equals("core")) { |
|
213 |
core = sg.getOptarg(); |
|
214 |
continue; |
|
215 |
} |
|
216 |
if (s.equals("pid")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
217 |
pid = sg.getOptarg(); |
31978 | 218 |
continue; |
219 |
} |
|
220 |
} |
|
221 |
||
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
222 |
buildAttachArgs(newArgs, pid, exe, core, true); |
31978 | 223 |
HSDB.main(newArgs.toArray(new String[newArgs.size()])); |
224 |
} |
|
225 |
||
226 |
private static void runJSTACK(String[] oldArgs) { |
|
227 |
SAGetopt sg = new SAGetopt(oldArgs); |
|
228 |
String[] longOpts = {"exe=", "core=", "pid=", |
|
229 |
"mixed", "locks"}; |
|
230 |
||
231 |
ArrayList<String> newArgs = new ArrayList(); |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
232 |
String pid = null; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
233 |
String exe = null; |
31978 | 234 |
String core = null; |
235 |
String s = null; |
|
236 |
||
237 |
while((s = sg.next(null, longOpts)) != null) { |
|
238 |
if (s.equals("exe")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
239 |
exe = sg.getOptarg(); |
31978 | 240 |
continue; |
241 |
} |
|
242 |
if (s.equals("core")) { |
|
243 |
core = sg.getOptarg(); |
|
244 |
continue; |
|
245 |
} |
|
246 |
if (s.equals("pid")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
247 |
pid = sg.getOptarg(); |
31978 | 248 |
continue; |
249 |
} |
|
250 |
if (s.equals("mixed")) { |
|
251 |
newArgs.add("-m"); |
|
252 |
continue; |
|
253 |
} |
|
254 |
if (s.equals("locks")) { |
|
255 |
newArgs.add("-l"); |
|
256 |
continue; |
|
257 |
} |
|
258 |
} |
|
259 |
||
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
260 |
buildAttachArgs(newArgs, pid, exe, core, false); |
40380
5e5a194ad1b4
8163185: jhsdb jstack cannot work with normal mode
ysuenaga
parents:
40101
diff
changeset
|
261 |
JStack jstack = new JStack(false, false); |
5e5a194ad1b4
8163185: jhsdb jstack cannot work with normal mode
ysuenaga
parents:
40101
diff
changeset
|
262 |
jstack.runWithArgs(newArgs.toArray(new String[newArgs.size()])); |
31978 | 263 |
} |
264 |
||
265 |
private static void runJMAP(String[] oldArgs) { |
|
266 |
SAGetopt sg = new SAGetopt(oldArgs); |
|
267 |
String[] longOpts = {"exe=", "core=", "pid=", |
|
38264 | 268 |
"heap", "binaryheap", "dumpfile=", "histo", "clstats", "finalizerinfo"}; |
31978 | 269 |
|
270 |
ArrayList<String> newArgs = new ArrayList(); |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
271 |
String pid = null; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
272 |
String exe = null; |
31978 | 273 |
String core = null; |
274 |
String s = null; |
|
38264 | 275 |
String dumpfile = null; |
276 |
boolean requestHeapdump = false; |
|
31978 | 277 |
|
278 |
while((s = sg.next(null, longOpts)) != null) { |
|
279 |
if (s.equals("exe")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
280 |
exe = sg.getOptarg(); |
31978 | 281 |
continue; |
282 |
} |
|
283 |
if (s.equals("core")) { |
|
284 |
core = sg.getOptarg(); |
|
285 |
continue; |
|
286 |
} |
|
287 |
if (s.equals("pid")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
288 |
pid = sg.getOptarg(); |
31978 | 289 |
continue; |
290 |
} |
|
291 |
if (s.equals("heap")) { |
|
292 |
newArgs.add("-heap"); |
|
293 |
continue; |
|
294 |
} |
|
295 |
if (s.equals("binaryheap")) { |
|
38264 | 296 |
requestHeapdump = true; |
297 |
continue; |
|
298 |
} |
|
299 |
if (s.equals("dumpfile")) { |
|
300 |
dumpfile = sg.getOptarg(); |
|
31978 | 301 |
continue; |
302 |
} |
|
303 |
if (s.equals("histo")) { |
|
304 |
newArgs.add("-histo"); |
|
305 |
continue; |
|
306 |
} |
|
307 |
if (s.equals("clstats")) { |
|
308 |
newArgs.add("-clstats"); |
|
309 |
continue; |
|
310 |
} |
|
311 |
if (s.equals("finalizerinfo")) { |
|
312 |
newArgs.add("-finalizerinfo"); |
|
313 |
continue; |
|
314 |
} |
|
315 |
} |
|
316 |
||
38264 | 317 |
if (!requestHeapdump && (dumpfile != null)) { |
318 |
throw new IllegalArgumentException("Unexpected argument dumpfile"); |
|
319 |
} |
|
320 |
if (requestHeapdump) { |
|
321 |
if (dumpfile == null) { |
|
322 |
newArgs.add("-heap:format=b"); |
|
323 |
} else { |
|
324 |
newArgs.add("-heap:format=b,file=" + dumpfile); |
|
325 |
} |
|
326 |
} |
|
327 |
||
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
328 |
buildAttachArgs(newArgs, pid, exe, core, false); |
31978 | 329 |
JMap.main(newArgs.toArray(new String[newArgs.size()])); |
330 |
} |
|
331 |
||
332 |
private static void runJINFO(String[] oldArgs) { |
|
333 |
SAGetopt sg = new SAGetopt(oldArgs); |
|
334 |
String[] longOpts = {"exe=", "core=", "pid=", |
|
335 |
"flags", "sysprops"}; |
|
336 |
||
337 |
ArrayList<String> newArgs = new ArrayList(); |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
338 |
String exe = null; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
339 |
String pid = null; |
31978 | 340 |
String core = null; |
341 |
String s = null; |
|
342 |
||
343 |
while((s = sg.next(null, longOpts)) != null) { |
|
344 |
if (s.equals("exe")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
345 |
exe = sg.getOptarg(); |
31978 | 346 |
continue; |
347 |
} |
|
348 |
if (s.equals("core")) { |
|
349 |
core = sg.getOptarg(); |
|
350 |
continue; |
|
351 |
} |
|
352 |
if (s.equals("pid")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
353 |
pid = sg.getOptarg(); |
31978 | 354 |
continue; |
355 |
} |
|
356 |
if (s.equals("flags")) { |
|
357 |
newArgs.add("-flags"); |
|
358 |
continue; |
|
359 |
} |
|
360 |
if (s.equals("sysprops")) { |
|
361 |
newArgs.add("-sysprops"); |
|
362 |
continue; |
|
363 |
} |
|
364 |
} |
|
365 |
||
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
366 |
buildAttachArgs(newArgs, pid, exe, core, false); |
31978 | 367 |
JInfo.main(newArgs.toArray(new String[newArgs.size()])); |
368 |
} |
|
369 |
||
37090 | 370 |
private static void runJSNAP(String[] oldArgs) { |
371 |
SAGetopt sg = new SAGetopt(oldArgs); |
|
37177 | 372 |
String[] longOpts = {"exe=", "core=", "pid=", "all"}; |
37090 | 373 |
|
374 |
ArrayList<String> newArgs = new ArrayList(); |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
375 |
String exe = null; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
376 |
String pid = null; |
37090 | 377 |
String core = null; |
378 |
String s = null; |
|
379 |
||
380 |
while((s = sg.next(null, longOpts)) != null) { |
|
381 |
if (s.equals("exe")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
382 |
exe = sg.getOptarg(); |
37090 | 383 |
continue; |
384 |
} |
|
385 |
if (s.equals("core")) { |
|
386 |
core = sg.getOptarg(); |
|
387 |
continue; |
|
388 |
} |
|
389 |
if (s.equals("pid")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
390 |
pid = sg.getOptarg(); |
37090 | 391 |
continue; |
392 |
} |
|
37177 | 393 |
if (s.equals("all")) { |
394 |
newArgs.add("-a"); |
|
395 |
continue; |
|
396 |
} |
|
37090 | 397 |
} |
398 |
||
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
399 |
buildAttachArgs(newArgs, pid, exe, core, false); |
37090 | 400 |
JSnap.main(newArgs.toArray(new String[newArgs.size()])); |
401 |
} |
|
402 |
||
40101 | 403 |
private static void runDEBUGD(String[] oldArgs) { |
404 |
// By default SA agent classes prefer Windows process debugger |
|
405 |
// to windbg debugger. SA expects special properties to be set |
|
406 |
// to choose other debuggers. We will set those here before |
|
407 |
// attaching to SA agent. |
|
408 |
System.setProperty("sun.jvm.hotspot.debugger.useWindbgDebugger", "true"); |
|
409 |
||
54917
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
410 |
SAGetopt sg = new SAGetopt(oldArgs); |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
411 |
String[] longOpts = {"exe=", "core=", "pid=", "serverid="}; |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
412 |
|
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
413 |
ArrayList<String> newArgs = new ArrayList<>(); |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
414 |
String exe = null; |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
415 |
String pid = null; |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
416 |
String core = null; |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
417 |
String s = null; |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
418 |
String serverid = null; |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
419 |
|
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
420 |
while((s = sg.next(null, longOpts)) != null) { |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
421 |
if (s.equals("exe")) { |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
422 |
exe = sg.getOptarg(); |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
423 |
continue; |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
424 |
} |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
425 |
if (s.equals("core")) { |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
426 |
core = sg.getOptarg(); |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
427 |
continue; |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
428 |
} |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
429 |
if (s.equals("pid")) { |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
430 |
pid = sg.getOptarg(); |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
431 |
continue; |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
432 |
} |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
433 |
if (s.equals("serverid")) { |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
434 |
serverid = sg.getOptarg(); |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
435 |
continue; |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
436 |
} |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
437 |
} |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
438 |
|
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
439 |
buildAttachArgs(newArgs, pid, exe, core, false); |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
440 |
if (serverid != null) { |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
441 |
newArgs.add(serverid); |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
442 |
} |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
443 |
|
40101 | 444 |
// delegate to the actual SA debug server. |
54917
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
445 |
sun.jvm.hotspot.DebugServer.main(newArgs.toArray(new String[newArgs.size()])); |
40101 | 446 |
} |
447 |
||
31978 | 448 |
public static void main(String[] args) { |
449 |
// Provide a help |
|
450 |
if (args.length == 0) { |
|
451 |
launcherHelp(); |
|
452 |
return; |
|
453 |
} |
|
40101 | 454 |
// No arguments imply help for debugd, jstack, jmap, jinfo but launch clhsdb and hsdb |
31978 | 455 |
if (args.length == 1 && !args[0].equals("clhsdb") && !args[0].equals("hsdb")) { |
456 |
toolHelp(args[0]); |
|
457 |
return; |
|
458 |
} |
|
459 |
||
460 |
for (String arg : args) { |
|
461 |
if (arg.equals("-h") || arg.equals("-help") || arg.equals("--help")) { |
|
462 |
toolHelp(args[0]); |
|
463 |
return; |
|
464 |
} |
|
465 |
} |
|
466 |
||
467 |
String[] oldArgs = Arrays.copyOfRange(args, 1, args.length); |
|
468 |
||
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
469 |
try { |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
470 |
// Run SA interactive mode |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
471 |
if (args[0].equals("clhsdb")) { |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
472 |
runCLHSDB(oldArgs); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
473 |
return; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
474 |
} |
31978 | 475 |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
476 |
if (args[0].equals("hsdb")) { |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
477 |
runHSDB(oldArgs); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
478 |
return; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
479 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
480 |
|
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
481 |
// Run SA tmtools mode |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
482 |
if (args[0].equals("jstack")) { |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
483 |
runJSTACK(oldArgs); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
484 |
return; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
485 |
} |
31978 | 486 |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
487 |
if (args[0].equals("jmap")) { |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
488 |
runJMAP(oldArgs); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
489 |
return; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
490 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
491 |
|
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
492 |
if (args[0].equals("jinfo")) { |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
493 |
runJINFO(oldArgs); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
494 |
return; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
495 |
} |
31978 | 496 |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
497 |
if (args[0].equals("jsnap")) { |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
498 |
runJSNAP(oldArgs); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
499 |
return; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
500 |
} |
31978 | 501 |
|
40101 | 502 |
if (args[0].equals("debugd")) { |
503 |
runDEBUGD(oldArgs); |
|
504 |
return; |
|
505 |
} |
|
506 |
||
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
507 |
throw new SAGetoptException("Unknown tool: " + args[0]); |
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
508 |
} catch (SAGetoptException e) { |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
509 |
System.err.println(e.getMessage()); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
510 |
toolHelp(args[0]); |
37090 | 511 |
} |
31978 | 512 |
} |
513 |
} |