< prev index next >

src/hotspot/share/gc/g1/g1MonitoringSupport.cpp

Print this page
rev 51294 : imported patch 8208669-gc-reorder
rev 51302 : imported patch 8209061-move-serviceability-to-monitoringsupport
rev 51303 : imported patch 8209062-cleanup-monitoringsupport
rev 51304 : [mq]: 8207200-getmemoryusage-consistency

@@ -85,10 +85,11 @@
   }
 };
 
 G1MonitoringSupport::G1MonitoringSupport(G1CollectedHeap* g1h) :
   _g1h(g1h),
+  _update_mutex(Mutex::leaf, "G1 Monitoring Support Lock", true, Monitor::_safepoint_check_never),
   _incremental_memory_manager("G1 Young Generation", "end of minor GC"),
   _full_gc_memory_manager("G1 Old Generation", "end of major GC"),
   _eden_pool(NULL),
   _survivor_pool(NULL),
   _old_pool(NULL),

@@ -199,10 +200,15 @@
   _incremental_memory_manager.add_pool(_eden_pool);
   _incremental_memory_manager.add_pool(_survivor_pool);
   _incremental_memory_manager.add_pool(_old_pool, false /* always_affected_by_gc */);
 }
 
+MemoryUsage G1MonitoringSupport::memory_usage() {
+  MutexLockerEx x(&_update_mutex, Mutex::_no_safepoint_check_flag);
+  return MemoryUsage(InitialHeapSize, _overall_used, _overall_committed, _g1h->max_capacity());
+}
+
 GrowableArray<GCMemoryManager*> G1MonitoringSupport::memory_managers() {
   GrowableArray<GCMemoryManager*> memory_managers(2);
   memory_managers.append(&_incremental_memory_manager);
   memory_managers.append(&_full_gc_memory_manager);
   return memory_managers;

@@ -217,10 +223,11 @@
 }
 
 void G1MonitoringSupport::recalculate_sizes() {
   assert_heap_locked_or_at_safepoint(true);
 
+  MutexLockerEx x(&_update_mutex, Mutex::_no_safepoint_check_flag);
   // Recalculate all the sizes from scratch.
 
   uint young_list_length = _g1h->young_regions_count();
   uint survivor_list_length = _g1h->survivor_regions_count();
   assert(young_list_length >= survivor_list_length, "invariant");

@@ -293,17 +300,45 @@
     CompressedClassSpaceCounters::update_performance_counters();
   }
 }
 
 void G1MonitoringSupport::update_eden_size() {
-  // Recalculate everything - this is fast enough.
+  // Recalculate everything - this should be fast enough and we are sure that we do not
+  // miss anything.
   recalculate_sizes();
   if (UsePerfData) {
     _eden_space_counters->update_used(_eden_space_used);
   }
 }
 
+MemoryUsage G1MonitoringSupport::eden_space_memory_usage(size_t initial_size, size_t max_size) {
+  MutexLockerEx x(&_update_mutex, Mutex::_no_safepoint_check_flag);
+
+  return MemoryUsage(initial_size,
+                     _eden_space_used,
+                     _eden_space_committed,
+                     max_size);
+}
+
+MemoryUsage G1MonitoringSupport::survivor_space_memory_usage(size_t initial_size, size_t max_size) {
+  MutexLockerEx x(&_update_mutex, Mutex::_no_safepoint_check_flag);
+
+  return MemoryUsage(initial_size,
+                     _survivor_space_used,
+                     _survivor_space_committed,
+                     max_size);
+}
+
+MemoryUsage G1MonitoringSupport::old_gen_memory_usage(size_t initial_size, size_t max_size) {
+  MutexLockerEx x(&_update_mutex, Mutex::_no_safepoint_check_flag);
+
+  return MemoryUsage(initial_size,
+                     _old_gen_used,
+                     _old_gen_committed,
+                     max_size);
+}
+
 G1MonitoringScope::G1MonitoringScope(G1MonitoringSupport* g1mm, bool full_gc, bool all_memory_pools_affected) :
   _tcs(full_gc ? g1mm->_full_collection_counters : g1mm->_incremental_collection_counters),
   _tms(full_gc ? &g1mm->_full_gc_memory_manager : &g1mm->_incremental_memory_manager,
        G1CollectedHeap::heap()->gc_cause(), all_memory_pools_affected) {
 }
< prev index next >