1.1 --- a/src/share/vm/runtime/frame.cpp Thu Aug 12 16:38:23 2010 -0700 1.2 +++ b/src/share/vm/runtime/frame.cpp Thu Aug 12 23:34:34 2010 -0700 1.3 @@ -215,17 +215,15 @@ 1.4 return !nm->is_at_poll_return(pc()); 1.5 } 1.6 1.7 -void frame::deoptimize(JavaThread* thread, bool thread_is_known_safe) { 1.8 -// Schedule deoptimization of an nmethod activation with this frame. 1.9 - 1.10 - // Store the original pc before an patch (or request to self-deopt) 1.11 - // in the published location of the frame. 1.12 - 1.13 +void frame::deoptimize(JavaThread* thread) { 1.14 + // Schedule deoptimization of an nmethod activation with this frame. 1.15 assert(_cb != NULL && _cb->is_nmethod(), "must be"); 1.16 nmethod* nm = (nmethod*)_cb; 1.17 1.18 // This is a fix for register window patching race 1.19 - if (NeedsDeoptSuspend && !thread_is_known_safe) { 1.20 + if (NeedsDeoptSuspend && Thread::current() != thread) { 1.21 + assert(SafepointSynchronize::is_at_safepoint(), 1.22 + "patching other threads for deopt may only occur at a safepoint"); 1.23 1.24 // It is possible especially with DeoptimizeALot/DeoptimizeRandom that 1.25 // we could see the frame again and ask for it to be deoptimized since 1.26 @@ -248,7 +246,11 @@ 1.27 // whether to spin or block. It isn't worth it. Just treat it like 1.28 // native and be done with it. 1.29 // 1.30 - JavaThreadState state = thread->thread_state(); 1.31 + // Examine the state of the thread at the start of safepoint since 1.32 + // threads that were in native at the start of the safepoint could 1.33 + // come to a halt during the safepoint, changing the current value 1.34 + // of the safepoint_state. 1.35 + JavaThreadState state = thread->safepoint_state()->orig_thread_state(); 1.36 if (state == _thread_in_native || state == _thread_in_native_trans) { 1.37 // Since we are at a safepoint the target thread will stop itself 1.38 // before it can return to java as long as we remain at the safepoint.