annotate agent/src/share/classes/sun/jvm/hotspot/tools/JInfo.java @ 12932:7fe6ef09d242

8025638: jmap returns 0 instead of 1 when it fails. Summary: Re-factored some code handling return values and fails/errors during tool execution. Reviewed-by: sla, kevinw Contributed-by: fredrik.arvidsson@oracle.com
author farvidsson
date Wed, 16 Oct 2013 09:20:23 +0200
parents 38ea2efa32a7
children b03f33670080
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.tools;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import sun.jvm.hotspot.runtime.*;
11054
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 1552
diff changeset
28 import sun.jvm.hotspot.debugger.JVMDebugger;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 public class JInfo extends Tool {
11054
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 1552
diff changeset
31 public JInfo() {
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 1552
diff changeset
32 super();
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 1552
diff changeset
33 }
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 1552
diff changeset
34
0
a61af66fc99e Initial load
duke
parents:
diff changeset
35 public JInfo(int m) {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 mode = m;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 }
a61af66fc99e Initial load
duke
parents:
diff changeset
38
11054
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 1552
diff changeset
39 public JInfo(JVMDebugger d) {
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 1552
diff changeset
40 super(d);
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 1552
diff changeset
41 }
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 1552
diff changeset
42
0
a61af66fc99e Initial load
duke
parents:
diff changeset
43 protected boolean needsJavaPrefix() {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 public String getName() {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 return "jinfo";
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 protected void printFlagsUsage() {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 System.out.println(" -flags\tto print VM flags");
a61af66fc99e Initial load
duke
parents:
diff changeset
53 System.out.println(" -sysprops\tto print Java System properties");
a61af66fc99e Initial load
duke
parents:
diff changeset
54 System.out.println(" <no option>\tto print both of the above");
a61af66fc99e Initial load
duke
parents:
diff changeset
55 super.printFlagsUsage();
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 public static final int MODE_FLAGS = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 public static final int MODE_SYSPROPS = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 public static final int MODE_BOTH = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 Tool tool = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 switch (mode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 case MODE_FLAGS:
a61af66fc99e Initial load
duke
parents:
diff changeset
66 printVMFlags();
a61af66fc99e Initial load
duke
parents:
diff changeset
67 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 case MODE_SYSPROPS:
a61af66fc99e Initial load
duke
parents:
diff changeset
69 tool = new SysPropsDumper();
a61af66fc99e Initial load
duke
parents:
diff changeset
70 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 case MODE_BOTH: {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 tool = new Tool() {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 Tool sysProps = new SysPropsDumper();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 sysProps.setAgent(getAgent());
a61af66fc99e Initial load
duke
parents:
diff changeset
76 System.out.println("Java System Properties:");
a61af66fc99e Initial load
duke
parents:
diff changeset
77 System.out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
78 sysProps.run();
a61af66fc99e Initial load
duke
parents:
diff changeset
79 System.out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
80 System.out.println("VM Flags:");
a61af66fc99e Initial load
duke
parents:
diff changeset
81 printVMFlags();
a61af66fc99e Initial load
duke
parents:
diff changeset
82 System.out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84 };
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
89 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
90 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92 tool.setAgent(getAgent());
a61af66fc99e Initial load
duke
parents:
diff changeset
93 tool.run();
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 public static void main(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 int mode = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 switch (args.length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 case 1:
a61af66fc99e Initial load
duke
parents:
diff changeset
100 if (args[0].charAt(0) == '-') {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // -h or -help or some invalid flag
a61af66fc99e Initial load
duke
parents:
diff changeset
102 new JInfo(mode).usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
103 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 mode = MODE_BOTH;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 case 2:
a61af66fc99e Initial load
duke
parents:
diff changeset
108 case 3: {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 String modeFlag = args[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
110 if (modeFlag.equals("-flags")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 mode = MODE_FLAGS;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 } else if (modeFlag.equals("-sysprops")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 mode = MODE_SYSPROPS;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 } else if (modeFlag.charAt(0) == '-') {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // -h or -help or some invalid flag
a61af66fc99e Initial load
duke
parents:
diff changeset
116 new JInfo(mode).usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
117 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 mode = MODE_BOTH;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 if (mode != MODE_BOTH) {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // we have to consume first flag argument.
a61af66fc99e Initial load
duke
parents:
diff changeset
123 String[] newArgs = new String[args.length - 1];
a61af66fc99e Initial load
duke
parents:
diff changeset
124 for (int i = 0; i < newArgs.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 newArgs[i] = args[i + 1];
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 args = newArgs;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
133 new JInfo(mode).usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 JInfo jinfo = new JInfo(mode);
12932
7fe6ef09d242 8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents: 11054
diff changeset
137 jinfo.execute(args);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 private void printVMFlags() {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 String str = Arguments.getJVMFlags();
a61af66fc99e Initial load
duke
parents:
diff changeset
142 if (str != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 System.out.println(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145 str = Arguments.getJVMArgs();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 if (str != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 System.out.println(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 private int mode;
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }