@@ -84,16 +84,16 @@ JavaThread* UpcallLinker::on_entry(UpcallStub::FrameData* context) {
8484 // since it can potentially block.
8585 context->new_handles = JNIHandleBlock::allocate_block (thread);
8686
87- // clear any pending exception in thread (native calls start with no exception pending)
88- thread->clear_pending_exception ();
89-
9087 // The call to transition_from_native below contains a safepoint check
9188 // which needs the code cache to be writable.
9289 MACOS_AARCH64_ONLY (ThreadWXEnable wx (WXWrite, thread));
9390
9491 // After this, we are officially in Java Code. This needs to be done before we change any of the thread local
9592 // info, since we cannot find oops before the new information is set up completely.
96- ThreadStateTransition::transition_from_native (thread, _thread_in_Java, true /* check_asyncs */ );
93+ ThreadStateTransition::transition_from_native (thread, _thread_in_Java, false /* check_asyncs */ );
94+
95+ // clear any pending exception in thread, in case someone forgot to check it after a JNI API call.
96+ thread->clear_pending_exception ();
9797
9898 context->old_handles = thread->active_handles ();
9999
@@ -119,20 +119,16 @@ void UpcallLinker::on_exit(UpcallStub::FrameData* context) {
119119 // restore previous handle block
120120 thread->set_active_handles (context->old_handles );
121121
122- thread->frame_anchor ()->zap ();
123-
124122 debug_only (thread->dec_java_call_counter ());
125123
124+ thread->frame_anchor ()->copy (&context->jfa );
125+
126126 // Old thread-local info. has been restored. We are now back in native code.
127127 ThreadStateTransition::transition_from_java (thread, _thread_in_native);
128128
129- thread->frame_anchor ()->copy (&context->jfa );
130-
131129 // Release handles after we are marked as being in native code again, since this
132130 // operation might block
133131 JNIHandleBlock::release_block (context->new_handles , thread);
134-
135- assert (!thread->has_pending_exception (), " Upcall can not throw an exception" );
136132}
137133
138134void UpcallLinker::handle_uncaught_exception (oop exception) {
0 commit comments