annotate agent/src/share/classes/sun/jvm/hotspot/tools/JInfo.java @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents a61af66fc99e
children 38ea2efa32a7
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.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 public class JInfo extends Tool {
a61af66fc99e Initial load
duke
parents:
diff changeset
30 public JInfo(int m) {
a61af66fc99e Initial load
duke
parents:
diff changeset
31 mode = m;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 }
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 protected boolean needsJavaPrefix() {
a61af66fc99e Initial load
duke
parents:
diff changeset
35 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 }
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 public String getName() {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 return "jinfo";
a61af66fc99e Initial load
duke
parents:
diff changeset
40 }
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 protected void printFlagsUsage() {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 System.out.println(" -flags\tto print VM flags");
a61af66fc99e Initial load
duke
parents:
diff changeset
44 System.out.println(" -sysprops\tto print Java System properties");
a61af66fc99e Initial load
duke
parents:
diff changeset
45 System.out.println(" <no option>\tto print both of the above");
a61af66fc99e Initial load
duke
parents:
diff changeset
46 super.printFlagsUsage();
a61af66fc99e Initial load
duke
parents:
diff changeset
47 }
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 public static final int MODE_FLAGS = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 public static final int MODE_SYSPROPS = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 public static final int MODE_BOTH = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 Tool tool = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 switch (mode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 case MODE_FLAGS:
a61af66fc99e Initial load
duke
parents:
diff changeset
57 printVMFlags();
a61af66fc99e Initial load
duke
parents:
diff changeset
58 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 case MODE_SYSPROPS:
a61af66fc99e Initial load
duke
parents:
diff changeset
60 tool = new SysPropsDumper();
a61af66fc99e Initial load
duke
parents:
diff changeset
61 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 case MODE_BOTH: {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 tool = new Tool() {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 Tool sysProps = new SysPropsDumper();
a61af66fc99e Initial load
duke
parents:
diff changeset
66 sysProps.setAgent(getAgent());
a61af66fc99e Initial load
duke
parents:
diff changeset
67 System.out.println("Java System Properties:");
a61af66fc99e Initial load
duke
parents:
diff changeset
68 System.out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
69 sysProps.run();
a61af66fc99e Initial load
duke
parents:
diff changeset
70 System.out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
71 System.out.println("VM Flags:");
a61af66fc99e Initial load
duke
parents:
diff changeset
72 printVMFlags();
a61af66fc99e Initial load
duke
parents:
diff changeset
73 System.out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75 };
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
80 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
81 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83 tool.setAgent(getAgent());
a61af66fc99e Initial load
duke
parents:
diff changeset
84 tool.run();
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 public static void main(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 int mode = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 switch (args.length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 case 1:
a61af66fc99e Initial load
duke
parents:
diff changeset
91 if (args[0].charAt(0) == '-') {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // -h or -help or some invalid flag
a61af66fc99e Initial load
duke
parents:
diff changeset
93 new JInfo(mode).usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
94 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 mode = MODE_BOTH;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 case 2:
a61af66fc99e Initial load
duke
parents:
diff changeset
99 case 3: {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 String modeFlag = args[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
101 if (modeFlag.equals("-flags")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 mode = MODE_FLAGS;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 } else if (modeFlag.equals("-sysprops")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 mode = MODE_SYSPROPS;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 } else if (modeFlag.charAt(0) == '-') {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // -h or -help or some invalid flag
a61af66fc99e Initial load
duke
parents:
diff changeset
107 new JInfo(mode).usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
108 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 mode = MODE_BOTH;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 if (mode != MODE_BOTH) {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // we have to consume first flag argument.
a61af66fc99e Initial load
duke
parents:
diff changeset
114 String[] newArgs = new String[args.length - 1];
a61af66fc99e Initial load
duke
parents:
diff changeset
115 for (int i = 0; i < newArgs.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 newArgs[i] = args[i + 1];
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 args = newArgs;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
124 new JInfo(mode).usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 JInfo jinfo = new JInfo(mode);
a61af66fc99e Initial load
duke
parents:
diff changeset
128 jinfo.start(args);
a61af66fc99e Initial load
duke
parents:
diff changeset
129 jinfo.stop();
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 private void printVMFlags() {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 String str = Arguments.getJVMFlags();
a61af66fc99e Initial load
duke
parents:
diff changeset
134 if (str != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 System.out.println(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 str = Arguments.getJVMArgs();
a61af66fc99e Initial load
duke
parents:
diff changeset
138 if (str != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 System.out.println(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 private int mode;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }