< prev index next >

src/hotspot/share/runtime/thread.cpp

Print this page
rev 47413 : Introduce SafepointMechanism


  60 #include "runtime/atomic.hpp"
  61 #include "runtime/biasedLocking.hpp"
  62 #include "runtime/commandLineFlagConstraintList.hpp"
  63 #include "runtime/commandLineFlagWriteableList.hpp"
  64 #include "runtime/commandLineFlagRangeList.hpp"
  65 #include "runtime/deoptimization.hpp"
  66 #include "runtime/frame.inline.hpp"
  67 #include "runtime/globals.hpp"
  68 #include "runtime/init.hpp"
  69 #include "runtime/interfaceSupport.hpp"
  70 #include "runtime/java.hpp"
  71 #include "runtime/javaCalls.hpp"
  72 #include "runtime/jniPeriodicChecker.hpp"
  73 #include "runtime/timerTrace.hpp"
  74 #include "runtime/memprofiler.hpp"
  75 #include "runtime/mutexLocker.hpp"
  76 #include "runtime/objectMonitor.hpp"
  77 #include "runtime/orderAccess.inline.hpp"
  78 #include "runtime/osThread.hpp"
  79 #include "runtime/safepoint.hpp"

  80 #include "runtime/sharedRuntime.hpp"
  81 #include "runtime/statSampler.hpp"
  82 #include "runtime/stubRoutines.hpp"
  83 #include "runtime/sweeper.hpp"
  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/align.hpp"


2355     thread->set_suspend_equivalent();
2356 
2357     // If the safepoint code sees the _thread_in_native_trans state, it will
2358     // wait until the thread changes to other thread state. There is no
2359     // guarantee on how soon we can obtain the SR_lock and complete the
2360     // self-suspend request. It would be a bad idea to let safepoint wait for
2361     // too long. Temporarily change the state to _thread_blocked to
2362     // let the VM thread know that this thread is ready for GC. The problem
2363     // of changing thread state is that safepoint could happen just after
2364     // java_suspend_self() returns after being resumed, and VM thread will
2365     // see the _thread_blocked state. We must check for safepoint
2366     // after restoring the state and make sure we won't leave while a safepoint
2367     // is in progress.
2368     thread->set_thread_state(_thread_blocked);
2369     thread->java_suspend_self();
2370     thread->set_thread_state(state);
2371 
2372     InterfaceSupport::serialize_thread_state_with_handler(thread);
2373   }
2374 
2375   if (SafepointSynchronize::do_call_back()) {
2376     // If we are safepointing, then block the caller which may not be
2377     // the same as the target thread (see above).
2378     SafepointSynchronize::block(curJT);
2379   }
2380 
2381   if (thread->is_deopt_suspend()) {
2382     thread->clear_deopt_suspend();
2383     RegisterMap map(thread, false);
2384     frame f = thread->last_frame();
2385     while (f.id() != thread->must_deopt_id() && ! f.is_first_frame()) {
2386       f = f.sender(&map);
2387     }
2388     if (f.id() == thread->must_deopt_id()) {
2389       thread->clear_must_deopt_id();
2390       f.deoptimize(thread);
2391     } else {
2392       fatal("missed deoptimization!");
2393     }
2394   }
2395 #if INCLUDE_TRACE
2396   if (thread->is_trace_suspend()) {
2397     TRACE_SUSPEND_THREAD(thread);
2398   }
2399 #endif




  60 #include "runtime/atomic.hpp"
  61 #include "runtime/biasedLocking.hpp"
  62 #include "runtime/commandLineFlagConstraintList.hpp"
  63 #include "runtime/commandLineFlagWriteableList.hpp"
  64 #include "runtime/commandLineFlagRangeList.hpp"
  65 #include "runtime/deoptimization.hpp"
  66 #include "runtime/frame.inline.hpp"
  67 #include "runtime/globals.hpp"
  68 #include "runtime/init.hpp"
  69 #include "runtime/interfaceSupport.hpp"
  70 #include "runtime/java.hpp"
  71 #include "runtime/javaCalls.hpp"
  72 #include "runtime/jniPeriodicChecker.hpp"
  73 #include "runtime/timerTrace.hpp"
  74 #include "runtime/memprofiler.hpp"
  75 #include "runtime/mutexLocker.hpp"
  76 #include "runtime/objectMonitor.hpp"
  77 #include "runtime/orderAccess.inline.hpp"
  78 #include "runtime/osThread.hpp"
  79 #include "runtime/safepoint.hpp"
  80 #include "runtime/safepointMechanism.inline.hpp"
  81 #include "runtime/sharedRuntime.hpp"
  82 #include "runtime/statSampler.hpp"
  83 #include "runtime/stubRoutines.hpp"
  84 #include "runtime/sweeper.hpp"
  85 #include "runtime/task.hpp"
  86 #include "runtime/thread.inline.hpp"
  87 #include "runtime/threadCritical.hpp"
  88 #include "runtime/vframe.hpp"
  89 #include "runtime/vframeArray.hpp"
  90 #include "runtime/vframe_hp.hpp"
  91 #include "runtime/vmThread.hpp"
  92 #include "runtime/vm_operations.hpp"
  93 #include "runtime/vm_version.hpp"
  94 #include "services/attachListener.hpp"
  95 #include "services/management.hpp"
  96 #include "services/memTracker.hpp"
  97 #include "services/threadService.hpp"
  98 #include "trace/traceMacros.hpp"
  99 #include "trace/tracing.hpp"
 100 #include "utilities/align.hpp"


2356     thread->set_suspend_equivalent();
2357 
2358     // If the safepoint code sees the _thread_in_native_trans state, it will
2359     // wait until the thread changes to other thread state. There is no
2360     // guarantee on how soon we can obtain the SR_lock and complete the
2361     // self-suspend request. It would be a bad idea to let safepoint wait for
2362     // too long. Temporarily change the state to _thread_blocked to
2363     // let the VM thread know that this thread is ready for GC. The problem
2364     // of changing thread state is that safepoint could happen just after
2365     // java_suspend_self() returns after being resumed, and VM thread will
2366     // see the _thread_blocked state. We must check for safepoint
2367     // after restoring the state and make sure we won't leave while a safepoint
2368     // is in progress.
2369     thread->set_thread_state(_thread_blocked);
2370     thread->java_suspend_self();
2371     thread->set_thread_state(state);
2372 
2373     InterfaceSupport::serialize_thread_state_with_handler(thread);
2374   }
2375 
2376   SafepointMechanism::block_if_requested(curJT);




2377 
2378   if (thread->is_deopt_suspend()) {
2379     thread->clear_deopt_suspend();
2380     RegisterMap map(thread, false);
2381     frame f = thread->last_frame();
2382     while (f.id() != thread->must_deopt_id() && ! f.is_first_frame()) {
2383       f = f.sender(&map);
2384     }
2385     if (f.id() == thread->must_deopt_id()) {
2386       thread->clear_must_deopt_id();
2387       f.deoptimize(thread);
2388     } else {
2389       fatal("missed deoptimization!");
2390     }
2391   }
2392 #if INCLUDE_TRACE
2393   if (thread->is_trace_suspend()) {
2394     TRACE_SUSPEND_THREAD(thread);
2395   }
2396 #endif


< prev index next >