8188105: Make -Xshare:auto the default for server VM
authoriklam
Mon, 23 Apr 2018 07:51:46 -0700
changeset 49853 08829995db7c
parent 49852 4d3218e5f170
child 49854 0724da162227
8188105: Make -Xshare:auto the default for server VM Reviewed-by: dholmes, lfoltan, acorn, mseledtsov, jiangli
src/hotspot/share/runtime/arguments.cpp
test/hotspot/jtreg/runtime/CDSCompressedKPtrs/XShareAuto.java
test/hotspot/jtreg/runtime/CompressedOops/CompressedClassPointers.java
--- a/src/hotspot/share/runtime/arguments.cpp	Mon Apr 23 16:25:16 2018 +0200
+++ b/src/hotspot/share/runtime/arguments.cpp	Mon Apr 23 07:51:46 2018 -0700
@@ -1820,18 +1820,6 @@
 
   GCConfig::initialize();
 
-#if COMPILER2_OR_JVMCI
-  // Shared spaces work fine with other GCs but causes bytecode rewriting
-  // to be disabled, which hurts interpreter performance and decreases
-  // server performance.  When -server is specified, keep the default off
-  // unless it is asked for.  Future work: either add bytecode rewriting
-  // at link time, or rewrite bytecodes in non-shared methods.
-  if (is_server_compilation_mode_vm() && !DumpSharedSpaces && !RequireSharedSpaces &&
-      (FLAG_IS_DEFAULT(UseSharedSpaces) || !UseSharedSpaces)) {
-    no_shared_spaces("COMPILER2 default: -Xshare:auto | off, have to manually setup to on.");
-  }
-#endif
-
 #if defined(IA32)
   // Only server compiler can optimize safepoints well enough.
   if (!is_server_compilation_mode_vm()) {
--- a/test/hotspot/jtreg/runtime/CDSCompressedKPtrs/XShareAuto.java	Mon Apr 23 16:25:16 2018 +0200
+++ b/test/hotspot/jtreg/runtime/CDSCompressedKPtrs/XShareAuto.java	Mon Apr 23 07:51:46 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2018, 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
@@ -25,7 +25,7 @@
  * @test
  * @requires vm.cds
  * @bug 8005933
- * @summary Test that -Xshare:auto uses CDS when explicitly specified with -server.
+ * @summary -Xshare:auto is the default when -Xshare is not specified
  * @library /test/lib
  * @modules java.base/jdk.internal.misc
  *          java.management
@@ -45,34 +45,30 @@
         output.shouldContain("Loading classes to share");
         output.shouldHaveExitValue(0);
 
-        pb = ProcessTools.createJavaProcessBuilder(
-            "-server", "-XX:+UnlockDiagnosticVMOptions",
-            "-XX:SharedArchiveFile=./XShareAuto.jsa", "-version");
-        output = new OutputAnalyzer(pb.start());
-        String outputString = output.getOutput();
-        // We asked for server but it could be aliased to something else
-        if (outputString.contains("Server VM") && !outputString.contains("emulated-client")) {
-            // In server case we don't expect to see sharing flag
-            output.shouldNotContain("sharing");
+
+        // We have 2 test cases:
+        String cases[] = {
+            "-Xshare:auto",    // case [1]: -Xshare:auto is explicitly specified.
+            "-showversion"     // case [2]: -Xshare:auto is not explicitly specified,
+                               //           but VM should still use it by default.
+        };
+
+        for (String x : cases) {
+            pb = ProcessTools.createJavaProcessBuilder(
+                "-XX:+UnlockDiagnosticVMOptions",
+                "-XX:SharedArchiveFile=./XShareAuto.jsa",
+                "-Xlog:cds",
+                x,
+                "-version");
+            output = new OutputAnalyzer(pb.start());
+            String outputString = output.getOutput();
+
+            if (!outputString.contains("Unable to map")) {
+                // sharing may not be enabled if XShareAuto.jsa cannot be mapped due to
+                // ASLR.
+                output.shouldContain("sharing");
+            }
             output.shouldHaveExitValue(0);
         }
-        else {
-            System.out.println("Skipping test - no Server VM available");
-            return;
-        }
-
-        pb = ProcessTools.createJavaProcessBuilder(
-            "-server", "-Xshare:auto", "-XX:+UnlockDiagnosticVMOptions",
-            "-XX:SharedArchiveFile=./XShareAuto.jsa", "-Xlog:cds", "-version");
-        output = new OutputAnalyzer(pb.start());
-        try {
-            output.shouldContain("sharing");
-        } catch (RuntimeException e) {
-            // if sharing failed due to ASLR or similar reasons,
-            // check whether sharing was attempted at all (UseSharedSpaces)
-            output.shouldContain("UseSharedSpaces:");
-            output.shouldNotContain("Unable to map %s");
-        }
-        output.shouldHaveExitValue(0);
     }
 }
--- a/test/hotspot/jtreg/runtime/CompressedOops/CompressedClassPointers.java	Mon Apr 23 16:25:16 2018 +0200
+++ b/test/hotspot/jtreg/runtime/CompressedOops/CompressedClassPointers.java	Mon Apr 23 07:51:46 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2018, 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
@@ -42,6 +42,8 @@
             "-XX:SharedBaseAddress=8g",
             "-Xmx128m",
             "-Xlog:gc+metaspace=trace",
+            "-Xshare:off",
+            "-Xlog:cds=trace",
             "-XX:+VerifyBeforeGC", "-version");
         OutputAnalyzer output = new OutputAnalyzer(pb.start());
         output.shouldContain("Narrow klass base: 0x0000000000000000");
@@ -54,6 +56,8 @@
             "-XX:CompressedClassSpaceSize=3g",
             "-Xmx128m",
             "-Xlog:gc+metaspace=trace",
+            "-Xshare:off",
+            "-Xlog:cds=trace",
             "-XX:+VerifyBeforeGC", "-version");
         OutputAnalyzer output = new OutputAnalyzer(pb.start());
         output.shouldContain("Narrow klass base: 0x0000000000000000, Narrow klass shift: 3");
@@ -66,6 +70,8 @@
             "-Xmx30g",
             "-XX:-UseAOT", // AOT explicitly set klass shift to 3.
             "-Xlog:gc+metaspace=trace",
+            "-Xshare:off",
+            "-Xlog:cds=trace",
             "-XX:+VerifyBeforeGC", "-version");
         OutputAnalyzer output = new OutputAnalyzer(pb.start());
         output.shouldNotContain("Narrow klass base: 0x0000000000000000");