提交 4b1ed28b 编写于 作者: K ksrini

7002386: (launcher) fix XshowSettings

Reviewed-by: darcy, mchung, naoto
上级 8f31caf3
...@@ -158,8 +158,9 @@ static jboolean IsWildCardEnabled(); ...@@ -158,8 +158,9 @@ static jboolean IsWildCardEnabled();
* Running Java code in primordial thread caused many problems. We will * Running Java code in primordial thread caused many problems. We will
* create a new thread to invoke JVM. See 6316197 for more information. * create a new thread to invoke JVM. See 6316197 for more information.
*/ */
static jlong threadStackSize = 0; /* stack size of the new thread */ static jlong threadStackSize = 0; /* stack size of the new thread */
static jlong heapSize = 0; /* heap size */ static jlong maxHeapSize = 0; /* max heap size */
static jlong initialHeapSize = 0; /* inital heap size */
int JNICALL JavaMain(void * args); /* entry point */ int JNICALL JavaMain(void * args); /* entry point */
...@@ -381,7 +382,7 @@ JavaMain(void * _args) ...@@ -381,7 +382,7 @@ JavaMain(void * _args)
if (showSettings != NULL) { if (showSettings != NULL) {
ShowSettings(env, showSettings); ShowSettings(env, showSettings);
CHECK_EXCEPTION_LEAVE(0); CHECK_EXCEPTION_LEAVE(1);
} }
/* If the user specified neither a class name nor a JAR file */ /* If the user specified neither a class name nor a JAR file */
if (printXUsage || printUsage || (jarfile == 0 && classname == 0)) { if (printXUsage || printUsage || (jarfile == 0 && classname == 0)) {
...@@ -689,7 +690,14 @@ AddOption(char *str, void *info) ...@@ -689,7 +690,14 @@ AddOption(char *str, void *info)
if (JLI_StrCCmp(str, "-Xmx") == 0) { if (JLI_StrCCmp(str, "-Xmx") == 0) {
jlong tmp; jlong tmp;
if (parse_size(str + 4, &tmp)) { if (parse_size(str + 4, &tmp)) {
heapSize = tmp; maxHeapSize = tmp;
}
}
if (JLI_StrCCmp(str, "-Xms") == 0) {
jlong tmp;
if (parse_size(str + 4, &tmp)) {
initialHeapSize = tmp;
} }
} }
} }
...@@ -1506,12 +1514,13 @@ ShowSettings(JNIEnv *env, char *optString) ...@@ -1506,12 +1514,13 @@ ShowSettings(JNIEnv *env, char *optString)
jstring joptString; jstring joptString;
NULL_CHECK(cls = FindBootStrapClass(env, "sun/launcher/LauncherHelper")); NULL_CHECK(cls = FindBootStrapClass(env, "sun/launcher/LauncherHelper"));
NULL_CHECK(showSettingsID = (*env)->GetStaticMethodID(env, cls, NULL_CHECK(showSettingsID = (*env)->GetStaticMethodID(env, cls,
"showSettings", "(ZLjava/lang/String;JJZ)V")); "showSettings", "(ZLjava/lang/String;JJJZ)V"));
joptString = (*env)->NewStringUTF(env, optString); joptString = (*env)->NewStringUTF(env, optString);
(*env)->CallStaticVoidMethod(env, cls, showSettingsID, (*env)->CallStaticVoidMethod(env, cls, showSettingsID,
JNI_TRUE, JNI_TRUE,
joptString, joptString,
(jlong)heapSize, (jlong)initialHeapSize,
(jlong)maxHeapSize,
(jlong)threadStackSize, (jlong)threadStackSize,
ServerClassMachine()); ServerClassMachine());
} }
......
...@@ -45,15 +45,18 @@ import java.io.PrintStream; ...@@ -45,15 +45,18 @@ import java.io.PrintStream;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Locale.Category;
import java.util.Properties; import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import java.util.jar.Attributes; import java.util.jar.Attributes;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.jar.Manifest; import java.util.jar.Manifest;
...@@ -73,11 +76,6 @@ public enum LauncherHelper { ...@@ -73,11 +76,6 @@ public enum LauncherHelper {
private static final String PROP_SETTINGS = "Property settings:"; private static final String PROP_SETTINGS = "Property settings:";
private static final String LOCALE_SETTINGS = "Locale settings:"; private static final String LOCALE_SETTINGS = "Locale settings:";
private static final long K = 1024;
private static final long M = K * K;
private static final long G = M * K;
private static final long T = G * K;
private static synchronized ResourceBundle getLauncherResourceBundle() { private static synchronized ResourceBundle getLauncherResourceBundle() {
if (javarb == null) { if (javarb == null) {
javarb = ResourceBundle.getBundle(defaultBundleName); javarb = ResourceBundle.getBundle(defaultBundleName);
...@@ -96,14 +94,20 @@ public enum LauncherHelper { ...@@ -96,14 +94,20 @@ public enum LauncherHelper {
* optionFlag: specifies which options to print default is all other * optionFlag: specifies which options to print default is all other
* possible values are vm, properties, locale. * possible values are vm, properties, locale.
* *
* initialHeapSize: in bytes, as set by the launcher, a zero-value indicates
* this code should determine this value, using a suitable method or
* the line could be omitted.
*
* maxHeapSize: in bytes, as set by the launcher, a zero-value indicates * maxHeapSize: in bytes, as set by the launcher, a zero-value indicates
* this code should determine this value, using a suitable method. * this code should determine this value, using a suitable method.
* *
* stackSize: in bytes, as set by the launcher, a zero-value indicates * stackSize: in bytes, as set by the launcher, a zero-value indicates
* this code determine this value, using a suitable method. * this code determine this value, using a suitable method or omit the
* line entirely.
*/ */
static void showSettings(boolean printToStderr, String optionFlag, static void showSettings(boolean printToStderr, String optionFlag,
long maxHeapSize, long stackSize, boolean isServer) { long initialHeapSize, long maxHeapSize, long stackSize,
boolean isServer) {
PrintStream ostream = (printToStderr) ? System.err : System.out; PrintStream ostream = (printToStderr) ? System.err : System.out;
String opts[] = optionFlag.split(":"); String opts[] = optionFlag.split(":");
...@@ -112,7 +116,8 @@ public enum LauncherHelper { ...@@ -112,7 +116,8 @@ public enum LauncherHelper {
: "all"; : "all";
switch (optStr) { switch (optStr) {
case "vm": case "vm":
printVmSettings(ostream, maxHeapSize, stackSize, isServer); printVmSettings(ostream, initialHeapSize, maxHeapSize,
stackSize, isServer);
break; break;
case "properties": case "properties":
printProperties(ostream); printProperties(ostream);
...@@ -121,7 +126,8 @@ public enum LauncherHelper { ...@@ -121,7 +126,8 @@ public enum LauncherHelper {
printLocale(ostream); printLocale(ostream);
break; break;
default: default:
printVmSettings(ostream, maxHeapSize, stackSize, isServer); printVmSettings(ostream, initialHeapSize, maxHeapSize,
stackSize, isServer);
printProperties(ostream); printProperties(ostream);
printLocale(ostream); printLocale(ostream);
break; break;
...@@ -131,18 +137,25 @@ public enum LauncherHelper { ...@@ -131,18 +137,25 @@ public enum LauncherHelper {
/* /*
* prints the main vm settings subopt/section * prints the main vm settings subopt/section
*/ */
private static void printVmSettings(PrintStream ostream, long maxHeapSize, private static void printVmSettings(PrintStream ostream,
long initialHeapSize, long maxHeapSize,
long stackSize, boolean isServer) { long stackSize, boolean isServer) {
ostream.println(VM_SETTINGS); ostream.println(VM_SETTINGS);
if (stackSize != 0L) { if (stackSize != 0L) {
ostream.println(INDENT + "Stack Size: " + scaleValue(stackSize)); ostream.println(INDENT + "Stack Size: " +
SizePrefix.scaleValue(stackSize));
}
if (initialHeapSize != 0L) {
ostream.println(INDENT + "Min. Heap Size: " +
SizePrefix.scaleValue(initialHeapSize));
} }
if (maxHeapSize != 0L) { if (maxHeapSize != 0L) {
ostream.println(INDENT + "Max. Heap Size: " + scaleValue(maxHeapSize)); ostream.println(INDENT + "Max. Heap Size: " +
SizePrefix.scaleValue(maxHeapSize));
} else { } else {
ostream.println(INDENT + "Max. Heap Size (Estimated): " ostream.println(INDENT + "Max. Heap Size (Estimated): "
+ scaleValue(Runtime.getRuntime().maxMemory())); + SizePrefix.scaleValue(Runtime.getRuntime().maxMemory()));
} }
ostream.println(INDENT + "Ergonomics Machine Class: " ostream.println(INDENT + "Ergonomics Machine Class: "
+ ((isServer) ? "server" : "client")); + ((isServer) ? "server" : "client"));
...@@ -151,28 +164,6 @@ public enum LauncherHelper { ...@@ -151,28 +164,6 @@ public enum LauncherHelper {
ostream.println(); ostream.println();
} }
/*
* scale the incoming values to a human readable form, represented as
* K, M, G and T, see java.c parse_size for the scaled values and
* suffixes.
*/
private static String scaleValue(double v) {
MathContext mc2 = new MathContext(3, RoundingMode.HALF_EVEN);
if (v >= K && v < M) {
return (new BigDecimal(v / K, mc2)).toPlainString() + "K";
} else if (v >= M && v < G) {
return (new BigDecimal(v / M, mc2)).toPlainString() + "M";
} else if (v >= G && v < T) {
return (new BigDecimal(v / G, mc2)).toPlainString() + "G";
} else if (v >= T) {
return (new BigDecimal(v / T, mc2)).toPlainString() + "T";
} else {
return String.format("%.0f", v);
}
}
/* /*
* prints the properties subopt/section * prints the properties subopt/section
*/ */
...@@ -196,16 +187,17 @@ public enum LauncherHelper { ...@@ -196,16 +187,17 @@ public enum LauncherHelper {
String key, String value) { String key, String value) {
ostream.print(INDENT + key + " = "); ostream.print(INDENT + key + " = ");
if (key.equals("line.separator")) { if (key.equals("line.separator")) {
byte[] bytes = value.getBytes(); for (byte b : value.getBytes()) {
for (byte b : bytes) {
switch (b) { switch (b) {
case 0xd: case 0xd:
ostream.print("CR "); ostream.print("\\r ");
break; break;
case 0xa: case 0xa:
ostream.print("LF "); ostream.print("\\n ");
break; break;
default: default:
// print any bizzare line separators in hex, but really
// shouldn't happen.
ostream.printf("0x%02X", b & 0xff); ostream.printf("0x%02X", b & 0xff);
break; break;
} }
...@@ -217,15 +209,14 @@ public enum LauncherHelper { ...@@ -217,15 +209,14 @@ public enum LauncherHelper {
ostream.println(value); ostream.println(value);
return; return;
} }
// pretty print the path values as a list
String[] values = value.split(System.getProperty("path.separator")); String[] values = value.split(System.getProperty("path.separator"));
int len = values.length; boolean first = true;
for (int i = 0 ; i < len ; i++) { for (String s : values) {
if (i == 0) { // first line treated specially if (first) { // first line treated specially
ostream.println(values[i]); ostream.println(s);
first = false;
} else { // following lines prefix with indents } else { // following lines prefix with indents
ostream.print(INDENT + INDENT); ostream.println(INDENT + INDENT + s);
ostream.println(values[i]);
} }
} }
} }
...@@ -236,21 +227,35 @@ public enum LauncherHelper { ...@@ -236,21 +227,35 @@ public enum LauncherHelper {
private static void printLocale(PrintStream ostream) { private static void printLocale(PrintStream ostream) {
Locale locale = Locale.getDefault(); Locale locale = Locale.getDefault();
ostream.println(LOCALE_SETTINGS); ostream.println(LOCALE_SETTINGS);
ostream.println(INDENT + "default locale = " + locale.getDisplayLanguage()); ostream.println(INDENT + "default locale = " +
locale.getDisplayLanguage());
ostream.println(INDENT + "default display locale = " +
Locale.getDefault(Category.DISPLAY).getDisplayName());
ostream.println(INDENT + "default format locale = " +
Locale.getDefault(Category.FORMAT).getDisplayName());
printLocales(ostream); printLocales(ostream);
ostream.println(); ostream.println();
} }
private static void printLocales(PrintStream ostream) { private static void printLocales(PrintStream ostream) {
Locale[] locales = Locale.getAvailableLocales(); Locale[] tlocales = Locale.getAvailableLocales();
final int len = locales == null ? 0 : locales.length; final int len = tlocales == null ? 0 : tlocales.length;
if (len < 1 ) { if (len < 1 ) {
return; return;
} }
// Locale does not implement Comparable so we convert it to String
// and sort it for pretty printing.
Set<String> sortedSet = new TreeSet<>();
for (Locale l : tlocales) {
sortedSet.add(l.toString());
}
ostream.print(INDENT + "available locales = "); ostream.print(INDENT + "available locales = ");
final int last = len - 1 ; Iterator<String> iter = sortedSet.iterator();
for (int i = 0; i < last ; i++) { final int last = len - 1;
ostream.print(locales[i]); for (int i = 0 ; iter.hasNext() ; i++) {
String s = iter.next();
ostream.print(s);
if (i != last) { if (i != last) {
ostream.print(", "); ostream.print(", ");
} }
...@@ -260,7 +265,42 @@ public enum LauncherHelper { ...@@ -260,7 +265,42 @@ public enum LauncherHelper {
ostream.print(INDENT + INDENT); ostream.print(INDENT + INDENT);
} }
} }
ostream.println(locales[last]); }
private enum SizePrefix {
KILO(1024, "K"),
MEGA(1024 * 1024, "M"),
GIGA(1024 * 1024 * 1024, "G"),
TERA(1024L * 1024L * 1024L * 1024L, "T");
long size;
String abbrev;
SizePrefix(long size, String abbrev) {
this.size = size;
this.abbrev = abbrev;
}
private static String scale(long v, SizePrefix prefix) {
return BigDecimal.valueOf(v).divide(BigDecimal.valueOf(prefix.size),
2, RoundingMode.HALF_EVEN).toPlainString() + prefix.abbrev;
}
/*
* scale the incoming values to a human readable form, represented as
* K, M, G and T, see java.c parse_size for the scaled values and
* suffixes. The lowest possible scaled value is Kilo.
*/
static String scaleValue(long v) {
if (v < MEGA.size) {
return scale(v, KILO);
} else if (v < GIGA.size) {
return scale(v, MEGA);
} else if (v < TERA.size) {
return scale(v, GIGA);
} else {
return scale(v, TERA);
}
}
} }
/** /**
......
...@@ -74,8 +74,15 @@ public class Settings { ...@@ -74,8 +74,15 @@ public class Settings {
static void runTestOptionDefault() throws IOException { static void runTestOptionDefault() throws IOException {
TestHelper.TestResult tr = null; TestHelper.TestResult tr = null;
tr = TestHelper.doExec(TestHelper.javaCmd, "-Xmx512m", "-Xss128k", tr = TestHelper.doExec(TestHelper.javaCmd, "-Xms64m", "-Xmx512m",
"-XshowSettings", "-jar", testJar.getAbsolutePath()); "-Xss128k", "-XshowSettings", "-jar", testJar.getAbsolutePath());
containsAllOptions(tr);
if (!tr.isOK()) {
System.out.println(tr.status);
throw new RuntimeException("test fails");
}
tr = TestHelper.doExec(TestHelper.javaCmd, "-Xms65536k", "-Xmx712m",
"-Xss122880", "-XshowSettings", "-jar", testJar.getAbsolutePath());
containsAllOptions(tr); containsAllOptions(tr);
if (!tr.isOK()) { if (!tr.isOK()) {
System.out.println(tr.status); System.out.println(tr.status);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册