8179268: Factor out AdaptiveSizePolicy from top-level interfaces CollectorPolicy and CollectedHeap
authorrkennke
Tue, 04 Jul 2017 20:41:33 +0200
changeset 46657 cc4ac8d1ef6b
parent 46656 ff494a8dcce9
child 46659 2a4cca319443
8179268: Factor out AdaptiveSizePolicy from top-level interfaces CollectorPolicy and CollectedHeap Reviewed-by: pliden, sjohanss
hotspot/src/share/vm/gc/parallel/parallelScavengeHeap.cpp
hotspot/src/share/vm/gc/parallel/parallelScavengeHeap.hpp
hotspot/src/share/vm/gc/shared/adaptiveSizePolicy.hpp
hotspot/src/share/vm/gc/shared/collectedHeap.hpp
hotspot/src/share/vm/gc/shared/collectorPolicy.cpp
hotspot/src/share/vm/gc/shared/collectorPolicy.hpp
hotspot/src/share/vm/runtime/java.cpp
--- a/hotspot/src/share/vm/gc/parallel/parallelScavengeHeap.cpp	Wed Jul 12 12:46:31 2017 +0000
+++ b/hotspot/src/share/vm/gc/parallel/parallelScavengeHeap.cpp	Tue Jul 04 20:41:33 2017 +0200
@@ -582,6 +582,8 @@
     double time = UseParallelOldGC ? PSParallelCompact::accumulated_time()->seconds() : PSMarkSweep::accumulated_time()->seconds();
     tty->print_cr("[Accumulated GC generation 1 time %3.7f secs]", time);
   }
+
+  AdaptiveSizePolicyOutput::print();
 }
 
 
--- a/hotspot/src/share/vm/gc/parallel/parallelScavengeHeap.hpp	Wed Jul 12 12:46:31 2017 +0000
+++ b/hotspot/src/share/vm/gc/parallel/parallelScavengeHeap.hpp	Tue Jul 04 20:41:33 2017 +0200
@@ -266,4 +266,33 @@
   size_t _metadata_used;
 };
 
+// Class that can be used to print information about the
+// adaptive size policy at intervals specified by
+// AdaptiveSizePolicyOutputInterval.  Only print information
+// if an adaptive size policy is in use.
+class AdaptiveSizePolicyOutput : AllStatic {
+  static bool enabled() {
+    return UseParallelGC &&
+           UseAdaptiveSizePolicy &&
+           log_is_enabled(Debug, gc, ergo);
+  }
+ public:
+  static void print() {
+    if (enabled()) {
+      ParallelScavengeHeap::heap()->size_policy()->print();
+    }
+  }
+
+  static void print(AdaptiveSizePolicy* size_policy, uint count) {
+    bool do_print =
+        enabled() &&
+        (AdaptiveSizePolicyOutputInterval > 0) &&
+        (count % AdaptiveSizePolicyOutputInterval) == 0;
+
+    if (do_print) {
+      size_policy->print();
+    }
+  }
+};
+
 #endif // SHARE_VM_GC_PARALLEL_PARALLELSCAVENGEHEAP_HPP
--- a/hotspot/src/share/vm/gc/shared/adaptiveSizePolicy.hpp	Wed Jul 12 12:46:31 2017 +0000
+++ b/hotspot/src/share/vm/gc/shared/adaptiveSizePolicy.hpp	Tue Jul 04 20:41:33 2017 +0200
@@ -505,33 +505,4 @@
   void print_tenuring_threshold(uint new_tenuring_threshold) const;
 };
 
-// Class that can be used to print information about the
-// adaptive size policy at intervals specified by
-// AdaptiveSizePolicyOutputInterval.  Only print information
-// if an adaptive size policy is in use.
-class AdaptiveSizePolicyOutput : StackObj {
-  static bool enabled() {
-    return UseParallelGC &&
-           UseAdaptiveSizePolicy &&
-           log_is_enabled(Debug, gc, ergo);
-  }
- public:
-  static void print() {
-    if (enabled()) {
-      Universe::heap()->size_policy()->print();
-    }
-  }
-
-  static void print(AdaptiveSizePolicy* size_policy, uint count) {
-    bool do_print =
-        enabled() &&
-        (AdaptiveSizePolicyOutputInterval > 0) &&
-        (count % AdaptiveSizePolicyOutputInterval) == 0;
-
-    if (do_print) {
-      size_policy->print();
-    }
-  }
-};
-
 #endif // SHARE_VM_GC_SHARED_ADAPTIVESIZEPOLICY_HPP
--- a/hotspot/src/share/vm/gc/shared/collectedHeap.hpp	Wed Jul 12 12:46:31 2017 +0000
+++ b/hotspot/src/share/vm/gc/shared/collectedHeap.hpp	Tue Jul 04 20:41:33 2017 +0200
@@ -478,9 +478,6 @@
 
   void increment_total_full_collections() { _total_full_collections++; }
 
-  // Return the AdaptiveSizePolicy for the heap.
-  virtual AdaptiveSizePolicy* size_policy() = 0;
-
   // Return the CollectorPolicy for the heap
   virtual CollectorPolicy* collector_policy() const = 0;
 
--- a/hotspot/src/share/vm/gc/shared/collectorPolicy.cpp	Wed Jul 12 12:46:31 2017 +0000
+++ b/hotspot/src/share/vm/gc/shared/collectorPolicy.cpp	Tue Jul 04 20:41:33 2017 +0200
@@ -51,7 +51,6 @@
     _initial_heap_byte_size(InitialHeapSize),
     _max_heap_byte_size(MaxHeapSize),
     _min_heap_byte_size(Arguments::min_heap_size()),
-    _size_policy(NULL),
     _should_clear_all_soft_refs(false),
     _all_soft_refs_clear(false)
 {}
@@ -157,12 +156,6 @@
 }
 
 void CollectorPolicy::cleared_all_soft_refs() {
-  // If near gc overhear limit, continue to clear SoftRefs.  SoftRefs may
-  // have been cleared in the last collection but if the gc overhear
-  // limit continues to be near, SoftRefs should still be cleared.
-  if (size_policy() != NULL) {
-    _should_clear_all_soft_refs = size_policy()->gc_overhead_limit_near();
-  }
   _all_soft_refs_clear = true;
 }
 
@@ -195,7 +188,8 @@
     _max_old_size(0),
     _gen_alignment(0),
     _young_gen_spec(NULL),
-    _old_gen_spec(NULL)
+    _old_gen_spec(NULL),
+    _size_policy(NULL)
 {}
 
 size_t GenCollectorPolicy::scale_by_NewRatio_aligned(size_t base_size) {
@@ -220,6 +214,17 @@
                                         GCTimeRatio);
 }
 
+void GenCollectorPolicy::cleared_all_soft_refs() {
+  // If near gc overhear limit, continue to clear SoftRefs.  SoftRefs may
+  // have been cleared in the last collection but if the gc overhear
+  // limit continues to be near, SoftRefs should still be cleared.
+  if (size_policy() != NULL) {
+    _should_clear_all_soft_refs = size_policy()->gc_overhead_limit_near();
+  }
+
+  CollectorPolicy::cleared_all_soft_refs();
+}
+
 size_t GenCollectorPolicy::young_gen_size_lower_bound() {
   // The young generation must be aligned and have room for eden + two survivors
   return align_up(3 * _space_alignment, _gen_alignment);
--- a/hotspot/src/share/vm/gc/shared/collectorPolicy.hpp	Wed Jul 12 12:46:31 2017 +0000
+++ b/hotspot/src/share/vm/gc/shared/collectorPolicy.hpp	Tue Jul 04 20:41:33 2017 +0200
@@ -72,9 +72,6 @@
   size_t _space_alignment;
   size_t _heap_alignment;
 
-  // The sizing of the heap is controlled by a sizing policy.
-  AdaptiveSizePolicy* _size_policy;
-
   // Set to true when policy wants soft refs cleared.
   // Reset to false by gc after it clears all soft refs.
   bool _should_clear_all_soft_refs;
@@ -105,7 +102,6 @@
   size_t max_heap_byte_size()     { return _max_heap_byte_size; }
   size_t min_heap_byte_size()     { return _min_heap_byte_size; }
 
-  AdaptiveSizePolicy* size_policy() { return _size_policy; }
   bool should_clear_all_soft_refs() { return _should_clear_all_soft_refs; }
   void set_should_clear_all_soft_refs(bool v) { _should_clear_all_soft_refs = v; }
   // Returns the current value of _should_clear_all_soft_refs.
@@ -116,7 +112,7 @@
 
   // Called by the GC after Soft Refs have been cleared to indicate
   // that the request in _should_clear_all_soft_refs has been fulfilled.
-  void cleared_all_soft_refs();
+  virtual void cleared_all_soft_refs();
 
   // Identification methods.
   virtual GenCollectorPolicy*           as_generation_policy()            { return NULL; }
@@ -160,7 +156,8 @@
 class GenCollectorPolicy : public CollectorPolicy {
   friend class TestGenCollectorPolicy;
   friend class VMStructs;
- protected:
+
+protected:
   size_t _min_young_size;
   size_t _initial_young_size;
   size_t _max_young_size;
@@ -177,6 +174,9 @@
 
   GCPolicyCounters* _gc_policy_counters;
 
+  // The sizing of the heap is controlled by a sizing policy.
+  AdaptiveSizePolicy* _size_policy;
+
   // Return true if an allocation should be attempted in the older generation
   // if it fails in the younger generation.  Return false, otherwise.
   virtual bool should_try_older_generation_allocation(size_t word_size) const;
@@ -249,9 +249,14 @@
   HeapWord *satisfy_failed_allocation(size_t size, bool is_tlab);
 
   // Adaptive size policy
+  AdaptiveSizePolicy* size_policy() { return _size_policy; }
+
   virtual void initialize_size_policy(size_t init_eden_size,
                                       size_t init_promo_size,
                                       size_t init_survivor_size);
+
+  virtual void cleared_all_soft_refs();
+
 };
 
 class MarkSweepPolicy : public GenCollectorPolicy {
--- a/hotspot/src/share/vm/runtime/java.cpp	Wed Jul 12 12:46:31 2017 +0000
+++ b/hotspot/src/share/vm/runtime/java.cpp	Tue Jul 04 20:41:33 2017 +0200
@@ -486,7 +486,6 @@
       ClassLoaderDataGraph::dump_on(log.trace_stream());
     }
   }
-  AdaptiveSizePolicyOutput::print();
 
   if (PrintBytecodeHistogram) {
     BytecodeHistogram::print();