< prev index next >

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

Print this page
rev 52961 : 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:


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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/gcCause.hpp"

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


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


 395 
 396   void set_eden_size(size_t new_size) {
 397     _eden_size = new_size;
 398   }
 399   void set_survivor_size(size_t new_size) {
 400     _survivor_size = new_size;
 401   }
 402 
 403   size_t calculated_eden_size_in_bytes() const {
 404     return _eden_size;
 405   }
 406 
 407   size_t calculated_promo_size_in_bytes() const {
 408     return _promo_size;
 409   }
 410 
 411   size_t calculated_survivor_size_in_bytes() const {
 412     return _survivor_size;
 413   }
 414 
 415   // This is a hint for the heap:  we've detected that gc times
 416   // are taking longer than GCTimeLimit allows.
 417   // Most heaps will choose to throw an OutOfMemoryError when
 418   // this occurs but it is up to the heap to request this information
 419   // of the policy
 420   bool gc_overhead_limit_exceeded() {
 421     return _gc_overhead_limit_exceeded;
 422   }
 423   void set_gc_overhead_limit_exceeded(bool v) {
 424     _gc_overhead_limit_exceeded = v;
 425   }
 426 
 427   // Tests conditions indicate the GC overhead limit is being approached.
 428   bool gc_overhead_limit_near() {
 429     return gc_overhead_limit_count() >=
 430         (AdaptiveSizePolicyGCTimeLimitThreshold - 1);



 431   }
 432   uint gc_overhead_limit_count() { return _gc_overhead_limit_count; }
 433   void reset_gc_overhead_limit_count() { _gc_overhead_limit_count = 0; }
 434   void inc_gc_overhead_limit_count() { _gc_overhead_limit_count++; }
 435   // accessors for flags recording the decisions to resize the
 436   // generations to meet the pause goal.
 437 
 438   int change_young_gen_for_min_pauses() const {
 439     return _change_young_gen_for_min_pauses;
 440   }
 441   void set_change_young_gen_for_min_pauses(int v) {
 442     _change_young_gen_for_min_pauses = v;
 443   }
 444   void set_decrease_for_footprint(int v) { _decrease_for_footprint = v; }
 445   int decrease_for_footprint() const { return _decrease_for_footprint; }
 446   int decide_at_full_gc() { return _decide_at_full_gc; }
 447   void set_decide_at_full_gc(int v) { _decide_at_full_gc = v; }
 448 
 449   // Check the conditions for an out-of-memory due to excessive GC time.
 450   // Set _gc_overhead_limit_exceeded if all the conditions have been met.
 451   void check_gc_overhead_limit(size_t young_live,
 452                                size_t eden_live,
 453                                size_t max_old_gen_size,
 454                                size_t max_eden_size,
 455                                bool   is_full_gc,
 456                                GCCause::Cause gc_cause,
 457                                SoftRefPolicy* soft_ref_policy);
 458 
 459   static bool should_update_promo_stats(GCCause::Cause cause) {
 460     return ((GCCause::is_user_requested_gc(cause)  &&
 461                UseAdaptiveSizePolicyWithSystemGC) ||
 462             GCCause::is_tenured_allocation_failure_gc(cause));
 463   }
 464 
 465   static bool should_update_eden_stats(GCCause::Cause cause) {
 466     return ((GCCause::is_user_requested_gc(cause)  &&
 467                UseAdaptiveSizePolicyWithSystemGC) ||
 468             GCCause::is_allocation_failure_gc(cause));
 469   }
 470 
 471   // Printing support
 472   virtual bool print() const;


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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/gcCause.hpp"
  29 #include "gc/shared/gcOverheadChecker.hpp"
  30 #include "gc/shared/gcUtil.hpp"
  31 #include "memory/allocation.hpp"
  32 
  33 // This class keeps statistical information and computes the
  34 // size of the heap.
  35 
  36 // Forward decls
  37 class elapsedTimer;

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


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










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


 385 
 386   void set_eden_size(size_t new_size) {
 387     _eden_size = new_size;
 388   }
 389   void set_survivor_size(size_t new_size) {
 390     _survivor_size = new_size;
 391   }
 392 
 393   size_t calculated_eden_size_in_bytes() const {
 394     return _eden_size;
 395   }
 396 
 397   size_t calculated_promo_size_in_bytes() const {
 398     return _promo_size;
 399   }
 400 
 401   size_t calculated_survivor_size_in_bytes() const {
 402     return _survivor_size;
 403   }
 404 





 405   bool gc_overhead_limit_exceeded() {
 406     return _overhead_checker.gc_overhead_limit_exceeded();
 407   }
 408   void set_gc_overhead_limit_exceeded(bool v) {
 409     _overhead_checker.set_gc_overhead_limit_exceeded(v);
 410   }
 411 

 412   bool gc_overhead_limit_near() {
 413     return _overhead_checker.gc_overhead_limit_near();
 414   }
 415 
 416   void reset_gc_overhead_limit_count() {
 417     _overhead_checker.reset_gc_overhead_limit_count();
 418   }



 419   // accessors for flags recording the decisions to resize the
 420   // generations to meet the pause goal.
 421 
 422   int change_young_gen_for_min_pauses() const {
 423     return _change_young_gen_for_min_pauses;
 424   }
 425   void set_change_young_gen_for_min_pauses(int v) {
 426     _change_young_gen_for_min_pauses = v;
 427   }
 428   void set_decrease_for_footprint(int v) { _decrease_for_footprint = v; }
 429   int decrease_for_footprint() const { return _decrease_for_footprint; }
 430   int decide_at_full_gc() { return _decide_at_full_gc; }
 431   void set_decide_at_full_gc(int v) { _decide_at_full_gc = v; }
 432 
 433   // Check the conditions for an out-of-memory due to excessive GC time.
 434   // Set _gc_overhead_limit_exceeded if all the conditions have been met.
 435   void check_gc_overhead_limit(size_t eden_live,

 436                                size_t max_old_gen_size,
 437                                size_t max_eden_size,
 438                                bool   is_full_gc,
 439                                GCCause::Cause gc_cause,
 440                                SoftRefPolicy* soft_ref_policy);
 441 
 442   static bool should_update_promo_stats(GCCause::Cause cause) {
 443     return ((GCCause::is_user_requested_gc(cause)  &&
 444                UseAdaptiveSizePolicyWithSystemGC) ||
 445             GCCause::is_tenured_allocation_failure_gc(cause));
 446   }
 447 
 448   static bool should_update_eden_stats(GCCause::Cause cause) {
 449     return ((GCCause::is_user_requested_gc(cause)  &&
 450                UseAdaptiveSizePolicyWithSystemGC) ||
 451             GCCause::is_allocation_failure_gc(cause));
 452   }
 453 
 454   // Printing support
 455   virtual bool print() const;
< prev index next >