371 */
372 void NMethodSweeper::force_sweep() {
373 ThreadBlockInVM tbivm(JavaThread::current());
374 MutexLockerEx waiter(CodeCache_lock, Mutex::_no_safepoint_check_flag);
375 // Request forced sweep
376 _force_sweep = true;
377 while (_force_sweep) {
378 // Notify sweeper that we want to force a sweep and wait for completion.
379 // In case a sweep currently takes place we timeout and try again because
380 // we want to enforce a full sweep.
381 CodeCache_lock->notify();
382 CodeCache_lock->wait(Mutex::_no_safepoint_check_flag, 1000);
383 }
384 }
385
386 /**
387 * Handle a safepoint request
388 */
389 void NMethodSweeper::handle_safepoint_request() {
390 JavaThread* thread = JavaThread::current();
391 if (SafepointMechanism::poll(thread)) {
392 if (PrintMethodFlushing && Verbose) {
393 tty->print_cr("### Sweep at %d out of %d, yielding to safepoint", _seen, CodeCache::nmethod_count());
394 }
395 MutexUnlockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
396
397 ThreadBlockInVM tbivm(thread);
398 thread->java_suspend_self();
399 }
400 }
401
402 /**
403 * This function invokes the sweeper if at least one of the three conditions is met:
404 * (1) The code cache is getting full
405 * (2) There are sufficient state changes in/since the last sweep.
406 * (3) We have not been sweeping for 'some time'
407 */
408 void NMethodSweeper::possibly_sweep() {
409 assert(JavaThread::current()->thread_state() == _thread_in_vm, "must run in vm mode");
410 // If there was no state change while nmethod sweeping, 'should_sweep' will be false.
411 // This is one of the two places where should_sweep can be set to true. The general
|
371 */
372 void NMethodSweeper::force_sweep() {
373 ThreadBlockInVM tbivm(JavaThread::current());
374 MutexLockerEx waiter(CodeCache_lock, Mutex::_no_safepoint_check_flag);
375 // Request forced sweep
376 _force_sweep = true;
377 while (_force_sweep) {
378 // Notify sweeper that we want to force a sweep and wait for completion.
379 // In case a sweep currently takes place we timeout and try again because
380 // we want to enforce a full sweep.
381 CodeCache_lock->notify();
382 CodeCache_lock->wait(Mutex::_no_safepoint_check_flag, 1000);
383 }
384 }
385
386 /**
387 * Handle a safepoint request
388 */
389 void NMethodSweeper::handle_safepoint_request() {
390 JavaThread* thread = JavaThread::current();
391 if (SafepointMechanism::should_block(thread)) {
392 if (PrintMethodFlushing && Verbose) {
393 tty->print_cr("### Sweep at %d out of %d, yielding to safepoint", _seen, CodeCache::nmethod_count());
394 }
395 MutexUnlockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
396
397 ThreadBlockInVM tbivm(thread);
398 thread->java_suspend_self();
399 }
400 }
401
402 /**
403 * This function invokes the sweeper if at least one of the three conditions is met:
404 * (1) The code cache is getting full
405 * (2) There are sufficient state changes in/since the last sweep.
406 * (3) We have not been sweeping for 'some time'
407 */
408 void NMethodSweeper::possibly_sweep() {
409 assert(JavaThread::current()->thread_state() == _thread_in_vm, "must run in vm mode");
410 // If there was no state change while nmethod sweeping, 'should_sweep' will be false.
411 // This is one of the two places where should_sweep can be set to true. The general
|