1 /*
2 * Copyright (c) 2000, 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 *
135
136 private Flag[] commandLineFlags;
137 private Map flagsMap;
138
139 private static Type intType;
140 private static Type uintType;
141 private static Type intxType;
142 private static Type uintxType;
143 private static Type sizetType;
144 private static Type uint64tType;
145 private static CIntegerType boolType;
146 private Boolean sharingEnabled;
147 private Boolean compressedOopsEnabled;
148 private Boolean compressedKlassPointersEnabled;
149
150 // command line flags supplied to VM - see struct JVMFlag in jvmFlag.hpp
151 public static final class Flag {
152 private String type;
153 private String name;
154 private Address addr;
155 private int flags;
156
157 private Flag(String type, String name, Address addr, int flags) {
158 this.type = type;
159 this.name = name;
160 this.addr = addr;
161 this.flags = flags;
162 }
163
164 public String getType() {
165 return type;
166 }
167
168 public String getName() {
169 return name;
170 }
171
172 public Address getAddress() {
173 return addr;
174 }
175
176 public int getOrigin() {
177 return flags & Flags_VALUE_ORIGIN_MASK;
178 }
179
180 // See JVMFlag::print_origin() in HotSpot
181 public String getOriginString() {
182 var origin = flags & Flags_VALUE_ORIGIN_MASK;
183 if (origin == Flags_DEFAULT) {
184 return "default";
185 } else if (origin == Flags_COMMAND_LINE) {
186 return "command line";
187 } else if (origin == Flags_ENVIRON_VAR) {
188 return "environment";
189 } else if (origin == Flags_CONFIG_FILE) {
190 return "config file";
191 } else if (origin == Flags_MANAGEMENT) {
192 return "management";
193 } else if (origin == Flags_ERGONOMIC) {
194 String result = "";
195 if ((flags & Flags_ORIG_COMMAND_LINE) == Flags_ORIG_COMMAND_LINE) {
196 result = "command line, ";
197 }
198 return result + "ergonomic";
199 } else if (origin == Flags_ATTACH_ON_DEMAND) {
200 return "attach";
201 } else if (origin == Flags_INTERNAL) {
202 return "internal";
203 } else if (origin == Flags_JIMAGE_RESOURCE) {
204 return "jimage";
205 } else {
206 throw new IllegalStateException(
207 "Unknown flag origin " + origin + " is detected in " + name);
208 }
209 }
210
211 public boolean isBool() {
212 return type.equals("bool");
213 }
214
215 public boolean getBool() {
990 // returns null, if not available.
991 public Flag[] getCommandLineFlags() {
992 if (commandLineFlags == null) {
993 readCommandLineFlags();
994 }
995
996 return commandLineFlags;
997 }
998
999 public Flag getCommandLineFlag(String name) {
1000 if (flagsMap == null) {
1001 flagsMap = new HashMap();
1002 Flag[] flags = getCommandLineFlags();
1003 for (int i = 0; i < flags.length; i++) {
1004 flagsMap.put(flags[i].getName(), flags[i]);
1005 }
1006 }
1007 return (Flag) flagsMap.get(name);
1008 }
1009
1010 private void readCommandLineFlags() {
1011 // get command line flags
1012 TypeDataBase db = getTypeDataBase();
1013 Type flagType = db.lookupType("JVMFlag");
1014 int numFlags = (int) flagType.getCIntegerField("numFlags").getValue();
1015 // NOTE: last flag contains null values.
1016 commandLineFlags = new Flag[numFlags - 1];
1017
1018 Address flagAddr = flagType.getAddressField("flags").getValue();
1019
1020 AddressField typeFld = flagType.getAddressField("_type");
1021 AddressField nameFld = flagType.getAddressField("_name");
1022 AddressField addrFld = flagType.getAddressField("_addr");
1023 CIntField flagsFld = new CIntField(flagType.getCIntegerField("_flags"), 0);
1024
1025 long flagSize = flagType.getSize(); // sizeof(Flag)
1026
1027 // NOTE: last flag contains null values.
1028 for (int f = 0; f < numFlags - 1; f++) {
1029 String type = CStringUtilities.getString(typeFld.getValue(flagAddr));
1030 String name = CStringUtilities.getString(nameFld.getValue(flagAddr));
1031 Address addr = addrFld.getValue(flagAddr);
1032 int flags = (int)flagsFld.getValue(flagAddr);
1033 commandLineFlags[f] = new Flag(type, name, addr, flags);
1034 flagAddr = flagAddr.addOffsetTo(flagSize);
1035 }
1036
1037 // sort flags by name
1038 Arrays.sort(commandLineFlags, new Comparator() {
1039 public int compare(Object o1, Object o2) {
1040 Flag f1 = (Flag) o1;
1041 Flag f2 = (Flag) o2;
1042 return f1.getName().compareTo(f2.getName());
1043 }
1044 });
1045 }
1046
1047 public String getSystemProperty(String key) {
1048 Properties props = getSystemProperties();
1049 return (props != null)? props.getProperty(key) : null;
1050 }
1051
1052 public Properties getSystemProperties() {
1053 if (sysProps == null) {
1054 readSystemProperties();
1055 }
|
1 /*
2 * Copyright (c) 2000, 2020, 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 *
135
136 private Flag[] commandLineFlags;
137 private Map flagsMap;
138
139 private static Type intType;
140 private static Type uintType;
141 private static Type intxType;
142 private static Type uintxType;
143 private static Type sizetType;
144 private static Type uint64tType;
145 private static CIntegerType boolType;
146 private Boolean sharingEnabled;
147 private Boolean compressedOopsEnabled;
148 private Boolean compressedKlassPointersEnabled;
149
150 // command line flags supplied to VM - see struct JVMFlag in jvmFlag.hpp
151 public static final class Flag {
152 private String type;
153 private String name;
154 private Address addr;
155 private int attr;
156
157 private Flag(String type, String name, Address addr, int attr) {
158 this.type = type;
159 this.name = name;
160 this.addr = addr;
161 this.attr = attr;
162 }
163
164 public String getType() {
165 return type;
166 }
167
168 public String getName() {
169 return name;
170 }
171
172 public Address getAddress() {
173 return addr;
174 }
175
176 public int getOrigin() {
177 return attr & Flags_VALUE_ORIGIN_MASK;
178 }
179
180 // See JVMFlag::print_origin() in HotSpot
181 public String getOriginString() {
182 var origin = attr & Flags_VALUE_ORIGIN_MASK;
183 if (origin == Flags_DEFAULT) {
184 return "default";
185 } else if (origin == Flags_COMMAND_LINE) {
186 return "command line";
187 } else if (origin == Flags_ENVIRON_VAR) {
188 return "environment";
189 } else if (origin == Flags_CONFIG_FILE) {
190 return "config file";
191 } else if (origin == Flags_MANAGEMENT) {
192 return "management";
193 } else if (origin == Flags_ERGONOMIC) {
194 String result = "";
195 if ((attr & Flags_ORIG_COMMAND_LINE) == Flags_ORIG_COMMAND_LINE) {
196 result = "command line, ";
197 }
198 return result + "ergonomic";
199 } else if (origin == Flags_ATTACH_ON_DEMAND) {
200 return "attach";
201 } else if (origin == Flags_INTERNAL) {
202 return "internal";
203 } else if (origin == Flags_JIMAGE_RESOURCE) {
204 return "jimage";
205 } else {
206 throw new IllegalStateException(
207 "Unknown flag origin " + origin + " is detected in " + name);
208 }
209 }
210
211 public boolean isBool() {
212 return type.equals("bool");
213 }
214
215 public boolean getBool() {
990 // returns null, if not available.
991 public Flag[] getCommandLineFlags() {
992 if (commandLineFlags == null) {
993 readCommandLineFlags();
994 }
995
996 return commandLineFlags;
997 }
998
999 public Flag getCommandLineFlag(String name) {
1000 if (flagsMap == null) {
1001 flagsMap = new HashMap();
1002 Flag[] flags = getCommandLineFlags();
1003 for (int i = 0; i < flags.length; i++) {
1004 flagsMap.put(flags[i].getName(), flags[i]);
1005 }
1006 }
1007 return (Flag) flagsMap.get(name);
1008 }
1009
1010 private static final String cmdFlagTypes[] = {
1011 "bool",
1012 "int",
1013 "uint",
1014 "intx",
1015 "uintx",
1016 "uint64_t",
1017 "size_t",
1018 "double",
1019 "ccstr",
1020 "ccstrlist"
1021 };
1022
1023 private void readCommandLineFlags() {
1024 // get command line flags
1025 TypeDataBase db = getTypeDataBase();
1026 Type flagType = db.lookupType("JVMFlag");
1027 Address head = flagType.getAddressField("_head").getValue();
1028 ArrayList<Flag> flags = new ArrayList<>();
1029
1030 CIntegerType shortType = (CIntegerType) db.lookupType("short");
1031 CIntegerField typeFld = flagType.getCIntegerField("_type");
1032 AddressField nameFld = flagType.getAddressField("_name");
1033 AddressField addrFld = flagType.getAddressField("_value_addr");
1034 AddressField nextFld = flagType.getAddressField("_next");
1035 CIntField attrsFld = new CIntField(flagType.getCIntegerField("_attr"), 0);
1036
1037 for (Address flag = head; flag != null; flag = nextFld.getValue(flag)) {
1038 int typeIndex = (int)typeFld.getCInteger(flag, shortType);
1039 String type = (0 <= typeIndex && typeIndex < cmdFlagTypes.length) ? cmdFlagTypes[typeIndex] : "unknown";
1040 String name = CStringUtilities.getString(nameFld.getValue(flag));
1041 Address addr = addrFld.getValue(flag);
1042 int attr = (int)attrsFld.getValue(flag);
1043 flags.add(new Flag(type, name, addr, attr));
1044 }
1045
1046 commandLineFlags = new Flag[flags.size()];
1047 flags.toArray(commandLineFlags);
1048
1049 // sort flags by name
1050 Arrays.sort(commandLineFlags, new Comparator() {
1051 public int compare(Object o1, Object o2) {
1052 Flag f1 = (Flag) o1;
1053 Flag f2 = (Flag) o2;
1054 return f1.getName().compareTo(f2.getName());
1055 }
1056 });
1057 }
1058
1059 public String getSystemProperty(String key) {
1060 Properties props = getSystemProperties();
1061 return (props != null)? props.getProperty(key) : null;
1062 }
1063
1064 public Properties getSystemProperties() {
1065 if (sysProps == null) {
1066 readSystemProperties();
1067 }
|