< prev index next >

src/share/vm/runtime/interfaceSupport.hpp

Print this page
rev 13142 : 8183198: Factor out thread state serialization into a proper helper function
Reviewed-by:

@@ -88,14 +88,36 @@
   static void verify_stack();
   static void verify_last_frame();
 # endif
 
  public:
-  // OS dependent stuff
+  static void serialize_thread_state_with_handler(JavaThread* thread) {
+    serialize_thread_state_internal(thread, true);
+  }
 
-#include OS_HEADER(interfaceSupport)
+  // Should only call this if we know that we have a proper SEH set up.
+  static void serialize_thread_state(JavaThread* thread) {
+    serialize_thread_state_internal(thread, false);
+  }
 
+ private:
+  static void serialize_thread_state_internal(JavaThread* thread, bool needs_exception_handler) {
+    // Make sure new state is seen by VM thread
+    if (os::is_MP()) {
+      if (UseMembar) {
+        // Force a fence between the write above and read below
+        OrderAccess::fence();
+      } else {
+        // store to serialize page so VM thread can do pseudo remote membar
+        if (needs_exception_handler) {
+          os::write_memory_serialize_page_with_handler(thread);
+        } else {
+          os::write_memory_serialize_page(thread);
+        }
+      }
+    }
+  }
 };
 
 
 // Basic class for all thread transition classes.
 

@@ -116,20 +138,11 @@
     assert((from & 1) == 0 && (to & 1) == 0, "odd numbers are transitions states");
     assert(thread->thread_state() == from, "coming from wrong thread state");
     // Change to transition state
     thread->set_thread_state((JavaThreadState)(from + 1));
 
-    // Make sure new state is seen by VM thread
-    if (os::is_MP()) {
-      if (UseMembar) {
-        // Force a fence between the write above and read below
-        OrderAccess::fence();
-      } else {
-        // store to serialize page so VM thread can do pseudo remote membar
-        os::write_memory_serialize_page(thread);
-      }
-    }
+    InterfaceSupport::serialize_thread_state(thread);
 
     if (SafepointSynchronize::do_call_back()) {
       SafepointSynchronize::block(thread);
     }
     thread->set_thread_state(to);

@@ -147,20 +160,11 @@
     assert(thread->thread_state() == from, "coming from wrong thread state");
     assert((from & 1) == 0 && (to & 1) == 0, "odd numbers are transitions states");
     // Change to transition state
     thread->set_thread_state((JavaThreadState)(from + 1));
 
-    // Make sure new state is seen by VM thread
-    if (os::is_MP()) {
-      if (UseMembar) {
-        // Force a fence between the write above and read below
-        OrderAccess::fence();
-      } else {
-        // Must use this rather than serialization page in particular on Windows
-        InterfaceSupport::serialize_memory(thread);
-      }
-    }
+    InterfaceSupport::serialize_thread_state_with_handler(thread);
 
     if (SafepointSynchronize::do_call_back()) {
       SafepointSynchronize::block(thread);
     }
     thread->set_thread_state(to);

@@ -180,20 +184,11 @@
     assert((to & 1) == 0, "odd numbers are transitions states");
     assert(thread->thread_state() == _thread_in_native, "coming from wrong thread state");
     // Change to transition state
     thread->set_thread_state(_thread_in_native_trans);
 
-    // Make sure new state is seen by GC thread
-    if (os::is_MP()) {
-      if (UseMembar) {
-        // Force a fence between the write above and read below
-        OrderAccess::fence();
-      } else {
-        // Must use this rather than serialization page in particular on Windows
-        InterfaceSupport::serialize_memory(thread);
-      }
-    }
+    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()) {
< prev index next >