< prev index next >

src/share/vm/gc/shared/collectorPolicy.cpp

Print this page
rev 13243 : 8179268: Factor out AdaptiveSizePolicy from top-level interfaces CollectorPolicy and CollectedHeap
Reviewed-by: pliden, mgerdin


  34 #include "gc/shared/vmGCOperations.hpp"
  35 #include "logging/log.hpp"
  36 #include "memory/universe.hpp"
  37 #include "runtime/arguments.hpp"
  38 #include "runtime/globals_extension.hpp"
  39 #include "runtime/handles.inline.hpp"
  40 #include "runtime/java.hpp"
  41 #include "runtime/thread.inline.hpp"
  42 #include "runtime/vmThread.hpp"
  43 #include "utilities/align.hpp"
  44 #include "utilities/macros.hpp"
  45 
  46 // CollectorPolicy methods
  47 
  48 CollectorPolicy::CollectorPolicy() :
  49     _space_alignment(0),
  50     _heap_alignment(0),
  51     _initial_heap_byte_size(InitialHeapSize),
  52     _max_heap_byte_size(MaxHeapSize),
  53     _min_heap_byte_size(Arguments::min_heap_size()),
  54     _size_policy(NULL),
  55     _should_clear_all_soft_refs(false),
  56     _all_soft_refs_clear(false)
  57 {}
  58 
  59 #ifdef ASSERT
  60 void CollectorPolicy::assert_flags() {
  61   assert(InitialHeapSize <= MaxHeapSize, "Ergonomics decided on incompatible initial and maximum heap sizes");
  62   assert(InitialHeapSize % _heap_alignment == 0, "InitialHeapSize alignment");
  63   assert(MaxHeapSize % _heap_alignment == 0, "MaxHeapSize alignment");
  64 }
  65 
  66 void CollectorPolicy::assert_size_info() {
  67   assert(InitialHeapSize == _initial_heap_byte_size, "Discrepancy between InitialHeapSize flag and local storage");
  68   assert(MaxHeapSize == _max_heap_byte_size, "Discrepancy between MaxHeapSize flag and local storage");
  69   assert(_max_heap_byte_size >= _min_heap_byte_size, "Ergonomics decided on incompatible minimum and maximum heap sizes");
  70   assert(_initial_heap_byte_size >= _min_heap_byte_size, "Ergonomics decided on incompatible initial and minimum heap sizes");
  71   assert(_max_heap_byte_size >= _initial_heap_byte_size, "Ergonomics decided on incompatible initial and maximum heap sizes");
  72   assert(_min_heap_byte_size % _heap_alignment == 0, "min_heap_byte_size alignment");
  73   assert(_initial_heap_byte_size % _heap_alignment == 0, "initial_heap_byte_size alignment");
  74   assert(_max_heap_byte_size % _heap_alignment == 0, "max_heap_byte_size alignment");


 140 }
 141 
 142 void CollectorPolicy::initialize_size_info() {
 143   log_debug(gc, heap)("Minimum heap " SIZE_FORMAT "  Initial heap " SIZE_FORMAT "  Maximum heap " SIZE_FORMAT,
 144                       _min_heap_byte_size, _initial_heap_byte_size, _max_heap_byte_size);
 145 
 146   DEBUG_ONLY(CollectorPolicy::assert_size_info();)
 147 }
 148 
 149 bool CollectorPolicy::use_should_clear_all_soft_refs(bool v) {
 150   bool result = _should_clear_all_soft_refs;
 151   set_should_clear_all_soft_refs(false);
 152   return result;
 153 }
 154 
 155 CardTableRS* CollectorPolicy::create_rem_set(MemRegion whole_heap) {
 156   return new CardTableRS(whole_heap);
 157 }
 158 
 159 void CollectorPolicy::cleared_all_soft_refs() {
 160   // If near gc overhear limit, continue to clear SoftRefs.  SoftRefs may
 161   // have been cleared in the last collection but if the gc overhear
 162   // limit continues to be near, SoftRefs should still be cleared.
 163   if (size_policy() != NULL) {
 164     _should_clear_all_soft_refs = size_policy()->gc_overhead_limit_near();
 165   }
 166   _all_soft_refs_clear = true;
 167 }
 168 
 169 size_t CollectorPolicy::compute_heap_alignment() {
 170   // The card marking array and the offset arrays for old generations are
 171   // committed in os pages as well. Make sure they are entirely full (to
 172   // avoid partial page problems), e.g. if 512 bytes heap corresponds to 1
 173   // byte entry and the os page size is 4096, the maximum heap size should
 174   // be 512*4096 = 2MB aligned.
 175 
 176   size_t alignment = CardTableRS::ct_max_alignment_constraint();
 177 
 178   if (UseLargePages) {
 179       // In presence of large pages we have to make sure that our
 180       // alignment is large page aware.
 181       alignment = lcm(os::large_page_size(), alignment);
 182   }
 183 
 184   return alignment;
 185 }
 186 
 187 // GenCollectorPolicy methods
 188 
 189 GenCollectorPolicy::GenCollectorPolicy() :
 190     _min_young_size(0),
 191     _initial_young_size(0),
 192     _max_young_size(0),
 193     _min_old_size(0),
 194     _initial_old_size(0),
 195     _max_old_size(0),
 196     _gen_alignment(0),
 197     _young_gen_spec(NULL),
 198     _old_gen_spec(NULL)

 199 {}
 200 
 201 size_t GenCollectorPolicy::scale_by_NewRatio_aligned(size_t base_size) {
 202   return align_down_bounded(base_size / (NewRatio + 1), _gen_alignment);
 203 }
 204 
 205 size_t GenCollectorPolicy::bound_minus_alignment(size_t desired_size,
 206                                                  size_t maximum_size) {
 207   size_t max_minus = maximum_size - _gen_alignment;
 208   return desired_size < max_minus ? desired_size : max_minus;
 209 }
 210 
 211 
 212 void GenCollectorPolicy::initialize_size_policy(size_t init_eden_size,
 213                                                 size_t init_promo_size,
 214                                                 size_t init_survivor_size) {
 215   const double max_gc_pause_sec = ((double) MaxGCPauseMillis) / 1000.0;
 216   _size_policy = new AdaptiveSizePolicy(init_eden_size,
 217                                         init_promo_size,
 218                                         init_survivor_size,
 219                                         max_gc_pause_sec,
 220                                         GCTimeRatio);











 221 }
 222 
 223 size_t GenCollectorPolicy::young_gen_size_lower_bound() {
 224   // The young generation must be aligned and have room for eden + two survivors
 225   return align_up(3 * _space_alignment, _gen_alignment);
 226 }
 227 
 228 size_t GenCollectorPolicy::old_gen_size_lower_bound() {
 229   return align_up(_space_alignment, _gen_alignment);
 230 }
 231 
 232 #ifdef ASSERT
 233 void GenCollectorPolicy::assert_flags() {
 234   CollectorPolicy::assert_flags();
 235   assert(NewSize >= _min_young_size, "Ergonomics decided on a too small young gen size");
 236   assert(NewSize <= MaxNewSize, "Ergonomics decided on incompatible initial and maximum young gen sizes");
 237   assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize < MaxHeapSize, "Ergonomics decided on incompatible maximum young gen and heap sizes");
 238   assert(NewSize % _gen_alignment == 0, "NewSize alignment");
 239   assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize % _gen_alignment == 0, "MaxNewSize alignment");
 240   assert(OldSize + NewSize <= MaxHeapSize, "Ergonomics decided on incompatible generation and heap sizes");




  34 #include "gc/shared/vmGCOperations.hpp"
  35 #include "logging/log.hpp"
  36 #include "memory/universe.hpp"
  37 #include "runtime/arguments.hpp"
  38 #include "runtime/globals_extension.hpp"
  39 #include "runtime/handles.inline.hpp"
  40 #include "runtime/java.hpp"
  41 #include "runtime/thread.inline.hpp"
  42 #include "runtime/vmThread.hpp"
  43 #include "utilities/align.hpp"
  44 #include "utilities/macros.hpp"
  45 
  46 // CollectorPolicy methods
  47 
  48 CollectorPolicy::CollectorPolicy() :
  49     _space_alignment(0),
  50     _heap_alignment(0),
  51     _initial_heap_byte_size(InitialHeapSize),
  52     _max_heap_byte_size(MaxHeapSize),
  53     _min_heap_byte_size(Arguments::min_heap_size()),

  54     _should_clear_all_soft_refs(false),
  55     _all_soft_refs_clear(false)
  56 {}
  57 
  58 #ifdef ASSERT
  59 void CollectorPolicy::assert_flags() {
  60   assert(InitialHeapSize <= MaxHeapSize, "Ergonomics decided on incompatible initial and maximum heap sizes");
  61   assert(InitialHeapSize % _heap_alignment == 0, "InitialHeapSize alignment");
  62   assert(MaxHeapSize % _heap_alignment == 0, "MaxHeapSize alignment");
  63 }
  64 
  65 void CollectorPolicy::assert_size_info() {
  66   assert(InitialHeapSize == _initial_heap_byte_size, "Discrepancy between InitialHeapSize flag and local storage");
  67   assert(MaxHeapSize == _max_heap_byte_size, "Discrepancy between MaxHeapSize flag and local storage");
  68   assert(_max_heap_byte_size >= _min_heap_byte_size, "Ergonomics decided on incompatible minimum and maximum heap sizes");
  69   assert(_initial_heap_byte_size >= _min_heap_byte_size, "Ergonomics decided on incompatible initial and minimum heap sizes");
  70   assert(_max_heap_byte_size >= _initial_heap_byte_size, "Ergonomics decided on incompatible initial and maximum heap sizes");
  71   assert(_min_heap_byte_size % _heap_alignment == 0, "min_heap_byte_size alignment");
  72   assert(_initial_heap_byte_size % _heap_alignment == 0, "initial_heap_byte_size alignment");
  73   assert(_max_heap_byte_size % _heap_alignment == 0, "max_heap_byte_size alignment");


 139 }
 140 
 141 void CollectorPolicy::initialize_size_info() {
 142   log_debug(gc, heap)("Minimum heap " SIZE_FORMAT "  Initial heap " SIZE_FORMAT "  Maximum heap " SIZE_FORMAT,
 143                       _min_heap_byte_size, _initial_heap_byte_size, _max_heap_byte_size);
 144 
 145   DEBUG_ONLY(CollectorPolicy::assert_size_info();)
 146 }
 147 
 148 bool CollectorPolicy::use_should_clear_all_soft_refs(bool v) {
 149   bool result = _should_clear_all_soft_refs;
 150   set_should_clear_all_soft_refs(false);
 151   return result;
 152 }
 153 
 154 CardTableRS* CollectorPolicy::create_rem_set(MemRegion whole_heap) {
 155   return new CardTableRS(whole_heap);
 156 }
 157 
 158 void CollectorPolicy::cleared_all_soft_refs() {






 159   _all_soft_refs_clear = true;
 160 }
 161 
 162 size_t CollectorPolicy::compute_heap_alignment() {
 163   // The card marking array and the offset arrays for old generations are
 164   // committed in os pages as well. Make sure they are entirely full (to
 165   // avoid partial page problems), e.g. if 512 bytes heap corresponds to 1
 166   // byte entry and the os page size is 4096, the maximum heap size should
 167   // be 512*4096 = 2MB aligned.
 168 
 169   size_t alignment = CardTableRS::ct_max_alignment_constraint();
 170 
 171   if (UseLargePages) {
 172       // In presence of large pages we have to make sure that our
 173       // alignment is large page aware.
 174       alignment = lcm(os::large_page_size(), alignment);
 175   }
 176 
 177   return alignment;
 178 }
 179 
 180 // GenCollectorPolicy methods
 181 
 182 GenCollectorPolicy::GenCollectorPolicy() :
 183     _min_young_size(0),
 184     _initial_young_size(0),
 185     _max_young_size(0),
 186     _min_old_size(0),
 187     _initial_old_size(0),
 188     _max_old_size(0),
 189     _gen_alignment(0),
 190     _young_gen_spec(NULL),
 191     _old_gen_spec(NULL),
 192     _size_policy(NULL)
 193 {}
 194 
 195 size_t GenCollectorPolicy::scale_by_NewRatio_aligned(size_t base_size) {
 196   return align_down_bounded(base_size / (NewRatio + 1), _gen_alignment);
 197 }
 198 
 199 size_t GenCollectorPolicy::bound_minus_alignment(size_t desired_size,
 200                                                  size_t maximum_size) {
 201   size_t max_minus = maximum_size - _gen_alignment;
 202   return desired_size < max_minus ? desired_size : max_minus;
 203 }
 204 
 205 
 206 void GenCollectorPolicy::initialize_size_policy(size_t init_eden_size,
 207                                                 size_t init_promo_size,
 208                                                 size_t init_survivor_size) {
 209   const double max_gc_pause_sec = ((double) MaxGCPauseMillis) / 1000.0;
 210   _size_policy = new AdaptiveSizePolicy(init_eden_size,
 211                                         init_promo_size,
 212                                         init_survivor_size,
 213                                         max_gc_pause_sec,
 214                                         GCTimeRatio);
 215 }
 216 
 217 void GenCollectorPolicy::cleared_all_soft_refs() {
 218   // If near gc overhear limit, continue to clear SoftRefs.  SoftRefs may
 219   // have been cleared in the last collection but if the gc overhear
 220   // limit continues to be near, SoftRefs should still be cleared.
 221   if (size_policy() != NULL) {
 222     _should_clear_all_soft_refs = size_policy()->gc_overhead_limit_near();
 223   }
 224 
 225   CollectorPolicy::cleared_all_soft_refs();
 226 }
 227 
 228 size_t GenCollectorPolicy::young_gen_size_lower_bound() {
 229   // The young generation must be aligned and have room for eden + two survivors
 230   return align_up(3 * _space_alignment, _gen_alignment);
 231 }
 232 
 233 size_t GenCollectorPolicy::old_gen_size_lower_bound() {
 234   return align_up(_space_alignment, _gen_alignment);
 235 }
 236 
 237 #ifdef ASSERT
 238 void GenCollectorPolicy::assert_flags() {
 239   CollectorPolicy::assert_flags();
 240   assert(NewSize >= _min_young_size, "Ergonomics decided on a too small young gen size");
 241   assert(NewSize <= MaxNewSize, "Ergonomics decided on incompatible initial and maximum young gen sizes");
 242   assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize < MaxHeapSize, "Ergonomics decided on incompatible maximum young gen and heap sizes");
 243   assert(NewSize % _gen_alignment == 0, "NewSize alignment");
 244   assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize % _gen_alignment == 0, "MaxNewSize alignment");
 245   assert(OldSize + NewSize <= MaxHeapSize, "Ergonomics decided on incompatible generation and heap sizes");


< prev index next >