294 return NULL;
295 }
296
297 // Increase time so that we can estimate when to invoke the sweeper again.
298 _time_counter++;
299
300 // Check for restart
301 if (_current.method() != NULL) {
302 if (_current.method()->is_nmethod()) {
303 assert(CodeCache::find_blob_unsafe(_current.method()) == _current.method(), "Sweeper nmethod cached state invalid");
304 } else if (_current.method()->is_aot()) {
305 assert(CodeCache::find_blob_unsafe(_current.method()->code_begin()) == _current.method(), "Sweeper AOT method cached state invalid");
306 } else {
307 ShouldNotReachHere();
308 }
309 }
310
311 return &set_hotness_closure;
312 }
313
314 /**
315 * This function triggers a VM operation that does stack scanning of active
316 * methods. Stack scanning is mandatory for the sweeper to make progress.
317 */
318 void NMethodSweeper::do_stack_scanning() {
319 assert(!CodeCache_lock->owned_by_self(), "just checking");
320 if (wait_for_stack_scanning()) {
321 if (ThreadLocalHandshakes) {
322 CodeBlobClosure* code_cl;
323 {
324 MutexLocker ccl(CodeCache_lock, Mutex::_no_safepoint_check_flag);
325 code_cl = prepare_mark_active_nmethods();
326 }
327 if (code_cl != NULL) {
328 NMethodMarkingThreadClosure tcl(code_cl);
329 Handshake::execute(&tcl);
330 }
331 } else {
332 VM_MarkActiveNMethods op;
333 VMThread::execute(&op);
334 }
335 }
336 }
337
338 void NMethodSweeper::sweeper_loop() {
339 bool timeout;
340 while (true) {
341 {
342 ThreadBlockInVM tbivm(JavaThread::current());
343 MonitorLocker waiter(CodeCache_lock, Mutex::_no_safepoint_check_flag);
344 const long wait_time = 60*60*24 * 1000;
345 timeout = waiter.wait(wait_time);
346 }
347 if (!timeout) {
348 possibly_sweep();
349 }
|
294 return NULL;
295 }
296
297 // Increase time so that we can estimate when to invoke the sweeper again.
298 _time_counter++;
299
300 // Check for restart
301 if (_current.method() != NULL) {
302 if (_current.method()->is_nmethod()) {
303 assert(CodeCache::find_blob_unsafe(_current.method()) == _current.method(), "Sweeper nmethod cached state invalid");
304 } else if (_current.method()->is_aot()) {
305 assert(CodeCache::find_blob_unsafe(_current.method()->code_begin()) == _current.method(), "Sweeper AOT method cached state invalid");
306 } else {
307 ShouldNotReachHere();
308 }
309 }
310
311 return &set_hotness_closure;
312 }
313
314 class NMethodMarkingHandshake : public HandshakeOperation {
315 NMethodMarkingThreadClosure* _cl;
316 public:
317 NMethodMarkingHandshake(NMethodMarkingThreadClosure* cl) : HandshakeOperation("NMethodMarking"), _cl(cl) {}
318 void do_thread(JavaThread* jt) {
319 _cl->do_thread(jt);
320 }
321 };
322
323 /**
324 * This function triggers a VM operation that does stack scanning of active
325 * methods. Stack scanning is mandatory for the sweeper to make progress.
326 */
327 void NMethodSweeper::do_stack_scanning() {
328 assert(!CodeCache_lock->owned_by_self(), "just checking");
329 if (wait_for_stack_scanning()) {
330 if (ThreadLocalHandshakes) {
331 CodeBlobClosure* code_cl;
332 {
333 MutexLocker ccl(CodeCache_lock, Mutex::_no_safepoint_check_flag);
334 code_cl = prepare_mark_active_nmethods();
335 }
336 if (code_cl != NULL) {
337 NMethodMarkingThreadClosure tcl(code_cl);
338 NMethodMarkingHandshake nm_hs(&tcl);
339 Handshake::execute(&nm_hs);
340 }
341 } else {
342 VM_MarkActiveNMethods op;
343 VMThread::execute(&op);
344 }
345 }
346 }
347
348 void NMethodSweeper::sweeper_loop() {
349 bool timeout;
350 while (true) {
351 {
352 ThreadBlockInVM tbivm(JavaThread::current());
353 MonitorLocker waiter(CodeCache_lock, Mutex::_no_safepoint_check_flag);
354 const long wait_time = 60*60*24 * 1000;
355 timeout = waiter.wait(wait_time);
356 }
357 if (!timeout) {
358 possibly_sweep();
359 }
|