< prev index next >

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

Print this page




  33 #include "gc/shared/space.hpp"
  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");
  74 }
  75 #endif // ASSERT


 128     if (InitialHeapSize < _min_heap_byte_size) {
 129       _min_heap_byte_size = InitialHeapSize;
 130     }
 131   }
 132 
 133   _initial_heap_byte_size = InitialHeapSize;
 134   _max_heap_byte_size = MaxHeapSize;
 135 
 136   FLAG_SET_ERGO(size_t, MinHeapDeltaBytes, align_up(MinHeapDeltaBytes, _space_alignment));
 137 
 138   DEBUG_ONLY(CollectorPolicy::assert_flags();)
 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 void CollectorPolicy::cleared_all_soft_refs() {
 155   _all_soft_refs_clear = true;
 156 }
 157 
 158 size_t CollectorPolicy::compute_heap_alignment() {
 159   // The card marking array and the offset arrays for old generations are
 160   // committed in os pages as well. Make sure they are entirely full (to
 161   // avoid partial page problems), e.g. if 512 bytes heap corresponds to 1
 162   // byte entry and the os page size is 4096, the maximum heap size should
 163   // be 512*4096 = 2MB aligned.
 164 
 165   size_t alignment = CardTableRS::ct_max_alignment_constraint();
 166 
 167   if (UseLargePages) {
 168       // In presence of large pages we have to make sure that our
 169       // alignment is large page aware.
 170       alignment = lcm(os::large_page_size(), alignment);
 171   }
 172 
 173   return alignment;
 174 }
 175 
 176 // GenCollectorPolicy methods
 177 


 191 size_t GenCollectorPolicy::scale_by_NewRatio_aligned(size_t base_size) {
 192   return align_down_bounded(base_size / (NewRatio + 1), _gen_alignment);
 193 }
 194 
 195 size_t GenCollectorPolicy::bound_minus_alignment(size_t desired_size,
 196                                                  size_t maximum_size) {
 197   size_t max_minus = maximum_size - _gen_alignment;
 198   return desired_size < max_minus ? desired_size : max_minus;
 199 }
 200 
 201 
 202 void GenCollectorPolicy::initialize_size_policy(size_t init_eden_size,
 203                                                 size_t init_promo_size,
 204                                                 size_t init_survivor_size) {
 205   const double max_gc_pause_sec = ((double) MaxGCPauseMillis) / 1000.0;
 206   _size_policy = new AdaptiveSizePolicy(init_eden_size,
 207                                         init_promo_size,
 208                                         init_survivor_size,
 209                                         max_gc_pause_sec,
 210                                         GCTimeRatio);
 211 }
 212 
 213 void GenCollectorPolicy::cleared_all_soft_refs() {
 214   // If near gc overhear limit, continue to clear SoftRefs.  SoftRefs may
 215   // have been cleared in the last collection but if the gc overhear
 216   // limit continues to be near, SoftRefs should still be cleared.
 217   if (size_policy() != NULL) {
 218     _should_clear_all_soft_refs = size_policy()->gc_overhead_limit_near();
 219   }
 220 
 221   CollectorPolicy::cleared_all_soft_refs();
 222 }
 223 
 224 size_t GenCollectorPolicy::young_gen_size_lower_bound() {
 225   // The young generation must be aligned and have room for eden + two survivors
 226   return align_up(3 * _space_alignment, _gen_alignment);
 227 }
 228 
 229 size_t GenCollectorPolicy::old_gen_size_lower_bound() {
 230   return align_up(_space_alignment, _gen_alignment);
 231 }
 232 
 233 #ifdef ASSERT
 234 void GenCollectorPolicy::assert_flags() {
 235   CollectorPolicy::assert_flags();
 236   assert(NewSize >= _min_young_size, "Ergonomics decided on a too small young gen size");
 237   assert(NewSize <= MaxNewSize, "Ergonomics decided on incompatible initial and maximum young gen sizes");
 238   assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize < MaxHeapSize, "Ergonomics decided on incompatible maximum young gen and heap sizes");
 239   assert(NewSize % _gen_alignment == 0, "NewSize alignment");
 240   assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize % _gen_alignment == 0, "MaxNewSize alignment");
 241   assert(OldSize + NewSize <= MaxHeapSize, "Ergonomics decided on incompatible generation and heap sizes");




  33 #include "gc/shared/space.hpp"
  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 {}
  55 
  56 #ifdef ASSERT
  57 void CollectorPolicy::assert_flags() {
  58   assert(InitialHeapSize <= MaxHeapSize, "Ergonomics decided on incompatible initial and maximum heap sizes");
  59   assert(InitialHeapSize % _heap_alignment == 0, "InitialHeapSize alignment");
  60   assert(MaxHeapSize % _heap_alignment == 0, "MaxHeapSize alignment");
  61 }
  62 
  63 void CollectorPolicy::assert_size_info() {
  64   assert(InitialHeapSize == _initial_heap_byte_size, "Discrepancy between InitialHeapSize flag and local storage");
  65   assert(MaxHeapSize == _max_heap_byte_size, "Discrepancy between MaxHeapSize flag and local storage");
  66   assert(_max_heap_byte_size >= _min_heap_byte_size, "Ergonomics decided on incompatible minimum and maximum heap sizes");
  67   assert(_initial_heap_byte_size >= _min_heap_byte_size, "Ergonomics decided on incompatible initial and minimum heap sizes");
  68   assert(_max_heap_byte_size >= _initial_heap_byte_size, "Ergonomics decided on incompatible initial and maximum heap sizes");
  69   assert(_min_heap_byte_size % _heap_alignment == 0, "min_heap_byte_size alignment");
  70   assert(_initial_heap_byte_size % _heap_alignment == 0, "initial_heap_byte_size alignment");
  71   assert(_max_heap_byte_size % _heap_alignment == 0, "max_heap_byte_size alignment");
  72 }
  73 #endif // ASSERT


 126     if (InitialHeapSize < _min_heap_byte_size) {
 127       _min_heap_byte_size = InitialHeapSize;
 128     }
 129   }
 130 
 131   _initial_heap_byte_size = InitialHeapSize;
 132   _max_heap_byte_size = MaxHeapSize;
 133 
 134   FLAG_SET_ERGO(size_t, MinHeapDeltaBytes, align_up(MinHeapDeltaBytes, _space_alignment));
 135 
 136   DEBUG_ONLY(CollectorPolicy::assert_flags();)
 137 }
 138 
 139 void CollectorPolicy::initialize_size_info() {
 140   log_debug(gc, heap)("Minimum heap " SIZE_FORMAT "  Initial heap " SIZE_FORMAT "  Maximum heap " SIZE_FORMAT,
 141                       _min_heap_byte_size, _initial_heap_byte_size, _max_heap_byte_size);
 142 
 143   DEBUG_ONLY(CollectorPolicy::assert_size_info();)
 144 }
 145 










 146 size_t CollectorPolicy::compute_heap_alignment() {
 147   // The card marking array and the offset arrays for old generations are
 148   // committed in os pages as well. Make sure they are entirely full (to
 149   // avoid partial page problems), e.g. if 512 bytes heap corresponds to 1
 150   // byte entry and the os page size is 4096, the maximum heap size should
 151   // be 512*4096 = 2MB aligned.
 152 
 153   size_t alignment = CardTableRS::ct_max_alignment_constraint();
 154 
 155   if (UseLargePages) {
 156       // In presence of large pages we have to make sure that our
 157       // alignment is large page aware.
 158       alignment = lcm(os::large_page_size(), alignment);
 159   }
 160 
 161   return alignment;
 162 }
 163 
 164 // GenCollectorPolicy methods
 165 


 179 size_t GenCollectorPolicy::scale_by_NewRatio_aligned(size_t base_size) {
 180   return align_down_bounded(base_size / (NewRatio + 1), _gen_alignment);
 181 }
 182 
 183 size_t GenCollectorPolicy::bound_minus_alignment(size_t desired_size,
 184                                                  size_t maximum_size) {
 185   size_t max_minus = maximum_size - _gen_alignment;
 186   return desired_size < max_minus ? desired_size : max_minus;
 187 }
 188 
 189 
 190 void GenCollectorPolicy::initialize_size_policy(size_t init_eden_size,
 191                                                 size_t init_promo_size,
 192                                                 size_t init_survivor_size) {
 193   const double max_gc_pause_sec = ((double) MaxGCPauseMillis) / 1000.0;
 194   _size_policy = new AdaptiveSizePolicy(init_eden_size,
 195                                         init_promo_size,
 196                                         init_survivor_size,
 197                                         max_gc_pause_sec,
 198                                         GCTimeRatio);











 199 }
 200 
 201 size_t GenCollectorPolicy::young_gen_size_lower_bound() {
 202   // The young generation must be aligned and have room for eden + two survivors
 203   return align_up(3 * _space_alignment, _gen_alignment);
 204 }
 205 
 206 size_t GenCollectorPolicy::old_gen_size_lower_bound() {
 207   return align_up(_space_alignment, _gen_alignment);
 208 }
 209 
 210 #ifdef ASSERT
 211 void GenCollectorPolicy::assert_flags() {
 212   CollectorPolicy::assert_flags();
 213   assert(NewSize >= _min_young_size, "Ergonomics decided on a too small young gen size");
 214   assert(NewSize <= MaxNewSize, "Ergonomics decided on incompatible initial and maximum young gen sizes");
 215   assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize < MaxHeapSize, "Ergonomics decided on incompatible maximum young gen and heap sizes");
 216   assert(NewSize % _gen_alignment == 0, "NewSize alignment");
 217   assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize % _gen_alignment == 0, "MaxNewSize alignment");
 218   assert(OldSize + NewSize <= MaxHeapSize, "Ergonomics decided on incompatible generation and heap sizes");


< prev index next >