8221509: Refactor assert( G1CollectedHeap::used() == recalculate_used() ) with better message
authorsangheki
Mon, 06 May 2019 14:19:48 -0700
changeset 54726 671e35cf611b
parent 54725 bfa52d3068f5
child 54727 0f798f21e8c2
8221509: Refactor assert( G1CollectedHeap::used() == recalculate_used() ) with better message Reviewed-by: tschatzl, manc
src/hotspot/share/gc/g1/g1CollectedHeap.cpp
src/hotspot/share/gc/g1/g1CollectedHeap.hpp
src/hotspot/share/gc/g1/g1Policy.cpp
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Mon May 06 15:25:57 2019 -0400
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Mon May 06 14:19:48 2019 -0700
@@ -1036,7 +1036,7 @@
 
 void G1CollectedHeap::verify_before_full_collection(bool explicit_gc) {
   assert(!GCCause::is_user_requested_gc(gc_cause()) || explicit_gc, "invariant");
-  assert(used() == recalculate_used(), "Should be equal");
+  assert_used_and_recalculate_used_equal(this);
   _verifier->verify_region_sets_optional();
   _verifier->verify_before_gc(G1HeapVerifier::G1VerifyFull);
   _verifier->check_bitmaps("Full GC Start");
@@ -4539,9 +4539,7 @@
       _archive_allocator->clear_used();
     }
   }
-  assert(used() == recalculate_used(),
-         "inconsistent used(), value: " SIZE_FORMAT " recalculated: " SIZE_FORMAT,
-         used(), recalculate_used());
+  assert_used_and_recalculate_used_equal(this);
 }
 
 // Methods for the mutator alloc region
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp	Mon May 06 15:25:57 2019 -0400
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp	Mon May 06 14:19:48 2019 -0700
@@ -354,6 +354,15 @@
     assert(Thread::current()->is_VM_thread(), "current thread is not VM thread"); \
   } while (0)
 
+#define assert_used_and_recalculate_used_equal(g1h)                           \
+  do {                                                                        \
+    size_t cur_used_bytes = g1h->used();                                      \
+    size_t recal_used_bytes = g1h->recalculate_used();                        \
+    assert(cur_used_bytes == recal_used_bytes, "Used(" SIZE_FORMAT ") is not" \
+           " same as recalculated used(" SIZE_FORMAT ").",                    \
+           cur_used_bytes, recal_used_bytes);                                 \
+  } while (0)
+
   const char* young_gc_name() const;
 
   // The young region list.
--- a/src/hotspot/share/gc/g1/g1Policy.cpp	Mon May 06 15:25:57 2019 -0400
+++ b/src/hotspot/share/gc/g1/g1Policy.cpp	Mon May 06 14:19:48 2019 -0700
@@ -487,10 +487,7 @@
   assert(max_survivor_regions() + _g1h->num_used_regions() <= _g1h->max_regions(),
          "Maximum survivor regions %u plus used regions %u exceeds max regions %u",
          max_survivor_regions(), _g1h->num_used_regions(), _g1h->max_regions());
-
-  assert(_g1h->used() == _g1h->recalculate_used(),
-         "sanity, used: " SIZE_FORMAT " recalculate_used: " SIZE_FORMAT,
-         _g1h->used(), _g1h->recalculate_used());
+  assert_used_and_recalculate_used_equal(_g1h);
 
   phase_times()->record_cur_collection_start_sec(start_time_sec);
   _pending_cards = _g1h->pending_card_num();
@@ -581,8 +578,8 @@
 void G1Policy::record_collection_pause_end(double pause_time_ms, size_t cards_scanned, size_t heap_used_bytes_before_gc) {
   double end_time_sec = os::elapsedTime();
 
+  assert_used_and_recalculate_used_equal(_g1h);
   size_t cur_used_bytes = _g1h->used();
-  assert(cur_used_bytes == _g1h->recalculate_used(), "It should!");
   bool this_pause_included_initial_mark = false;
   bool this_pause_was_young_only = collector_state()->in_young_only_phase();