jdk/src/share/bin/java.c
changeset 7297 906c58a8b849
parent 7028 adadd244f506
child 7810 d4730191e53c
--- a/jdk/src/share/bin/java.c	Wed Nov 24 07:43:06 2010 +0800
+++ b/jdk/src/share/bin/java.c	Tue Nov 23 16:52:39 2010 -0800
@@ -65,6 +65,7 @@
 static jboolean showVersion = JNI_FALSE;  /* print but continue */
 static jboolean printUsage = JNI_FALSE;   /* print and exit*/
 static jboolean printXUsage = JNI_FALSE;  /* print and exit*/
+static char     *showSettings = NULL;      /* print but continue */
 
 static const char *_program_name;
 static const char *_launcher_name;
@@ -109,6 +110,7 @@
 
 static void PrintJavaVersion(JNIEnv *env, jboolean extraLF);
 static void PrintUsage(JNIEnv* env, jboolean doXUsage);
+static void ShowSettings(JNIEnv* env, char *optString);
 
 static void SetPaths(int argc, char **argv);
 
@@ -157,6 +159,7 @@
  * create a new thread to invoke JVM. See 6316197 for more information.
  */
 static jlong threadStackSize = 0;  /* stack size of the new thread */
+static jlong heapSize        = 0;  /* heap size */
 
 int JNICALL JavaMain(void * args); /* entry point                  */
 
@@ -376,6 +379,10 @@
         }
     }
 
+    if (showSettings != NULL) {
+        ShowSettings(env, showSettings);
+        CHECK_EXCEPTION_LEAVE(0);
+    }
     /* If the user specified neither a class name nor a JAR file */
     if (printXUsage || printUsage || (jarfile == 0 && classname == 0)) {
         PrintUsage(env, printXUsage);
@@ -611,7 +618,7 @@
 
 /* copied from HotSpot function "atomll()" */
 static int
-parse_stack_size(const char *s, jlong *result) {
+parse_size(const char *s, jlong *result) {
   jlong n = 0;
   int args_read = sscanf(s, jlong_format_specifier(), &n);
   if (args_read != 1) {
@@ -673,10 +680,17 @@
     options[numOptions++].extraInfo = info;
 
     if (JLI_StrCCmp(str, "-Xss") == 0) {
-      jlong tmp;
-      if (parse_stack_size(str + 4, &tmp)) {
-        threadStackSize = tmp;
-      }
+        jlong tmp;
+        if (parse_size(str + 4, &tmp)) {
+            threadStackSize = tmp;
+        }
+    }
+
+    if (JLI_StrCCmp(str, "-Xmx") == 0) {
+        jlong tmp;
+        if (parse_size(str + 4, &tmp)) {
+            heapSize = tmp;
+        }
     }
 }
 
@@ -1015,6 +1029,13 @@
             printXUsage = JNI_TRUE;
             return JNI_TRUE;
 /*
+ * The following case checks for -XshowSettings OR -XshowSetting:SUBOPT.
+ * In the latter case, any SUBOPT value not recognized will default to "all"
+ */
+        } else if (JLI_StrCmp(arg, "-XshowSettings") == 0 ||
+                JLI_StrCCmp(arg, "-XshowSettings:") == 0) {
+            showSettings = arg;
+/*
  * The following case provide backward compatibility with old-style
  * command line options.
  */
@@ -1475,6 +1496,27 @@
 }
 
 /*
+ * Prints all the Java settings, see the java implementation for more details.
+ */
+static void
+ShowSettings(JNIEnv *env, char *optString)
+{
+    jclass cls;
+    jmethodID showSettingsID;
+    jstring joptString;
+    NULL_CHECK(cls = FindBootStrapClass(env, "sun/launcher/LauncherHelper"));
+    NULL_CHECK(showSettingsID = (*env)->GetStaticMethodID(env, cls,
+            "showSettings", "(ZLjava/lang/String;JJZ)V"));
+    joptString = (*env)->NewStringUTF(env, optString);
+    (*env)->CallStaticVoidMethod(env, cls, showSettingsID,
+                                 JNI_TRUE,
+                                 joptString,
+                                 (jlong)heapSize,
+                                 (jlong)threadStackSize,
+                                 ServerClassMachine());
+}
+
+/*
  * Prints default usage or the Xusage message, see sun.launcher.LauncherHelper.java
  */
 static void