Mercurial > hg > graal-jvmci-8
comparison src/share/vm/memory/generation.cpp @ 9072:8617e38bb4cb
8008508: CMS does not correctly reduce heap size after a Full GC
Reviewed-by: johnc, ysr
author | jmasa |
---|---|
date | Mon, 11 Feb 2013 10:31:56 -0800 |
parents | da91efe96a93 |
children | f2110083203d |
comparison
equal
deleted
inserted
replaced
9071:68fe50d4f1d5 | 9072:8617e38bb4cb |
---|---|
380 } | 380 } |
381 | 381 |
382 CardGeneration::CardGeneration(ReservedSpace rs, size_t initial_byte_size, | 382 CardGeneration::CardGeneration(ReservedSpace rs, size_t initial_byte_size, |
383 int level, | 383 int level, |
384 GenRemSet* remset) : | 384 GenRemSet* remset) : |
385 Generation(rs, initial_byte_size, level), _rs(remset) | 385 Generation(rs, initial_byte_size, level), _rs(remset), |
386 _shrink_factor(0), _min_heap_delta_bytes(), _capacity_at_prologue(), | |
387 _used_at_prologue() | |
386 { | 388 { |
387 HeapWord* start = (HeapWord*)rs.base(); | 389 HeapWord* start = (HeapWord*)rs.base(); |
388 size_t reserved_byte_size = rs.size(); | 390 size_t reserved_byte_size = rs.size(); |
389 assert((uintptr_t(start) & 3) == 0, "bad alignment"); | 391 assert((uintptr_t(start) & 3) == 0, "bad alignment"); |
390 assert((reserved_byte_size & 3) == 0, "bad alignment"); | 392 assert((reserved_byte_size & 3) == 0, "bad alignment"); |
404 if (reserved_mr.end() != Universe::heap()->reserved_region().end()) { | 406 if (reserved_mr.end() != Universe::heap()->reserved_region().end()) { |
405 // Don't check at the very end of the heap as we'll assert that we're probing off | 407 // Don't check at the very end of the heap as we'll assert that we're probing off |
406 // the end if we try. | 408 // the end if we try. |
407 guarantee(_rs->is_aligned(reserved_mr.end()), "generation must be card aligned"); | 409 guarantee(_rs->is_aligned(reserved_mr.end()), "generation must be card aligned"); |
408 } | 410 } |
411 _min_heap_delta_bytes = MinHeapDeltaBytes; | |
412 _capacity_at_prologue = initial_byte_size; | |
413 _used_at_prologue = 0; | |
409 } | 414 } |
410 | 415 |
411 bool CardGeneration::expand(size_t bytes, size_t expand_bytes) { | 416 bool CardGeneration::expand(size_t bytes, size_t expand_bytes) { |
412 assert_locked_or_safepoint(Heap_lock); | 417 assert_locked_or_safepoint(Heap_lock); |
413 if (bytes == 0) { | 418 if (bytes == 0) { |
454 // generation's cards. | 459 // generation's cards. |
455 void CardGeneration::invalidate_remembered_set() { | 460 void CardGeneration::invalidate_remembered_set() { |
456 _rs->invalidate(used_region()); | 461 _rs->invalidate(used_region()); |
457 } | 462 } |
458 | 463 |
464 | |
465 void CardGeneration::compute_new_size() { | |
466 assert(_shrink_factor <= 100, "invalid shrink factor"); | |
467 size_t current_shrink_factor = _shrink_factor; | |
468 _shrink_factor = 0; | |
469 | |
470 // We don't have floating point command-line arguments | |
471 // Note: argument processing ensures that MinHeapFreeRatio < 100. | |
472 const double minimum_free_percentage = MinHeapFreeRatio / 100.0; | |
473 const double maximum_used_percentage = 1.0 - minimum_free_percentage; | |
474 | |
475 // Compute some numbers about the state of the heap. | |
476 const size_t used_after_gc = used(); | |
477 const size_t capacity_after_gc = capacity(); | |
478 | |
479 const double min_tmp = used_after_gc / maximum_used_percentage; | |
480 size_t minimum_desired_capacity = (size_t)MIN2(min_tmp, double(max_uintx)); | |
481 // Don't shrink less than the initial generation size | |
482 minimum_desired_capacity = MAX2(minimum_desired_capacity, | |
483 spec()->init_size()); | |
484 assert(used_after_gc <= minimum_desired_capacity, "sanity check"); | |
485 | |
486 if (PrintGC && Verbose) { | |
487 const size_t free_after_gc = free(); | |
488 const double free_percentage = ((double)free_after_gc) / capacity_after_gc; | |
489 gclog_or_tty->print_cr("TenuredGeneration::compute_new_size: "); | |
490 gclog_or_tty->print_cr(" " | |
491 " minimum_free_percentage: %6.2f" | |
492 " maximum_used_percentage: %6.2f", | |
493 minimum_free_percentage, | |
494 maximum_used_percentage); | |
495 gclog_or_tty->print_cr(" " | |
496 " free_after_gc : %6.1fK" | |
497 " used_after_gc : %6.1fK" | |
498 " capacity_after_gc : %6.1fK", | |
499 free_after_gc / (double) K, | |
500 used_after_gc / (double) K, | |
501 capacity_after_gc / (double) K); | |
502 gclog_or_tty->print_cr(" " | |
503 " free_percentage: %6.2f", | |
504 free_percentage); | |
505 } | |
506 | |
507 if (capacity_after_gc < minimum_desired_capacity) { | |
508 // If we have less free space than we want then expand | |
509 size_t expand_bytes = minimum_desired_capacity - capacity_after_gc; | |
510 // Don't expand unless it's significant | |
511 if (expand_bytes >= _min_heap_delta_bytes) { | |
512 expand(expand_bytes, 0); // safe if expansion fails | |
513 } | |
514 if (PrintGC && Verbose) { | |
515 gclog_or_tty->print_cr(" expanding:" | |
516 " minimum_desired_capacity: %6.1fK" | |
517 " expand_bytes: %6.1fK" | |
518 " _min_heap_delta_bytes: %6.1fK", | |
519 minimum_desired_capacity / (double) K, | |
520 expand_bytes / (double) K, | |
521 _min_heap_delta_bytes / (double) K); | |
522 } | |
523 return; | |
524 } | |
525 | |
526 // No expansion, now see if we want to shrink | |
527 size_t shrink_bytes = 0; | |
528 // We would never want to shrink more than this | |
529 size_t max_shrink_bytes = capacity_after_gc - minimum_desired_capacity; | |
530 | |
531 if (MaxHeapFreeRatio < 100) { | |
532 const double maximum_free_percentage = MaxHeapFreeRatio / 100.0; | |
533 const double minimum_used_percentage = 1.0 - maximum_free_percentage; | |
534 const double max_tmp = used_after_gc / minimum_used_percentage; | |
535 size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(max_uintx)); | |
536 maximum_desired_capacity = MAX2(maximum_desired_capacity, | |
537 spec()->init_size()); | |
538 if (PrintGC && Verbose) { | |
539 gclog_or_tty->print_cr(" " | |
540 " maximum_free_percentage: %6.2f" | |
541 " minimum_used_percentage: %6.2f", | |
542 maximum_free_percentage, | |
543 minimum_used_percentage); | |
544 gclog_or_tty->print_cr(" " | |
545 " _capacity_at_prologue: %6.1fK" | |
546 " minimum_desired_capacity: %6.1fK" | |
547 " maximum_desired_capacity: %6.1fK", | |
548 _capacity_at_prologue / (double) K, | |
549 minimum_desired_capacity / (double) K, | |
550 maximum_desired_capacity / (double) K); | |
551 } | |
552 assert(minimum_desired_capacity <= maximum_desired_capacity, | |
553 "sanity check"); | |
554 | |
555 if (capacity_after_gc > maximum_desired_capacity) { | |
556 // Capacity too large, compute shrinking size | |
557 shrink_bytes = capacity_after_gc - maximum_desired_capacity; | |
558 // We don't want shrink all the way back to initSize if people call | |
559 // System.gc(), because some programs do that between "phases" and then | |
560 // we'd just have to grow the heap up again for the next phase. So we | |
561 // damp the shrinking: 0% on the first call, 10% on the second call, 40% | |
562 // on the third call, and 100% by the fourth call. But if we recompute | |
563 // size without shrinking, it goes back to 0%. | |
564 shrink_bytes = shrink_bytes / 100 * current_shrink_factor; | |
565 assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size"); | |
566 if (current_shrink_factor == 0) { | |
567 _shrink_factor = 10; | |
568 } else { | |
569 _shrink_factor = MIN2(current_shrink_factor * 4, (size_t) 100); | |
570 } | |
571 if (PrintGC && Verbose) { | |
572 gclog_or_tty->print_cr(" " | |
573 " shrinking:" | |
574 " initSize: %.1fK" | |
575 " maximum_desired_capacity: %.1fK", | |
576 spec()->init_size() / (double) K, | |
577 maximum_desired_capacity / (double) K); | |
578 gclog_or_tty->print_cr(" " | |
579 " shrink_bytes: %.1fK" | |
580 " current_shrink_factor: %d" | |
581 " new shrink factor: %d" | |
582 " _min_heap_delta_bytes: %.1fK", | |
583 shrink_bytes / (double) K, | |
584 current_shrink_factor, | |
585 _shrink_factor, | |
586 _min_heap_delta_bytes / (double) K); | |
587 } | |
588 } | |
589 } | |
590 | |
591 if (capacity_after_gc > _capacity_at_prologue) { | |
592 // We might have expanded for promotions, in which case we might want to | |
593 // take back that expansion if there's room after GC. That keeps us from | |
594 // stretching the heap with promotions when there's plenty of room. | |
595 size_t expansion_for_promotion = capacity_after_gc - _capacity_at_prologue; | |
596 expansion_for_promotion = MIN2(expansion_for_promotion, max_shrink_bytes); | |
597 // We have two shrinking computations, take the largest | |
598 shrink_bytes = MAX2(shrink_bytes, expansion_for_promotion); | |
599 assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size"); | |
600 if (PrintGC && Verbose) { | |
601 gclog_or_tty->print_cr(" " | |
602 " aggressive shrinking:" | |
603 " _capacity_at_prologue: %.1fK" | |
604 " capacity_after_gc: %.1fK" | |
605 " expansion_for_promotion: %.1fK" | |
606 " shrink_bytes: %.1fK", | |
607 capacity_after_gc / (double) K, | |
608 _capacity_at_prologue / (double) K, | |
609 expansion_for_promotion / (double) K, | |
610 shrink_bytes / (double) K); | |
611 } | |
612 } | |
613 // Don't shrink unless it's significant | |
614 if (shrink_bytes >= _min_heap_delta_bytes) { | |
615 shrink(shrink_bytes); | |
616 } | |
617 } | |
459 | 618 |
460 // Currently nothing to do. | 619 // Currently nothing to do. |
461 void CardGeneration::prepare_for_verify() {} | 620 void CardGeneration::prepare_for_verify() {} |
462 | 621 |
463 | 622 |