# HG changeset patch # User rkennke # Date 1499193693 -7200 # Tue Jul 04 20:41:33 2017 +0200 # Node ID c4df803e89ae10b7f84832797d5baed9c8b34d39 # Parent 9da0c9f26e79493c0564c5ae316080abb2603c5e 8179268: Factor out AdaptiveSizePolicy from top-level interfaces CollectorPolicy and CollectedHeap Reviewed-by: pliden, mgerdin diff --git a/src/share/vm/gc/parallel/parallelScavengeHeap.hpp b/src/share/vm/gc/parallel/parallelScavengeHeap.hpp --- a/src/share/vm/gc/parallel/parallelScavengeHeap.hpp +++ b/src/share/vm/gc/parallel/parallelScavengeHeap.hpp @@ -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 diff --git a/src/share/vm/gc/shared/adaptiveSizePolicy.hpp b/src/share/vm/gc/shared/adaptiveSizePolicy.hpp --- a/src/share/vm/gc/shared/adaptiveSizePolicy.hpp +++ b/src/share/vm/gc/shared/adaptiveSizePolicy.hpp @@ -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 diff --git a/src/share/vm/gc/shared/collectedHeap.hpp b/src/share/vm/gc/shared/collectedHeap.hpp --- a/src/share/vm/gc/shared/collectedHeap.hpp +++ b/src/share/vm/gc/shared/collectedHeap.hpp @@ -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; diff --git a/src/share/vm/gc/shared/collectorPolicy.cpp b/src/share/vm/gc/shared/collectorPolicy.cpp --- a/src/share/vm/gc/shared/collectorPolicy.cpp +++ b/src/share/vm/gc/shared/collectorPolicy.cpp @@ -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); diff --git a/src/share/vm/gc/shared/collectorPolicy.hpp b/src/share/vm/gc/shared/collectorPolicy.hpp --- a/src/share/vm/gc/shared/collectorPolicy.hpp +++ b/src/share/vm/gc/shared/collectorPolicy.hpp @@ -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 { diff --git a/src/share/vm/runtime/java.cpp b/src/share/vm/runtime/java.cpp --- a/src/share/vm/runtime/java.cpp +++ b/src/share/vm/runtime/java.cpp @@ -76,6 +76,7 @@ #include "utilities/vmError.hpp" #if INCLUDE_ALL_GCS #include "gc/cms/concurrentMarkSweepThread.hpp" +#include "gc/parallel/parallelScavengeHeap.hpp" #include "gc/parallel/psScavenge.hpp" #endif // INCLUDE_ALL_GCS #ifdef COMPILER1 @@ -486,7 +487,10 @@ ClassLoaderDataGraph::dump_on(log.trace_stream()); } } + +#if INCLUDE_ALL_GCS AdaptiveSizePolicyOutput::print(); +#endif if (PrintBytecodeHistogram) { BytecodeHistogram::print();