src/share/vm/runtime/sweeper.cpp
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File
sweeper-safepoints Cdiff src/share/vm/runtime/sweeper.cpp
src/share/vm/runtime/sweeper.cpp
Print this page
*** 124,138 ****
#define SWEEP(nm)
#endif
long NMethodSweeper::_traversals = 0; // No. of stack traversals performed
- nmethod* NMethodSweeper::_current = NULL; // Current nmethod
int NMethodSweeper::_seen = 0 ; // No. of nmethods we have currently processed in current pass of CodeCache
- volatile int NMethodSweeper::_invocations = 0; // No. of invocations left until we are completed with this pass
volatile int NMethodSweeper::_sweep_started = 0; // Whether a sweep is in progress.
jint NMethodSweeper::_locked_seen = 0;
jint NMethodSweeper::_not_entrant_seen_on_stack = 0;
bool NMethodSweeper::_rescan = false;
bool NMethodSweeper::_do_sweep = false;
--- 124,138 ----
#define SWEEP(nm)
#endif
long NMethodSweeper::_traversals = 0; // No. of stack traversals performed
int NMethodSweeper::_seen = 0 ; // No. of nmethods we have currently processed in current pass of CodeCache
+ int NMethodSweeper::_invocations = 0; // No. of invocations of the sweeper
volatile int NMethodSweeper::_sweep_started = 0; // Whether a sweep is in progress.
+ volatile nmethod* NMethodSweeper::_current = NULL; // Current nmethod
jint NMethodSweeper::_locked_seen = 0;
jint NMethodSweeper::_not_entrant_seen_on_stack = 0;
bool NMethodSweeper::_rescan = false;
bool NMethodSweeper::_do_sweep = false;
*** 174,184 ****
// Check for restart
assert(CodeCache::find_blob_unsafe(_current) == _current, "Sweeper nmethod cached state invalid");
if (_current == NULL) {
_seen = 0;
! _invocations = NmethodSweepFraction;
_current = CodeCache::first_nmethod();
_traversals += 1;
if (PrintMethodFlushing) {
tty->print_cr("### Sweep: stack traversal %d", _traversals);
}
--- 174,184 ----
// Check for restart
assert(CodeCache::find_blob_unsafe(_current) == _current, "Sweeper nmethod cached state invalid");
if (_current == NULL) {
_seen = 0;
! _invocations = 0;
_current = CodeCache::first_nmethod();
_traversals += 1;
if (PrintMethodFlushing) {
tty->print_cr("### Sweep: stack traversal %d", _traversals);
}
*** 217,227 ****
void NMethodSweeper::possibly_sweep() {
assert(JavaThread::current()->thread_state() == _thread_in_vm, "must run in vm mode");
if ((!MethodFlushing) || (!_do_sweep)) return;
! if (_invocations > 0) {
// Only one thread at a time will sweep
jint old = Atomic::cmpxchg( 1, &_sweep_started, 0 );
if (old != 0) {
return;
}
--- 217,227 ----
void NMethodSweeper::possibly_sweep() {
assert(JavaThread::current()->thread_state() == _thread_in_vm, "must run in vm mode");
if ((!MethodFlushing) || (!_do_sweep)) return;
! if (_current != NULL) {
// Only one thread at a time will sweep
jint old = Atomic::cmpxchg( 1, &_sweep_started, 0 );
if (old != 0) {
return;
}
*** 230,274 ****
// Create the ring buffer for the logging code
_records = NEW_C_HEAP_ARRAY(SweeperRecord, SweeperLogEntries);
memset(_records, 0, sizeof(SweeperRecord) * SweeperLogEntries);
}
#endif
! if (_invocations > 0) {
sweep_code_cache();
- _invocations--;
}
_sweep_started = 0;
}
}
! void NMethodSweeper::sweep_code_cache() {
#ifdef ASSERT
jlong sweep_start;
if (PrintMethodFlushing) {
sweep_start = os::javaTimeMillis();
}
#endif
if (PrintMethodFlushing && Verbose) {
! tty->print_cr("### Sweep at %d out of %d. Invocations left: %d", _seen, CodeCache::nof_nmethods(), _invocations);
}
- // We want to visit all nmethods after NmethodSweepFraction
- // invocations so divide the remaining number of nmethods by the
- // remaining number of invocations. This is only an estimate since
- // the number of nmethods changes during the sweep so the final
- // stage must iterate until it there are no more nmethods.
- int todo = (CodeCache::nof_nmethods() - _seen) / _invocations;
-
assert(!SafepointSynchronize::is_at_safepoint(), "should not be in safepoint when we get here");
assert(!CodeCache_lock->owned_by_self(), "just checking");
{
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
// The last invocation iterates until there are no more nmethods
! for (int i = 0; (i < todo || _invocations == 1) && _current != NULL; i++) {
// Since we will give up the CodeCache_lock, always skip ahead
// to the next nmethod. Other blobs can be deleted by other
// threads but nmethods are only reclaimed by the sweeper.
nmethod* next = CodeCache::next_nmethod(_current);
--- 230,277 ----
// Create the ring buffer for the logging code
_records = NEW_C_HEAP_ARRAY(SweeperRecord, SweeperLogEntries);
memset(_records, 0, sizeof(SweeperRecord) * SweeperLogEntries);
}
#endif
! if (_current != NULL) {
sweep_code_cache();
}
+ _invocations++;
_sweep_started = 0;
}
}
! void NMethodSweeper::sweep_code_cache(void) {
#ifdef ASSERT
jlong sweep_start;
if (PrintMethodFlushing) {
sweep_start = os::javaTimeMillis();
}
#endif
if (PrintMethodFlushing && Verbose) {
! tty->print_cr("### Sweep at %d out of %d, invocations %d", _seen, CodeCache::nof_nmethods(), _invocations);
}
assert(!SafepointSynchronize::is_at_safepoint(), "should not be in safepoint when we get here");
assert(!CodeCache_lock->owned_by_self(), "just checking");
{
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
// The last invocation iterates until there are no more nmethods
! for (int i = 0; (i < NMethodSweepLimit || CompileTheWorld) && _current != NULL; i++) {
! if (!CompileTheWorld && SafepointSynchronize::is_synchronizing()) { // Safepoint request
! if (PrintMethodFlushing && Verbose) {
! tty->print_cr("### Sweep at %d out of %d, safepoint", _seen, CodeCache::nof_nmethods());
! }
! MutexUnlockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
+ assert(Thread::current()->is_Java_thread(), "should be java thread");
+ JavaThread* thread = (JavaThread*)Thread::current();
+ ThreadBlockInVM tbivm(thread);
+ thread->java_suspend_self();
+ }
// Since we will give up the CodeCache_lock, always skip ahead
// to the next nmethod. Other blobs can be deleted by other
// threads but nmethods are only reclaimed by the sweeper.
nmethod* next = CodeCache::next_nmethod(_current);
*** 280,291 ****
_seen++;
_current = next;
}
}
- assert(_invocations > 1 || _current == NULL, "must have scanned the whole cache");
-
if (_current == NULL && !_rescan && (_locked_seen || _not_entrant_seen_on_stack)) {
// we've completed a scan without making progress but there were
// nmethods we were unable to process either because they were
// locked or were still on stack. We don't have to aggresively
// clean them up so just stop scanning. We could scan once more
--- 283,292 ----
*** 301,311 ****
jlong sweep_end = os::javaTimeMillis();
tty->print_cr("### sweeper: sweep time(%d): " INT64_FORMAT, _invocations, sweep_end - sweep_start);
}
#endif
! if (_invocations == 1) {
log_sweep("finished");
}
}
class NMethodMarker: public StackObj {
--- 302,312 ----
jlong sweep_end = os::javaTimeMillis();
tty->print_cr("### sweeper: sweep time(%d): " INT64_FORMAT, _invocations, sweep_end - sweep_start);
}
#endif
! if (_current == NULL) {
log_sweep("finished");
}
}
class NMethodMarker: public StackObj {
src/share/vm/runtime/sweeper.cpp
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File