< prev index next >

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

Print this page




 191   _rs->invalidate(used_region());
 192 }
 193 
 194 void CardGeneration::compute_new_size() {
 195   assert(_shrink_factor <= 100, "invalid shrink factor");
 196   size_t current_shrink_factor = _shrink_factor;
 197   _shrink_factor = 0;
 198 
 199   // We don't have floating point command-line arguments
 200   // Note:  argument processing ensures that MinHeapFreeRatio < 100.
 201   const double minimum_free_percentage = MinHeapFreeRatio / 100.0;
 202   const double maximum_used_percentage = 1.0 - minimum_free_percentage;
 203 
 204   // Compute some numbers about the state of the heap.
 205   const size_t used_after_gc = used();
 206   const size_t capacity_after_gc = capacity();
 207 
 208   const double min_tmp = used_after_gc / maximum_used_percentage;
 209   size_t minimum_desired_capacity = (size_t)MIN2(min_tmp, double(max_uintx));
 210   // Don't shrink less than the initial generation size
 211   minimum_desired_capacity = MAX2(minimum_desired_capacity,
 212                                   spec()->init_size());
 213   assert(used_after_gc <= minimum_desired_capacity, "sanity check");
 214 
 215   if (PrintGC && Verbose) {
 216     const size_t free_after_gc = free();
 217     const double free_percentage = ((double)free_after_gc) / capacity_after_gc;
 218     gclog_or_tty->print_cr("TenuredGeneration::compute_new_size: ");
 219     gclog_or_tty->print_cr("  "
 220                   "  minimum_free_percentage: %6.2f"
 221                   "  maximum_used_percentage: %6.2f",
 222                   minimum_free_percentage,
 223                   maximum_used_percentage);
 224     gclog_or_tty->print_cr("  "
 225                   "   free_after_gc   : %6.1fK"
 226                   "   used_after_gc   : %6.1fK"
 227                   "   capacity_after_gc   : %6.1fK",
 228                   free_after_gc / (double) K,
 229                   used_after_gc / (double) K,
 230                   capacity_after_gc / (double) K);
 231     gclog_or_tty->print_cr("  "
 232                   "   free_percentage: %6.2f",


 245                     "  minimum_desired_capacity: %6.1fK"
 246                     "  expand_bytes: %6.1fK"
 247                     "  _min_heap_delta_bytes: %6.1fK",
 248                     minimum_desired_capacity / (double) K,
 249                     expand_bytes / (double) K,
 250                     _min_heap_delta_bytes / (double) K);
 251     }
 252     return;
 253   }
 254 
 255   // No expansion, now see if we want to shrink
 256   size_t shrink_bytes = 0;
 257   // We would never want to shrink more than this
 258   size_t max_shrink_bytes = capacity_after_gc - minimum_desired_capacity;
 259 
 260   if (MaxHeapFreeRatio < 100) {
 261     const double maximum_free_percentage = MaxHeapFreeRatio / 100.0;
 262     const double minimum_used_percentage = 1.0 - maximum_free_percentage;
 263     const double max_tmp = used_after_gc / minimum_used_percentage;
 264     size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(max_uintx));
 265     maximum_desired_capacity = MAX2(maximum_desired_capacity,
 266                                     spec()->init_size());
 267     if (PrintGC && Verbose) {
 268       gclog_or_tty->print_cr("  "
 269                              "  maximum_free_percentage: %6.2f"
 270                              "  minimum_used_percentage: %6.2f",
 271                              maximum_free_percentage,
 272                              minimum_used_percentage);
 273       gclog_or_tty->print_cr("  "
 274                              "  _capacity_at_prologue: %6.1fK"
 275                              "  minimum_desired_capacity: %6.1fK"
 276                              "  maximum_desired_capacity: %6.1fK",
 277                              _capacity_at_prologue / (double) K,
 278                              minimum_desired_capacity / (double) K,
 279                              maximum_desired_capacity / (double) K);
 280     }
 281     assert(minimum_desired_capacity <= maximum_desired_capacity,
 282            "sanity check");
 283 
 284     if (capacity_after_gc > maximum_desired_capacity) {
 285       // Capacity too large, compute shrinking size
 286       shrink_bytes = capacity_after_gc - maximum_desired_capacity;
 287       // We don't want shrink all the way back to initSize if people call
 288       // System.gc(), because some programs do that between "phases" and then
 289       // we'd just have to grow the heap up again for the next phase.  So we
 290       // damp the shrinking: 0% on the first call, 10% on the second call, 40%
 291       // on the third call, and 100% by the fourth call.  But if we recompute
 292       // size without shrinking, it goes back to 0%.
 293       shrink_bytes = shrink_bytes / 100 * current_shrink_factor;
 294       assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size");
 295       if (current_shrink_factor == 0) {
 296         _shrink_factor = 10;
 297       } else {
 298         _shrink_factor = MIN2(current_shrink_factor * 4, (size_t) 100);
 299       }
 300       if (PrintGC && Verbose) {
 301         gclog_or_tty->print_cr("  "
 302                       "  shrinking:"
 303                       "  initSize: %.1fK"
 304                       "  maximum_desired_capacity: %.1fK",
 305                       spec()->init_size() / (double) K,
 306                       maximum_desired_capacity / (double) K);
 307         gclog_or_tty->print_cr("  "
 308                       "  shrink_bytes: %.1fK"
 309                       "  current_shrink_factor: " SIZE_FORMAT
 310                       "  new shrink factor: " SIZE_FORMAT
 311                       "  _min_heap_delta_bytes: %.1fK",
 312                       shrink_bytes / (double) K,
 313                       current_shrink_factor,
 314                       _shrink_factor,
 315                       _min_heap_delta_bytes / (double) K);
 316       }
 317     }
 318   }
 319 
 320   if (capacity_after_gc > _capacity_at_prologue) {
 321     // We might have expanded for promotions, in which case we might want to
 322     // take back that expansion if there's room after GC.  That keeps us from
 323     // stretching the heap with promotions when there's plenty of room.
 324     size_t expansion_for_promotion = capacity_after_gc - _capacity_at_prologue;
 325     expansion_for_promotion = MIN2(expansion_for_promotion, max_shrink_bytes);
 326     // We have two shrinking computations, take the largest
 327     shrink_bytes = MAX2(shrink_bytes, expansion_for_promotion);
 328     assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size");
 329     if (PrintGC && Verbose) {
 330       gclog_or_tty->print_cr("  "
 331                              "  aggressive shrinking:"
 332                              "  _capacity_at_prologue: %.1fK"
 333                              "  capacity_after_gc: %.1fK"
 334                              "  expansion_for_promotion: %.1fK"
 335                              "  shrink_bytes: %.1fK",




 191   _rs->invalidate(used_region());
 192 }
 193 
 194 void CardGeneration::compute_new_size() {
 195   assert(_shrink_factor <= 100, "invalid shrink factor");
 196   size_t current_shrink_factor = _shrink_factor;
 197   _shrink_factor = 0;
 198 
 199   // We don't have floating point command-line arguments
 200   // Note:  argument processing ensures that MinHeapFreeRatio < 100.
 201   const double minimum_free_percentage = MinHeapFreeRatio / 100.0;
 202   const double maximum_used_percentage = 1.0 - minimum_free_percentage;
 203 
 204   // Compute some numbers about the state of the heap.
 205   const size_t used_after_gc = used();
 206   const size_t capacity_after_gc = capacity();
 207 
 208   const double min_tmp = used_after_gc / maximum_used_percentage;
 209   size_t minimum_desired_capacity = (size_t)MIN2(min_tmp, double(max_uintx));
 210   // Don't shrink less than the initial generation size
 211   minimum_desired_capacity = MAX2(minimum_desired_capacity, initial_size());

 212   assert(used_after_gc <= minimum_desired_capacity, "sanity check");
 213 
 214   if (PrintGC && Verbose) {
 215     const size_t free_after_gc = free();
 216     const double free_percentage = ((double)free_after_gc) / capacity_after_gc;
 217     gclog_or_tty->print_cr("TenuredGeneration::compute_new_size: ");
 218     gclog_or_tty->print_cr("  "
 219                   "  minimum_free_percentage: %6.2f"
 220                   "  maximum_used_percentage: %6.2f",
 221                   minimum_free_percentage,
 222                   maximum_used_percentage);
 223     gclog_or_tty->print_cr("  "
 224                   "   free_after_gc   : %6.1fK"
 225                   "   used_after_gc   : %6.1fK"
 226                   "   capacity_after_gc   : %6.1fK",
 227                   free_after_gc / (double) K,
 228                   used_after_gc / (double) K,
 229                   capacity_after_gc / (double) K);
 230     gclog_or_tty->print_cr("  "
 231                   "   free_percentage: %6.2f",


 244                     "  minimum_desired_capacity: %6.1fK"
 245                     "  expand_bytes: %6.1fK"
 246                     "  _min_heap_delta_bytes: %6.1fK",
 247                     minimum_desired_capacity / (double) K,
 248                     expand_bytes / (double) K,
 249                     _min_heap_delta_bytes / (double) K);
 250     }
 251     return;
 252   }
 253 
 254   // No expansion, now see if we want to shrink
 255   size_t shrink_bytes = 0;
 256   // We would never want to shrink more than this
 257   size_t max_shrink_bytes = capacity_after_gc - minimum_desired_capacity;
 258 
 259   if (MaxHeapFreeRatio < 100) {
 260     const double maximum_free_percentage = MaxHeapFreeRatio / 100.0;
 261     const double minimum_used_percentage = 1.0 - maximum_free_percentage;
 262     const double max_tmp = used_after_gc / minimum_used_percentage;
 263     size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(max_uintx));
 264     maximum_desired_capacity = MAX2(maximum_desired_capacity, initial_size());

 265     if (PrintGC && Verbose) {
 266       gclog_or_tty->print_cr("  "
 267                              "  maximum_free_percentage: %6.2f"
 268                              "  minimum_used_percentage: %6.2f",
 269                              maximum_free_percentage,
 270                              minimum_used_percentage);
 271       gclog_or_tty->print_cr("  "
 272                              "  _capacity_at_prologue: %6.1fK"
 273                              "  minimum_desired_capacity: %6.1fK"
 274                              "  maximum_desired_capacity: %6.1fK",
 275                              _capacity_at_prologue / (double) K,
 276                              minimum_desired_capacity / (double) K,
 277                              maximum_desired_capacity / (double) K);
 278     }
 279     assert(minimum_desired_capacity <= maximum_desired_capacity,
 280            "sanity check");
 281 
 282     if (capacity_after_gc > maximum_desired_capacity) {
 283       // Capacity too large, compute shrinking size
 284       shrink_bytes = capacity_after_gc - maximum_desired_capacity;
 285       // We don't want shrink all the way back to initSize if people call
 286       // System.gc(), because some programs do that between "phases" and then
 287       // we'd just have to grow the heap up again for the next phase.  So we
 288       // damp the shrinking: 0% on the first call, 10% on the second call, 40%
 289       // on the third call, and 100% by the fourth call.  But if we recompute
 290       // size without shrinking, it goes back to 0%.
 291       shrink_bytes = shrink_bytes / 100 * current_shrink_factor;
 292       assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size");
 293       if (current_shrink_factor == 0) {
 294         _shrink_factor = 10;
 295       } else {
 296         _shrink_factor = MIN2(current_shrink_factor * 4, (size_t) 100);
 297       }
 298       if (PrintGC && Verbose) {
 299         gclog_or_tty->print_cr("  "
 300                                "  shrinking:"
 301                                "  initSize: %.1fK"
 302                                "  maximum_desired_capacity: %.1fK",
 303                                initial_size() / (double) K,
 304                                maximum_desired_capacity / (double) K);
 305         gclog_or_tty->print_cr("  "
 306                                "  shrink_bytes: %.1fK"
 307                                "  current_shrink_factor: " SIZE_FORMAT
 308                                "  new shrink factor: " SIZE_FORMAT
 309                                "  _min_heap_delta_bytes: %.1fK",
 310                                shrink_bytes / (double) K,
 311                                current_shrink_factor,
 312                                _shrink_factor,
 313                                _min_heap_delta_bytes / (double) K);
 314       }
 315     }
 316   }
 317 
 318   if (capacity_after_gc > _capacity_at_prologue) {
 319     // We might have expanded for promotions, in which case we might want to
 320     // take back that expansion if there's room after GC.  That keeps us from
 321     // stretching the heap with promotions when there's plenty of room.
 322     size_t expansion_for_promotion = capacity_after_gc - _capacity_at_prologue;
 323     expansion_for_promotion = MIN2(expansion_for_promotion, max_shrink_bytes);
 324     // We have two shrinking computations, take the largest
 325     shrink_bytes = MAX2(shrink_bytes, expansion_for_promotion);
 326     assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size");
 327     if (PrintGC && Verbose) {
 328       gclog_or_tty->print_cr("  "
 329                              "  aggressive shrinking:"
 330                              "  _capacity_at_prologue: %.1fK"
 331                              "  capacity_after_gc: %.1fK"
 332                              "  expansion_for_promotion: %.1fK"
 333                              "  shrink_bytes: %.1fK",


< prev index next >