changeset 9616:61530c614f13

Assert heap size consistency withing lock, to avoid race.
author rkennke
date Fri, 11 Sep 2015 18:36:30 +0200
parents 145927fd1e5c
children cff0ec3d1627
files src/share/vm/gc/shenandoah/shenandoahHeapRegionSet.cpp
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/gc/shenandoah/shenandoahHeapRegionSet.cpp	Fri Sep 11 18:36:05 2015 +0200
+++ b/src/share/vm/gc/shenandoah/shenandoahHeapRegionSet.cpp	Fri Sep 11 18:36:30 2015 +0200
@@ -334,7 +334,17 @@
 }
 
 size_t ShenandoahHeapRegionSet::available() const {
-  assert(ShenandoahHeap::heap()->capacity() - ShenandoahHeap::heap()->used()>= _available, "must not be > heap free");
+#ifdef ASSERT
+  // Need to grab the lock here, because the different counters are updated
+  // within the lock. Otherwise we sometimes get inconsistent results.
+  {
+    MutexLockerEx ml(ShenandoahHeap_lock, true);
+    assert(ShenandoahHeap::heap()->capacity() - ShenandoahHeap::heap()->used()>= _available,
+	   err_msg("must not be > heap free, capacity: "SIZE_FORMAT", used: "SIZE_FORMAT", available: "SIZE_FORMAT,
+		   ShenandoahHeap::heap()->capacity(), ShenandoahHeap::heap()->used(), _available)
+	   );
+  }
+#endif
   return _available;
 }