< prev index next >

src/java.base/share/classes/sun/launcher/LauncherHelper.java

Print this page
@  rev 57586 : Review changes
|
~

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -43,14 +43,14 @@
 import java.io.IOException;
 import java.io.PrintStream;
 import java.io.UnsupportedEncodingException;
 import java.lang.module.Configuration;
 import java.lang.module.ModuleDescriptor;
-import java.lang.module.ModuleDescriptor.Requires;
 import java.lang.module.ModuleDescriptor.Exports;
 import java.lang.module.ModuleDescriptor.Opens;
 import java.lang.module.ModuleDescriptor.Provides;
+import java.lang.module.ModuleDescriptor.Requires;
 import java.lang.module.ModuleFinder;
 import java.lang.module.ModuleReference;
 import java.lang.module.ResolvedModule;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;

@@ -60,12 +60,12 @@
 import java.net.URI;
 import java.nio.charset.Charset;
 import java.nio.file.DirectoryStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.text.Normalizer;
 import java.text.MessageFormat;
+import java.text.Normalizer;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;

@@ -323,93 +323,130 @@
             return;
         }
 
         ostream.println(INDENT + "Provider: " + c.getProvider());
         ostream.println(INDENT + "Effective CPU Count: " + c.getEffectiveCpuCount());
-        ostream.println(INDENT + "CPU Period: " + c.getCpuPeriod() +
-               (c.getCpuPeriod() == -1 ? "" : "us"));
-        ostream.println(INDENT + "CPU Quota: " + c.getCpuQuota() +
-               (c.getCpuQuota() == -1 ? "" : "us"));
-        ostream.println(INDENT + "CPU Shares: " + c.getCpuShares());
+        ostream.println(formatCpuVal(c.getCpuPeriod(), INDENT + "CPU Period: "));
+        ostream.println(formatCpuVal(c.getCpuQuota(), INDENT + "CPU Quota: "));
+        ostream.println(formatCpuVal(c.getCpuShares(), INDENT + "CPU Shares: "));
 
         int cpus[] = c.getCpuSetCpus();
+        if (cpus != null) {
         ostream.println(INDENT + "List of Processors, "
                 + cpus.length + " total: ");
 
         ostream.print(INDENT);
         for (int i = 0; i < cpus.length; i++) {
             ostream.print(cpus[i] + " ");
         }
         if (cpus.length > 0) {
             ostream.println("");
         }
+        } else {
+            ostream.println(INDENT + "List of Processors: N/A");
+        }
 
         cpus = c.getEffectiveCpuSetCpus();
+        if (cpus != null) {
         ostream.println(INDENT + "List of Effective Processors, "
                 + cpus.length + " total: ");
 
         ostream.print(INDENT);
         for (int i = 0; i < cpus.length; i++) {
             ostream.print(cpus[i] + " ");
         }
         if (cpus.length > 0) {
             ostream.println("");
         }
+        } else {
+            ostream.println(INDENT + "List of Effective Processors: N/A");
+        }
 
         int mems[] = c.getCpuSetMems();
+        if (mems != null) {
         ostream.println(INDENT + "List of Memory Nodes, "
                 + mems.length + " total: ");
 
         ostream.print(INDENT);
         for (int i = 0; i < mems.length; i++) {
             ostream.print(mems[i] + " ");
         }
         if (mems.length > 0) {
             ostream.println("");
         }
+        } else {
+            ostream.println(INDENT + "List of Memory Nodes: N/A");
+        }
 
         mems = c.getEffectiveCpuSetMems();
+        if (mems != null) {
         ostream.println(INDENT + "List of Available Memory Nodes, "
                 + mems.length + " total: ");
 
         ostream.print(INDENT);
         for (int i = 0; i < mems.length; i++) {
             ostream.print(mems[i] + " ");
         }
         if (mems.length > 0) {
             ostream.println("");
         }
+        } else {
+            ostream.println(INDENT + "List of Available Memory Nodes: N/A");
+        }
 
-        ostream.println(INDENT + "CPUSet Memory Pressure Enabled: "
-                + c.isCpuSetMemoryPressureEnabled());
+        ostream.println(formatBoolean(c.isCpuSetMemoryPressureEnabled(),
+                                      INDENT + "CPUSet Memory Pressure Enabled: "));
 
         long limit = c.getMemoryLimit();
-        ostream.println(INDENT + "Memory Limit: " +
-                ((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited"));
+        ostream.println(formatLimitString(limit, INDENT + "Memory Limit: "));
 
         limit = c.getMemorySoftLimit();
-        ostream.println(INDENT + "Memory Soft Limit: " +
-                ((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited"));
+        ostream.println(formatLimitString(limit, INDENT + "Memory Soft Limit: "));
 
         limit = c.getMemoryAndSwapLimit();
-        ostream.println(INDENT + "Memory & Swap Limit: " +
-                ((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited"));
+        ostream.println(formatLimitString(limit, INDENT + "Memory & Swap Limit: "));
 
         limit = c.getKernelMemoryLimit();
-        ostream.println(INDENT + "Kernel Memory Limit: " +
-                ((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited"));
+        ostream.println(formatLimitString(limit, INDENT + "Kernel Memory Limit: "));
 
         limit = c.getTcpMemoryLimit();
-        ostream.println(INDENT + "TCP Memory Limit: " +
-                ((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited"));
+        ostream.println(formatLimitString(limit, INDENT + "TCP Memory Limit: "));
 
-        ostream.println(INDENT + "Out Of Memory Killer Enabled: "
-                + c.isMemoryOOMKillEnabled());
+        ostream.println(formatBoolean(c.isMemoryOOMKillEnabled(),
+                                      INDENT + "Out Of Memory Killer Enabled: "));
 
         ostream.println("");
     }
 
+    private static String formatLimitString(long limit, String prefix) {
+        if (limit >= 0) {
+            return prefix + SizePrefix.scaleValue(limit);
+        } else if (limit == Metrics.LONG_RETVAL_NOT_SUPPORTED) {
+            return prefix + "N/A";
+        } else {
+            return prefix + "Unlimited";
+        }
+    }
+
+    private static String formatCpuVal(long cpuVal, String prefix) {
+        if (cpuVal >= 0) {
+            return prefix + cpuVal + "us";
+        } else if (cpuVal == Metrics.LONG_RETVAL_NOT_SUPPORTED) {
+            return prefix + "N/A";
+        } else {
+            return prefix + cpuVal;
+        }
+    }
+
+    private static String formatBoolean(Boolean value, String prefix) {
+        if (value == Metrics.BOOL_RETVAL_NOT_SUPPORTED) {
+            return prefix + "N/A";
+        } else {
+            return prefix + value;
+        }
+    }
+
     private enum SizePrefix {
 
         KILO(1024, "K"),
         MEGA(1024 * 1024, "M"),
         GIGA(1024 * 1024 * 1024, "G"),
< prev index next >