935
936 void ConcurrentMarkSweepGeneration::compute_new_size_free_list() {
937 assert_locked_or_safepoint(Heap_lock);
938
939 // If incremental collection failed, we just want to expand
940 // to the limit.
941 if (incremental_collection_failed()) {
942 clear_incremental_collection_failed();
943 grow_to_reserved();
944 return;
945 }
946
947 double free_percentage = ((double) free()) / capacity();
948 double desired_free_percentage = (double) MinHeapFreeRatio / 100;
949 double maximum_free_percentage = (double) MaxHeapFreeRatio / 100;
950
951 // compute expansion delta needed for reaching desired free percentage
952 if (free_percentage < desired_free_percentage) {
953 size_t desired_capacity = (size_t)(used() / ((double) 1 - desired_free_percentage));
954 assert(desired_capacity >= capacity(), "invalid expansion size");
955 size_t expand_bytes = MAX2(desired_capacity - capacity(), MinHeapDeltaBytes);
956 if (PrintGCDetails && Verbose) {
957 size_t desired_capacity = (size_t)(used() / ((double) 1 - desired_free_percentage));
958 gclog_or_tty->print_cr("\nFrom compute_new_size: ");
959 gclog_or_tty->print_cr(" Free fraction %f", free_percentage);
960 gclog_or_tty->print_cr(" Desired free fraction %f",
961 desired_free_percentage);
962 gclog_or_tty->print_cr(" Maximum free fraction %f",
963 maximum_free_percentage);
964 gclog_or_tty->print_cr(" Capacity "SIZE_FORMAT, capacity()/1000);
965 gclog_or_tty->print_cr(" Desired capacity "SIZE_FORMAT,
966 desired_capacity/1000);
967 int prev_level = level() - 1;
968 if (prev_level >= 0) {
969 size_t prev_size = 0;
970 GenCollectedHeap* gch = GenCollectedHeap::heap();
971 Generation* prev_gen = gch->_gens[prev_level];
972 prev_size = prev_gen->capacity();
973 gclog_or_tty->print_cr(" Younger gen size "SIZE_FORMAT,
974 prev_size/1000);
975 }
6538 AdaptiveSizePolicyOutput(sp, gch->total_collections());
6539 if (asynch) {
6540 CMSTokenSyncWithLocks ts(true, bitMapLock());
6541
6542 // If the state is not "Resetting", the foreground thread
6543 // has done a collection and the resetting.
6544 if (_collectorState != Resetting) {
6545 assert(_collectorState == Idling, "The state should only change"
6546 " because the foreground collector has finished the collection");
6547 return;
6548 }
6549
6550 // Clear the mark bitmap (no grey objects to start with)
6551 // for the next cycle.
6552 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty);
6553 CMSPhaseAccounting cmspa(this, "reset", !PrintGCDetails);
6554
6555 HeapWord* curAddr = _markBitMap.startWord();
6556 while (curAddr < _markBitMap.endWord()) {
6557 size_t remaining = pointer_delta(_markBitMap.endWord(), curAddr);
6558 MemRegion chunk(curAddr, MIN2(CMSBitMapYieldQuantum, remaining));
6559 _markBitMap.clear_large_range(chunk);
6560 if (ConcurrentMarkSweepThread::should_yield() &&
6561 !foregroundGCIsActive() &&
6562 CMSYield) {
6563 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(),
6564 "CMS thread should hold CMS token");
6565 assert_lock_strong(bitMapLock());
6566 bitMapLock()->unlock();
6567 ConcurrentMarkSweepThread::desynchronize(true);
6568 ConcurrentMarkSweepThread::acknowledge_yield_request();
6569 stopTimer();
6570 if (PrintCMSStatistics != 0) {
6571 incrementYields();
6572 }
6573 icms_wait();
6574
6575 // See the comment in coordinator_yield()
6576 for (unsigned i = 0; i < CMSYieldSleepCount &&
6577 ConcurrentMarkSweepThread::should_yield() &&
6578 !CMSCollector::foregroundGCIsActive(); ++i) {
6837 return true;
6838 }
6839
6840 // XXX FIX ME !!! In the MT case we come in here holding a
6841 // leaf lock. For printing we need to take a further lock
6842 // which has lower rank. We need to recalibrate the two
6843 // lock-ranks involved in order to be able to print the
6844 // messages below. (Or defer the printing to the caller.
6845 // For now we take the expedient path of just disabling the
6846 // messages for the problematic case.)
6847 void CMSMarkStack::expand() {
6848 assert(_capacity <= MarkStackSizeMax, "stack bigger than permitted");
6849 if (_capacity == MarkStackSizeMax) {
6850 if (_hit_limit++ == 0 && !CMSConcurrentMTEnabled && PrintGCDetails) {
6851 // We print a warning message only once per CMS cycle.
6852 gclog_or_tty->print_cr(" (benign) Hit CMSMarkStack max size limit");
6853 }
6854 return;
6855 }
6856 // Double capacity if possible
6857 size_t new_capacity = MIN2(_capacity*2, MarkStackSizeMax);
6858 // Do not give up existing stack until we have managed to
6859 // get the double capacity that we desired.
6860 ReservedSpace rs(ReservedSpace::allocation_align_size_up(
6861 new_capacity * sizeof(oop)));
6862 if (rs.is_reserved()) {
6863 // Release the backing store associated with old stack
6864 _virtual_space.release();
6865 // Reinitialize virtual space for new stack
6866 if (!_virtual_space.initialize(rs, rs.size())) {
6867 fatal("Not enough swap for expanded marking stack");
6868 }
6869 _base = (oop*)(_virtual_space.low());
6870 _index = 0;
6871 _capacity = new_capacity;
6872 } else if (_failed_double++ == 0 && !CMSConcurrentMTEnabled && PrintGCDetails) {
6873 // Failed to double capacity, continue;
6874 // we print a detail message only once per CMS cycle.
6875 gclog_or_tty->print(" (benign) Failed to expand marking stack from "SIZE_FORMAT"K to "
6876 SIZE_FORMAT"K",
6877 _capacity / K, new_capacity / K);
|
935
936 void ConcurrentMarkSweepGeneration::compute_new_size_free_list() {
937 assert_locked_or_safepoint(Heap_lock);
938
939 // If incremental collection failed, we just want to expand
940 // to the limit.
941 if (incremental_collection_failed()) {
942 clear_incremental_collection_failed();
943 grow_to_reserved();
944 return;
945 }
946
947 double free_percentage = ((double) free()) / capacity();
948 double desired_free_percentage = (double) MinHeapFreeRatio / 100;
949 double maximum_free_percentage = (double) MaxHeapFreeRatio / 100;
950
951 // compute expansion delta needed for reaching desired free percentage
952 if (free_percentage < desired_free_percentage) {
953 size_t desired_capacity = (size_t)(used() / ((double) 1 - desired_free_percentage));
954 assert(desired_capacity >= capacity(), "invalid expansion size");
955 size_t expand_bytes = MAX2(desired_capacity - capacity(), (size_t)MinHeapDeltaBytes);
956 if (PrintGCDetails && Verbose) {
957 size_t desired_capacity = (size_t)(used() / ((double) 1 - desired_free_percentage));
958 gclog_or_tty->print_cr("\nFrom compute_new_size: ");
959 gclog_or_tty->print_cr(" Free fraction %f", free_percentage);
960 gclog_or_tty->print_cr(" Desired free fraction %f",
961 desired_free_percentage);
962 gclog_or_tty->print_cr(" Maximum free fraction %f",
963 maximum_free_percentage);
964 gclog_or_tty->print_cr(" Capacity "SIZE_FORMAT, capacity()/1000);
965 gclog_or_tty->print_cr(" Desired capacity "SIZE_FORMAT,
966 desired_capacity/1000);
967 int prev_level = level() - 1;
968 if (prev_level >= 0) {
969 size_t prev_size = 0;
970 GenCollectedHeap* gch = GenCollectedHeap::heap();
971 Generation* prev_gen = gch->_gens[prev_level];
972 prev_size = prev_gen->capacity();
973 gclog_or_tty->print_cr(" Younger gen size "SIZE_FORMAT,
974 prev_size/1000);
975 }
6538 AdaptiveSizePolicyOutput(sp, gch->total_collections());
6539 if (asynch) {
6540 CMSTokenSyncWithLocks ts(true, bitMapLock());
6541
6542 // If the state is not "Resetting", the foreground thread
6543 // has done a collection and the resetting.
6544 if (_collectorState != Resetting) {
6545 assert(_collectorState == Idling, "The state should only change"
6546 " because the foreground collector has finished the collection");
6547 return;
6548 }
6549
6550 // Clear the mark bitmap (no grey objects to start with)
6551 // for the next cycle.
6552 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty);
6553 CMSPhaseAccounting cmspa(this, "reset", !PrintGCDetails);
6554
6555 HeapWord* curAddr = _markBitMap.startWord();
6556 while (curAddr < _markBitMap.endWord()) {
6557 size_t remaining = pointer_delta(_markBitMap.endWord(), curAddr);
6558 MemRegion chunk(curAddr, MIN2((size_t)CMSBitMapYieldQuantum, remaining));
6559 _markBitMap.clear_large_range(chunk);
6560 if (ConcurrentMarkSweepThread::should_yield() &&
6561 !foregroundGCIsActive() &&
6562 CMSYield) {
6563 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(),
6564 "CMS thread should hold CMS token");
6565 assert_lock_strong(bitMapLock());
6566 bitMapLock()->unlock();
6567 ConcurrentMarkSweepThread::desynchronize(true);
6568 ConcurrentMarkSweepThread::acknowledge_yield_request();
6569 stopTimer();
6570 if (PrintCMSStatistics != 0) {
6571 incrementYields();
6572 }
6573 icms_wait();
6574
6575 // See the comment in coordinator_yield()
6576 for (unsigned i = 0; i < CMSYieldSleepCount &&
6577 ConcurrentMarkSweepThread::should_yield() &&
6578 !CMSCollector::foregroundGCIsActive(); ++i) {
6837 return true;
6838 }
6839
6840 // XXX FIX ME !!! In the MT case we come in here holding a
6841 // leaf lock. For printing we need to take a further lock
6842 // which has lower rank. We need to recalibrate the two
6843 // lock-ranks involved in order to be able to print the
6844 // messages below. (Or defer the printing to the caller.
6845 // For now we take the expedient path of just disabling the
6846 // messages for the problematic case.)
6847 void CMSMarkStack::expand() {
6848 assert(_capacity <= MarkStackSizeMax, "stack bigger than permitted");
6849 if (_capacity == MarkStackSizeMax) {
6850 if (_hit_limit++ == 0 && !CMSConcurrentMTEnabled && PrintGCDetails) {
6851 // We print a warning message only once per CMS cycle.
6852 gclog_or_tty->print_cr(" (benign) Hit CMSMarkStack max size limit");
6853 }
6854 return;
6855 }
6856 // Double capacity if possible
6857 size_t new_capacity = MIN2(_capacity*2, (size_t)MarkStackSizeMax);
6858 // Do not give up existing stack until we have managed to
6859 // get the double capacity that we desired.
6860 ReservedSpace rs(ReservedSpace::allocation_align_size_up(
6861 new_capacity * sizeof(oop)));
6862 if (rs.is_reserved()) {
6863 // Release the backing store associated with old stack
6864 _virtual_space.release();
6865 // Reinitialize virtual space for new stack
6866 if (!_virtual_space.initialize(rs, rs.size())) {
6867 fatal("Not enough swap for expanded marking stack");
6868 }
6869 _base = (oop*)(_virtual_space.low());
6870 _index = 0;
6871 _capacity = new_capacity;
6872 } else if (_failed_double++ == 0 && !CMSConcurrentMTEnabled && PrintGCDetails) {
6873 // Failed to double capacity, continue;
6874 // we print a detail message only once per CMS cycle.
6875 gclog_or_tty->print(" (benign) Failed to expand marking stack from "SIZE_FORMAT"K to "
6876 SIZE_FORMAT"K",
6877 _capacity / K, new_capacity / K);
|