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