Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/JInfo.java
41161 views
1
/*
2
* Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.
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
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
package sun.jvm.hotspot.tools;
26
27
import sun.jvm.hotspot.debugger.JVMDebugger;
28
import sun.jvm.hotspot.runtime.Arguments;
29
import sun.jvm.hotspot.runtime.VM;
30
31
public class JInfo extends Tool {
32
public JInfo() {
33
super();
34
}
35
36
public JInfo(int m) {
37
mode = m;
38
}
39
40
public JInfo(JVMDebugger d) {
41
super(d);
42
}
43
44
protected boolean needsJavaPrefix() {
45
return false;
46
}
47
48
@Override
49
public String getName() {
50
return "jinfo";
51
}
52
53
protected void printFlagsUsage() {
54
System.out.println(" -flags\tto print VM flags");
55
System.out.println(" -sysprops\tto print Java System properties");
56
System.out.println(" <no option>\tto print both of the above");
57
super.printFlagsUsage();
58
}
59
60
public static final int MODE_FLAGS = 0;
61
public static final int MODE_SYSPROPS = 1;
62
public static final int MODE_BOTH = 2;
63
64
public void run() {
65
Tool tool = null;
66
switch (mode) {
67
case MODE_FLAGS:
68
printVMFlags();
69
return;
70
case MODE_SYSPROPS:
71
tool = new SysPropsDumper();
72
break;
73
case MODE_BOTH: {
74
tool = new Tool() {
75
public void run() {
76
Tool sysProps = new SysPropsDumper();
77
sysProps.setAgent(getAgent());
78
System.out.println("Java System Properties:");
79
System.out.println();
80
sysProps.run();
81
System.out.println();
82
System.out.println("VM Flags:");
83
printVMFlags();
84
System.out.println();
85
}
86
};
87
}
88
break;
89
90
default:
91
usage();
92
break;
93
}
94
tool.setAgent(getAgent());
95
tool.run();
96
}
97
98
public void runWithArgs(String... args) {
99
int mode = -1;
100
switch (args.length) {
101
case 1:
102
if (args[0].charAt(0) == '-') {
103
// -h or -help or some invalid flag
104
usage();
105
} else {
106
mode = MODE_BOTH;
107
}
108
break;
109
case 2:
110
case 3: {
111
String modeFlag = args[0];
112
if (modeFlag.equals("-flags")) {
113
mode = MODE_FLAGS;
114
} else if (modeFlag.equals("-sysprops")) {
115
mode = MODE_SYSPROPS;
116
} else if (modeFlag.charAt(0) == '-') {
117
// -h or -help or some invalid flag
118
usage();
119
} else {
120
mode = MODE_BOTH;
121
}
122
123
if (mode != MODE_BOTH) {
124
// we have to consume first flag argument.
125
String[] newArgs = new String[args.length - 1];
126
for (int i = 0; i < newArgs.length; i++) {
127
newArgs[i] = args[i + 1];
128
}
129
args = newArgs;
130
}
131
break;
132
}
133
134
default:
135
usage();
136
}
137
138
this.mode = mode;
139
execute(args);
140
}
141
142
public static void main(String[] args) {
143
JInfo jinfo = new JInfo();
144
jinfo.runWithArgs(args);
145
}
146
147
private void printVMFlags() {
148
VM.Flag[] flags = VM.getVM().getCommandLineFlags();
149
System.out.print("Non-default VM flags: ");
150
for (VM.Flag flag : flags) {
151
if (flag.getOrigin() == VM.Flags_DEFAULT) {
152
// only print flags which aren't their defaults
153
continue;
154
}
155
if (flag.isBool()) {
156
String onoff = flag.getBool() ? "+" : "-";
157
System.out.print("-XX:" + onoff + flag.getName() + " ");
158
} else {
159
System.out.print("-XX:" + flag.getName() + "="
160
+ flag.getValue() + " ");
161
}
162
}
163
System.out.println();
164
165
System.out.print("Command line: ");
166
String str = Arguments.getJVMFlags();
167
if (str != null) {
168
System.out.print(str + " ");
169
}
170
str = Arguments.getJVMArgs();
171
if (str != null) {
172
System.out.print(str);
173
}
174
System.out.println();
175
}
176
177
private int mode;
178
}
179
180