author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 57794 | ffdb18fb88b9 |
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; |
|
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
29 |
import java.util.ArrayList; |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
30 |
import java.util.HashMap; |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
31 |
import java.util.List; |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
32 |
import java.util.Map; |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
33 |
import java.util.function.Consumer; |
31978 | 34 |
|
35 |
import sun.jvm.hotspot.tools.JStack; |
|
36 |
import sun.jvm.hotspot.tools.JMap; |
|
37 |
import sun.jvm.hotspot.tools.JInfo; |
|
37090 | 38 |
import sun.jvm.hotspot.tools.JSnap; |
31978 | 39 |
|
40 |
public class SALauncher { |
|
41 |
||
42 |
private static boolean launcherHelp() { |
|
43 |
System.out.println(" clhsdb \tcommand line debugger"); |
|
44 |
System.out.println(" hsdb \tui debugger"); |
|
54917
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
45 |
System.out.println(" debugd --help\tto get more information"); |
31978 | 46 |
System.out.println(" jstack --help\tto get more information"); |
47 |
System.out.println(" jmap --help\tto get more information"); |
|
48 |
System.out.println(" jinfo --help\tto get more information"); |
|
37090 | 49 |
System.out.println(" jsnap --help\tto get more information"); |
31978 | 50 |
return false; |
51 |
} |
|
52 |
||
55073
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
53 |
private static boolean commonHelp(String mode) { |
55650
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
54 |
return commonHelp(mode, false); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
55 |
} |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
56 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
57 |
private static boolean commonHelpWithConnect(String mode) { |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
58 |
return commonHelp(mode, true); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
59 |
} |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
60 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
61 |
private static boolean commonHelp(String mode, boolean canConnectToRemote) { |
31978 | 62 |
// --pid <pid> |
63 |
// --exe <exe> |
|
64 |
// --core <core> |
|
55650
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
65 |
// --connect [<id>@]<host> |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
66 |
System.out.println(" --pid <pid> To attach to and operate on the given live process."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
67 |
System.out.println(" --core <corefile> To operate on the given core file."); |
55073
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
68 |
System.out.println(" --exe <executable for corefile>"); |
55650
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
69 |
if (canConnectToRemote) { |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
70 |
System.out.println(" --connect [<id>@]<host> To connect to a remote debug server (debugd)."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
71 |
} |
55073
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
72 |
System.out.println(); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
73 |
System.out.println(" The --core and --exe options must be set together to give the core"); |
55650
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
74 |
System.out.println(" file, and associated executable, to operate on. They can use"); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
75 |
System.out.println(" absolute or relative paths."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
76 |
System.out.println(" The --pid option can be set to operate on a live process."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
77 |
if (canConnectToRemote) { |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
78 |
System.out.println(" The --connect option can be set to connect to a debug server (debugd)."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
79 |
System.out.println(" --core, --pid, and --connect are mutually exclusive."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
80 |
} else { |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
81 |
System.out.println(" --core and --pid are mutually exclusive."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
82 |
} |
55073
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
83 |
System.out.println(); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
84 |
System.out.println(" Examples: jhsdb " + mode + " --pid 1234"); |
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
85 |
System.out.println(" or jhsdb " + mode + " --core ./core.1234 --exe ./myexe"); |
55650
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
86 |
if (canConnectToRemote) { |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
87 |
System.out.println(" or jhsdb " + mode + " --connect debugserver"); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
88 |
System.out.println(" or jhsdb " + mode + " --connect id@debugserver"); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
89 |
} |
31978 | 90 |
return false; |
91 |
} |
|
92 |
||
40101 | 93 |
private static boolean debugdHelp() { |
94 |
// [options] <pid> [server-id] |
|
95 |
// [options] <executable> <core> [server-id] |
|
55650
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
96 |
System.out.println(" --serverid <id> A unique identifier for this debug server."); |
55073
f4702c8c9b3f
8223814: SA: jhsdb common help needs to be more detailed
ysuenaga
parents:
54917
diff
changeset
|
97 |
return commonHelp("debugd"); |
40101 | 98 |
} |
99 |
||
31978 | 100 |
private static boolean jinfoHelp() { |
101 |
// --flags -> -flags |
|
102 |
// --sysprops -> -sysprops |
|
55650
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
103 |
System.out.println(" --flags To print VM flags."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
104 |
System.out.println(" --sysprops To print Java System properties."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
105 |
System.out.println(" <no option> To print both of the above."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
106 |
return commonHelpWithConnect("jinfo"); |
31978 | 107 |
} |
108 |
||
109 |
private static boolean jmapHelp() { |
|
110 |
// --heap -> -heap |
|
111 |
// --binaryheap -> -heap:format=b |
|
112 |
// --histo -> -histo |
|
113 |
// --clstats -> -clstats |
|
114 |
// --finalizerinfo -> -finalizerinfo |
|
115 |
||
55650
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
116 |
System.out.println(" <no option> To print same info as Solaris pmap."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
117 |
System.out.println(" --heap To print java heap summary."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
118 |
System.out.println(" --binaryheap To dump java heap in hprof binary format."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
119 |
System.out.println(" --dumpfile <name> The name of the dump file."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
120 |
System.out.println(" --histo To print histogram of java object heap."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
121 |
System.out.println(" --clstats To print class loader statistics."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
122 |
System.out.println(" --finalizerinfo To print information on objects awaiting finalization."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
123 |
return commonHelpWithConnect("jmap"); |
31978 | 124 |
} |
125 |
||
126 |
private static boolean jstackHelp() { |
|
127 |
// --locks -> -l |
|
128 |
// --mixed -> -m |
|
55650
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
129 |
System.out.println(" --locks To print java.util.concurrent locks."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
130 |
System.out.println(" --mixed To print both Java and native frames (mixed mode)."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
131 |
return commonHelpWithConnect("jstack"); |
31978 | 132 |
} |
133 |
||
37090 | 134 |
private static boolean jsnapHelp() { |
55650
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
135 |
System.out.println(" --all To print all performance counters."); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
136 |
return commonHelpWithConnect("jsnap"); |
37090 | 137 |
} |
138 |
||
31978 | 139 |
private static boolean toolHelp(String toolName) { |
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
140 |
switch (toolName) { |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
141 |
case "jstack": |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
142 |
return jstackHelp(); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
143 |
case "jinfo": |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
144 |
return jinfoHelp(); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
145 |
case "jmap": |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
146 |
return jmapHelp(); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
147 |
case "jsnap": |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
148 |
return jsnapHelp(); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
149 |
case "debugd": |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
150 |
return debugdHelp(); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
151 |
case "hsdb": |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
152 |
case "clhsdb": |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
153 |
return commonHelp(toolName); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
154 |
default: |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
155 |
return launcherHelp(); |
31978 | 156 |
} |
157 |
} |
|
158 |
||
55650
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
159 |
private static final String NO_REMOTE = null; |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
160 |
|
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
161 |
private static String[] buildAttachArgs(Map<String, String> newArgMap, |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
162 |
boolean allowEmpty) { |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
163 |
String pid = newArgMap.remove("pid"); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
164 |
String exe = newArgMap.remove("exe"); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
165 |
String core = newArgMap.remove("core"); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
166 |
String connect = newArgMap.remove("connect"); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
167 |
if (!allowEmpty && (pid == null) && (exe == null) && (connect == NO_REMOTE)) { |
55650
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
168 |
throw new SAGetoptException("You have to set --pid or --exe or --connect."); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
169 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
170 |
|
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
171 |
List<String> newArgs = new ArrayList<>(); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
172 |
for (var entry : newArgMap.entrySet()) { |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
173 |
newArgs.add(entry.getKey()); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
174 |
if (entry.getValue() != null) { |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
175 |
newArgs.add(entry.getValue()); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
176 |
} |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
177 |
} |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
178 |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
179 |
if (pid != null) { // Attach to live process |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
180 |
if (exe != null) { |
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
181 |
throw new SAGetoptException("Unnecessary argument: --exe"); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
182 |
} else if (core != null) { |
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
183 |
throw new SAGetoptException("Unnecessary argument: --core"); |
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
184 |
} else if (connect != NO_REMOTE) { |
55650
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
185 |
throw new SAGetoptException("Unnecessary argument: --connect"); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
186 |
} else if (!pid.matches("^\\d+$")) { |
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
187 |
throw new SAGetoptException("Invalid pid: " + pid); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
188 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
189 |
|
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
190 |
newArgs.add(pid); |
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
191 |
} else if (exe != null) { |
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
192 |
if (connect != NO_REMOTE) { |
55650
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
193 |
throw new SAGetoptException("Unnecessary argument: --connect"); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
55073
diff
changeset
|
194 |
} else if (exe.length() == 0) { |
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
195 |
throw new SAGetoptException("You have to set --exe."); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
196 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
197 |
|
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
198 |
newArgs.add(exe); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
199 |
|
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
200 |
if ((core == null) || (core.length() == 0)) { |
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
201 |
throw new SAGetoptException("You have to set --core."); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
202 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
203 |
|
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
204 |
newArgs.add(core); |
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
205 |
} else if (connect != NO_REMOTE) { |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
206 |
newArgs.add(connect); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
207 |
} |
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
208 |
|
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
209 |
return newArgs.toArray(new String[0]); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
210 |
} |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
211 |
|
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
212 |
/** |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
213 |
* This method converts jhsdb-style options (oldArgs) to old fashioned |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
214 |
* style. SALauncher delegates the work to the entry point of each tool. |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
215 |
* Thus we need to convert the arguments. |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
216 |
* For example, `jhsdb jstack --mixed` needs to be converted to `jstack -m`. |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
217 |
* |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
218 |
* longOptsMap holds the rule how this method should convert the args. |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
219 |
* The key is the name of jhsdb style, the value is the name of |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
220 |
* old fashioned style. If you want to convert mixed option in jstack, |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
221 |
* you need to set "mixed" to the key, and to set "-m" to the value |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
222 |
* in longOptsMap. If the option have the value, you need to add "=" to |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
223 |
* the key like "exe=". |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
224 |
* |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
225 |
* You also can set the options which cannot be mapped to old fashioned |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
226 |
* arguments. For example, `jhsdb jmap --binaryheap` cannot be mapped to |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
227 |
* `jmap` option directly. But you set it to longOptsMap, then you can know |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
228 |
* the user sets "binaryheap" option, and SALauncher should set |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
229 |
* "-heap:format:b" to jmap option. |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
230 |
* |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
231 |
* This method returns the map of the old fashioned key/val pairs. |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
232 |
* It can be used to build args in string array at buildAttachArgs(). |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
233 |
*/ |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
234 |
private static Map<String, String> parseOptions(String[] oldArgs, |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
235 |
Map<String, String> longOptsMap) { |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
236 |
SAGetopt sg = new SAGetopt(oldArgs); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
237 |
String[] longOpts = longOptsMap.keySet().toArray(new String[0]); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
238 |
Map<String, String> newArgMap = new HashMap<>(); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
239 |
|
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
240 |
/* |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
241 |
* Parse each jhsdb-style option via SAGetopt. |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
242 |
* SAGetopt parses and validates the argument. If the user passes invalid |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
243 |
* option, SAGetoptException will be occurred at SAGetopt::next. |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
244 |
* Thus there is no need to validate it here. |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
245 |
* |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
246 |
* We can get option value via SAGetopt::get. If jhsdb-style option has |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
247 |
* '=' at the tail, we put old fashioned option with it to newArgMap. |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
248 |
*/ |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
249 |
String s; |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
250 |
while ((s = sg.next(null, longOpts)) != null) { |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
251 |
var val = longOptsMap.get(s); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
252 |
if (val != null) { |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
253 |
newArgMap.put(val, null); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
254 |
} else { |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
255 |
val = longOptsMap.get(s + "="); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
256 |
if (val != null) { |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
257 |
newArgMap.put(val, sg.getOptarg()); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
258 |
} |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
259 |
} |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
260 |
} |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
261 |
|
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
262 |
return newArgMap; |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
263 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
264 |
|
31978 | 265 |
private static void runCLHSDB(String[] oldArgs) { |
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
266 |
Map<String, String> longOptsMap = Map.of("exe=", "exe", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
267 |
"core=", "core", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
268 |
"pid=", "pid"); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
269 |
Map<String, String> newArgMap = parseOptions(oldArgs, longOptsMap); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
270 |
CLHSDB.main(buildAttachArgs(newArgMap, true)); |
31978 | 271 |
} |
272 |
||
273 |
private static void runHSDB(String[] oldArgs) { |
|
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
274 |
Map<String, String> longOptsMap = Map.of("exe=", "exe", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
275 |
"core=", "core", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
276 |
"pid=", "pid"); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
277 |
Map<String, String> newArgMap = parseOptions(oldArgs, longOptsMap); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
278 |
HSDB.main(buildAttachArgs(newArgMap, true)); |
31978 | 279 |
} |
280 |
||
281 |
private static void runJSTACK(String[] oldArgs) { |
|
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
282 |
Map<String, String> longOptsMap = Map.of("exe=", "exe", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
283 |
"core=", "core", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
284 |
"pid=", "pid", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
285 |
"connect=", "connect", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
286 |
"mixed", "-m", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
287 |
"locks", "-l"); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
288 |
Map<String, String> newArgMap = parseOptions(oldArgs, longOptsMap); |
40380
5e5a194ad1b4
8163185: jhsdb jstack cannot work with normal mode
ysuenaga
parents:
40101
diff
changeset
|
289 |
JStack jstack = new JStack(false, false); |
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
290 |
jstack.runWithArgs(buildAttachArgs(newArgMap, false)); |
31978 | 291 |
} |
292 |
||
293 |
private static void runJMAP(String[] oldArgs) { |
|
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
294 |
Map<String, String> longOptsMap = Map.of("exe=", "exe", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
295 |
"core=", "core", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
296 |
"pid=", "pid", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
297 |
"connect=", "connect", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
298 |
"heap", "-heap", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
299 |
"binaryheap", "binaryheap", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
300 |
"dumpfile=", "dumpfile", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
301 |
"histo", "-histo", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
302 |
"clstats", "-clstats", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
303 |
"finalizerinfo", "-finalizerinfo"); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
304 |
Map<String, String> newArgMap = parseOptions(oldArgs, longOptsMap); |
31978 | 305 |
|
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
306 |
boolean requestHeapdump = newArgMap.containsKey("binaryheap"); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
307 |
String dumpfile = newArgMap.get("dumpfile"); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
308 |
if (!requestHeapdump && (dumpfile != null)) { |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
309 |
throw new IllegalArgumentException("Unexpected argument: dumpfile"); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
310 |
} |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
311 |
if (requestHeapdump) { |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
312 |
if (dumpfile == null) { |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
313 |
newArgMap.put("-heap:format=b", null); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
314 |
} else { |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
315 |
newArgMap.put("-heap:format=b,file=" + dumpfile, null); |
31978 | 316 |
} |
317 |
} |
|
318 |
||
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
319 |
newArgMap.remove("binaryheap"); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
320 |
newArgMap.remove("dumpfile"); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
321 |
JMap.main(buildAttachArgs(newArgMap, false)); |
31978 | 322 |
} |
323 |
||
324 |
private static void runJINFO(String[] oldArgs) { |
|
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
325 |
Map<String, String> longOptsMap = Map.of("exe=", "exe", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
326 |
"core=", "core", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
327 |
"pid=", "pid", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
328 |
"connect=", "connect", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
329 |
"flags", "-flags", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
330 |
"sysprops", "-sysprops"); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
331 |
Map<String, String> newArgMap = parseOptions(oldArgs, longOptsMap); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
332 |
JInfo.main(buildAttachArgs(newArgMap, false)); |
31978 | 333 |
} |
334 |
||
37090 | 335 |
private static void runJSNAP(String[] oldArgs) { |
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
336 |
Map<String, String> longOptsMap = Map.of("exe=", "exe", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
337 |
"core=", "core", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
338 |
"pid=", "pid", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
339 |
"connect=", "connect", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
340 |
"all", "-a"); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
341 |
Map<String, String> newArgMap = parseOptions(oldArgs, longOptsMap); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
342 |
JSnap.main(buildAttachArgs(newArgMap, false)); |
37090 | 343 |
} |
344 |
||
40101 | 345 |
private static void runDEBUGD(String[] oldArgs) { |
346 |
// By default SA agent classes prefer Windows process debugger |
|
347 |
// to windbg debugger. SA expects special properties to be set |
|
348 |
// to choose other debuggers. We will set those here before |
|
349 |
// attaching to SA agent. |
|
350 |
System.setProperty("sun.jvm.hotspot.debugger.useWindbgDebugger", "true"); |
|
351 |
||
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
352 |
Map<String, String> longOptsMap = Map.of("exe=", "exe", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
353 |
"core=", "core", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
354 |
"pid=", "pid", |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
355 |
"serverid=", "serverid"); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
356 |
Map<String, String> newArgMap = parseOptions(oldArgs, longOptsMap); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
357 |
var serverid = newArgMap.remove("serverid"); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
358 |
List<String> newArgArray = new ArrayList<>(); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
359 |
newArgArray.addAll(Arrays.asList(buildAttachArgs(newArgMap, false))); |
54917
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
360 |
|
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
361 |
// `serverid` must be located at the tail. |
54917
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
362 |
if (serverid != null) { |
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
363 |
newArgArray.add(serverid); |
54917
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
364 |
} |
81852d53e585
8223665: SA: debugd options should follow jhsdb style
ysuenaga
parents:
47216
diff
changeset
|
365 |
|
40101 | 366 |
// delegate to the actual SA debug server. |
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
367 |
DebugServer.main(newArgArray.toArray(new String[0])); |
40101 | 368 |
} |
369 |
||
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
370 |
// Key: tool name, Value: launcher method |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
371 |
private static Map<String, Consumer<String[]>> toolMap = |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
372 |
Map.of("clhsdb", SALauncher::runCLHSDB, |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
373 |
"hsdb", SALauncher::runHSDB, |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
374 |
"jstack", SALauncher::runJSTACK, |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
375 |
"jmap", SALauncher::runJMAP, |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
376 |
"jinfo", SALauncher::runJINFO, |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
377 |
"jsnap", SALauncher::runJSNAP, |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
378 |
"debugd", SALauncher::runDEBUGD); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
379 |
|
31978 | 380 |
public static void main(String[] args) { |
381 |
// Provide a help |
|
382 |
if (args.length == 0) { |
|
383 |
launcherHelp(); |
|
384 |
return; |
|
385 |
} |
|
40101 | 386 |
// No arguments imply help for debugd, jstack, jmap, jinfo but launch clhsdb and hsdb |
31978 | 387 |
if (args.length == 1 && !args[0].equals("clhsdb") && !args[0].equals("hsdb")) { |
388 |
toolHelp(args[0]); |
|
389 |
return; |
|
390 |
} |
|
391 |
||
392 |
for (String arg : args) { |
|
393 |
if (arg.equals("-h") || arg.equals("-help") || arg.equals("--help")) { |
|
394 |
toolHelp(args[0]); |
|
395 |
return; |
|
396 |
} |
|
397 |
} |
|
398 |
||
399 |
String[] oldArgs = Arrays.copyOfRange(args, 1, args.length); |
|
400 |
||
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
401 |
try { |
57794
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
402 |
var func = toolMap.get(args[0]); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
403 |
if (func == null) { |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
404 |
throw new SAGetoptException("Unknown tool: " + args[0]); |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
405 |
} else { |
ffdb18fb88b9
8226204: SA: Refactoring for option processing in SALauncher
ysuenaga
parents:
55650
diff
changeset
|
406 |
func.accept(oldArgs); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
407 |
} |
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
408 |
} catch (SAGetoptException e) { |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
409 |
System.err.println(e.getMessage()); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
410 |
toolHelp(args[0]); |
37090 | 411 |
} |
31978 | 412 |
} |
413 |
} |