--- a/src/hotspot/share/runtime/thread.cpp Mon Mar 25 09:35:40 2019 +0100
+++ b/src/hotspot/share/runtime/thread.cpp Thu Mar 28 11:08:23 2019 +0100
@@ -1836,6 +1836,10 @@
// Thread is now sufficiently initialized to be handled by the safepoint code as being
// in the VM. Change thread state from _thread_new to _thread_in_vm
ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm);
+ // Before a thread is on the threads list it is always safe, so after leaving the
+ // _thread_new we should emit a instruction barrier. The distance to modified code
+ // from here is probably far enough, but this is consistent and safe.
+ OrderAccess::cross_modify_fence();
assert(JavaThread::current() == this, "sanity check");
assert(!Thread::current()->owns_locks(), "sanity check");
@@ -2439,7 +2443,6 @@
this->SR_lock()->wait(Mutex::_no_safepoint_check_flag);
}
}
-
return ret;
}
@@ -2467,6 +2470,9 @@
set_thread_state(_thread_blocked);
java_suspend_self();
set_thread_state(state);
+ // Since we are not using a regular thread-state transition helper here,
+ // we must manually emit the instruction barrier after leaving a safe state.
+ OrderAccess::cross_modify_fence();
InterfaceSupport::serialize_thread_state_with_handler(this);
if (state != _thread_in_native) {
SafepointMechanism::block_if_requested(this);