8209061: Move G1 serviceability functionality to G1MonitoringSupport
authortschatzl
Wed, 22 Aug 2018 20:37:07 +0200
changeset 51497 ec014e5694ec
parent 51496 bf6b66fa8bdf
child 51498 9a5200b84046
8209061: Move G1 serviceability functionality to G1MonitoringSupport Reviewed-by: phh, sangheki
src/hotspot/share/gc/g1/g1CollectedHeap.cpp
src/hotspot/share/gc/g1/g1CollectedHeap.hpp
src/hotspot/share/gc/g1/g1FullCollector.cpp
src/hotspot/share/gc/g1/g1FullCollector.hpp
src/hotspot/share/gc/g1/g1FullGCScope.cpp
src/hotspot/share/gc/g1/g1FullGCScope.hpp
src/hotspot/share/gc/g1/g1MonitoringSupport.cpp
src/hotspot/share/gc/g1/g1MonitoringSupport.hpp
src/hotspot/share/services/memoryPool.hpp
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Wed Aug 22 20:37:07 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Wed Aug 22 20:37:07 2018 +0200
@@ -1125,7 +1125,7 @@
   const bool do_clear_all_soft_refs = clear_all_soft_refs ||
       soft_ref_policy()->should_clear_all_soft_refs();
 
-  G1FullCollector collector(this, &_full_gc_memory_manager, explicit_gc, do_clear_all_soft_refs);
+  G1FullCollector collector(this, explicit_gc, do_clear_all_soft_refs);
   GCTraceTime(Info, gc) tm("Pause Full", NULL, gc_cause(), true);
 
   collector.prepare_collection();
@@ -1474,11 +1474,6 @@
   _collector_policy(collector_policy),
   _card_table(NULL),
   _soft_ref_policy(),
-  _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),
   _old_set("Old Region Set", new OldRegionSetChecker()),
   _archive_set("Archive Region Set", new ArchiveRegionSetChecker()),
   _humongous_set("Humongous Region Set", new HumongousRegionSetChecker()),
@@ -1808,20 +1803,6 @@
   return JNI_OK;
 }
 
-void G1CollectedHeap::initialize_serviceability() {
-  _eden_pool = new G1EdenPool(this);
-  _survivor_pool = new G1SurvivorPool(this);
-  _old_pool = new G1OldGenPool(this);
-
-  _full_gc_memory_manager.add_pool(_eden_pool);
-  _full_gc_memory_manager.add_pool(_survivor_pool);
-  _full_gc_memory_manager.add_pool(_old_pool);
-
-  _memory_manager.add_pool(_eden_pool);
-  _memory_manager.add_pool(_survivor_pool);
-  _memory_manager.add_pool(_old_pool, false /* always_affected_by_gc */);
-}
-
 void G1CollectedHeap::stop() {
   // Stop all concurrent threads. We do this to make sure these threads
   // do not continue to execute and access resources (e.g. logging)
@@ -2918,9 +2899,9 @@
     active_workers = workers()->update_active_workers(active_workers);
     log_info(gc,task)("Using %u workers of %u for evacuation", active_workers, workers()->total_workers());
 
-    TraceCollectorStats tcs(g1mm()->incremental_collection_counters());
-    TraceMemoryManagerStats tms(&_memory_manager, gc_cause(),
-                                collector_state()->yc_type() == Mixed /* allMemoryPoolsAffected */);
+    G1MonitoringScope ms(g1mm(),
+                         false /* full_gc */,
+                         collector_state()->yc_type() == Mixed /* all_memory_pools_affected */);
 
     G1HeapTransition heap_transition(this);
     size_t heap_used_bytes_before_gc = used();
@@ -4995,17 +4976,14 @@
   CodeCache::blobs_do(&blob_cl);
 }
 
+void G1CollectedHeap::initialize_serviceability() {
+  _g1mm->initialize_serviceability();
+}
+
 GrowableArray<GCMemoryManager*> G1CollectedHeap::memory_managers() {
-  GrowableArray<GCMemoryManager*> memory_managers(2);
-  memory_managers.append(&_memory_manager);
-  memory_managers.append(&_full_gc_memory_manager);
-  return memory_managers;
+  return _g1mm->memory_managers();
 }
 
 GrowableArray<MemoryPool*> G1CollectedHeap::memory_pools() {
-  GrowableArray<MemoryPool*> memory_pools(3);
-  memory_pools.append(_eden_pool);
-  memory_pools.append(_survivor_pool);
-  memory_pools.append(_old_pool);
-  return memory_pools;
+  return _g1mm->memory_pools();
 }
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp	Wed Aug 22 20:37:07 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp	Wed Aug 22 20:37:07 2018 +0200
@@ -51,7 +51,6 @@
 #include "gc/shared/preservedMarks.hpp"
 #include "gc/shared/softRefPolicy.hpp"
 #include "memory/memRegion.hpp"
-#include "services/memoryManager.hpp"
 #include "utilities/stack.hpp"
 
 // A "G1CollectedHeap" is an implementation of a java heap for HotSpot.
@@ -67,6 +66,7 @@
 class G1ParScanThreadStateSet;
 class G1ParScanThreadState;
 class MemoryPool;
+class MemoryManager;
 class ObjectClosure;
 class SpaceClosure;
 class CompactibleSpaceClosure;
@@ -160,13 +160,6 @@
 
   SoftRefPolicy      _soft_ref_policy;
 
-  GCMemoryManager _memory_manager;
-  GCMemoryManager _full_gc_memory_manager;
-
-  MemoryPool* _eden_pool;
-  MemoryPool* _survivor_pool;
-  MemoryPool* _old_pool;
-
   static size_t _humongous_object_threshold_in_words;
 
   // These sets keep track of old, archive and humongous regions respectively.
@@ -174,8 +167,6 @@
   HeapRegionSet _archive_set;
   HeapRegionSet _humongous_set;
 
-  virtual void initialize_serviceability();
-
   void eagerly_reclaim_humongous_regions();
   // Start a new incremental collection set for the next pause.
   void start_new_collection_set();
@@ -969,6 +960,7 @@
 
   virtual SoftRefPolicy* soft_ref_policy();
 
+  virtual void initialize_serviceability();
   virtual GrowableArray<GCMemoryManager*> memory_managers();
   virtual GrowableArray<MemoryPool*> memory_pools();
 
--- a/src/hotspot/share/gc/g1/g1FullCollector.cpp	Wed Aug 22 20:37:07 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1FullCollector.cpp	Wed Aug 22 20:37:07 2018 +0200
@@ -103,9 +103,9 @@
   return worker_count;
 }
 
-G1FullCollector::G1FullCollector(G1CollectedHeap* heap, GCMemoryManager* memory_manager, bool explicit_gc, bool clear_soft_refs) :
+G1FullCollector::G1FullCollector(G1CollectedHeap* heap, bool explicit_gc, bool clear_soft_refs) :
     _heap(heap),
-    _scope(memory_manager, explicit_gc, clear_soft_refs),
+    _scope(heap->g1mm(), explicit_gc, clear_soft_refs),
     _num_workers(calc_active_workers()),
     _oop_queue_set(_num_workers),
     _array_queue_set(_num_workers),
--- a/src/hotspot/share/gc/g1/g1FullCollector.hpp	Wed Aug 22 20:37:07 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1FullCollector.hpp	Wed Aug 22 20:37:07 2018 +0200
@@ -72,7 +72,7 @@
   ReferenceProcessorSubjectToDiscoveryMutator _is_subject_mutator;
 
 public:
-  G1FullCollector(G1CollectedHeap* heap, GCMemoryManager* memory_manager, bool explicit_gc, bool clear_soft_refs);
+  G1FullCollector(G1CollectedHeap* heap, bool explicit_gc, bool clear_soft_refs);
   ~G1FullCollector();
 
   void prepare_collection();
--- a/src/hotspot/share/gc/g1/g1FullGCScope.cpp	Wed Aug 22 20:37:07 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1FullGCScope.cpp	Wed Aug 22 20:37:07 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, 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
@@ -25,7 +25,7 @@
 #include "precompiled.hpp"
 #include "gc/g1/g1FullGCScope.hpp"
 
-G1FullGCScope::G1FullGCScope(GCMemoryManager* memory_manager, bool explicit_gc, bool clear_soft) :
+G1FullGCScope::G1FullGCScope(G1MonitoringSupport* monitoring_support, bool explicit_gc, bool clear_soft) :
     _rm(),
     _explicit_gc(explicit_gc),
     _g1h(G1CollectedHeap::heap()),
@@ -36,8 +36,7 @@
     _active(),
     _cpu_time(),
     _soft_refs(clear_soft, _g1h->soft_ref_policy()),
-    _collector_stats(_g1h->g1mm()->full_collection_counters()),
-    _memory_stats(memory_manager, _g1h->gc_cause()),
+    _monitoring_scope(monitoring_support, true /* full_gc */, true /* all_memory_pools_affected */),
     _heap_transition(_g1h) {
   _timer.register_gc_start();
   _tracer.report_gc_start(_g1h->gc_cause(), _timer.gc_start());
--- a/src/hotspot/share/gc/g1/g1FullGCScope.hpp	Wed Aug 22 20:37:07 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1FullGCScope.hpp	Wed Aug 22 20:37:07 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, 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
@@ -27,7 +27,6 @@
 
 #include "gc/g1/g1CollectedHeap.hpp"
 #include "gc/g1/g1HeapTransition.hpp"
-#include "gc/shared/collectorCounters.hpp"
 #include "gc/shared/gcId.hpp"
 #include "gc/shared/gcTrace.hpp"
 #include "gc/shared/gcTraceTime.hpp"
@@ -51,12 +50,11 @@
   IsGCActiveMark          _active;
   GCTraceCPUTime          _cpu_time;
   ClearedAllSoftRefs      _soft_refs;
-  TraceCollectorStats     _collector_stats;
-  TraceMemoryManagerStats _memory_stats;
+  G1MonitoringScope       _monitoring_scope;
   G1HeapTransition        _heap_transition;
 
 public:
-  G1FullGCScope(GCMemoryManager* memory_manager, bool explicit_gc, bool clear_soft);
+  G1FullGCScope(G1MonitoringSupport* monitoring_support, bool explicit_gc, bool clear_soft);
   ~G1FullGCScope();
 
   bool is_explicit_gc();
--- a/src/hotspot/share/gc/g1/g1MonitoringSupport.cpp	Wed Aug 22 20:37:07 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1MonitoringSupport.cpp	Wed Aug 22 20:37:07 2018 +0200
@@ -26,9 +26,10 @@
 #include "gc/g1/g1CollectedHeap.inline.hpp"
 #include "gc/g1/g1MonitoringSupport.hpp"
 #include "gc/g1/g1Policy.hpp"
-#include "gc/shared/collectorCounters.hpp"
+#include "gc/g1/g1MemoryPool.hpp"
 #include "gc/shared/hSpaceCounters.hpp"
 #include "memory/metaspaceCounters.hpp"
+#include "services/memoryPool.hpp"
 
 G1GenerationCounters::G1GenerationCounters(G1MonitoringSupport* g1mm,
                                            const char* name,
@@ -77,6 +78,11 @@
 
 G1MonitoringSupport::G1MonitoringSupport(G1CollectedHeap* g1h) :
   _g1h(g1h),
+  _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),
   _incremental_collection_counters(NULL),
   _full_collection_counters(NULL),
   _conc_collection_counters(NULL),
@@ -183,6 +189,41 @@
   }
 }
 
+G1MonitoringSupport::~G1MonitoringSupport() {
+  delete _eden_pool;
+  delete _survivor_pool;
+  delete _old_pool;
+}
+
+void G1MonitoringSupport::initialize_serviceability() {
+  _eden_pool = new G1EdenPool(_g1h);
+  _survivor_pool = new G1SurvivorPool(_g1h);
+  _old_pool = new G1OldGenPool(_g1h);
+
+  _full_gc_memory_manager.add_pool(_eden_pool);
+  _full_gc_memory_manager.add_pool(_survivor_pool);
+  _full_gc_memory_manager.add_pool(_old_pool);
+
+  _memory_manager.add_pool(_eden_pool);
+  _memory_manager.add_pool(_survivor_pool);
+  _memory_manager.add_pool(_old_pool, false /* always_affected_by_gc */);
+}
+
+GrowableArray<GCMemoryManager*> G1MonitoringSupport::memory_managers() {
+  GrowableArray<GCMemoryManager*> memory_managers(2);
+  memory_managers.append(&_memory_manager);
+  memory_managers.append(&_full_gc_memory_manager);
+  return memory_managers;
+}
+
+GrowableArray<MemoryPool*> G1MonitoringSupport::memory_pools() {
+  GrowableArray<MemoryPool*> memory_pools(3);
+  memory_pools.append(_eden_pool);
+  memory_pools.append(_survivor_pool);
+  memory_pools.append(_old_pool);
+  return memory_pools;
+}
+
 void G1MonitoringSupport::recalculate_sizes() {
   // Recalculate all the sizes from scratch. We assume that this is
   // called at a point where no concurrent updates to the various
@@ -261,16 +302,16 @@
 void G1MonitoringSupport::update_sizes() {
   recalculate_sizes();
   if (UsePerfData) {
-    eden_counters()->update_capacity(pad_capacity(eden_space_committed()));
-    eden_counters()->update_used(eden_space_used());
-    // only the to survivor space (s1) is active, so we don't need to
-    // update the counters for the from survivor space (s0)
-    to_counters()->update_capacity(pad_capacity(survivor_space_committed()));
-    to_counters()->update_used(survivor_space_used());
-    old_space_counters()->update_capacity(pad_capacity(old_space_committed()));
-    old_space_counters()->update_used(old_space_used());
-    old_collection_counters()->update_all();
-    young_collection_counters()->update_all();
+    _eden_counters->update_capacity(pad_capacity(eden_space_committed()));
+    _eden_counters->update_used(eden_space_used());
+    // only the "to" survivor space is active, so we don't need to
+    // update the counters for the "from" survivor space
+    _to_counters->update_capacity(pad_capacity(survivor_space_committed()));
+    _to_counters->update_used(survivor_space_used());
+    _old_space_counters->update_capacity(pad_capacity(old_space_committed()));
+    _old_space_counters->update_used(old_space_used());
+    _old_collection_counters->update_all();
+    _young_collection_counters->update_all();
     MetaspaceCounters::update_performance_counters();
     CompressedClassSpaceCounters::update_performance_counters();
   }
@@ -279,6 +320,12 @@
 void G1MonitoringSupport::update_eden_size() {
   recalculate_eden_size();
   if (UsePerfData) {
-    eden_counters()->update_used(eden_space_used());
+    _eden_counters->update_used(eden_space_used());
   }
 }
+
+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->_memory_manager,
+       G1CollectedHeap::heap()->gc_cause(), all_memory_pools_affected) {
+}
--- a/src/hotspot/share/gc/g1/g1MonitoringSupport.hpp	Wed Aug 22 20:37:07 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1MonitoringSupport.hpp	Wed Aug 22 20:37:07 2018 +0200
@@ -25,11 +25,15 @@
 #ifndef SHARE_VM_GC_G1_G1MONITORINGSUPPORT_HPP
 #define SHARE_VM_GC_G1_G1MONITORINGSUPPORT_HPP
 
+#include "gc/shared/collectorCounters.hpp"
 #include "gc/shared/generationCounters.hpp"
+#include "services/memoryManager.hpp"
+#include "services/memoryService.hpp"
 
 class CollectorCounters;
 class G1CollectedHeap;
 class HSpaceCounters;
+class MemoryPool;
 
 // Class for monitoring logical spaces in G1. It provides data for
 // both G1's jstat counters as well as G1's memory pools.
@@ -116,9 +120,18 @@
 
 class G1MonitoringSupport : public CHeapObj<mtGC> {
   friend class VMStructs;
+  friend class G1MonitoringScope;
 
   G1CollectedHeap* _g1h;
 
+  // java.lang.management MemoryManager and MemoryPool support
+  GCMemoryManager _memory_manager;
+  GCMemoryManager _full_gc_memory_manager;
+
+  MemoryPool* _eden_pool;
+  MemoryPool* _survivor_pool;
+  MemoryPool* _old_pool;
+
   // jstat performance counters
   //  incremental collections both young and mixed
   CollectorCounters*   _incremental_collection_counters;
@@ -183,6 +196,11 @@
 
  public:
   G1MonitoringSupport(G1CollectedHeap* g1h);
+  ~G1MonitoringSupport();
+
+  void initialize_serviceability();
+  GrowableArray<GCMemoryManager*> memory_managers();
+  GrowableArray<MemoryPool*> memory_pools();
 
   // Unfortunately, the jstat tool assumes that no space has 0
   // capacity. In our case, given that each space is logical, it's
@@ -206,25 +224,9 @@
   // allocated and update any jstat counters that need to be updated.
   void update_eden_size();
 
-  CollectorCounters* incremental_collection_counters() {
-    return _incremental_collection_counters;
-  }
-  CollectorCounters* full_collection_counters() {
-    return _full_collection_counters;
-  }
   CollectorCounters* conc_collection_counters() {
     return _conc_collection_counters;
   }
-  GenerationCounters* young_collection_counters() {
-    return _young_collection_counters;
-  }
-  GenerationCounters* old_collection_counters() {
-    return _old_collection_counters;
-  }
-  HSpaceCounters*      old_space_counters() { return _old_space_counters; }
-  HSpaceCounters*      eden_counters() { return _eden_counters; }
-  HSpaceCounters*      from_counters() { return _from_counters; }
-  HSpaceCounters*      to_counters() { return _to_counters; }
 
   // Monitoring support used by
   //   MemoryService
@@ -248,6 +250,14 @@
   size_t old_space_used()             { return _old_used;             }
 };
 
+// Scope object for java.lang.management support.
+class G1MonitoringScope : public StackObj {
+  TraceCollectorStats _tcs;
+  TraceMemoryManagerStats _tms;
+public:
+  G1MonitoringScope(G1MonitoringSupport* g1mm, bool full_gc, bool all_memory_pools_affected);
+};
+
 class G1GenerationCounters: public GenerationCounters {
 protected:
   G1MonitoringSupport* _g1mm;
--- a/src/hotspot/share/services/memoryPool.hpp	Wed Aug 22 20:37:07 2018 +0200
+++ b/src/hotspot/share/services/memoryPool.hpp	Wed Aug 22 20:37:07 2018 +0200
@@ -85,6 +85,8 @@
              bool support_usage_threshold,
              bool support_gc_threshold);
 
+  virtual ~MemoryPool() { }
+
   const char* name()                       { return _name; }
   bool        is_heap()                    { return _type == Heap; }
   bool        is_non_heap()                { return _type == NonHeap; }