< prev index next >

src/hotspot/share/runtime/interfaceSupport.hpp

Print this page
rev 47589 : Introduce SafepointMechanism
rev 47591 : Add Thread Local handshakes and thread local polling

@@ -28,11 +28,11 @@
 #include "gc/shared/gcLocker.hpp"
 #include "runtime/handles.inline.hpp"
 #include "runtime/mutexLocker.hpp"
 #include "runtime/orderAccess.hpp"
 #include "runtime/os.hpp"
-#include "runtime/safepoint.hpp"
+#include "runtime/safepointMechanism.inline.hpp"
 #include "runtime/thread.inline.hpp"
 #include "runtime/vmThread.hpp"
 #include "utilities/globalDefinitions.hpp"
 #include "utilities/macros.hpp"
 #include "utilities/preserveException.hpp"

@@ -140,13 +140,11 @@
     // Change to transition state
     thread->set_thread_state((JavaThreadState)(from + 1));
 
     InterfaceSupport::serialize_thread_state(thread);
 
-    if (SafepointSynchronize::do_call_back()) {
-      SafepointSynchronize::block(thread);
-    }
+    SafepointMechanism::block_if_requested(thread);
     thread->set_thread_state(to);
 
     CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops();)
   }
 

@@ -162,13 +160,11 @@
     // Change to transition state
     thread->set_thread_state((JavaThreadState)(from + 1));
 
     InterfaceSupport::serialize_thread_state_with_handler(thread);
 
-    if (SafepointSynchronize::do_call_back()) {
-      SafepointSynchronize::block(thread);
-    }
+    SafepointMechanism::block_if_requested(thread);
     thread->set_thread_state(to);
 
     CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops();)
   }
 

@@ -189,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 (SafepointSynchronize::do_call_back() || 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();)
     }

@@ -205,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 >