< prev index next >

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

Print this page




 268   assert(_min_young_size + _min_old_size <= _min_heap_byte_size, "Minimum generation sizes exceed minimum heap size");
 269   assert(_initial_young_size + _initial_old_size == _initial_heap_byte_size, "Initial generation sizes should match initial heap size");
 270   assert(_max_young_size + _max_old_size == _max_heap_byte_size, "Maximum generation sizes should match maximum heap size");
 271 }
 272 #endif // ASSERT
 273 
 274 void GenCollectorPolicy::initialize_flags() {
 275   CollectorPolicy::initialize_flags();
 276 
 277   assert(_gen_alignment != 0, "Generation alignment not set up properly");
 278   assert(_heap_alignment >= _gen_alignment,
 279          "heap_alignment: " SIZE_FORMAT " less than gen_alignment: " SIZE_FORMAT,
 280          _heap_alignment, _gen_alignment);
 281   assert(_gen_alignment % _space_alignment == 0,
 282          "gen_alignment: " SIZE_FORMAT " not aligned by space_alignment: " SIZE_FORMAT,
 283          _gen_alignment, _space_alignment);
 284   assert(_heap_alignment % _gen_alignment == 0,
 285          "heap_alignment: " SIZE_FORMAT " not aligned by gen_alignment: " SIZE_FORMAT,
 286          _heap_alignment, _gen_alignment);
 287 
 288   // All generational heaps have a youngest gen; handle those flags here
 289 
 290   // Make sure the heap is large enough for two generations
 291   size_t smallest_new_size = young_gen_size_lower_bound();
 292   size_t smallest_heap_size = align_size_up(smallest_new_size + old_gen_size_lower_bound(),
 293                                            _heap_alignment);
 294   if (MaxHeapSize < smallest_heap_size) {
 295     FLAG_SET_ERGO(size_t, MaxHeapSize, smallest_heap_size);
 296     _max_heap_byte_size = MaxHeapSize;
 297   }
 298   // If needed, synchronize _min_heap_byte size and _initial_heap_byte_size
 299   if (_min_heap_byte_size < smallest_heap_size) {
 300     _min_heap_byte_size = smallest_heap_size;
 301     if (InitialHeapSize < _min_heap_byte_size) {
 302       FLAG_SET_ERGO(size_t, InitialHeapSize, smallest_heap_size);
 303       _initial_heap_byte_size = smallest_heap_size;
 304     }
 305   }
 306 
 307   // Make sure NewSize allows an old generation to fit even if set on the command line
 308   if (FLAG_IS_CMDLINE(NewSize) && NewSize >= _initial_heap_byte_size) {
 309     log_warning(gc, ergo)("NewSize was set larger than initial heap size, will use initial heap size.");
 310     NewSize = bound_minus_alignment(NewSize, _initial_heap_byte_size);
 311   }
 312 
 313   // Now take the actual NewSize into account. We will silently increase NewSize
 314   // if the user specified a smaller or unaligned value.
 315   size_t bounded_new_size = bound_minus_alignment(NewSize, MaxHeapSize);
 316   bounded_new_size = MAX2(smallest_new_size, (size_t)align_size_down(bounded_new_size, _gen_alignment));
 317   if (bounded_new_size != NewSize) {
 318     // Do not use FLAG_SET_ERGO to update NewSize here, since this will override
 319     // if NewSize was set on the command line or not. This information is needed
 320     // later when setting the initial and minimum young generation size.
 321     NewSize = bounded_new_size;
 322   }
 323   _min_young_size = smallest_new_size;
 324   _initial_young_size = NewSize;
 325 
 326   if (!FLAG_IS_DEFAULT(MaxNewSize)) {
 327     if (MaxNewSize >= MaxHeapSize) {
 328       // Make sure there is room for an old generation
 329       size_t smaller_max_new_size = MaxHeapSize - _gen_alignment;
 330       if (FLAG_IS_CMDLINE(MaxNewSize)) {
 331         log_warning(gc, ergo)("MaxNewSize (" SIZE_FORMAT "k) is equal to or greater than the entire "
 332                               "heap (" SIZE_FORMAT "k).  A new max generation size of " SIZE_FORMAT "k will be used.",
 333                               MaxNewSize/K, MaxHeapSize/K, smaller_max_new_size/K);
 334       }
 335       FLAG_SET_ERGO(size_t, MaxNewSize, smaller_max_new_size);
 336       if (NewSize > MaxNewSize) {
 337         FLAG_SET_ERGO(size_t, NewSize, MaxNewSize);
 338         _initial_young_size = NewSize;
 339       }
 340     } else if (MaxNewSize < _initial_young_size) {
 341       FLAG_SET_ERGO(size_t, MaxNewSize, _initial_young_size);


 344     }
 345     _max_young_size = MaxNewSize;
 346   }
 347 
 348   if (NewSize > MaxNewSize) {
 349     // At this point this should only happen if the user specifies a large NewSize and/or
 350     // a small (but not too small) MaxNewSize.
 351     if (FLAG_IS_CMDLINE(MaxNewSize)) {
 352       log_warning(gc, ergo)("NewSize (" SIZE_FORMAT "k) is greater than the MaxNewSize (" SIZE_FORMAT "k). "
 353                             "A new max generation size of " SIZE_FORMAT "k will be used.",
 354                             NewSize/K, MaxNewSize/K, NewSize/K);
 355     }
 356     FLAG_SET_ERGO(size_t, MaxNewSize, NewSize);
 357     _max_young_size = MaxNewSize;
 358   }
 359 
 360   if (SurvivorRatio < 1 || NewRatio < 1) {
 361     vm_exit_during_initialization("Invalid young gen ratio specified");
 362   }
 363 
 364   OldSize = MAX2(OldSize, old_gen_size_lower_bound());


 365   if (!is_size_aligned(OldSize, _gen_alignment)) {
 366     // Setting OldSize directly to preserve information about the possible
 367     // setting of OldSize on the command line.
 368     OldSize = align_size_down(OldSize, _gen_alignment);
 369   }
 370 
 371   if (FLAG_IS_CMDLINE(OldSize) && FLAG_IS_DEFAULT(MaxHeapSize)) {
 372     // NewRatio will be used later to set the young generation size so we use
 373     // it to calculate how big the heap should be based on the requested OldSize
 374     // and NewRatio.
 375     assert(NewRatio > 0, "NewRatio should have been set up earlier");
 376     size_t calculated_heapsize = (OldSize / NewRatio) * (NewRatio + 1);
 377 
 378     calculated_heapsize = align_size_up(calculated_heapsize, _heap_alignment);
 379     FLAG_SET_ERGO(size_t, MaxHeapSize, calculated_heapsize);
 380     _max_heap_byte_size = MaxHeapSize;
 381     FLAG_SET_ERGO(size_t, InitialHeapSize, calculated_heapsize);
 382     _initial_heap_byte_size = InitialHeapSize;
 383   }
 384 
 385   // Adjust NewSize and OldSize or MaxHeapSize to match each other
 386   if (NewSize + OldSize > MaxHeapSize) {
 387     if (_max_heap_size_cmdline) {
 388       // Somebody has set a maximum heap size with the intention that we should not




 268   assert(_min_young_size + _min_old_size <= _min_heap_byte_size, "Minimum generation sizes exceed minimum heap size");
 269   assert(_initial_young_size + _initial_old_size == _initial_heap_byte_size, "Initial generation sizes should match initial heap size");
 270   assert(_max_young_size + _max_old_size == _max_heap_byte_size, "Maximum generation sizes should match maximum heap size");
 271 }
 272 #endif // ASSERT
 273 
 274 void GenCollectorPolicy::initialize_flags() {
 275   CollectorPolicy::initialize_flags();
 276 
 277   assert(_gen_alignment != 0, "Generation alignment not set up properly");
 278   assert(_heap_alignment >= _gen_alignment,
 279          "heap_alignment: " SIZE_FORMAT " less than gen_alignment: " SIZE_FORMAT,
 280          _heap_alignment, _gen_alignment);
 281   assert(_gen_alignment % _space_alignment == 0,
 282          "gen_alignment: " SIZE_FORMAT " not aligned by space_alignment: " SIZE_FORMAT,
 283          _gen_alignment, _space_alignment);
 284   assert(_heap_alignment % _gen_alignment == 0,
 285          "heap_alignment: " SIZE_FORMAT " not aligned by gen_alignment: " SIZE_FORMAT,
 286          _heap_alignment, _gen_alignment);
 287 
 288   // All generational heaps have a young gen; handle those flags here
 289 
 290   // Make sure the heap is large enough for two generations
 291   size_t smallest_new_size = young_gen_size_lower_bound();
 292   size_t smallest_heap_size = align_size_up(smallest_new_size + old_gen_size_lower_bound(),
 293                                            _heap_alignment);
 294   if (MaxHeapSize < smallest_heap_size) {
 295     FLAG_SET_ERGO(size_t, MaxHeapSize, smallest_heap_size);
 296     _max_heap_byte_size = MaxHeapSize;
 297   }
 298   // If needed, synchronize _min_heap_byte size and _initial_heap_byte_size
 299   if (_min_heap_byte_size < smallest_heap_size) {
 300     _min_heap_byte_size = smallest_heap_size;
 301     if (InitialHeapSize < _min_heap_byte_size) {
 302       FLAG_SET_ERGO(size_t, InitialHeapSize, smallest_heap_size);
 303       _initial_heap_byte_size = smallest_heap_size;
 304     }
 305   }
 306 
 307   // Make sure NewSize allows an old generation to fit even if set on the command line
 308   if (FLAG_IS_CMDLINE(NewSize) && NewSize >= _initial_heap_byte_size) {
 309     log_warning(gc, ergo)("NewSize was set larger than initial heap size, will use initial heap size.");
 310     FLAG_SET_ERGO(size_t, NewSize, bound_minus_alignment(NewSize, _initial_heap_byte_size));
 311   }
 312 
 313   // Now take the actual NewSize into account. We will silently increase NewSize
 314   // if the user specified a smaller or unaligned value.
 315   size_t bounded_new_size = bound_minus_alignment(NewSize, MaxHeapSize);
 316   bounded_new_size = MAX2(smallest_new_size, (size_t)align_size_down(bounded_new_size, _gen_alignment));
 317   if (bounded_new_size != NewSize) {
 318     FLAG_SET_ERGO(size_t, NewSize, bounded_new_size);



 319   }
 320   _min_young_size = smallest_new_size;
 321   _initial_young_size = NewSize;
 322 
 323   if (!FLAG_IS_DEFAULT(MaxNewSize)) {
 324     if (MaxNewSize >= MaxHeapSize) {
 325       // Make sure there is room for an old generation
 326       size_t smaller_max_new_size = MaxHeapSize - _gen_alignment;
 327       if (FLAG_IS_CMDLINE(MaxNewSize)) {
 328         log_warning(gc, ergo)("MaxNewSize (" SIZE_FORMAT "k) is equal to or greater than the entire "
 329                               "heap (" SIZE_FORMAT "k).  A new max generation size of " SIZE_FORMAT "k will be used.",
 330                               MaxNewSize/K, MaxHeapSize/K, smaller_max_new_size/K);
 331       }
 332       FLAG_SET_ERGO(size_t, MaxNewSize, smaller_max_new_size);
 333       if (NewSize > MaxNewSize) {
 334         FLAG_SET_ERGO(size_t, NewSize, MaxNewSize);
 335         _initial_young_size = NewSize;
 336       }
 337     } else if (MaxNewSize < _initial_young_size) {
 338       FLAG_SET_ERGO(size_t, MaxNewSize, _initial_young_size);


 341     }
 342     _max_young_size = MaxNewSize;
 343   }
 344 
 345   if (NewSize > MaxNewSize) {
 346     // At this point this should only happen if the user specifies a large NewSize and/or
 347     // a small (but not too small) MaxNewSize.
 348     if (FLAG_IS_CMDLINE(MaxNewSize)) {
 349       log_warning(gc, ergo)("NewSize (" SIZE_FORMAT "k) is greater than the MaxNewSize (" SIZE_FORMAT "k). "
 350                             "A new max generation size of " SIZE_FORMAT "k will be used.",
 351                             NewSize/K, MaxNewSize/K, NewSize/K);
 352     }
 353     FLAG_SET_ERGO(size_t, MaxNewSize, NewSize);
 354     _max_young_size = MaxNewSize;
 355   }
 356 
 357   if (SurvivorRatio < 1 || NewRatio < 1) {
 358     vm_exit_during_initialization("Invalid young gen ratio specified");
 359   }
 360 
 361   if (OldSize < old_gen_size_lower_bound()) {
 362     FLAG_SET_ERGO(size_t, OldSize, old_gen_size_lower_bound());
 363   }
 364   if (!is_size_aligned(OldSize, _gen_alignment)) {
 365     FLAG_SET_ERGO(size_t, OldSize, align_size_down(OldSize, _gen_alignment));


 366   }
 367 
 368   if (FLAG_IS_CMDLINE(OldSize) && FLAG_IS_DEFAULT(MaxHeapSize)) {
 369     // NewRatio will be used later to set the young generation size so we use
 370     // it to calculate how big the heap should be based on the requested OldSize
 371     // and NewRatio.
 372     assert(NewRatio > 0, "NewRatio should have been set up earlier");
 373     size_t calculated_heapsize = (OldSize / NewRatio) * (NewRatio + 1);
 374 
 375     calculated_heapsize = align_size_up(calculated_heapsize, _heap_alignment);
 376     FLAG_SET_ERGO(size_t, MaxHeapSize, calculated_heapsize);
 377     _max_heap_byte_size = MaxHeapSize;
 378     FLAG_SET_ERGO(size_t, InitialHeapSize, calculated_heapsize);
 379     _initial_heap_byte_size = InitialHeapSize;
 380   }
 381 
 382   // Adjust NewSize and OldSize or MaxHeapSize to match each other
 383   if (NewSize + OldSize > MaxHeapSize) {
 384     if (_max_heap_size_cmdline) {
 385       // Somebody has set a maximum heap size with the intention that we should not


< prev index next >