< prev index next >

src/hotspot/share/gc/shared/adaptiveSizePolicy.hpp

Print this page
rev 52582 : 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
Summary: Move check_gc_overhead_limit() and related code to its own class
Reviewed-by:


  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_SHARED_ADAPTIVESIZEPOLICY_HPP
  26 #define SHARE_VM_GC_SHARED_ADAPTIVESIZEPOLICY_HPP
  27 
  28 #include "gc/shared/collectedHeap.hpp"
  29 #include "gc/shared/gcCause.hpp"
  30 #include "gc/shared/gcUtil.hpp"

  31 #include "logging/log.hpp"
  32 #include "memory/allocation.hpp"
  33 #include "memory/universe.hpp"
  34 
  35 // This class keeps statistical information and computes the
  36 // size of the heap.
  37 
  38 // Forward decls
  39 class elapsedTimer;
  40 class SoftRefPolicy;
  41 
  42 class AdaptiveSizePolicy : public CHeapObj<mtGC> {
  43  friend class GCAdaptivePolicyCounters;
  44  friend class PSGCAdaptivePolicyCounters;
  45  friend class CMSGCAdaptivePolicyCounters;
  46  protected:
  47 
  48   enum GCPolicyKind {
  49     _gc_adaptive_size_policy,
  50     _gc_ps_adaptive_size_policy,
  51     _gc_cms_adaptive_size_policy
  52   };
  53   virtual GCPolicyKind kind() const { return _gc_adaptive_size_policy; }
  54 
  55   enum SizePolicyTrueValues {
  56     decrease_old_gen_for_throughput_true = -7,
  57     decrease_young_gen_for_througput_true = -6,
  58 
  59     increase_old_gen_for_min_pauses_true = -5,
  60     decrease_old_gen_for_min_pauses_true = -4,


  67     increase_young_gen_for_maj_pauses_true = 3,
  68 
  69     increase_old_gen_for_throughput_true = 4,
  70     increase_young_gen_for_througput_true = 5,
  71 
  72     decrease_young_gen_for_footprint_true = 6,
  73     decrease_old_gen_for_footprint_true = 7,
  74     decide_at_full_gc_true = 8
  75   };
  76 
  77   // Goal for the fraction of the total time during which application
  78   // threads run
  79   const double _throughput_goal;
  80 
  81   // Last calculated sizes, in bytes, and aligned
  82   size_t _eden_size;        // calculated eden free space in bytes
  83   size_t _promo_size;       // calculated cms gen free space in bytes
  84 
  85   size_t _survivor_size;    // calculated survivor size in bytes
  86 
  87   // This is a hint for the heap:  we've detected that GC times
  88   // are taking longer than GCTimeLimit allows.
  89   bool _gc_overhead_limit_exceeded;
  90   // Use for diagnostics only.  If UseGCOverheadLimit is false,
  91   // this variable is still set.
  92   bool _print_gc_overhead_limit_would_be_exceeded;
  93   // Count of consecutive GC that have exceeded the
  94   // GC time limit criterion
  95   uint _gc_overhead_limit_count;
  96   // This flag signals that GCTimeLimit is being exceeded
  97   // but may not have done so for the required number of consecutive
  98   // collections
  99 
 100   // Minor collection timers used to determine both
 101   // pause and interval times for collections
 102   static elapsedTimer _minor_timer;
 103 
 104   // Major collection timers, used to determine both
 105   // pause and interval times for collections
 106   static elapsedTimer _major_timer;
 107 
 108   // Time statistics
 109   AdaptivePaddedAverage*   _avg_minor_pause;
 110   AdaptiveWeightedAverage* _avg_minor_interval;
 111   AdaptiveWeightedAverage* _avg_minor_gc_cost;
 112 
 113   AdaptiveWeightedAverage* _avg_major_interval;
 114   AdaptiveWeightedAverage* _avg_major_gc_cost;
 115 
 116   // Footprint statistics
 117   AdaptiveWeightedAverage* _avg_young_live;
 118   AdaptiveWeightedAverage* _avg_eden_live;


 428 
 429   void set_eden_size(size_t new_size) {
 430     _eden_size = new_size;
 431   }
 432   void set_survivor_size(size_t new_size) {
 433     _survivor_size = new_size;
 434   }
 435 
 436   size_t calculated_eden_size_in_bytes() const {
 437     return _eden_size;
 438   }
 439 
 440   size_t calculated_promo_size_in_bytes() const {
 441     return _promo_size;
 442   }
 443 
 444   size_t calculated_survivor_size_in_bytes() const {
 445     return _survivor_size;
 446   }
 447 
 448   // This is a hint for the heap:  we've detected that gc times
 449   // are taking longer than GCTimeLimit allows.
 450   // Most heaps will choose to throw an OutOfMemoryError when
 451   // this occurs but it is up to the heap to request this information
 452   // of the policy
 453   bool gc_overhead_limit_exceeded() {
 454     return _gc_overhead_limit_exceeded;
 455   }
 456   void set_gc_overhead_limit_exceeded(bool v) {
 457     _gc_overhead_limit_exceeded = v;
 458   }
 459 
 460   // Tests conditions indicate the GC overhead limit is being approached.
 461   bool gc_overhead_limit_near() {
 462     return gc_overhead_limit_count() >=
 463         (AdaptiveSizePolicyGCTimeLimitThreshold - 1);



 464   }
 465   uint gc_overhead_limit_count() { return _gc_overhead_limit_count; }
 466   void reset_gc_overhead_limit_count() { _gc_overhead_limit_count = 0; }
 467   void inc_gc_overhead_limit_count() { _gc_overhead_limit_count++; }
 468   // accessors for flags recording the decisions to resize the
 469   // generations to meet the pause goal.
 470 
 471   int change_young_gen_for_min_pauses() const {
 472     return _change_young_gen_for_min_pauses;
 473   }
 474   void set_change_young_gen_for_min_pauses(int v) {
 475     _change_young_gen_for_min_pauses = v;
 476   }
 477   void set_decrease_for_footprint(int v) { _decrease_for_footprint = v; }
 478   int decrease_for_footprint() const { return _decrease_for_footprint; }
 479   int decide_at_full_gc() { return _decide_at_full_gc; }
 480   void set_decide_at_full_gc(int v) { _decide_at_full_gc = v; }
 481 
 482   // Check the conditions for an out-of-memory due to excessive GC time.
 483   // Set _gc_overhead_limit_exceeded if all the conditions have been met.
 484   void check_gc_overhead_limit(size_t young_live,
 485                                size_t eden_live,
 486                                size_t max_old_gen_size,
 487                                size_t max_eden_size,
 488                                bool   is_full_gc,
 489                                GCCause::Cause gc_cause,
 490                                SoftRefPolicy* soft_ref_policy);
 491 
 492   static bool should_update_promo_stats(GCCause::Cause cause) {
 493     return ((GCCause::is_user_requested_gc(cause)  &&
 494                UseAdaptiveSizePolicyWithSystemGC) ||
 495             GCCause::is_tenured_allocation_failure_gc(cause));
 496   }
 497 
 498   static bool should_update_eden_stats(GCCause::Cause cause) {
 499     return ((GCCause::is_user_requested_gc(cause)  &&
 500                UseAdaptiveSizePolicyWithSystemGC) ||
 501             GCCause::is_allocation_failure_gc(cause));
 502   }
 503 
 504   // Printing support
 505   virtual bool print() const;


  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_SHARED_ADAPTIVESIZEPOLICY_HPP
  26 #define SHARE_VM_GC_SHARED_ADAPTIVESIZEPOLICY_HPP
  27 
  28 #include "gc/shared/collectedHeap.hpp"
  29 #include "gc/shared/gcCause.hpp"
  30 #include "gc/shared/gcUtil.hpp"
  31 #include "gc/shared/overheadChecker.hpp"
  32 #include "logging/log.hpp"
  33 #include "memory/allocation.hpp"
  34 #include "memory/universe.hpp"
  35 
  36 // This class keeps statistical information and computes the
  37 // size of the heap.
  38 
  39 // Forward decls
  40 class elapsedTimer;

  41 
  42 class AdaptiveSizePolicy : public CHeapObj<mtGC> {
  43  friend class GCAdaptivePolicyCounters;
  44  friend class PSGCAdaptivePolicyCounters;
  45  friend class CMSGCAdaptivePolicyCounters;
  46  protected:
  47 
  48   enum GCPolicyKind {
  49     _gc_adaptive_size_policy,
  50     _gc_ps_adaptive_size_policy,
  51     _gc_cms_adaptive_size_policy
  52   };
  53   virtual GCPolicyKind kind() const { return _gc_adaptive_size_policy; }
  54 
  55   enum SizePolicyTrueValues {
  56     decrease_old_gen_for_throughput_true = -7,
  57     decrease_young_gen_for_througput_true = -6,
  58 
  59     increase_old_gen_for_min_pauses_true = -5,
  60     decrease_old_gen_for_min_pauses_true = -4,


  67     increase_young_gen_for_maj_pauses_true = 3,
  68 
  69     increase_old_gen_for_throughput_true = 4,
  70     increase_young_gen_for_througput_true = 5,
  71 
  72     decrease_young_gen_for_footprint_true = 6,
  73     decrease_old_gen_for_footprint_true = 7,
  74     decide_at_full_gc_true = 8
  75   };
  76 
  77   // Goal for the fraction of the total time during which application
  78   // threads run
  79   const double _throughput_goal;
  80 
  81   // Last calculated sizes, in bytes, and aligned
  82   size_t _eden_size;        // calculated eden free space in bytes
  83   size_t _promo_size;       // calculated cms gen free space in bytes
  84 
  85   size_t _survivor_size;    // calculated survivor size in bytes
  86 
  87   // Support for UseGCOverheadLimit
  88   OverheadChecker _overhead_checker;










  89 
  90   // Minor collection timers used to determine both
  91   // pause and interval times for collections
  92   static elapsedTimer _minor_timer;
  93 
  94   // Major collection timers, used to determine both
  95   // pause and interval times for collections
  96   static elapsedTimer _major_timer;
  97 
  98   // Time statistics
  99   AdaptivePaddedAverage*   _avg_minor_pause;
 100   AdaptiveWeightedAverage* _avg_minor_interval;
 101   AdaptiveWeightedAverage* _avg_minor_gc_cost;
 102 
 103   AdaptiveWeightedAverage* _avg_major_interval;
 104   AdaptiveWeightedAverage* _avg_major_gc_cost;
 105 
 106   // Footprint statistics
 107   AdaptiveWeightedAverage* _avg_young_live;
 108   AdaptiveWeightedAverage* _avg_eden_live;


 418 
 419   void set_eden_size(size_t new_size) {
 420     _eden_size = new_size;
 421   }
 422   void set_survivor_size(size_t new_size) {
 423     _survivor_size = new_size;
 424   }
 425 
 426   size_t calculated_eden_size_in_bytes() const {
 427     return _eden_size;
 428   }
 429 
 430   size_t calculated_promo_size_in_bytes() const {
 431     return _promo_size;
 432   }
 433 
 434   size_t calculated_survivor_size_in_bytes() const {
 435     return _survivor_size;
 436   }
 437 





 438   bool gc_overhead_limit_exceeded() {
 439     return _overhead_checker.gc_overhead_limit_exceeded();
 440   }
 441   void set_gc_overhead_limit_exceeded(bool v) {
 442     _overhead_checker.set_gc_overhead_limit_exceeded(v);
 443   }
 444 

 445   bool gc_overhead_limit_near() {
 446     return _overhead_checker.gc_overhead_limit_near();
 447   }
 448 
 449   void reset_gc_overhead_limit_count() {
 450     _overhead_checker.reset_gc_overhead_limit_count();
 451   }



 452   // accessors for flags recording the decisions to resize the
 453   // generations to meet the pause goal.
 454 
 455   int change_young_gen_for_min_pauses() const {
 456     return _change_young_gen_for_min_pauses;
 457   }
 458   void set_change_young_gen_for_min_pauses(int v) {
 459     _change_young_gen_for_min_pauses = v;
 460   }
 461   void set_decrease_for_footprint(int v) { _decrease_for_footprint = v; }
 462   int decrease_for_footprint() const { return _decrease_for_footprint; }
 463   int decide_at_full_gc() { return _decide_at_full_gc; }
 464   void set_decide_at_full_gc(int v) { _decide_at_full_gc = v; }
 465 
 466   // Check the conditions for an out-of-memory due to excessive GC time.
 467   // Set _gc_overhead_limit_exceeded if all the conditions have been met.
 468   void check_gc_overhead_limit(size_t eden_live,

 469                                size_t max_old_gen_size,
 470                                size_t max_eden_size,
 471                                bool   is_full_gc,
 472                                GCCause::Cause gc_cause,
 473                                SoftRefPolicy* soft_ref_policy);
 474 
 475   static bool should_update_promo_stats(GCCause::Cause cause) {
 476     return ((GCCause::is_user_requested_gc(cause)  &&
 477                UseAdaptiveSizePolicyWithSystemGC) ||
 478             GCCause::is_tenured_allocation_failure_gc(cause));
 479   }
 480 
 481   static bool should_update_eden_stats(GCCause::Cause cause) {
 482     return ((GCCause::is_user_requested_gc(cause)  &&
 483                UseAdaptiveSizePolicyWithSystemGC) ||
 484             GCCause::is_allocation_failure_gc(cause));
 485   }
 486 
 487   // Printing support
 488   virtual bool print() const;
< prev index next >