annotate agent/src/share/classes/sun/jvm/hotspot/tools/JInfo.java @ 13387:b03f33670080

6606002: jinfo doesn't detect dynamic vm flags changing Reviewed-by: coleenp, jbachorik, sspitsyn
author sla
date Thu, 14 Nov 2013 19:30:07 +0100
parents 7fe6ef09d242
children de6a9e811145
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
11054
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 1552
diff changeset
27 import sun.jvm.hotspot.debugger.JVMDebugger;
13387
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
28 import sun.jvm.hotspot.runtime.Arguments;
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
29 import sun.jvm.hotspot.runtime.VM;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 public class JInfo extends Tool {
11054
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 1552
diff changeset
32 public JInfo() {
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 1552
diff changeset
33 super();
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 1552
diff changeset
34 }
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 1552
diff changeset
35
0
a61af66fc99e Initial load
duke
parents:
diff changeset
36 public JInfo(int m) {
a61af66fc99e Initial load
duke
parents:
diff changeset
37 mode = m;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 }
a61af66fc99e Initial load
duke
parents:
diff changeset
39
11054
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 1552
diff changeset
40 public JInfo(JVMDebugger d) {
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 1552
diff changeset
41 super(d);
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 1552
diff changeset
42 }
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 1552
diff changeset
43
0
a61af66fc99e Initial load
duke
parents:
diff changeset
44 protected boolean needsJavaPrefix() {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 }
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 public String getName() {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 return "jinfo";
a61af66fc99e Initial load
duke
parents:
diff changeset
50 }
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 protected void printFlagsUsage() {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 System.out.println(" -flags\tto print VM flags");
a61af66fc99e Initial load
duke
parents:
diff changeset
54 System.out.println(" -sysprops\tto print Java System properties");
a61af66fc99e Initial load
duke
parents:
diff changeset
55 System.out.println(" <no option>\tto print both of the above");
a61af66fc99e Initial load
duke
parents:
diff changeset
56 super.printFlagsUsage();
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 public static final int MODE_FLAGS = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 public static final int MODE_SYSPROPS = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 public static final int MODE_BOTH = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 Tool tool = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 switch (mode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 case MODE_FLAGS:
a61af66fc99e Initial load
duke
parents:
diff changeset
67 printVMFlags();
a61af66fc99e Initial load
duke
parents:
diff changeset
68 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 case MODE_SYSPROPS:
a61af66fc99e Initial load
duke
parents:
diff changeset
70 tool = new SysPropsDumper();
a61af66fc99e Initial load
duke
parents:
diff changeset
71 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 case MODE_BOTH: {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 tool = new Tool() {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 Tool sysProps = new SysPropsDumper();
a61af66fc99e Initial load
duke
parents:
diff changeset
76 sysProps.setAgent(getAgent());
a61af66fc99e Initial load
duke
parents:
diff changeset
77 System.out.println("Java System Properties:");
a61af66fc99e Initial load
duke
parents:
diff changeset
78 System.out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
79 sysProps.run();
a61af66fc99e Initial load
duke
parents:
diff changeset
80 System.out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
81 System.out.println("VM Flags:");
a61af66fc99e Initial load
duke
parents:
diff changeset
82 printVMFlags();
a61af66fc99e Initial load
duke
parents:
diff changeset
83 System.out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85 };
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
90 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
91 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93 tool.setAgent(getAgent());
a61af66fc99e Initial load
duke
parents:
diff changeset
94 tool.run();
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 public static void main(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 int mode = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 switch (args.length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 case 1:
a61af66fc99e Initial load
duke
parents:
diff changeset
101 if (args[0].charAt(0) == '-') {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // -h or -help or some invalid flag
a61af66fc99e Initial load
duke
parents:
diff changeset
103 new JInfo(mode).usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
104 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 mode = MODE_BOTH;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 case 2:
a61af66fc99e Initial load
duke
parents:
diff changeset
109 case 3: {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 String modeFlag = args[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
111 if (modeFlag.equals("-flags")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 mode = MODE_FLAGS;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 } else if (modeFlag.equals("-sysprops")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 mode = MODE_SYSPROPS;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 } else if (modeFlag.charAt(0) == '-') {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // -h or -help or some invalid flag
a61af66fc99e Initial load
duke
parents:
diff changeset
117 new JInfo(mode).usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
118 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 mode = MODE_BOTH;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 if (mode != MODE_BOTH) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // we have to consume first flag argument.
a61af66fc99e Initial load
duke
parents:
diff changeset
124 String[] newArgs = new String[args.length - 1];
a61af66fc99e Initial load
duke
parents:
diff changeset
125 for (int i = 0; i < newArgs.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 newArgs[i] = args[i + 1];
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128 args = newArgs;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
134 new JInfo(mode).usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 JInfo jinfo = new JInfo(mode);
12932
7fe6ef09d242 8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents: 11054
diff changeset
138 jinfo.execute(args);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 private void printVMFlags() {
13387
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
142 VM.Flag[] flags = VM.getVM().getCommandLineFlags();
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
143 System.out.print("Non-default VM flags: ");
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
144 for (VM.Flag flag : flags) {
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
145 if (flag.getOrigin() == 0) {
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
146 // only print flags which aren't their defaults
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
147 continue;
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
148 }
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
149 if (flag.isBool()) {
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
150 String onoff = flag.getBool() ? "+" : "-";
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
151 System.out.print("-XX:" + onoff + flag.getName() + " ");
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
152 } else {
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
153 System.out.print("-XX:" + flag.getName() + "="
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
154 + flag.getValue() + " ");
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
155 }
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
156 }
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
157 System.out.println();
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
158
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
159 System.out.print("Command line: ");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
160 String str = Arguments.getJVMFlags();
a61af66fc99e Initial load
duke
parents:
diff changeset
161 if (str != null) {
13387
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
162 System.out.print(str + " ");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164 str = Arguments.getJVMArgs();
a61af66fc99e Initial load
duke
parents:
diff changeset
165 if (str != null) {
13387
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
166 System.out.print(str);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
13387
b03f33670080 6606002: jinfo doesn't detect dynamic vm flags changing
sla
parents: 12932
diff changeset
168 System.out.println();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 private int mode;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }