8152176: Big ParGCCardsPerStrideChunk values can cause overflow for CMS GC
authorsangheki
Fri, 01 Apr 2016 09:43:13 -0700
changeset 37233 e8e674469545
parent 37232 be6614a0fd2b
child 37234 07d212151499
8152176: Big ParGCCardsPerStrideChunk values can cause overflow for CMS GC Summary: Limit the max value of ParGCCardsPerStrideChunk based on card table size and other stride flags Reviewed-by: jmasa, tbenson
hotspot/src/share/vm/gc/shared/cardTableModRefBS.hpp
hotspot/src/share/vm/runtime/commandLineFlagConstraintsGC.cpp
hotspot/src/share/vm/runtime/commandLineFlagConstraintsGC.hpp
hotspot/src/share/vm/runtime/globals.hpp
--- a/hotspot/src/share/vm/gc/shared/cardTableModRefBS.hpp	Fri Apr 01 16:15:37 2016 +0300
+++ b/hotspot/src/share/vm/gc/shared/cardTableModRefBS.hpp	Fri Apr 01 09:43:13 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, 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
@@ -89,14 +89,6 @@
   MemRegion _guard_region;
 
  protected:
-  // Initialization utilities; covered_words is the size of the covered region
-  // in, um, words.
-  inline size_t cards_required(size_t covered_words) {
-    // Add one for a guard card, used to detect errors.
-    const size_t words = align_size_up(covered_words, card_size_in_words);
-    return words / card_size_in_words + 1;
-  }
-
   inline size_t compute_byte_map_size();
 
   // Finds and return the index of the region, if any, to which the given
@@ -172,6 +164,14 @@
 
   bool has_write_ref_pre_barrier() { return false; }
 
+  // Initialization utilities; covered_words is the size of the covered region
+  // in, um, words.
+  inline size_t cards_required(size_t covered_words) {
+    // Add one for a guard card, used to detect errors.
+    const size_t words = align_size_up(covered_words, card_size_in_words);
+    return words / card_size_in_words + 1;
+  }
+
 protected:
 
   CardTableModRefBS(MemRegion whole_heap, const BarrierSet::FakeRtti& fake_rtti);
--- a/hotspot/src/share/vm/runtime/commandLineFlagConstraintsGC.cpp	Fri Apr 01 16:15:37 2016 +0300
+++ b/hotspot/src/share/vm/runtime/commandLineFlagConstraintsGC.cpp	Fri Apr 01 09:43:13 2016 -0700
@@ -382,6 +382,39 @@
   return Flag::SUCCESS;
 }
 
+Flag::Error ParGCCardsPerStrideChunkConstraintFunc(intx value, bool verbose) {
+#if INCLUDE_ALL_GCS
+  if (UseConcMarkSweepGC) {
+    // ParGCCardsPerStrideChunk should be compared with card table size.
+    size_t heap_size = Universe::heap()->reserved_region().word_size();
+    CardTableModRefBS* bs = (CardTableModRefBS*)GenCollectedHeap::heap()->rem_set()->bs();
+    size_t card_table_size = bs->cards_required(heap_size) - 1; // Valid card table size
+
+    if ((size_t)value > card_table_size) {
+      CommandLineError::print(verbose,
+                              "ParGCCardsPerStrideChunk (" INTX_FORMAT ") is too large for the heap size and "
+                              "must be less than or equal to card table size (" SIZE_FORMAT ")\n",
+                              value, card_table_size);
+      return Flag::VIOLATES_CONSTRAINT;
+    }
+
+    // ParGCCardsPerStrideChunk is used with n_strides(ParallelGCThreads*ParGCStridesPerThread)
+    // from CardTableModRefBSForCTRS::process_stride(). Note that ParGCStridesPerThread is already checked
+    // not to make an overflow with ParallelGCThreads from its constraint function.
+    uintx n_strides = ParallelGCThreads * ParGCStridesPerThread;
+    uintx ergo_max = max_uintx / n_strides;
+    if ((uintx)value > ergo_max) {
+      CommandLineError::print(verbose,
+                              "ParGCCardsPerStrideChunk (" INTX_FORMAT ") must be "
+                              "less than or equal to ergonomic maximum (" UINTX_FORMAT ")\n",
+                              value, ergo_max);
+      return Flag::VIOLATES_CONSTRAINT;
+    }
+  }
+#endif
+  return Flag::SUCCESS;
+}
+
 Flag::Error CMSOldPLABMinConstraintFunc(size_t value, bool verbose) {
   Flag::Error status = Flag::SUCCESS;
 
--- a/hotspot/src/share/vm/runtime/commandLineFlagConstraintsGC.hpp	Fri Apr 01 16:15:37 2016 +0300
+++ b/hotspot/src/share/vm/runtime/commandLineFlagConstraintsGC.hpp	Fri Apr 01 09:43:13 2016 -0700
@@ -56,6 +56,7 @@
 #endif // INCLUDE_ALL_GCS
 
 Flag::Error ParGCStridesPerThreadConstraintFunc(uintx value, bool verbose);
+Flag::Error ParGCCardsPerStrideChunkConstraintFunc(intx value, bool verbose);
 Flag::Error CMSOldPLABMinConstraintFunc(size_t value, bool verbose);
 Flag::Error CMSOldPLABMaxConstraintFunc(size_t value, bool verbose);
 Flag::Error MarkStackSizeConstraintFunc(size_t value, bool verbose);
--- a/hotspot/src/share/vm/runtime/globals.hpp	Fri Apr 01 16:15:37 2016 +0300
+++ b/hotspot/src/share/vm/runtime/globals.hpp	Fri Apr 01 09:43:13 2016 -0700
@@ -1629,6 +1629,7 @@
           "The number of cards in each chunk of the parallel chunks used "  \
           "during card table scanning")                                     \
           range(1, max_intx)                                                \
+          constraint(ParGCCardsPerStrideChunkConstraintFunc,AfterMemoryInit)\
                                                                             \
   product(uintx, OldPLABWeight, 50,                                         \
           "Percentage (0-100) used to weight the current sample when "      \