8014408: G1: crashes with assert assert(prev_committed_card_num == _committed_max_card_num) failed
authorjohnc
Wed, 15 May 2013 22:35:36 -0700
changeset 17394 156f30e1d09a
parent 17393 7e99f263902c
child 17395 2cd3ef1be718
8014408: G1: crashes with assert assert(prev_committed_card_num == _committed_max_card_num) failed Summary: Mismatch in the card number calculation between next and previous committed sizes of the card counts table. Reviewed-by: jmasa, tschatzl
hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.cpp
hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.hpp
--- a/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.cpp	Wed May 15 10:41:22 2013 -0700
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.cpp	Wed May 15 22:35:36 2013 -0700
@@ -101,20 +101,23 @@
          ReservedSpace::allocation_align_size_up(_committed_size),
          err_msg("Unaligned? committed_size: " SIZE_FORMAT, _committed_size));
 
-  // Verify that the committed space for the card counts
-  // matches our committed max card num.
+  // Verify that the committed space for the card counts matches our
+  // committed max card num. Note for some allocation alignments, the
+  // amount of space actually committed for the counts table will be able
+  // to span more cards than the number spanned by the maximum heap.
   size_t prev_committed_size = _committed_size;
-  size_t prev_committed_card_num = prev_committed_size / sizeof(jbyte);
+  size_t prev_committed_card_num = committed_to_card_num(prev_committed_size);
+
   assert(prev_committed_card_num == _committed_max_card_num,
          err_msg("Card mismatch: "
                  "prev: " SIZE_FORMAT ", "
-                 "committed: "SIZE_FORMAT,
-                 prev_committed_card_num, _committed_max_card_num));
+                 "committed: "SIZE_FORMAT", "
+                 "reserved: "SIZE_FORMAT,
+                 prev_committed_card_num, _committed_max_card_num, _reserved_max_card_num));
 
   size_t new_size = (heap_capacity >> CardTableModRefBS::card_shift) * sizeof(jbyte);
   size_t new_committed_size = ReservedSpace::allocation_align_size_up(new_size);
-  size_t new_committed_card_num =
-                MIN2(_reserved_max_card_num, new_committed_size / sizeof(jbyte));
+  size_t new_committed_card_num = committed_to_card_num(new_committed_size);
 
   if (_committed_max_card_num < new_committed_card_num) {
     // we need to expand the backing store for the card counts
--- a/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.hpp	Wed May 15 10:41:22 2013 -0700
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.hpp	Wed May 15 22:35:36 2013 -0700
@@ -94,6 +94,14 @@
     return (jbyte*) (_ct_bot + card_num);
   }
 
+  // Helper routine.
+  // Returns the number of cards that can be counted by the given committed
+  // table size, with a maximum of the number of cards spanned by the max
+  // capacity of the heap.
+  size_t committed_to_card_num(size_t committed_size) {
+    return MIN2(_reserved_max_card_num, committed_size / sizeof(jbyte));
+  }
+
   // Clear the counts table for the given (exclusive) index range.
   void clear_range(size_t from_card_num, size_t to_card_num);