author | jdv |
Wed, 18 Apr 2018 13:22:53 +0530 | |
changeset 49996 | 39dc39093c5e |
parent 48543 | 7067fe4e054e |
child 55758 | bbe9c361a477 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
48543
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.tools.jinfo; |
|
27 |
||
28 |
import java.io.IOException; |
|
29 |
import java.io.InputStream; |
|
38361
8ea2d56bfdf3
8154985: Add the ability to use main class as lookup (as jcmd) to jinfo, jmap, jstack
rehn
parents:
38360
diff
changeset
|
30 |
import java.util.Collection; |
2 | 31 |
|
32 |
import com.sun.tools.attach.VirtualMachine; |
|
38956
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
33 |
import com.sun.tools.attach.VirtualMachineDescriptor; |
23058
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
34 |
|
2 | 35 |
import sun.tools.attach.HotSpotVirtualMachine; |
38361
8ea2d56bfdf3
8154985: Add the ability to use main class as lookup (as jcmd) to jinfo, jmap, jstack
rehn
parents:
38360
diff
changeset
|
36 |
import sun.tools.common.ProcessArgumentMatcher; |
2 | 37 |
|
38 |
/* |
|
39 |
* This class is the main class for the JInfo utility. It parses its arguments |
|
21278 | 40 |
* and decides if the command should be satisfied using the VM attach mechanism |
23058
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
41 |
* or an SA tool. |
2 | 42 |
*/ |
23939
63144ee0e772
8039080: "jinfo server_id@host" fails with "Invalid process identifier"
jbachorik
parents:
23740
diff
changeset
|
43 |
final public class JInfo { |
2 | 44 |
|
38360
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
45 |
public static void main(String[] args) throws Exception { |
2 | 46 |
if (args.length == 0) { |
38360
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
47 |
usage(1); // no arguments |
2 | 48 |
} |
38360
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
49 |
checkForUnsupportedOptions(args); |
2 | 50 |
|
38360
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
51 |
boolean doFlag = false; |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
52 |
boolean doFlags = false; |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
53 |
boolean doSysprops = false; |
38956
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
54 |
int flag = -1; |
38360
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
55 |
|
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
56 |
// Parse the options (arguments starting with "-" ) |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
57 |
int optionCount = 0; |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
58 |
while (optionCount < args.length) { |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
59 |
String arg = args[optionCount]; |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
60 |
if (!arg.startsWith("-")) { |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
61 |
break; |
2 | 62 |
} |
38360
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
63 |
|
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
64 |
optionCount++; |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
65 |
|
48543
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
47216
diff
changeset
|
66 |
if (arg.equals("-?") || |
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
47216
diff
changeset
|
67 |
arg.equals("-h") || |
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
47216
diff
changeset
|
68 |
arg.equals("--help") || |
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
47216
diff
changeset
|
69 |
// -help: legacy. |
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
47216
diff
changeset
|
70 |
arg.equals("-help")) { |
38360
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
71 |
usage(0); |
23058
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
72 |
} |
38360
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
73 |
|
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
74 |
if (arg.equals("-flag")) { |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
75 |
doFlag = true; |
38956
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
76 |
// Consume the flag |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
77 |
if (optionCount < args.length) { |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
78 |
flag = optionCount++; |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
79 |
break; |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
80 |
} |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
81 |
usage(1); |
23939
63144ee0e772
8039080: "jinfo server_id@host" fails with "Invalid process identifier"
jbachorik
parents:
23740
diff
changeset
|
82 |
} |
38360
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
83 |
|
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
84 |
if (arg.equals("-flags")) { |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
85 |
doFlags = true; |
38956
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
86 |
break; |
23939
63144ee0e772
8039080: "jinfo server_id@host" fails with "Invalid process identifier"
jbachorik
parents:
23740
diff
changeset
|
87 |
} |
63144ee0e772
8039080: "jinfo server_id@host" fails with "Invalid process identifier"
jbachorik
parents:
23740
diff
changeset
|
88 |
|
38360
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
89 |
if (arg.equals("-sysprops")) { |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
90 |
doSysprops = true; |
38956
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
91 |
break; |
38360
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
92 |
} |
2 | 93 |
} |
94 |
||
38360
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
95 |
int paramCount = args.length - optionCount; |
38956
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
96 |
if (paramCount != 1) { |
38360
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
97 |
usage(1); |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
98 |
} |
23058
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
99 |
|
38956
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
100 |
String parg = args[optionCount]; |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
101 |
|
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
102 |
ProcessArgumentMatcher ap = new ProcessArgumentMatcher(parg); |
44422
14ab3266fe62
8176533: REGRESSION: a java process is not recognized by jcmd/jinfo/jstack/jmap tool
rehn
parents:
38956
diff
changeset
|
103 |
Collection<String> pids = ap.getVirtualMachinePids(JInfo.class); |
38956
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
104 |
|
44422
14ab3266fe62
8176533: REGRESSION: a java process is not recognized by jcmd/jinfo/jstack/jmap tool
rehn
parents:
38956
diff
changeset
|
105 |
if (pids.isEmpty()) { |
38956
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
106 |
System.err.println("Could not find any processes matching : '" + parg + "'"); |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
107 |
System.exit(1); |
38360
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
108 |
} |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
109 |
|
44422
14ab3266fe62
8176533: REGRESSION: a java process is not recognized by jcmd/jinfo/jstack/jmap tool
rehn
parents:
38956
diff
changeset
|
110 |
for (String pid : pids) { |
14ab3266fe62
8176533: REGRESSION: a java process is not recognized by jcmd/jinfo/jstack/jmap tool
rehn
parents:
38956
diff
changeset
|
111 |
if (pids.size() > 1) { |
14ab3266fe62
8176533: REGRESSION: a java process is not recognized by jcmd/jinfo/jstack/jmap tool
rehn
parents:
38956
diff
changeset
|
112 |
System.out.println("Pid:" + pid); |
38956
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
113 |
} |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
114 |
if (!doFlag && !doFlags && !doSysprops) { |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
115 |
// Print flags and sysporps if no options given |
44422
14ab3266fe62
8176533: REGRESSION: a java process is not recognized by jcmd/jinfo/jstack/jmap tool
rehn
parents:
38956
diff
changeset
|
116 |
sysprops(pid); |
38956
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
117 |
System.out.println(); |
44422
14ab3266fe62
8176533: REGRESSION: a java process is not recognized by jcmd/jinfo/jstack/jmap tool
rehn
parents:
38956
diff
changeset
|
118 |
flags(pid); |
38956
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
119 |
System.out.println(); |
44422
14ab3266fe62
8176533: REGRESSION: a java process is not recognized by jcmd/jinfo/jstack/jmap tool
rehn
parents:
38956
diff
changeset
|
120 |
commandLine(pid); |
38361
8ea2d56bfdf3
8154985: Add the ability to use main class as lookup (as jcmd) to jinfo, jmap, jstack
rehn
parents:
38360
diff
changeset
|
121 |
} |
38956
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
122 |
if (doFlag) { |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
123 |
if (flag < 0) { |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
124 |
System.err.println("Missing flag"); |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
125 |
usage(1); |
38361
8ea2d56bfdf3
8154985: Add the ability to use main class as lookup (as jcmd) to jinfo, jmap, jstack
rehn
parents:
38360
diff
changeset
|
126 |
} |
44422
14ab3266fe62
8176533: REGRESSION: a java process is not recognized by jcmd/jinfo/jstack/jmap tool
rehn
parents:
38956
diff
changeset
|
127 |
flag(pid, args[flag]); |
38956
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
128 |
} |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
129 |
if (doFlags) { |
44422
14ab3266fe62
8176533: REGRESSION: a java process is not recognized by jcmd/jinfo/jstack/jmap tool
rehn
parents:
38956
diff
changeset
|
130 |
flags(pid); |
38956
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
131 |
} |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
38361
diff
changeset
|
132 |
if (doSysprops) { |
44422
14ab3266fe62
8176533: REGRESSION: a java process is not recognized by jcmd/jinfo/jstack/jmap tool
rehn
parents:
38956
diff
changeset
|
133 |
sysprops(pid); |
2 | 134 |
} |
135 |
} |
|
136 |
} |
|
137 |
||
138 |
private static void flag(String pid, String option) throws IOException { |
|
23058
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
139 |
HotSpotVirtualMachine vm = (HotSpotVirtualMachine) attach(pid); |
2 | 140 |
String flag; |
141 |
InputStream in; |
|
142 |
int index = option.indexOf('='); |
|
143 |
if (index != -1) { |
|
144 |
flag = option.substring(0, index); |
|
145 |
String value = option.substring(index + 1); |
|
23058
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
146 |
in = vm.setFlag(flag, value); |
2 | 147 |
} else { |
148 |
char c = option.charAt(0); |
|
149 |
switch (c) { |
|
150 |
case '+': |
|
151 |
flag = option.substring(1); |
|
23058
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
152 |
in = vm.setFlag(flag, "1"); |
2 | 153 |
break; |
154 |
case '-': |
|
155 |
flag = option.substring(1); |
|
23058
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
156 |
in = vm.setFlag(flag, "0"); |
2 | 157 |
break; |
158 |
default: |
|
159 |
flag = option; |
|
23058
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
160 |
in = vm.printFlag(flag); |
2 | 161 |
break; |
162 |
} |
|
163 |
} |
|
164 |
||
165 |
drain(vm, in); |
|
166 |
} |
|
167 |
||
23058
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
168 |
private static void flags(String pid) throws IOException { |
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
169 |
HotSpotVirtualMachine vm = (HotSpotVirtualMachine) attach(pid); |
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
170 |
InputStream in = vm.executeJCmd("VM.flags"); |
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
171 |
System.out.println("VM Flags:"); |
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
172 |
drain(vm, in); |
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
173 |
} |
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
174 |
|
24569 | 175 |
private static void commandLine(String pid) throws IOException { |
176 |
HotSpotVirtualMachine vm = (HotSpotVirtualMachine) attach(pid); |
|
177 |
InputStream in = vm.executeJCmd("VM.command_line"); |
|
178 |
drain(vm, in); |
|
179 |
} |
|
180 |
||
23058
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
181 |
private static void sysprops(String pid) throws IOException { |
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
182 |
HotSpotVirtualMachine vm = (HotSpotVirtualMachine) attach(pid); |
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
183 |
InputStream in = vm.executeJCmd("VM.system_properties"); |
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
184 |
System.out.println("Java System Properties:"); |
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
185 |
drain(vm, in); |
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
186 |
} |
2e261b4319e9
8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents:
23010
diff
changeset
|
187 |
|
2 | 188 |
// Attach to <pid>, exiting if we fail to attach |
189 |
private static VirtualMachine attach(String pid) { |
|
190 |
try { |
|
191 |
return VirtualMachine.attach(pid); |
|
192 |
} catch (Exception x) { |
|
193 |
String msg = x.getMessage(); |
|
194 |
if (msg != null) { |
|
195 |
System.err.println(pid + ": " + msg); |
|
196 |
} else { |
|
197 |
x.printStackTrace(); |
|
198 |
} |
|
199 |
System.exit(1); |
|
200 |
return null; // keep compiler happy |
|
201 |
} |
|
202 |
} |
|
203 |
||
204 |
// Read the stream from the target VM until EOF, then detach |
|
205 |
private static void drain(VirtualMachine vm, InputStream in) throws IOException { |
|
206 |
// read to EOF and just print output |
|
207 |
byte b[] = new byte[256]; |
|
208 |
int n; |
|
209 |
do { |
|
210 |
n = in.read(b); |
|
211 |
if (n > 0) { |
|
212 |
String s = new String(b, 0, n, "UTF-8"); |
|
213 |
System.out.print(s); |
|
214 |
} |
|
215 |
} while (n > 0); |
|
216 |
in.close(); |
|
217 |
vm.detach(); |
|
218 |
} |
|
219 |
||
38360
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
220 |
private static void checkForUnsupportedOptions(String[] args) { |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
221 |
// Check arguments for -F, and non-numeric value |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
222 |
// and warn the user that SA is not supported anymore |
38361
8ea2d56bfdf3
8154985: Add the ability to use main class as lookup (as jcmd) to jinfo, jmap, jstack
rehn
parents:
38360
diff
changeset
|
223 |
int maxCount = 1; |
38360
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
224 |
int paramCount = 0; |
2 | 225 |
|
38360
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
226 |
for (String s : args) { |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
227 |
if (s.equals("-F")) { |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
228 |
SAOptionError("-F option used"); |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
229 |
} |
38361
8ea2d56bfdf3
8154985: Add the ability to use main class as lookup (as jcmd) to jinfo, jmap, jstack
rehn
parents:
38360
diff
changeset
|
230 |
if (s.equals("-flag")) { |
8ea2d56bfdf3
8154985: Add the ability to use main class as lookup (as jcmd) to jinfo, jmap, jstack
rehn
parents:
38360
diff
changeset
|
231 |
maxCount = 2; |
8ea2d56bfdf3
8154985: Add the ability to use main class as lookup (as jcmd) to jinfo, jmap, jstack
rehn
parents:
38360
diff
changeset
|
232 |
} |
38360
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
233 |
if (! s.startsWith("-")) { |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
234 |
paramCount += 1; |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
235 |
} |
2 | 236 |
} |
237 |
||
38361
8ea2d56bfdf3
8154985: Add the ability to use main class as lookup (as jcmd) to jinfo, jmap, jstack
rehn
parents:
38360
diff
changeset
|
238 |
if (paramCount > maxCount) { |
8ea2d56bfdf3
8154985: Add the ability to use main class as lookup (as jcmd) to jinfo, jmap, jstack
rehn
parents:
38360
diff
changeset
|
239 |
SAOptionError("More than " + maxCount + " non-option argument"); |
38360
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
240 |
} |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
241 |
} |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
242 |
|
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
243 |
private static void SAOptionError(String msg) { |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
244 |
System.err.println("Error: " + msg); |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
245 |
System.err.println("Cannot connect to core dump or remote debug server. Use jhsdb jinfo instead"); |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
246 |
System.exit(1); |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
247 |
} |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
248 |
|
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
249 |
// print usage message |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
250 |
private static void usage(int exit) { |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
251 |
System.err.println("Usage:"); |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
252 |
System.err.println(" jinfo <option> <pid>"); |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
253 |
System.err.println(" (to connect to a running process)"); |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
254 |
System.err.println(""); |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
255 |
System.err.println("where <option> is one of:"); |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
256 |
System.err.println(" -flag <name> to print the value of the named VM flag"); |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
257 |
System.err.println(" -flag [+|-]<name> to enable or disable the named VM flag"); |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
258 |
System.err.println(" -flag <name>=<value> to set the named VM flag to the given value"); |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
259 |
System.err.println(" -flags to print VM flags"); |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
260 |
System.err.println(" -sysprops to print Java system properties"); |
fb63be22ffa6
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36511
diff
changeset
|
261 |
System.err.println(" <no option> to print both VM flags and system properties"); |
48543
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
47216
diff
changeset
|
262 |
System.err.println(" -? | -h | --help | -help to print this help message"); |
21673
c5d341bc60dd
8027765: Make exit codes and stdout/stderr printing from jmap/jinfo/jstack/jps consistent
sla
parents:
21278
diff
changeset
|
263 |
System.exit(exit); |
2 | 264 |
} |
265 |
} |