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