< prev index next >

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

Print this page




  88     if (FLAG_IS_CMDLINE(InitialHeapSize) && InitialHeapSize > MaxHeapSize) {
  89       vm_exit_during_initialization("Initial heap size set to a larger value than the maximum heap size");
  90     }
  91     if (_min_heap_byte_size != 0 && MaxHeapSize < _min_heap_byte_size) {
  92       vm_exit_during_initialization("Incompatible minimum and maximum heap sizes specified");
  93     }
  94   }
  95 
  96   // Check heap parameter properties
  97   if (MaxHeapSize < 2 * M) {
  98     vm_exit_during_initialization("Too small maximum heap");
  99   }
 100   if (InitialHeapSize < M) {
 101     vm_exit_during_initialization("Too small initial heap");
 102   }
 103   if (_min_heap_byte_size < M) {
 104     vm_exit_during_initialization("Too small minimum heap");
 105   }
 106 
 107   // User inputs from -Xmx and -Xms must be aligned
 108   _min_heap_byte_size = align_size_up(_min_heap_byte_size, _heap_alignment);
 109   size_t aligned_initial_heap_size = align_size_up(InitialHeapSize, _heap_alignment);
 110   size_t aligned_max_heap_size = align_size_up(MaxHeapSize, _heap_alignment);
 111 
 112   // Write back to flags if the values changed
 113   if (aligned_initial_heap_size != InitialHeapSize) {
 114     FLAG_SET_ERGO(size_t, InitialHeapSize, aligned_initial_heap_size);
 115   }
 116   if (aligned_max_heap_size != MaxHeapSize) {
 117     FLAG_SET_ERGO(size_t, MaxHeapSize, aligned_max_heap_size);
 118   }
 119 
 120   if (FLAG_IS_CMDLINE(InitialHeapSize) && _min_heap_byte_size != 0 &&
 121       InitialHeapSize < _min_heap_byte_size) {
 122     vm_exit_during_initialization("Incompatible minimum and initial heap sizes specified");
 123   }
 124   if (!FLAG_IS_DEFAULT(InitialHeapSize) && InitialHeapSize > MaxHeapSize) {
 125     FLAG_SET_ERGO(size_t, MaxHeapSize, InitialHeapSize);
 126   } else if (!FLAG_IS_DEFAULT(MaxHeapSize) && InitialHeapSize > MaxHeapSize) {
 127     FLAG_SET_ERGO(size_t, InitialHeapSize, MaxHeapSize);
 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_size_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 CardTableRS* CollectorPolicy::create_rem_set(MemRegion whole_heap) {
 155   return new CardTableRS(whole_heap);
 156 }


 181   }
 182 
 183   return alignment;
 184 }
 185 
 186 // GenCollectorPolicy methods
 187 
 188 GenCollectorPolicy::GenCollectorPolicy() :
 189     _min_young_size(0),
 190     _initial_young_size(0),
 191     _max_young_size(0),
 192     _min_old_size(0),
 193     _initial_old_size(0),
 194     _max_old_size(0),
 195     _gen_alignment(0),
 196     _young_gen_spec(NULL),
 197     _old_gen_spec(NULL)
 198 {}
 199 
 200 size_t GenCollectorPolicy::scale_by_NewRatio_aligned(size_t base_size) {
 201   return align_size_down_bounded(base_size / (NewRatio + 1), _gen_alignment);
 202 }
 203 
 204 size_t GenCollectorPolicy::bound_minus_alignment(size_t desired_size,
 205                                                  size_t maximum_size) {
 206   size_t max_minus = maximum_size - _gen_alignment;
 207   return desired_size < max_minus ? desired_size : max_minus;
 208 }
 209 
 210 
 211 void GenCollectorPolicy::initialize_size_policy(size_t init_eden_size,
 212                                                 size_t init_promo_size,
 213                                                 size_t init_survivor_size) {
 214   const double max_gc_pause_sec = ((double) MaxGCPauseMillis) / 1000.0;
 215   _size_policy = new AdaptiveSizePolicy(init_eden_size,
 216                                         init_promo_size,
 217                                         init_survivor_size,
 218                                         max_gc_pause_sec,
 219                                         GCTimeRatio);
 220 }
 221 
 222 size_t GenCollectorPolicy::young_gen_size_lower_bound() {
 223   // The young generation must be aligned and have room for eden + two survivors
 224   return align_size_up(3 * _space_alignment, _gen_alignment);
 225 }
 226 
 227 size_t GenCollectorPolicy::old_gen_size_lower_bound() {
 228   return align_size_up(_space_alignment, _gen_alignment);
 229 }
 230 
 231 #ifdef ASSERT
 232 void GenCollectorPolicy::assert_flags() {
 233   CollectorPolicy::assert_flags();
 234   assert(NewSize >= _min_young_size, "Ergonomics decided on a too small young gen size");
 235   assert(NewSize <= MaxNewSize, "Ergonomics decided on incompatible initial and maximum young gen sizes");
 236   assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize < MaxHeapSize, "Ergonomics decided on incompatible maximum young gen and heap sizes");
 237   assert(NewSize % _gen_alignment == 0, "NewSize alignment");
 238   assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize % _gen_alignment == 0, "MaxNewSize alignment");
 239   assert(OldSize + NewSize <= MaxHeapSize, "Ergonomics decided on incompatible generation and heap sizes");
 240   assert(OldSize % _gen_alignment == 0, "OldSize alignment");
 241 }
 242 
 243 void GenCollectorPolicy::assert_size_info() {
 244   CollectorPolicy::assert_size_info();
 245   // GenCollectorPolicy::initialize_size_info may update the MaxNewSize
 246   assert(MaxNewSize < MaxHeapSize, "Ergonomics decided on incompatible maximum young and heap sizes");
 247   assert(NewSize == _initial_young_size, "Discrepancy between NewSize flag and local storage");
 248   assert(MaxNewSize == _max_young_size, "Discrepancy between MaxNewSize flag and local storage");


 270 #endif // ASSERT
 271 
 272 void GenCollectorPolicy::initialize_flags() {
 273   CollectorPolicy::initialize_flags();
 274 
 275   assert(_gen_alignment != 0, "Generation alignment not set up properly");
 276   assert(_heap_alignment >= _gen_alignment,
 277          "heap_alignment: " SIZE_FORMAT " less than gen_alignment: " SIZE_FORMAT,
 278          _heap_alignment, _gen_alignment);
 279   assert(_gen_alignment % _space_alignment == 0,
 280          "gen_alignment: " SIZE_FORMAT " not aligned by space_alignment: " SIZE_FORMAT,
 281          _gen_alignment, _space_alignment);
 282   assert(_heap_alignment % _gen_alignment == 0,
 283          "heap_alignment: " SIZE_FORMAT " not aligned by gen_alignment: " SIZE_FORMAT,
 284          _heap_alignment, _gen_alignment);
 285 
 286   // All generational heaps have a young gen; handle those flags here
 287 
 288   // Make sure the heap is large enough for two generations
 289   size_t smallest_new_size = young_gen_size_lower_bound();
 290   size_t smallest_heap_size = align_size_up(smallest_new_size + old_gen_size_lower_bound(),
 291                                            _heap_alignment);
 292   if (MaxHeapSize < smallest_heap_size) {
 293     FLAG_SET_ERGO(size_t, MaxHeapSize, smallest_heap_size);
 294     _max_heap_byte_size = MaxHeapSize;
 295   }
 296   // If needed, synchronize _min_heap_byte size and _initial_heap_byte_size
 297   if (_min_heap_byte_size < smallest_heap_size) {
 298     _min_heap_byte_size = smallest_heap_size;
 299     if (InitialHeapSize < _min_heap_byte_size) {
 300       FLAG_SET_ERGO(size_t, InitialHeapSize, smallest_heap_size);
 301       _initial_heap_byte_size = smallest_heap_size;
 302     }
 303   }
 304 
 305   // Make sure NewSize allows an old generation to fit even if set on the command line
 306   if (FLAG_IS_CMDLINE(NewSize) && NewSize >= _initial_heap_byte_size) {
 307     log_warning(gc, ergo)("NewSize was set larger than initial heap size, will use initial heap size.");
 308     FLAG_SET_ERGO(size_t, NewSize, bound_minus_alignment(NewSize, _initial_heap_byte_size));
 309   }
 310 
 311   // Now take the actual NewSize into account. We will silently increase NewSize
 312   // if the user specified a smaller or unaligned value.
 313   size_t bounded_new_size = bound_minus_alignment(NewSize, MaxHeapSize);
 314   bounded_new_size = MAX2(smallest_new_size, align_size_down(bounded_new_size, _gen_alignment));
 315   if (bounded_new_size != NewSize) {
 316     FLAG_SET_ERGO(size_t, NewSize, bounded_new_size);
 317   }
 318   _min_young_size = smallest_new_size;
 319   _initial_young_size = NewSize;
 320 
 321   if (!FLAG_IS_DEFAULT(MaxNewSize)) {
 322     if (MaxNewSize >= MaxHeapSize) {
 323       // Make sure there is room for an old generation
 324       size_t smaller_max_new_size = MaxHeapSize - _gen_alignment;
 325       if (FLAG_IS_CMDLINE(MaxNewSize)) {
 326         log_warning(gc, ergo)("MaxNewSize (" SIZE_FORMAT "k) is equal to or greater than the entire "
 327                               "heap (" SIZE_FORMAT "k).  A new max generation size of " SIZE_FORMAT "k will be used.",
 328                               MaxNewSize/K, MaxHeapSize/K, smaller_max_new_size/K);
 329       }
 330       FLAG_SET_ERGO(size_t, MaxNewSize, smaller_max_new_size);
 331       if (NewSize > MaxNewSize) {
 332         FLAG_SET_ERGO(size_t, NewSize, MaxNewSize);
 333         _initial_young_size = NewSize;
 334       }
 335     } else if (MaxNewSize < _initial_young_size) {
 336       FLAG_SET_ERGO(size_t, MaxNewSize, _initial_young_size);
 337     } else if (!is_size_aligned(MaxNewSize, _gen_alignment)) {
 338       FLAG_SET_ERGO(size_t, MaxNewSize, align_size_down(MaxNewSize, _gen_alignment));
 339     }
 340     _max_young_size = MaxNewSize;
 341   }
 342 
 343   if (NewSize > MaxNewSize) {
 344     // At this point this should only happen if the user specifies a large NewSize and/or
 345     // a small (but not too small) MaxNewSize.
 346     if (FLAG_IS_CMDLINE(MaxNewSize)) {
 347       log_warning(gc, ergo)("NewSize (" SIZE_FORMAT "k) is greater than the MaxNewSize (" SIZE_FORMAT "k). "
 348                             "A new max generation size of " SIZE_FORMAT "k will be used.",
 349                             NewSize/K, MaxNewSize/K, NewSize/K);
 350     }
 351     FLAG_SET_ERGO(size_t, MaxNewSize, NewSize);
 352     _max_young_size = MaxNewSize;
 353   }
 354 
 355   if (SurvivorRatio < 1 || NewRatio < 1) {
 356     vm_exit_during_initialization("Invalid young gen ratio specified");
 357   }
 358 
 359   if (OldSize < old_gen_size_lower_bound()) {
 360     FLAG_SET_ERGO(size_t, OldSize, old_gen_size_lower_bound());
 361   }
 362   if (!is_size_aligned(OldSize, _gen_alignment)) {
 363     FLAG_SET_ERGO(size_t, OldSize, align_size_down(OldSize, _gen_alignment));
 364   }
 365 
 366   if (FLAG_IS_CMDLINE(OldSize) && FLAG_IS_DEFAULT(MaxHeapSize)) {
 367     // NewRatio will be used later to set the young generation size so we use
 368     // it to calculate how big the heap should be based on the requested OldSize
 369     // and NewRatio.
 370     assert(NewRatio > 0, "NewRatio should have been set up earlier");
 371     size_t calculated_heapsize = (OldSize / NewRatio) * (NewRatio + 1);
 372 
 373     calculated_heapsize = align_size_up(calculated_heapsize, _heap_alignment);
 374     FLAG_SET_ERGO(size_t, MaxHeapSize, calculated_heapsize);
 375     _max_heap_byte_size = MaxHeapSize;
 376     FLAG_SET_ERGO(size_t, InitialHeapSize, calculated_heapsize);
 377     _initial_heap_byte_size = InitialHeapSize;
 378   }
 379 
 380   // Adjust NewSize and OldSize or MaxHeapSize to match each other
 381   if (NewSize + OldSize > MaxHeapSize) {
 382     if (FLAG_IS_CMDLINE(MaxHeapSize)) {
 383       // Somebody has set a maximum heap size with the intention that we should not
 384       // exceed it. Adjust New/OldSize as necessary.
 385       size_t calculated_size = NewSize + OldSize;
 386       double shrink_factor = (double) MaxHeapSize / calculated_size;
 387       size_t smaller_new_size = align_size_down((size_t)(NewSize * shrink_factor), _gen_alignment);
 388       FLAG_SET_ERGO(size_t, NewSize, MAX2(young_gen_size_lower_bound(), smaller_new_size));
 389       _initial_young_size = NewSize;
 390 
 391       // OldSize is already aligned because above we aligned MaxHeapSize to
 392       // _heap_alignment, and we just made sure that NewSize is aligned to
 393       // _gen_alignment. In initialize_flags() we verified that _heap_alignment
 394       // is a multiple of _gen_alignment.
 395       FLAG_SET_ERGO(size_t, OldSize, MaxHeapSize - NewSize);
 396     } else {
 397       FLAG_SET_ERGO(size_t, MaxHeapSize, align_size_up(NewSize + OldSize, _heap_alignment));
 398       _max_heap_byte_size = MaxHeapSize;
 399     }
 400   }
 401 
 402   // Update NewSize, if possible, to avoid sizing the young gen too small when only
 403   // OldSize is set on the command line.
 404   if (FLAG_IS_CMDLINE(OldSize) && !FLAG_IS_CMDLINE(NewSize)) {
 405     if (OldSize < _initial_heap_byte_size) {
 406       size_t new_size = _initial_heap_byte_size - OldSize;
 407       // Need to compare against the flag value for max since _max_young_size
 408       // might not have been set yet.
 409       if (new_size >= _min_young_size && new_size <= MaxNewSize) {
 410         FLAG_SET_ERGO(size_t, NewSize, new_size);
 411         _initial_young_size = NewSize;
 412       }
 413     }
 414   }
 415 
 416   always_do_update_barrier = UseConcMarkSweepGC;
 417 




  88     if (FLAG_IS_CMDLINE(InitialHeapSize) && InitialHeapSize > MaxHeapSize) {
  89       vm_exit_during_initialization("Initial heap size set to a larger value than the maximum heap size");
  90     }
  91     if (_min_heap_byte_size != 0 && MaxHeapSize < _min_heap_byte_size) {
  92       vm_exit_during_initialization("Incompatible minimum and maximum heap sizes specified");
  93     }
  94   }
  95 
  96   // Check heap parameter properties
  97   if (MaxHeapSize < 2 * M) {
  98     vm_exit_during_initialization("Too small maximum heap");
  99   }
 100   if (InitialHeapSize < M) {
 101     vm_exit_during_initialization("Too small initial heap");
 102   }
 103   if (_min_heap_byte_size < M) {
 104     vm_exit_during_initialization("Too small minimum heap");
 105   }
 106 
 107   // User inputs from -Xmx and -Xms must be aligned
 108   _min_heap_byte_size = align_up(_min_heap_byte_size, _heap_alignment);
 109   size_t aligned_initial_heap_size = align_up(InitialHeapSize, _heap_alignment);
 110   size_t aligned_max_heap_size = align_up(MaxHeapSize, _heap_alignment);
 111 
 112   // Write back to flags if the values changed
 113   if (aligned_initial_heap_size != InitialHeapSize) {
 114     FLAG_SET_ERGO(size_t, InitialHeapSize, aligned_initial_heap_size);
 115   }
 116   if (aligned_max_heap_size != MaxHeapSize) {
 117     FLAG_SET_ERGO(size_t, MaxHeapSize, aligned_max_heap_size);
 118   }
 119 
 120   if (FLAG_IS_CMDLINE(InitialHeapSize) && _min_heap_byte_size != 0 &&
 121       InitialHeapSize < _min_heap_byte_size) {
 122     vm_exit_during_initialization("Incompatible minimum and initial heap sizes specified");
 123   }
 124   if (!FLAG_IS_DEFAULT(InitialHeapSize) && InitialHeapSize > MaxHeapSize) {
 125     FLAG_SET_ERGO(size_t, MaxHeapSize, InitialHeapSize);
 126   } else if (!FLAG_IS_DEFAULT(MaxHeapSize) && InitialHeapSize > MaxHeapSize) {
 127     FLAG_SET_ERGO(size_t, InitialHeapSize, MaxHeapSize);
 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 CardTableRS* CollectorPolicy::create_rem_set(MemRegion whole_heap) {
 155   return new CardTableRS(whole_heap);
 156 }


 181   }
 182 
 183   return alignment;
 184 }
 185 
 186 // GenCollectorPolicy methods
 187 
 188 GenCollectorPolicy::GenCollectorPolicy() :
 189     _min_young_size(0),
 190     _initial_young_size(0),
 191     _max_young_size(0),
 192     _min_old_size(0),
 193     _initial_old_size(0),
 194     _max_old_size(0),
 195     _gen_alignment(0),
 196     _young_gen_spec(NULL),
 197     _old_gen_spec(NULL)
 198 {}
 199 
 200 size_t GenCollectorPolicy::scale_by_NewRatio_aligned(size_t base_size) {
 201   return align_down_bounded(base_size / (NewRatio + 1), _gen_alignment);
 202 }
 203 
 204 size_t GenCollectorPolicy::bound_minus_alignment(size_t desired_size,
 205                                                  size_t maximum_size) {
 206   size_t max_minus = maximum_size - _gen_alignment;
 207   return desired_size < max_minus ? desired_size : max_minus;
 208 }
 209 
 210 
 211 void GenCollectorPolicy::initialize_size_policy(size_t init_eden_size,
 212                                                 size_t init_promo_size,
 213                                                 size_t init_survivor_size) {
 214   const double max_gc_pause_sec = ((double) MaxGCPauseMillis) / 1000.0;
 215   _size_policy = new AdaptiveSizePolicy(init_eden_size,
 216                                         init_promo_size,
 217                                         init_survivor_size,
 218                                         max_gc_pause_sec,
 219                                         GCTimeRatio);
 220 }
 221 
 222 size_t GenCollectorPolicy::young_gen_size_lower_bound() {
 223   // The young generation must be aligned and have room for eden + two survivors
 224   return align_up(3 * _space_alignment, _gen_alignment);
 225 }
 226 
 227 size_t GenCollectorPolicy::old_gen_size_lower_bound() {
 228   return align_up(_space_alignment, _gen_alignment);
 229 }
 230 
 231 #ifdef ASSERT
 232 void GenCollectorPolicy::assert_flags() {
 233   CollectorPolicy::assert_flags();
 234   assert(NewSize >= _min_young_size, "Ergonomics decided on a too small young gen size");
 235   assert(NewSize <= MaxNewSize, "Ergonomics decided on incompatible initial and maximum young gen sizes");
 236   assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize < MaxHeapSize, "Ergonomics decided on incompatible maximum young gen and heap sizes");
 237   assert(NewSize % _gen_alignment == 0, "NewSize alignment");
 238   assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize % _gen_alignment == 0, "MaxNewSize alignment");
 239   assert(OldSize + NewSize <= MaxHeapSize, "Ergonomics decided on incompatible generation and heap sizes");
 240   assert(OldSize % _gen_alignment == 0, "OldSize alignment");
 241 }
 242 
 243 void GenCollectorPolicy::assert_size_info() {
 244   CollectorPolicy::assert_size_info();
 245   // GenCollectorPolicy::initialize_size_info may update the MaxNewSize
 246   assert(MaxNewSize < MaxHeapSize, "Ergonomics decided on incompatible maximum young and heap sizes");
 247   assert(NewSize == _initial_young_size, "Discrepancy between NewSize flag and local storage");
 248   assert(MaxNewSize == _max_young_size, "Discrepancy between MaxNewSize flag and local storage");


 270 #endif // ASSERT
 271 
 272 void GenCollectorPolicy::initialize_flags() {
 273   CollectorPolicy::initialize_flags();
 274 
 275   assert(_gen_alignment != 0, "Generation alignment not set up properly");
 276   assert(_heap_alignment >= _gen_alignment,
 277          "heap_alignment: " SIZE_FORMAT " less than gen_alignment: " SIZE_FORMAT,
 278          _heap_alignment, _gen_alignment);
 279   assert(_gen_alignment % _space_alignment == 0,
 280          "gen_alignment: " SIZE_FORMAT " not aligned by space_alignment: " SIZE_FORMAT,
 281          _gen_alignment, _space_alignment);
 282   assert(_heap_alignment % _gen_alignment == 0,
 283          "heap_alignment: " SIZE_FORMAT " not aligned by gen_alignment: " SIZE_FORMAT,
 284          _heap_alignment, _gen_alignment);
 285 
 286   // All generational heaps have a young gen; handle those flags here
 287 
 288   // Make sure the heap is large enough for two generations
 289   size_t smallest_new_size = young_gen_size_lower_bound();
 290   size_t smallest_heap_size = align_up(smallest_new_size + old_gen_size_lower_bound(),
 291                                            _heap_alignment);
 292   if (MaxHeapSize < smallest_heap_size) {
 293     FLAG_SET_ERGO(size_t, MaxHeapSize, smallest_heap_size);
 294     _max_heap_byte_size = MaxHeapSize;
 295   }
 296   // If needed, synchronize _min_heap_byte size and _initial_heap_byte_size
 297   if (_min_heap_byte_size < smallest_heap_size) {
 298     _min_heap_byte_size = smallest_heap_size;
 299     if (InitialHeapSize < _min_heap_byte_size) {
 300       FLAG_SET_ERGO(size_t, InitialHeapSize, smallest_heap_size);
 301       _initial_heap_byte_size = smallest_heap_size;
 302     }
 303   }
 304 
 305   // Make sure NewSize allows an old generation to fit even if set on the command line
 306   if (FLAG_IS_CMDLINE(NewSize) && NewSize >= _initial_heap_byte_size) {
 307     log_warning(gc, ergo)("NewSize was set larger than initial heap size, will use initial heap size.");
 308     FLAG_SET_ERGO(size_t, NewSize, bound_minus_alignment(NewSize, _initial_heap_byte_size));
 309   }
 310 
 311   // Now take the actual NewSize into account. We will silently increase NewSize
 312   // if the user specified a smaller or unaligned value.
 313   size_t bounded_new_size = bound_minus_alignment(NewSize, MaxHeapSize);
 314   bounded_new_size = MAX2(smallest_new_size, align_down(bounded_new_size, _gen_alignment));
 315   if (bounded_new_size != NewSize) {
 316     FLAG_SET_ERGO(size_t, NewSize, bounded_new_size);
 317   }
 318   _min_young_size = smallest_new_size;
 319   _initial_young_size = NewSize;
 320 
 321   if (!FLAG_IS_DEFAULT(MaxNewSize)) {
 322     if (MaxNewSize >= MaxHeapSize) {
 323       // Make sure there is room for an old generation
 324       size_t smaller_max_new_size = MaxHeapSize - _gen_alignment;
 325       if (FLAG_IS_CMDLINE(MaxNewSize)) {
 326         log_warning(gc, ergo)("MaxNewSize (" SIZE_FORMAT "k) is equal to or greater than the entire "
 327                               "heap (" SIZE_FORMAT "k).  A new max generation size of " SIZE_FORMAT "k will be used.",
 328                               MaxNewSize/K, MaxHeapSize/K, smaller_max_new_size/K);
 329       }
 330       FLAG_SET_ERGO(size_t, MaxNewSize, smaller_max_new_size);
 331       if (NewSize > MaxNewSize) {
 332         FLAG_SET_ERGO(size_t, NewSize, MaxNewSize);
 333         _initial_young_size = NewSize;
 334       }
 335     } else if (MaxNewSize < _initial_young_size) {
 336       FLAG_SET_ERGO(size_t, MaxNewSize, _initial_young_size);
 337     } else if (!is_aligned(MaxNewSize, _gen_alignment)) {
 338       FLAG_SET_ERGO(size_t, MaxNewSize, align_down(MaxNewSize, _gen_alignment));
 339     }
 340     _max_young_size = MaxNewSize;
 341   }
 342 
 343   if (NewSize > MaxNewSize) {
 344     // At this point this should only happen if the user specifies a large NewSize and/or
 345     // a small (but not too small) MaxNewSize.
 346     if (FLAG_IS_CMDLINE(MaxNewSize)) {
 347       log_warning(gc, ergo)("NewSize (" SIZE_FORMAT "k) is greater than the MaxNewSize (" SIZE_FORMAT "k). "
 348                             "A new max generation size of " SIZE_FORMAT "k will be used.",
 349                             NewSize/K, MaxNewSize/K, NewSize/K);
 350     }
 351     FLAG_SET_ERGO(size_t, MaxNewSize, NewSize);
 352     _max_young_size = MaxNewSize;
 353   }
 354 
 355   if (SurvivorRatio < 1 || NewRatio < 1) {
 356     vm_exit_during_initialization("Invalid young gen ratio specified");
 357   }
 358 
 359   if (OldSize < old_gen_size_lower_bound()) {
 360     FLAG_SET_ERGO(size_t, OldSize, old_gen_size_lower_bound());
 361   }
 362   if (!is_aligned(OldSize, _gen_alignment)) {
 363     FLAG_SET_ERGO(size_t, OldSize, align_down(OldSize, _gen_alignment));
 364   }
 365 
 366   if (FLAG_IS_CMDLINE(OldSize) && FLAG_IS_DEFAULT(MaxHeapSize)) {
 367     // NewRatio will be used later to set the young generation size so we use
 368     // it to calculate how big the heap should be based on the requested OldSize
 369     // and NewRatio.
 370     assert(NewRatio > 0, "NewRatio should have been set up earlier");
 371     size_t calculated_heapsize = (OldSize / NewRatio) * (NewRatio + 1);
 372 
 373     calculated_heapsize = align_up(calculated_heapsize, _heap_alignment);
 374     FLAG_SET_ERGO(size_t, MaxHeapSize, calculated_heapsize);
 375     _max_heap_byte_size = MaxHeapSize;
 376     FLAG_SET_ERGO(size_t, InitialHeapSize, calculated_heapsize);
 377     _initial_heap_byte_size = InitialHeapSize;
 378   }
 379 
 380   // Adjust NewSize and OldSize or MaxHeapSize to match each other
 381   if (NewSize + OldSize > MaxHeapSize) {
 382     if (FLAG_IS_CMDLINE(MaxHeapSize)) {
 383       // Somebody has set a maximum heap size with the intention that we should not
 384       // exceed it. Adjust New/OldSize as necessary.
 385       size_t calculated_size = NewSize + OldSize;
 386       double shrink_factor = (double) MaxHeapSize / calculated_size;
 387       size_t smaller_new_size = align_down((size_t)(NewSize * shrink_factor), _gen_alignment);
 388       FLAG_SET_ERGO(size_t, NewSize, MAX2(young_gen_size_lower_bound(), smaller_new_size));
 389       _initial_young_size = NewSize;
 390 
 391       // OldSize is already aligned because above we aligned MaxHeapSize to
 392       // _heap_alignment, and we just made sure that NewSize is aligned to
 393       // _gen_alignment. In initialize_flags() we verified that _heap_alignment
 394       // is a multiple of _gen_alignment.
 395       FLAG_SET_ERGO(size_t, OldSize, MaxHeapSize - NewSize);
 396     } else {
 397       FLAG_SET_ERGO(size_t, MaxHeapSize, align_up(NewSize + OldSize, _heap_alignment));
 398       _max_heap_byte_size = MaxHeapSize;
 399     }
 400   }
 401 
 402   // Update NewSize, if possible, to avoid sizing the young gen too small when only
 403   // OldSize is set on the command line.
 404   if (FLAG_IS_CMDLINE(OldSize) && !FLAG_IS_CMDLINE(NewSize)) {
 405     if (OldSize < _initial_heap_byte_size) {
 406       size_t new_size = _initial_heap_byte_size - OldSize;
 407       // Need to compare against the flag value for max since _max_young_size
 408       // might not have been set yet.
 409       if (new_size >= _min_young_size && new_size <= MaxNewSize) {
 410         FLAG_SET_ERGO(size_t, NewSize, new_size);
 411         _initial_young_size = NewSize;
 412       }
 413     }
 414   }
 415 
 416   always_do_update_barrier = UseConcMarkSweepGC;
 417 


< prev index next >