1 /*
2 * Copyright (c) 2007, 2017, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
74 import java.util.HashMap;
75 import java.util.Iterator;
76 import java.util.List;
77 import java.util.Locale;
78 import java.util.Locale.Category;
79 import java.util.Map;
80 import java.util.Optional;
81 import java.util.Properties;
82 import java.util.ResourceBundle;
83 import java.util.Set;
84 import java.util.TreeSet;
85 import java.util.jar.Attributes;
86 import java.util.jar.JarFile;
87 import java.util.jar.Manifest;
88 import java.util.stream.Collectors;
89 import java.util.stream.Stream;
90
91 import jdk.internal.misc.VM;
92 import jdk.internal.module.ModuleBootstrap;
93 import jdk.internal.module.Modules;
94
95 public final class LauncherHelper {
96
97 // No instantiation
98 private LauncherHelper() {}
99
100 // used to identify JavaFX applications
101 private static final String JAVAFX_APPLICATION_MARKER =
102 "JavaFX-Application-Class";
103 private static final String JAVAFX_APPLICATION_CLASS_NAME =
104 "javafx.application.Application";
105 private static final String JAVAFX_FXHELPER_CLASS_NAME_SUFFIX =
106 "sun.launcher.LauncherHelper$FXHelper";
107 private static final String LAUNCHER_AGENT_CLASS = "Launcher-Agent-Class";
108 private static final String MAIN_CLASS = "Main-Class";
109 private static final String ADD_EXPORTS = "Add-Exports";
110 private static final String ADD_OPENS = "Add-Opens";
111
112 private static StringBuilder outBuf = new StringBuilder();
113
134 * by default -XshowSettings is equivalent to -XshowSettings:all,
135 * Specific information may be gotten by using suboptions with possible
136 * values vm, properties and locale.
137 *
138 * printToStderr: choose between stdout and stderr
139 *
140 * optionFlag: specifies which options to print default is all other
141 * possible values are vm, properties, locale.
142 *
143 * initialHeapSize: in bytes, as set by the launcher, a zero-value indicates
144 * this code should determine this value, using a suitable method or
145 * the line could be omitted.
146 *
147 * maxHeapSize: in bytes, as set by the launcher, a zero-value indicates
148 * this code should determine this value, using a suitable method.
149 *
150 * stackSize: in bytes, as set by the launcher, a zero-value indicates
151 * this code determine this value, using a suitable method or omit the
152 * line entirely.
153 */
154 static void showSettings(boolean printToStderr, String optionFlag,
155 long initialHeapSize, long maxHeapSize, long stackSize) {
156
157 initOutput(printToStderr);
158 String opts[] = optionFlag.split(":");
159 String optStr = (opts.length > 1 && opts[1] != null)
160 ? opts[1].trim()
161 : "all";
162 switch (optStr) {
163 case "vm":
164 printVmSettings(initialHeapSize, maxHeapSize, stackSize);
165 break;
166 case "properties":
167 printProperties();
168 break;
169 case "locale":
170 printLocale();
171 break;
172 default:
173 printVmSettings(initialHeapSize, maxHeapSize, stackSize);
174 printProperties();
175 printLocale();
176 break;
177 }
178 }
179
180 /*
181 * prints the main vm settings subopt/section
182 */
183 private static void printVmSettings(
184 long initialHeapSize, long maxHeapSize,
185 long stackSize) {
186
187 ostream.println(VM_SETTINGS);
188 if (stackSize != 0L) {
189 ostream.println(INDENT + "Stack Size: " +
190 SizePrefix.scaleValue(stackSize));
191 }
192 if (initialHeapSize != 0L) {
193 ostream.println(INDENT + "Min. Heap Size: " +
194 SizePrefix.scaleValue(initialHeapSize));
195 }
288 Set<String> sortedSet = new TreeSet<>();
289 for (Locale l : tlocales) {
290 sortedSet.add(l.toString());
291 }
292
293 ostream.print(INDENT + "available locales = ");
294 Iterator<String> iter = sortedSet.iterator();
295 final int last = len - 1;
296 for (int i = 0 ; iter.hasNext() ; i++) {
297 String s = iter.next();
298 ostream.print(s);
299 if (i != last) {
300 ostream.print(", ");
301 }
302 // print columns of 8
303 if ((i + 1) % 8 == 0) {
304 ostream.println();
305 ostream.print(INDENT + INDENT);
306 }
307 }
308 }
309
310 private enum SizePrefix {
311
312 KILO(1024, "K"),
313 MEGA(1024 * 1024, "M"),
314 GIGA(1024 * 1024 * 1024, "G"),
315 TERA(1024L * 1024L * 1024L * 1024L, "T");
316 long size;
317 String abbrev;
318
319 SizePrefix(long size, String abbrev) {
320 this.size = size;
321 this.abbrev = abbrev;
322 }
323
324 private static String scale(long v, SizePrefix prefix) {
325 return BigDecimal.valueOf(v).divide(BigDecimal.valueOf(prefix.size),
326 2, RoundingMode.HALF_EVEN).toPlainString() + prefix.abbrev;
327 }
|
1 /*
2 * Copyright (c) 2007, 2018, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
74 import java.util.HashMap;
75 import java.util.Iterator;
76 import java.util.List;
77 import java.util.Locale;
78 import java.util.Locale.Category;
79 import java.util.Map;
80 import java.util.Optional;
81 import java.util.Properties;
82 import java.util.ResourceBundle;
83 import java.util.Set;
84 import java.util.TreeSet;
85 import java.util.jar.Attributes;
86 import java.util.jar.JarFile;
87 import java.util.jar.Manifest;
88 import java.util.stream.Collectors;
89 import java.util.stream.Stream;
90
91 import jdk.internal.misc.VM;
92 import jdk.internal.module.ModuleBootstrap;
93 import jdk.internal.module.Modules;
94 import jdk.internal.platform.Container;
95 import jdk.internal.platform.Metrics;
96
97
98 public final class LauncherHelper {
99
100 // No instantiation
101 private LauncherHelper() {}
102
103 // used to identify JavaFX applications
104 private static final String JAVAFX_APPLICATION_MARKER =
105 "JavaFX-Application-Class";
106 private static final String JAVAFX_APPLICATION_CLASS_NAME =
107 "javafx.application.Application";
108 private static final String JAVAFX_FXHELPER_CLASS_NAME_SUFFIX =
109 "sun.launcher.LauncherHelper$FXHelper";
110 private static final String LAUNCHER_AGENT_CLASS = "Launcher-Agent-Class";
111 private static final String MAIN_CLASS = "Main-Class";
112 private static final String ADD_EXPORTS = "Add-Exports";
113 private static final String ADD_OPENS = "Add-Opens";
114
115 private static StringBuilder outBuf = new StringBuilder();
116
137 * by default -XshowSettings is equivalent to -XshowSettings:all,
138 * Specific information may be gotten by using suboptions with possible
139 * values vm, properties and locale.
140 *
141 * printToStderr: choose between stdout and stderr
142 *
143 * optionFlag: specifies which options to print default is all other
144 * possible values are vm, properties, locale.
145 *
146 * initialHeapSize: in bytes, as set by the launcher, a zero-value indicates
147 * this code should determine this value, using a suitable method or
148 * the line could be omitted.
149 *
150 * maxHeapSize: in bytes, as set by the launcher, a zero-value indicates
151 * this code should determine this value, using a suitable method.
152 *
153 * stackSize: in bytes, as set by the launcher, a zero-value indicates
154 * this code determine this value, using a suitable method or omit the
155 * line entirely.
156 */
157 @SuppressWarnings("fallthrough")
158 static void showSettings(boolean printToStderr, String optionFlag,
159 long initialHeapSize, long maxHeapSize, long stackSize) {
160
161 initOutput(printToStderr);
162 String opts[] = optionFlag.split(":");
163 String optStr = (opts.length > 1 && opts[1] != null)
164 ? opts[1].trim()
165 : "all";
166 switch (optStr) {
167 case "vm":
168 printVmSettings(initialHeapSize, maxHeapSize, stackSize);
169 break;
170 case "properties":
171 printProperties();
172 break;
173 case "locale":
174 printLocale();
175 break;
176 case "system":
177 if (System.getProperty("os.name").contains("Linux")) {
178 printSystemMetrics();
179 break;
180 }
181 default:
182 printVmSettings(initialHeapSize, maxHeapSize, stackSize);
183 printProperties();
184 printLocale();
185 if (System.getProperty("os.name").contains("Linux")) {
186 printSystemMetrics();
187 }
188 break;
189 }
190 }
191
192 /*
193 * prints the main vm settings subopt/section
194 */
195 private static void printVmSettings(
196 long initialHeapSize, long maxHeapSize,
197 long stackSize) {
198
199 ostream.println(VM_SETTINGS);
200 if (stackSize != 0L) {
201 ostream.println(INDENT + "Stack Size: " +
202 SizePrefix.scaleValue(stackSize));
203 }
204 if (initialHeapSize != 0L) {
205 ostream.println(INDENT + "Min. Heap Size: " +
206 SizePrefix.scaleValue(initialHeapSize));
207 }
300 Set<String> sortedSet = new TreeSet<>();
301 for (Locale l : tlocales) {
302 sortedSet.add(l.toString());
303 }
304
305 ostream.print(INDENT + "available locales = ");
306 Iterator<String> iter = sortedSet.iterator();
307 final int last = len - 1;
308 for (int i = 0 ; iter.hasNext() ; i++) {
309 String s = iter.next();
310 ostream.print(s);
311 if (i != last) {
312 ostream.print(", ");
313 }
314 // print columns of 8
315 if ((i + 1) % 8 == 0) {
316 ostream.println();
317 ostream.print(INDENT + INDENT);
318 }
319 }
320 }
321
322 public static void printSystemMetrics() {
323 Metrics c = Container.metrics();
324
325 ostream.println("Operating System Metrics:");
326
327 if (c == null) {
328 ostream.println(INDENT + "No metrics available for this platform");
329 return;
330 }
331
332 ostream.println(INDENT + "Provider: " + c.getProvider());
333 ostream.println(INDENT + "Effective CPU Count: " + c.getEffectiveCpuCount());
334 ostream.println(INDENT + "CPU Period: " + c.getCpuPeriod());
335 ostream.println(INDENT + "CPU Quota: " + c.getCpuQuota());
336 ostream.println(INDENT + "CPU Shares: " + c.getCpuShares());
337
338 int cpus[] = c.getCpuSetCpus();
339 ostream.println(INDENT + "List of Processors, "
340 + cpus.length + " total: ");
341
342 ostream.print(INDENT);
343 for (int i = 0; i < cpus.length; i++) {
344 ostream.print(cpus[i] + " ");
345 }
346 if (cpus.length > 0) {
347 ostream.println("");
348 }
349
350 cpus = c.getEffectiveCpuSetCpus();
351 ostream.println(INDENT + "List of Effective Processors, "
352 + cpus.length + " total: ");
353
354 ostream.print(INDENT);
355 for (int i = 0; i < cpus.length; i++) {
356 ostream.print(cpus[i] + " ");
357 }
358 if (cpus.length > 0) {
359 ostream.println("");
360 }
361
362 int mems[] = c.getCpuSetMems();
363 ostream.println(INDENT + "List of Memory Nodes, "
364 + mems.length + " total: ");
365
366 ostream.print(INDENT);
367 for (int i = 0; i < mems.length; i++) {
368 ostream.print(mems[i] + " ");
369 }
370 if (mems.length > 0) {
371 ostream.println("");
372 }
373
374 mems = c.getEffectiveCpuSetMems();
375 ostream.println(INDENT + "List of Available Memory Nodes, "
376 + mems.length + " total: ");
377
378 ostream.print(INDENT);
379 for (int i = 0; i < mems.length; i++) {
380 ostream.print(mems[i] + " ");
381 }
382 if (mems.length > 0) {
383 ostream.println("");
384 }
385
386 ostream.println(INDENT + "CPUSet Memory Pressure Enabled: "
387 + c.isCpuSetMemoryPressureEnabled());
388
389 long limit = c.getMemoryLimit();
390 ostream.println(INDENT + "Memory Limit: " +
391 ((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited"));
392
393 limit = c.getMemorySoftLimit();
394 ostream.println(INDENT + "Memory Soft Limit: " +
395 ((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited"));
396
397 limit = c.getMemoryAndSwapLimit();
398 ostream.println(INDENT + "Memory & Swap Limit: " +
399 ((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited"));
400
401 limit = c.getKernelMemoryLimit();
402 ostream.println(INDENT + "Kernel Memory Limit: " +
403 ((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited"));
404
405 limit = c.getTcpMemoryLimit();
406 ostream.println(INDENT + "TCP Memory Limit: " +
407 ((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited"));
408
409 ostream.println(INDENT + "Out Of Memory Killer Enabled: "
410 + c.isMemoryOOMKillEnabled());
411
412 ostream.println("");
413 }
414
415 private enum SizePrefix {
416
417 KILO(1024, "K"),
418 MEGA(1024 * 1024, "M"),
419 GIGA(1024 * 1024 * 1024, "G"),
420 TERA(1024L * 1024L * 1024L * 1024L, "T");
421 long size;
422 String abbrev;
423
424 SizePrefix(long size, String abbrev) {
425 this.size = size;
426 this.abbrev = abbrev;
427 }
428
429 private static String scale(long v, SizePrefix prefix) {
430 return BigDecimal.valueOf(v).divide(BigDecimal.valueOf(prefix.size),
431 2, RoundingMode.HALF_EVEN).toPlainString() + prefix.abbrev;
432 }
|