< prev index next >

src/hotspot/share/runtime/interfaceSupport.hpp

Print this page
rev 47413 : Introduce SafepointMechanism
rev 47415 : Add Thread Local handshakes and thread local polling

@@ -185,11 +185,11 @@
     InterfaceSupport::serialize_thread_state_with_handler(thread);
 
     // We never install asynchronous exceptions when coming (back) in
     // to the runtime from native code because the runtime is not set
     // up to handle exceptions floating around at arbitrary points.
-    if (SafepointMechanism::poll() || thread->is_suspend_after_native()) {
+    if (SafepointMechanism::poll(thread) || thread->is_suspend_after_native()) {
       JavaThread::check_safepoint_and_suspend_for_native_trans(thread);
 
       // Clear unhandled oops anywhere where we could block, even if we don't.
       CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops();)
     }

@@ -201,10 +201,42 @@
    void trans_from_java(JavaThreadState to)              { transition_from_java(_thread, to); }
    void trans_from_native(JavaThreadState to)            { transition_from_native(_thread, to); }
    void trans_and_fence(JavaThreadState from, JavaThreadState to) { transition_and_fence(_thread, from, to); }
 };
 
+class ThreadInVMForHandshake : public ThreadStateTransition {
+  const JavaThreadState _original_state;
+
+  void transition_back() {
+    // This can be invoked from transition states and must return to the original state properly
+    assert(_thread->thread_state() == _thread_in_vm, "should only call when leaving VM after handshake");
+    _thread->set_thread_state(_thread_in_vm_trans);
+
+    InterfaceSupport::serialize_thread_state(_thread);
+
+    SafepointMechanism::block_if_requested(_thread);
+
+    _thread->set_thread_state(_original_state);
+  }
+
+ public:
+
+  ThreadInVMForHandshake(JavaThread* thread) : ThreadStateTransition(thread),
+      _original_state(thread->thread_state()) {
+
+    if (thread->has_last_Java_frame()) {
+      thread->frame_anchor()->make_walkable(thread);
+    }
+
+    thread->set_thread_state(_thread_in_vm);
+  }
+
+  ~ThreadInVMForHandshake() {
+    transition_back();
+  }
+
+};
 
 class ThreadInVMfromJava : public ThreadStateTransition {
  public:
   ThreadInVMfromJava(JavaThread* thread) : ThreadStateTransition(thread) {
     trans_from_java(_thread_in_vm);
< prev index next >