170
171 // Same as above, but assumes from = _thread_in_Java. This is simpler, since we
172 // never block on entry to the VM. This will break the code, since e.g. preserve arguments
173 // have not been setup.
174 static inline void transition_from_java(JavaThread *thread, JavaThreadState to) {
175 assert(thread->thread_state() == _thread_in_Java, "coming from wrong thread state");
176 thread->set_thread_state(to);
177 }
178
179 static inline void transition_from_native(JavaThread *thread, JavaThreadState to) {
180 assert((to & 1) == 0, "odd numbers are transitions states");
181 assert(thread->thread_state() == _thread_in_native, "coming from wrong thread state");
182 // Change to transition state
183 thread->set_thread_state(_thread_in_native_trans);
184
185 InterfaceSupport::serialize_thread_state_with_handler(thread);
186
187 // We never install asynchronous exceptions when coming (back) in
188 // to the runtime from native code because the runtime is not set
189 // up to handle exceptions floating around at arbitrary points.
190 if (SafepointMechanism::poll() || thread->is_suspend_after_native()) {
191 JavaThread::check_safepoint_and_suspend_for_native_trans(thread);
192
193 // Clear unhandled oops anywhere where we could block, even if we don't.
194 CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops();)
195 }
196
197 thread->set_thread_state(to);
198 }
199 protected:
200 void trans(JavaThreadState from, JavaThreadState to) { transition(_thread, from, to); }
201 void trans_from_java(JavaThreadState to) { transition_from_java(_thread, to); }
202 void trans_from_native(JavaThreadState to) { transition_from_native(_thread, to); }
203 void trans_and_fence(JavaThreadState from, JavaThreadState to) { transition_and_fence(_thread, from, to); }
204 };
205
206
207 class ThreadInVMfromJava : public ThreadStateTransition {
208 public:
209 ThreadInVMfromJava(JavaThread* thread) : ThreadStateTransition(thread) {
210 trans_from_java(_thread_in_vm);
211 }
212 ~ThreadInVMfromJava() {
213 if (_thread->stack_yellow_reserved_zone_disabled()) {
214 _thread->enable_stack_yellow_reserved_zone();
215 }
216 trans(_thread_in_vm, _thread_in_Java);
217 // Check for pending. async. exceptions or suspends.
218 if (_thread->has_special_runtime_exit_condition()) _thread->handle_special_runtime_exit_condition();
219 }
220 };
221
222
223 class ThreadInVMfromUnknown {
224 private:
225 JavaThread* _thread;
|
170
171 // Same as above, but assumes from = _thread_in_Java. This is simpler, since we
172 // never block on entry to the VM. This will break the code, since e.g. preserve arguments
173 // have not been setup.
174 static inline void transition_from_java(JavaThread *thread, JavaThreadState to) {
175 assert(thread->thread_state() == _thread_in_Java, "coming from wrong thread state");
176 thread->set_thread_state(to);
177 }
178
179 static inline void transition_from_native(JavaThread *thread, JavaThreadState to) {
180 assert((to & 1) == 0, "odd numbers are transitions states");
181 assert(thread->thread_state() == _thread_in_native, "coming from wrong thread state");
182 // Change to transition state
183 thread->set_thread_state(_thread_in_native_trans);
184
185 InterfaceSupport::serialize_thread_state_with_handler(thread);
186
187 // We never install asynchronous exceptions when coming (back) in
188 // to the runtime from native code because the runtime is not set
189 // up to handle exceptions floating around at arbitrary points.
190 if (SafepointMechanism::poll(thread) || thread->is_suspend_after_native()) {
191 JavaThread::check_safepoint_and_suspend_for_native_trans(thread);
192
193 // Clear unhandled oops anywhere where we could block, even if we don't.
194 CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops();)
195 }
196
197 thread->set_thread_state(to);
198 }
199 protected:
200 void trans(JavaThreadState from, JavaThreadState to) { transition(_thread, from, to); }
201 void trans_from_java(JavaThreadState to) { transition_from_java(_thread, to); }
202 void trans_from_native(JavaThreadState to) { transition_from_native(_thread, to); }
203 void trans_and_fence(JavaThreadState from, JavaThreadState to) { transition_and_fence(_thread, from, to); }
204 };
205
206 class ThreadInVMForHandshake : public ThreadStateTransition {
207 const JavaThreadState _original_state;
208
209 void transition_back() {
210 // This can be invoked from transition states and must return to the original state properly
211 assert(_thread->thread_state() == _thread_in_vm, "should only call when leaving VM after handshake");
212 _thread->set_thread_state(_thread_in_vm_trans);
213
214 InterfaceSupport::serialize_thread_state(_thread);
215
216 SafepointMechanism::block_if_requested(_thread);
217
218 _thread->set_thread_state(_original_state);
219 }
220
221 public:
222
223 ThreadInVMForHandshake(JavaThread* thread) : ThreadStateTransition(thread),
224 _original_state(thread->thread_state()) {
225
226 if (thread->has_last_Java_frame()) {
227 thread->frame_anchor()->make_walkable(thread);
228 }
229
230 thread->set_thread_state(_thread_in_vm);
231 }
232
233 ~ThreadInVMForHandshake() {
234 transition_back();
235 }
236
237 };
238
239 class ThreadInVMfromJava : public ThreadStateTransition {
240 public:
241 ThreadInVMfromJava(JavaThread* thread) : ThreadStateTransition(thread) {
242 trans_from_java(_thread_in_vm);
243 }
244 ~ThreadInVMfromJava() {
245 if (_thread->stack_yellow_reserved_zone_disabled()) {
246 _thread->enable_stack_yellow_reserved_zone();
247 }
248 trans(_thread_in_vm, _thread_in_Java);
249 // Check for pending. async. exceptions or suspends.
250 if (_thread->has_special_runtime_exit_condition()) _thread->handle_special_runtime_exit_condition();
251 }
252 };
253
254
255 class ThreadInVMfromUnknown {
256 private:
257 JavaThread* _thread;
|