8068582: UseSerialGC not always set up properly
authorpliden
Mon, 20 Apr 2015 08:53:08 +0200
changeset 30271 97a537c6526e
parent 30270 d241c747e6b3
child 30272 8cbe337a692c
child 30274 0942042b7d7c
8068582: UseSerialGC not always set up properly Reviewed-by: jmasa, brutisso, sjohanss
hotspot/src/share/vm/memory/genCollectedHeap.hpp
hotspot/src/share/vm/memory/universe.cpp
hotspot/src/share/vm/runtime/arguments.cpp
hotspot/test/gc/arguments/TestSelectDefaultGC.java
hotspot/test/gc/startup_warnings/TestParNewSerialOld.java
--- a/hotspot/src/share/vm/memory/genCollectedHeap.hpp	Mon Apr 20 16:18:02 2015 +0200
+++ b/hotspot/src/share/vm/memory/genCollectedHeap.hpp	Mon Apr 20 08:53:08 2015 +0200
@@ -273,11 +273,6 @@
   // only and may need to be re-examined in case other
   // kinds of collectors are implemented in the future.
   virtual bool can_elide_initializing_store_barrier(oop new_obj) {
-    // We wanted to assert that:-
-    // assert(UseSerialGC || UseConcMarkSweepGC,
-    //       "Check can_elide_initializing_store_barrier() for this collector");
-    // but unfortunately the flag UseSerialGC need not necessarily always
-    // be set when DefNew+Tenured are being used.
     return is_in_young(new_obj);
   }
 
--- a/hotspot/src/share/vm/memory/universe.cpp	Mon Apr 20 16:18:02 2015 +0200
+++ b/hotspot/src/share/vm/memory/universe.cpp	Mon Apr 20 08:53:08 2015 +0200
@@ -714,7 +714,6 @@
     fatal("UseG1GC not supported in this VM.");
   } else if (UseConcMarkSweepGC) {
     fatal("UseConcMarkSweepGC not supported in this VM.");
-  }
 #else
   if (UseParallelGC) {
     status = Universe::create_heap<ParallelScavengeHeap, GenerationSizer>();
@@ -722,12 +721,11 @@
     status = Universe::create_heap<G1CollectedHeap, G1CollectorPolicyExt>();
   } else if (UseConcMarkSweepGC) {
     status = Universe::create_heap<GenCollectedHeap, ConcurrentMarkSweepPolicy>();
-  }
 #endif
-  else { // UseSerialGC
-    // Don't assert that UseSerialGC is set here because there are cases
-    // where no GC it set and we then fall back to using SerialGC.
+  } else if (UseSerialGC) {
     status = Universe::create_heap<GenCollectedHeap, MarkSweepPolicy>();
+  } else {
+    ShouldNotReachHere();
   }
 
   if (status != JNI_OK) {
--- a/hotspot/src/share/vm/runtime/arguments.cpp	Mon Apr 20 16:18:02 2015 +0200
+++ b/hotspot/src/share/vm/runtime/arguments.cpp	Mon Apr 20 08:53:08 2015 +0200
@@ -1565,12 +1565,15 @@
     } else {
       FLAG_SET_ERGO(bool, UseParallelGC, true);
     }
+  } else {
+    FLAG_SET_ERGO(bool, UseSerialGC, true);
   }
 }
 
 void Arguments::select_gc() {
   if (!gc_selected()) {
     select_gc_ergonomically();
+    guarantee(gc_selected(), "No GC selected");
   }
 }
 
@@ -2096,10 +2099,8 @@
   }
 
   if (UseParNewGC && !UseConcMarkSweepGC) {
-    // !UseConcMarkSweepGC means that we are using serial old gc. Unfortunately we don't
-    // set up UseSerialGC properly, so that can't be used in the check here.
     jio_fprintf(defaultStream::error_stream(),
-        "It is not possible to combine the ParNew young collector with the Serial old collector.\n");
+        "It is not possible to combine the ParNew young collector with any collector other than CMS.\n");
     return false;
   }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/arguments/TestSelectDefaultGC.java	Mon Apr 20 08:53:08 2015 +0200
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test TestSelectDefaultGC
+ * @summary Test selection of GC when no GC option is specified
+ * @bug 8068582
+ * @key gc
+ * @library /testlibrary
+ * @modules java.base/sun.misc
+ *          java.management
+ * @run driver TestSelectDefaultGC
+ */
+
+import com.oracle.java.testlibrary.*;
+import java.util.regex.*;
+
+public class TestSelectDefaultGC {
+    public static boolean versionStringContains(OutputAnalyzer output, String pattern) {
+        Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(output.getStderr());
+        return matcher.find();
+    }
+
+    public static void assertVMOption(OutputAnalyzer output, String option, boolean value) {
+        output.shouldMatch(" " + option + " .*=.* " + value + " ");
+    }
+
+    public static void main(String[] args) throws Exception {
+        // Start VM without specifying GC
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintFlagsFinal", "-version");
+        OutputAnalyzer output = new OutputAnalyzer(pb.start());
+        output.shouldHaveExitValue(0);
+
+        boolean isServerVM = versionStringContains(output, "Server VM");
+
+        // Verify GC selection
+        assertVMOption(output, "UseParallelGC",      isServerVM);
+        assertVMOption(output, "UseParallelOldGC",   isServerVM);
+        assertVMOption(output, "UseSerialGC",        !isServerVM);
+        assertVMOption(output, "UseConcMarkSweepGC", false);
+        assertVMOption(output, "UseG1GC",            false);
+        assertVMOption(output, "UseParNewGC",        false);
+    }
+}
--- a/hotspot/test/gc/startup_warnings/TestParNewSerialOld.java	Mon Apr 20 16:18:02 2015 +0200
+++ b/hotspot/test/gc/startup_warnings/TestParNewSerialOld.java	Mon Apr 20 08:53:08 2015 +0200
@@ -40,7 +40,7 @@
   public static void main(String args[]) throws Exception {
     ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseParNewGC", "-version");
     OutputAnalyzer output = new OutputAnalyzer(pb.start());
-    output.shouldContain("It is not possible to combine the ParNew young collector with the Serial old collector.");
+    output.shouldContain("It is not possible to combine the ParNew young collector with any collector other than CMS.");
     output.shouldContain("Error");
     output.shouldHaveExitValue(1);
   }