< prev index next >

src/hotspot/share/runtime/vm_operations.cpp

Print this page
rev 47287 : Port 09.17.Thread_SMR_logging_update from JDK9 to JDK10
rev 47289 : eosterlund, stefank CR - refactor code into threadSMR.cpp and threadSMR.hpp
rev 47290 : eosterlund CR - need more inline fixes.
rev 47291 : eosterlund, stefank CR - more inline and style cleanups
rev 47292 : stefank, coleenp CR - refactor most JavaThreadIterator usage to use JavaThreadIteratorWithHandle.


 131   NMethodSweeper::mark_active_nmethods();
 132 }
 133 
 134 VM_DeoptimizeFrame::VM_DeoptimizeFrame(JavaThread* thread, intptr_t* id, int reason) {
 135   _thread = thread;
 136   _id     = id;
 137   _reason = reason;
 138 }
 139 
 140 
 141 void VM_DeoptimizeFrame::doit() {
 142   assert(_reason > Deoptimization::Reason_none && _reason < Deoptimization::Reason_LIMIT, "invalid deopt reason");
 143   Deoptimization::deoptimize_frame_internal(_thread, _id, (Deoptimization::DeoptReason)_reason);
 144 }
 145 
 146 
 147 #ifndef PRODUCT
 148 
 149 void VM_DeoptimizeAll::doit() {
 150   DeoptimizationMarker dm;
 151   ThreadsListHandle tlh;
 152   JavaThreadIterator jti(tlh.list());
 153   // deoptimize all java threads in the system
 154   if (DeoptimizeALot) {
 155     for (JavaThread* thread = jti.first(); thread != NULL; thread = jti.next()) {
 156       if (thread->has_last_Java_frame()) {
 157         thread->deoptimize();
 158       }
 159     }
 160   } else if (DeoptimizeRandom) {
 161 
 162     // Deoptimize some selected threads and frames
 163     int tnum = os::random() & 0x3;
 164     int fnum =  os::random() & 0x3;
 165     int tcount = 0;
 166     for (JavaThread* thread = jti.first(); thread != NULL; thread = jti.next()) {
 167       if (thread->has_last_Java_frame()) {
 168         if (tcount++ == tnum)  {
 169         tcount = 0;
 170           int fcount = 0;
 171           // Deoptimize some selected frames.
 172           // Biased llocking wants a updated register map
 173           for(StackFrameStream fst(thread, UseBiasedLocking); !fst.is_done(); fst.next()) {
 174             if (fst.current()->can_be_deoptimized()) {
 175               if (fcount++ == fnum) {
 176                 fcount = 0;
 177                 Deoptimization::deoptimize(thread, *fst.current(), fst.register_map());
 178               }
 179             }
 180           }
 181         }
 182       }
 183     }
 184   }
 185 }
 186 


 408 ThreadSnapshot* VM_ThreadDump::snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl) {
 409   ThreadSnapshot* snapshot = new ThreadSnapshot(_result->t_list(), java_thread);
 410   snapshot->dump_stack_at_safepoint(_max_depth, _with_locked_monitors);
 411   snapshot->set_concurrent_locks(tcl);
 412   return snapshot;
 413 }
 414 
 415 volatile bool VM_Exit::_vm_exited = false;
 416 Thread * VM_Exit::_shutdown_thread = NULL;
 417 
 418 int VM_Exit::set_vm_exited() {
 419 
 420   Thread * thr_cur = Thread::current();
 421 
 422   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already");
 423 
 424   int num_active = 0;
 425 
 426   _shutdown_thread = thr_cur;
 427   _vm_exited = true;                                // global flag
 428   ThreadsListHandle tlh;
 429   JavaThreadIterator jti(tlh.list());
 430   for (JavaThread *thr = jti.first(); thr != NULL; thr = jti.next()) {
 431     if (thr!=thr_cur && thr->thread_state() == _thread_in_native) {
 432       ++num_active;
 433       thr->set_terminated(JavaThread::_vm_exited);  // per-thread flag
 434     }
 435   }
 436 
 437   return num_active;
 438 }
 439 
 440 int VM_Exit::wait_for_threads_in_native_to_block() {
 441   // VM exits at safepoint. This function must be called at the final safepoint
 442   // to wait for threads in _thread_in_native state to be quiescent.
 443   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already");
 444 
 445   Thread * thr_cur = Thread::current();
 446   Monitor timer(Mutex::leaf, "VM_Exit timer", true,
 447                 Monitor::_safepoint_check_never);
 448 
 449   // Compiler threads need longer wait because they can access VM data directly
 450   // while in native. If they are active and some structures being used are
 451   // deleted by the shutdown sequence, they will crash. On the other hand, user
 452   // threads must go through native=>Java/VM transitions first to access VM
 453   // data, and they will be stopped during state transition. In theory, we
 454   // don't have to wait for user threads to be quiescent, but it's always
 455   // better to terminate VM when current thread is the only active thread, so
 456   // wait for user threads too. Numbers are in 10 milliseconds.
 457   int max_wait_user_thread = 30;                  // at least 300 milliseconds
 458   int max_wait_compiler_thread = 1000;            // at least 10 seconds
 459 
 460   int max_wait = max_wait_compiler_thread;
 461 
 462   int attempts = 0;
 463   ThreadsListHandle tlh;
 464   JavaThreadIterator jti(tlh.list());
 465   while (true) {
 466     int num_active = 0;
 467     int num_active_compiler_thread = 0;
 468 
 469     for (JavaThread *thr = jti.first(); thr != NULL; thr = jti.next()) {

 470       if (thr!=thr_cur && thr->thread_state() == _thread_in_native) {
 471         num_active++;
 472         if (thr->is_Compiler_thread()) {
 473           num_active_compiler_thread++;
 474         }
 475       }
 476     }
 477 
 478     if (num_active == 0) {
 479        return 0;
 480     } else if (attempts > max_wait) {
 481        return num_active;
 482     } else if (num_active_compiler_thread == 0 && attempts > max_wait_user_thread) {
 483        return num_active;
 484     }
 485 
 486     attempts++;
 487 
 488     MutexLockerEx ml(&timer, Mutex::_no_safepoint_check_flag);
 489     timer.wait(Mutex::_no_safepoint_check_flag, 10);




 131   NMethodSweeper::mark_active_nmethods();
 132 }
 133 
 134 VM_DeoptimizeFrame::VM_DeoptimizeFrame(JavaThread* thread, intptr_t* id, int reason) {
 135   _thread = thread;
 136   _id     = id;
 137   _reason = reason;
 138 }
 139 
 140 
 141 void VM_DeoptimizeFrame::doit() {
 142   assert(_reason > Deoptimization::Reason_none && _reason < Deoptimization::Reason_LIMIT, "invalid deopt reason");
 143   Deoptimization::deoptimize_frame_internal(_thread, _id, (Deoptimization::DeoptReason)_reason);
 144 }
 145 
 146 
 147 #ifndef PRODUCT
 148 
 149 void VM_DeoptimizeAll::doit() {
 150   DeoptimizationMarker dm;
 151   JavaThreadIteratorWithHandle jtiwh;

 152   // deoptimize all java threads in the system
 153   if (DeoptimizeALot) {
 154     for (; JavaThread *thread = jtiwh.next(); ) {
 155       if (thread->has_last_Java_frame()) {
 156         thread->deoptimize();
 157       }
 158     }
 159   } else if (DeoptimizeRandom) {
 160 
 161     // Deoptimize some selected threads and frames
 162     int tnum = os::random() & 0x3;
 163     int fnum =  os::random() & 0x3;
 164     int tcount = 0;
 165     for (; JavaThread *thread = jtiwh.next(); ) {
 166       if (thread->has_last_Java_frame()) {
 167         if (tcount++ == tnum)  {
 168         tcount = 0;
 169           int fcount = 0;
 170           // Deoptimize some selected frames.
 171           // Biased llocking wants a updated register map
 172           for(StackFrameStream fst(thread, UseBiasedLocking); !fst.is_done(); fst.next()) {
 173             if (fst.current()->can_be_deoptimized()) {
 174               if (fcount++ == fnum) {
 175                 fcount = 0;
 176                 Deoptimization::deoptimize(thread, *fst.current(), fst.register_map());
 177               }
 178             }
 179           }
 180         }
 181       }
 182     }
 183   }
 184 }
 185 


 407 ThreadSnapshot* VM_ThreadDump::snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl) {
 408   ThreadSnapshot* snapshot = new ThreadSnapshot(_result->t_list(), java_thread);
 409   snapshot->dump_stack_at_safepoint(_max_depth, _with_locked_monitors);
 410   snapshot->set_concurrent_locks(tcl);
 411   return snapshot;
 412 }
 413 
 414 volatile bool VM_Exit::_vm_exited = false;
 415 Thread * VM_Exit::_shutdown_thread = NULL;
 416 
 417 int VM_Exit::set_vm_exited() {
 418 
 419   Thread * thr_cur = Thread::current();
 420 
 421   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already");
 422 
 423   int num_active = 0;
 424 
 425   _shutdown_thread = thr_cur;
 426   _vm_exited = true;                                // global flag
 427   for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thr = jtiwh.next(); ) {


 428     if (thr!=thr_cur && thr->thread_state() == _thread_in_native) {
 429       ++num_active;
 430       thr->set_terminated(JavaThread::_vm_exited);  // per-thread flag
 431     }
 432   }
 433 
 434   return num_active;
 435 }
 436 
 437 int VM_Exit::wait_for_threads_in_native_to_block() {
 438   // VM exits at safepoint. This function must be called at the final safepoint
 439   // to wait for threads in _thread_in_native state to be quiescent.
 440   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already");
 441 
 442   Thread * thr_cur = Thread::current();
 443   Monitor timer(Mutex::leaf, "VM_Exit timer", true,
 444                 Monitor::_safepoint_check_never);
 445 
 446   // Compiler threads need longer wait because they can access VM data directly
 447   // while in native. If they are active and some structures being used are
 448   // deleted by the shutdown sequence, they will crash. On the other hand, user
 449   // threads must go through native=>Java/VM transitions first to access VM
 450   // data, and they will be stopped during state transition. In theory, we
 451   // don't have to wait for user threads to be quiescent, but it's always
 452   // better to terminate VM when current thread is the only active thread, so
 453   // wait for user threads too. Numbers are in 10 milliseconds.
 454   int max_wait_user_thread = 30;                  // at least 300 milliseconds
 455   int max_wait_compiler_thread = 1000;            // at least 10 seconds
 456 
 457   int max_wait = max_wait_compiler_thread;
 458 
 459   int attempts = 0;
 460   JavaThreadIteratorWithHandle jtiwh;

 461   while (true) {
 462     int num_active = 0;
 463     int num_active_compiler_thread = 0;
 464 
 465     jtiwh.rewind();
 466     for (; JavaThread *thr = jtiwh.next(); ) {
 467       if (thr!=thr_cur && thr->thread_state() == _thread_in_native) {
 468         num_active++;
 469         if (thr->is_Compiler_thread()) {
 470           num_active_compiler_thread++;
 471         }
 472       }
 473     }
 474 
 475     if (num_active == 0) {
 476        return 0;
 477     } else if (attempts > max_wait) {
 478        return num_active;
 479     } else if (num_active_compiler_thread == 0 && attempts > max_wait_user_thread) {
 480        return num_active;
 481     }
 482 
 483     attempts++;
 484 
 485     MutexLockerEx ml(&timer, Mutex::_no_safepoint_check_flag);
 486     timer.wait(Mutex::_no_safepoint_check_flag, 10);


< prev index next >