< prev index next >

src/share/vm/runtime/thread.cpp

Print this page




  84 #include "runtime/task.hpp"
  85 #include "runtime/thread.inline.hpp"
  86 #include "runtime/threadCritical.hpp"
  87 #include "runtime/vframe.hpp"
  88 #include "runtime/vframeArray.hpp"
  89 #include "runtime/vframe_hp.hpp"
  90 #include "runtime/vmThread.hpp"
  91 #include "runtime/vm_operations.hpp"
  92 #include "runtime/vm_version.hpp"
  93 #include "services/attachListener.hpp"
  94 #include "services/management.hpp"
  95 #include "services/memTracker.hpp"
  96 #include "services/threadService.hpp"
  97 #include "trace/traceMacros.hpp"
  98 #include "trace/tracing.hpp"
  99 #include "utilities/defaultStream.hpp"
 100 #include "utilities/dtrace.hpp"
 101 #include "utilities/events.hpp"
 102 #include "utilities/macros.hpp"
 103 #include "utilities/preserveException.hpp"

 104 #if INCLUDE_ALL_GCS
 105 #include "gc/cms/concurrentMarkSweepThread.hpp"
 106 #include "gc/g1/concurrentMarkThread.inline.hpp"
 107 #include "gc/parallel/pcTasks.hpp"
 108 #endif // INCLUDE_ALL_GCS
 109 #if INCLUDE_JVMCI
 110 #include "jvmci/jvmciCompiler.hpp"
 111 #include "jvmci/jvmciRuntime.hpp"
 112 #endif
 113 #ifdef COMPILER1
 114 #include "c1/c1_Compiler.hpp"
 115 #endif
 116 #ifdef COMPILER2
 117 #include "opto/c2compiler.hpp"
 118 #include "opto/idealGraphPrinter.hpp"
 119 #endif
 120 #if INCLUDE_RTM_OPT
 121 #include "runtime/rtmLocking.hpp"
 122 #endif
 123 


1271     }
1272   }
1273 
1274   return time_slept;
1275 }
1276 
1277 void WatcherThread::run() {
1278   assert(this == watcher_thread(), "just checking");
1279 
1280   this->record_stack_base_and_size();
1281   this->set_native_thread_name(this->name());
1282   this->set_active_handles(JNIHandleBlock::allocate_block());
1283   while (true) {
1284     assert(watcher_thread() == Thread::current(), "thread consistency check");
1285     assert(watcher_thread() == this, "thread consistency check");
1286 
1287     // Calculate how long it'll be until the next PeriodicTask work
1288     // should be done, and sleep that amount of time.
1289     int time_waited = sleep();
1290 
1291     if (is_error_reported()) {
1292       // A fatal error has happened, the error handler(VMError::report_and_die)
1293       // should abort JVM after creating an error log file. However in some
1294       // rare cases, the error handler itself might deadlock. Here periodically
1295       // check for error reporting timeouts, and if it happens, just proceed to
1296       // abort the VM.
1297 
1298       // This code is in WatcherThread because WatcherThread wakes up
1299       // periodically so the fatal error handler doesn't need to do anything;
1300       // also because the WatcherThread is less likely to crash than other
1301       // threads.
1302 
1303       for (;;) {
1304         // Note: we use naked sleep in this loop because we want to avoid using
1305         // any kind of VM infrastructure which may be broken at this point.
1306         if (VMError::check_timeout()) {
1307           // We hit error reporting timeout. Error reporting was interrupted and
1308           // will be wrapping things up now (closing files etc). Give it some more
1309           // time, then quit the VM.
1310           os::naked_short_sleep(200);
1311           // Print a message to stderr.


4131   _vm_complete = false;
4132 #endif
4133   // Wait until we are the last non-daemon thread to execute
4134   { MutexLocker nu(Threads_lock);
4135     while (Threads::number_of_non_daemon_threads() > 1)
4136       // This wait should make safepoint checks, wait without a timeout,
4137       // and wait as a suspend-equivalent condition.
4138       //
4139       // Note: If the FlatProfiler is running and this thread is waiting
4140       // for another non-daemon thread to finish, then the FlatProfiler
4141       // is waiting for the external suspend request on this thread to
4142       // complete. wait_for_ext_suspend_completion() will eventually
4143       // timeout, but that takes time. Making this wait a suspend-
4144       // equivalent condition solves that timeout problem.
4145       //
4146       Threads_lock->wait(!Mutex::_no_safepoint_check_flag, 0,
4147                          Mutex::_as_suspend_equivalent_flag);
4148   }
4149 
4150   // Hang forever on exit if we are reporting an error.
4151   if (ShowMessageBoxOnError && is_error_reported()) {
4152     os::infinite_sleep();
4153   }
4154   os::wait_for_keypress_at_exit();
4155 
4156   // run Java level shutdown hooks
4157   thread->invoke_shutdown_hooks();
4158 
4159   before_exit(thread);
4160 
4161   thread->exit(true);
4162 
4163   // Stop VM thread.
4164   {
4165     // 4945125 The vm thread comes to a safepoint during exit.
4166     // GC vm_operations can get caught at the safepoint, and the
4167     // heap is unparseable if they are caught. Grab the Heap_lock
4168     // to prevent this. The GC vm_operations will not be able to
4169     // queue until after the vm thread is dead. After this point,
4170     // we'll never emerge out of the safepoint before the VM exits.
4171 




  84 #include "runtime/task.hpp"
  85 #include "runtime/thread.inline.hpp"
  86 #include "runtime/threadCritical.hpp"
  87 #include "runtime/vframe.hpp"
  88 #include "runtime/vframeArray.hpp"
  89 #include "runtime/vframe_hp.hpp"
  90 #include "runtime/vmThread.hpp"
  91 #include "runtime/vm_operations.hpp"
  92 #include "runtime/vm_version.hpp"
  93 #include "services/attachListener.hpp"
  94 #include "services/management.hpp"
  95 #include "services/memTracker.hpp"
  96 #include "services/threadService.hpp"
  97 #include "trace/traceMacros.hpp"
  98 #include "trace/tracing.hpp"
  99 #include "utilities/defaultStream.hpp"
 100 #include "utilities/dtrace.hpp"
 101 #include "utilities/events.hpp"
 102 #include "utilities/macros.hpp"
 103 #include "utilities/preserveException.hpp"
 104 #include "utilities/vmError.hpp"
 105 #if INCLUDE_ALL_GCS
 106 #include "gc/cms/concurrentMarkSweepThread.hpp"
 107 #include "gc/g1/concurrentMarkThread.inline.hpp"
 108 #include "gc/parallel/pcTasks.hpp"
 109 #endif // INCLUDE_ALL_GCS
 110 #if INCLUDE_JVMCI
 111 #include "jvmci/jvmciCompiler.hpp"
 112 #include "jvmci/jvmciRuntime.hpp"
 113 #endif
 114 #ifdef COMPILER1
 115 #include "c1/c1_Compiler.hpp"
 116 #endif
 117 #ifdef COMPILER2
 118 #include "opto/c2compiler.hpp"
 119 #include "opto/idealGraphPrinter.hpp"
 120 #endif
 121 #if INCLUDE_RTM_OPT
 122 #include "runtime/rtmLocking.hpp"
 123 #endif
 124 


1272     }
1273   }
1274 
1275   return time_slept;
1276 }
1277 
1278 void WatcherThread::run() {
1279   assert(this == watcher_thread(), "just checking");
1280 
1281   this->record_stack_base_and_size();
1282   this->set_native_thread_name(this->name());
1283   this->set_active_handles(JNIHandleBlock::allocate_block());
1284   while (true) {
1285     assert(watcher_thread() == Thread::current(), "thread consistency check");
1286     assert(watcher_thread() == this, "thread consistency check");
1287 
1288     // Calculate how long it'll be until the next PeriodicTask work
1289     // should be done, and sleep that amount of time.
1290     int time_waited = sleep();
1291 
1292     if (VMError::is_error_reported()) {
1293       // A fatal error has happened, the error handler(VMError::report_and_die)
1294       // should abort JVM after creating an error log file. However in some
1295       // rare cases, the error handler itself might deadlock. Here periodically
1296       // check for error reporting timeouts, and if it happens, just proceed to
1297       // abort the VM.
1298 
1299       // This code is in WatcherThread because WatcherThread wakes up
1300       // periodically so the fatal error handler doesn't need to do anything;
1301       // also because the WatcherThread is less likely to crash than other
1302       // threads.
1303 
1304       for (;;) {
1305         // Note: we use naked sleep in this loop because we want to avoid using
1306         // any kind of VM infrastructure which may be broken at this point.
1307         if (VMError::check_timeout()) {
1308           // We hit error reporting timeout. Error reporting was interrupted and
1309           // will be wrapping things up now (closing files etc). Give it some more
1310           // time, then quit the VM.
1311           os::naked_short_sleep(200);
1312           // Print a message to stderr.


4132   _vm_complete = false;
4133 #endif
4134   // Wait until we are the last non-daemon thread to execute
4135   { MutexLocker nu(Threads_lock);
4136     while (Threads::number_of_non_daemon_threads() > 1)
4137       // This wait should make safepoint checks, wait without a timeout,
4138       // and wait as a suspend-equivalent condition.
4139       //
4140       // Note: If the FlatProfiler is running and this thread is waiting
4141       // for another non-daemon thread to finish, then the FlatProfiler
4142       // is waiting for the external suspend request on this thread to
4143       // complete. wait_for_ext_suspend_completion() will eventually
4144       // timeout, but that takes time. Making this wait a suspend-
4145       // equivalent condition solves that timeout problem.
4146       //
4147       Threads_lock->wait(!Mutex::_no_safepoint_check_flag, 0,
4148                          Mutex::_as_suspend_equivalent_flag);
4149   }
4150 
4151   // Hang forever on exit if we are reporting an error.
4152   if (ShowMessageBoxOnError && VMError::is_error_reported()) {
4153     os::infinite_sleep();
4154   }
4155   os::wait_for_keypress_at_exit();
4156 
4157   // run Java level shutdown hooks
4158   thread->invoke_shutdown_hooks();
4159 
4160   before_exit(thread);
4161 
4162   thread->exit(true);
4163 
4164   // Stop VM thread.
4165   {
4166     // 4945125 The vm thread comes to a safepoint during exit.
4167     // GC vm_operations can get caught at the safepoint, and the
4168     // heap is unparseable if they are caught. Grab the Heap_lock
4169     // to prevent this. The GC vm_operations will not be able to
4170     // queue until after the vm thread is dead. After this point,
4171     // we'll never emerge out of the safepoint before the VM exits.
4172 


< prev index next >