2643 CMSSynchronousYieldRequest yr; |
2643 CMSSynchronousYieldRequest yr; |
2644 assert(!tlab, "Can't deal with TLAB allocation"); |
2644 assert(!tlab, "Can't deal with TLAB allocation"); |
2645 MutexLocker x(freelistLock(), Mutex::_no_safepoint_check_flag); |
2645 MutexLocker x(freelistLock(), Mutex::_no_safepoint_check_flag); |
2646 expand_for_gc_cause(word_size*HeapWordSize, MinHeapDeltaBytes, CMSExpansionCause::_satisfy_allocation); |
2646 expand_for_gc_cause(word_size*HeapWordSize, MinHeapDeltaBytes, CMSExpansionCause::_satisfy_allocation); |
2647 if (GCExpandToAllocateDelayMillis > 0) { |
2647 if (GCExpandToAllocateDelayMillis > 0) { |
2648 os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); |
2648 os::naked_sleep(GCExpandToAllocateDelayMillis); |
2649 } |
2649 } |
2650 return have_lock_and_allocate(word_size, tlab); |
2650 return have_lock_and_allocate(word_size, tlab); |
2651 } |
2651 } |
2652 |
2652 |
2653 void ConcurrentMarkSweepGeneration::expand_for_gc_cause( |
2653 void ConcurrentMarkSweepGeneration::expand_for_gc_cause( |
2682 expand_for_gc_cause(word_sz*HeapWordSize, MinHeapDeltaBytes, CMSExpansionCause::_allocate_par_lab); |
2682 expand_for_gc_cause(word_sz*HeapWordSize, MinHeapDeltaBytes, CMSExpansionCause::_allocate_par_lab); |
2683 // Now go around the loop and try alloc again; |
2683 // Now go around the loop and try alloc again; |
2684 // A competing par_promote might beat us to the expansion space, |
2684 // A competing par_promote might beat us to the expansion space, |
2685 // so we may go around the loop again if promotion fails again. |
2685 // so we may go around the loop again if promotion fails again. |
2686 if (GCExpandToAllocateDelayMillis > 0) { |
2686 if (GCExpandToAllocateDelayMillis > 0) { |
2687 os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); |
2687 os::naked_sleep(GCExpandToAllocateDelayMillis); |
2688 } |
2688 } |
2689 } |
2689 } |
2690 } |
2690 } |
2691 |
2691 |
2692 |
2692 |
2709 expand_for_gc_cause(refill_size_bytes, MinHeapDeltaBytes, CMSExpansionCause::_allocate_par_spooling_space); |
2709 expand_for_gc_cause(refill_size_bytes, MinHeapDeltaBytes, CMSExpansionCause::_allocate_par_spooling_space); |
2710 // Now go around the loop and try alloc again; |
2710 // Now go around the loop and try alloc again; |
2711 // A competing allocation might beat us to the expansion space, |
2711 // A competing allocation might beat us to the expansion space, |
2712 // so we may go around the loop again if allocation fails again. |
2712 // so we may go around the loop again if allocation fails again. |
2713 if (GCExpandToAllocateDelayMillis > 0) { |
2713 if (GCExpandToAllocateDelayMillis > 0) { |
2714 os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); |
2714 os::naked_sleep(GCExpandToAllocateDelayMillis); |
2715 } |
2715 } |
2716 } |
2716 } |
2717 } |
2717 } |
2718 |
2718 |
2719 void ConcurrentMarkSweepGeneration::shrink(size_t bytes) { |
2719 void ConcurrentMarkSweepGeneration::shrink(size_t bytes) { |
3542 // |
3542 // |
3543 // Tony 2006.06.29 |
3543 // Tony 2006.06.29 |
3544 for (unsigned i = 0; i < CMSCoordinatorYieldSleepCount && |
3544 for (unsigned i = 0; i < CMSCoordinatorYieldSleepCount && |
3545 ConcurrentMarkSweepThread::should_yield() && |
3545 ConcurrentMarkSweepThread::should_yield() && |
3546 !CMSCollector::foregroundGCIsActive(); ++i) { |
3546 !CMSCollector::foregroundGCIsActive(); ++i) { |
3547 os::sleep(Thread::current(), 1, false); |
3547 os::naked_short_sleep(1); |
3548 } |
3548 } |
3549 |
3549 |
3550 ConcurrentMarkSweepThread::synchronize(true); |
3550 ConcurrentMarkSweepThread::synchronize(true); |
3551 _bit_map_lock->lock_without_safepoint_check(); |
3551 _bit_map_lock->lock_without_safepoint_check(); |
3552 _collector->startTimer(); |
3552 _collector->startTimer(); |
5539 |
5539 |
5540 // See the comment in coordinator_yield() |
5540 // See the comment in coordinator_yield() |
5541 for (unsigned i = 0; i < CMSYieldSleepCount && |
5541 for (unsigned i = 0; i < CMSYieldSleepCount && |
5542 ConcurrentMarkSweepThread::should_yield() && |
5542 ConcurrentMarkSweepThread::should_yield() && |
5543 !CMSCollector::foregroundGCIsActive(); ++i) { |
5543 !CMSCollector::foregroundGCIsActive(); ++i) { |
5544 os::sleep(Thread::current(), 1, false); |
5544 os::naked_short_sleep(1); |
5545 } |
5545 } |
5546 |
5546 |
5547 ConcurrentMarkSweepThread::synchronize(true); |
5547 ConcurrentMarkSweepThread::synchronize(true); |
5548 bitMapLock()->lock_without_safepoint_check(); |
5548 bitMapLock()->lock_without_safepoint_check(); |
5549 startTimer(); |
5549 startTimer(); |
5993 for (unsigned i = 0; |
5993 for (unsigned i = 0; |
5994 i < CMSYieldSleepCount && |
5994 i < CMSYieldSleepCount && |
5995 ConcurrentMarkSweepThread::should_yield() && |
5995 ConcurrentMarkSweepThread::should_yield() && |
5996 !CMSCollector::foregroundGCIsActive(); |
5996 !CMSCollector::foregroundGCIsActive(); |
5997 ++i) { |
5997 ++i) { |
5998 os::sleep(Thread::current(), 1, false); |
5998 os::naked_short_sleep(1); |
5999 } |
5999 } |
6000 |
6000 |
6001 ConcurrentMarkSweepThread::synchronize(true); |
6001 ConcurrentMarkSweepThread::synchronize(true); |
6002 _freelistLock->lock_without_safepoint_check(); |
6002 _freelistLock->lock_without_safepoint_check(); |
6003 _bit_map->lock()->lock_without_safepoint_check(); |
6003 _bit_map->lock()->lock_without_safepoint_check(); |
6148 |
6148 |
6149 // See the comment in coordinator_yield() |
6149 // See the comment in coordinator_yield() |
6150 for (unsigned i = 0; i < CMSYieldSleepCount && |
6150 for (unsigned i = 0; i < CMSYieldSleepCount && |
6151 ConcurrentMarkSweepThread::should_yield() && |
6151 ConcurrentMarkSweepThread::should_yield() && |
6152 !CMSCollector::foregroundGCIsActive(); ++i) { |
6152 !CMSCollector::foregroundGCIsActive(); ++i) { |
6153 os::sleep(Thread::current(), 1, false); |
6153 os::naked_short_sleep(1); |
6154 } |
6154 } |
6155 |
6155 |
6156 ConcurrentMarkSweepThread::synchronize(true); |
6156 ConcurrentMarkSweepThread::synchronize(true); |
6157 _freelistLock->lock_without_safepoint_check(); |
6157 _freelistLock->lock_without_safepoint_check(); |
6158 _bitMap->lock()->lock_without_safepoint_check(); |
6158 _bitMap->lock()->lock_without_safepoint_check(); |
6215 |
6215 |
6216 // See the comment in coordinator_yield() |
6216 // See the comment in coordinator_yield() |
6217 for (unsigned i = 0; i < CMSYieldSleepCount && |
6217 for (unsigned i = 0; i < CMSYieldSleepCount && |
6218 ConcurrentMarkSweepThread::should_yield() && |
6218 ConcurrentMarkSweepThread::should_yield() && |
6219 !CMSCollector::foregroundGCIsActive(); ++i) { |
6219 !CMSCollector::foregroundGCIsActive(); ++i) { |
6220 os::sleep(Thread::current(), 1, false); |
6220 os::naked_short_sleep(1); |
6221 } |
6221 } |
6222 |
6222 |
6223 ConcurrentMarkSweepThread::synchronize(true); |
6223 ConcurrentMarkSweepThread::synchronize(true); |
6224 _bit_map->lock()->lock_without_safepoint_check(); |
6224 _bit_map->lock()->lock_without_safepoint_check(); |
6225 _collector->startTimer(); |
6225 _collector->startTimer(); |
6366 |
6366 |
6367 // See the comment in coordinator_yield() |
6367 // See the comment in coordinator_yield() |
6368 for (unsigned i = 0; i < CMSYieldSleepCount && |
6368 for (unsigned i = 0; i < CMSYieldSleepCount && |
6369 ConcurrentMarkSweepThread::should_yield() && |
6369 ConcurrentMarkSweepThread::should_yield() && |
6370 !CMSCollector::foregroundGCIsActive(); ++i) { |
6370 !CMSCollector::foregroundGCIsActive(); ++i) { |
6371 os::sleep(Thread::current(), 1, false); |
6371 os::naked_short_sleep(1); |
6372 } |
6372 } |
6373 |
6373 |
6374 ConcurrentMarkSweepThread::synchronize(true); |
6374 ConcurrentMarkSweepThread::synchronize(true); |
6375 _bitMap->lock()->lock_without_safepoint_check(); |
6375 _bitMap->lock()->lock_without_safepoint_check(); |
6376 _collector->startTimer(); |
6376 _collector->startTimer(); |
6980 |
6980 |
6981 // See the comment in coordinator_yield() |
6981 // See the comment in coordinator_yield() |
6982 for (unsigned i = 0; i < CMSYieldSleepCount && |
6982 for (unsigned i = 0; i < CMSYieldSleepCount && |
6983 ConcurrentMarkSweepThread::should_yield() && |
6983 ConcurrentMarkSweepThread::should_yield() && |
6984 !CMSCollector::foregroundGCIsActive(); ++i) { |
6984 !CMSCollector::foregroundGCIsActive(); ++i) { |
6985 os::sleep(Thread::current(), 1, false); |
6985 os::naked_short_sleep(1); |
6986 } |
6986 } |
6987 |
6987 |
6988 ConcurrentMarkSweepThread::synchronize(true); |
6988 ConcurrentMarkSweepThread::synchronize(true); |
6989 bml->lock_without_safepoint_check(); |
6989 bml->lock_without_safepoint_check(); |
6990 |
6990 |
7545 |
7545 |
7546 // See the comment in coordinator_yield() |
7546 // See the comment in coordinator_yield() |
7547 for (unsigned i = 0; i < CMSYieldSleepCount && |
7547 for (unsigned i = 0; i < CMSYieldSleepCount && |
7548 ConcurrentMarkSweepThread::should_yield() && |
7548 ConcurrentMarkSweepThread::should_yield() && |
7549 !CMSCollector::foregroundGCIsActive(); ++i) { |
7549 !CMSCollector::foregroundGCIsActive(); ++i) { |
7550 os::sleep(Thread::current(), 1, false); |
7550 os::naked_short_sleep(1); |
7551 } |
7551 } |
7552 |
7552 |
7553 ConcurrentMarkSweepThread::synchronize(true); |
7553 ConcurrentMarkSweepThread::synchronize(true); |
7554 _freelistLock->lock_without_safepoint_check(); |
7554 _freelistLock->lock_without_safepoint_check(); |
7555 _bitMap->lock()->lock_without_safepoint_check(); |
7555 _bitMap->lock()->lock_without_safepoint_check(); |
7843 if (_overflow_list == NULL) { |
7843 if (_overflow_list == NULL) { |
7844 return false; |
7844 return false; |
7845 } |
7845 } |
7846 // Grab the entire list; we'll put back a suffix |
7846 // Grab the entire list; we'll put back a suffix |
7847 oop prefix = cast_to_oop(Atomic::xchg((oopDesc*)BUSY, &_overflow_list)); |
7847 oop prefix = cast_to_oop(Atomic::xchg((oopDesc*)BUSY, &_overflow_list)); |
7848 Thread* tid = Thread::current(); |
|
7849 // Before "no_of_gc_threads" was introduced CMSOverflowSpinCount was |
7848 // Before "no_of_gc_threads" was introduced CMSOverflowSpinCount was |
7850 // set to ParallelGCThreads. |
7849 // set to ParallelGCThreads. |
7851 size_t CMSOverflowSpinCount = (size_t) no_of_gc_threads; // was ParallelGCThreads; |
7850 size_t CMSOverflowSpinCount = (size_t) no_of_gc_threads; // was ParallelGCThreads; |
7852 size_t sleep_time_millis = MAX2((size_t)1, num/100); |
7851 size_t sleep_time_millis = MAX2((size_t)1, num/100); |
7853 // If the list is busy, we spin for a short while, |
7852 // If the list is busy, we spin for a short while, |
7854 // sleeping between attempts to get the list. |
7853 // sleeping between attempts to get the list. |
7855 for (size_t spin = 0; prefix == BUSY && spin < CMSOverflowSpinCount; spin++) { |
7854 for (size_t spin = 0; prefix == BUSY && spin < CMSOverflowSpinCount; spin++) { |
7856 os::sleep(tid, sleep_time_millis, false); |
7855 os::naked_sleep(sleep_time_millis); |
7857 if (_overflow_list == NULL) { |
7856 if (_overflow_list == NULL) { |
7858 // Nothing left to take |
7857 // Nothing left to take |
7859 return false; |
7858 return false; |
7860 } else if (_overflow_list != BUSY) { |
7859 } else if (_overflow_list != BUSY) { |
7861 // Try and grab the prefix |
7860 // Try and grab the prefix |