@@ -943,19 +943,21 @@ void ThreadSafepointState::print_on(outputStream *st) const {
943943
944944// Process pending operation.
945945void ThreadSafepointState::handle_polling_page_exception () {
946+ JavaThread* self = thread ();
947+ assert (self == Thread::current ()->as_Java_thread (), " must be self" );
946948
947949 // Step 1: Find the nmethod from the return address
948- address real_return_addr = thread () ->saved_exception_pc ();
950+ address real_return_addr = self ->saved_exception_pc ();
949951
950952 CodeBlob *cb = CodeCache::find_blob (real_return_addr);
951953 assert (cb != NULL && cb->is_compiled (), " return address should be in nmethod" );
952954 CompiledMethod* nm = (CompiledMethod*)cb;
953955
954956 // Find frame of caller
955- frame stub_fr = thread () ->last_frame ();
957+ frame stub_fr = self ->last_frame ();
956958 CodeBlob* stub_cb = stub_fr.cb ();
957959 assert (stub_cb->is_safepoint_stub (), " must be a safepoint stub" );
958- RegisterMap map (thread () , true , false );
960+ RegisterMap map (self , true , false );
959961 frame caller_fr = stub_fr.sender (&map);
960962
961963 // Should only be poll_return or poll
@@ -976,17 +978,18 @@ void ThreadSafepointState::handle_polling_page_exception() {
976978 // to keep it in a handle.
977979 oop result = caller_fr.saved_oop_result (&map);
978980 assert (oopDesc::is_oop_or_null (result), " must be oop" );
979- return_value = Handle (thread () , result);
981+ return_value = Handle (self , result);
980982 assert (Universe::heap ()->is_in_or_null (result), " must be heap pointer" );
981983 }
982984
983985 // We get here if compiled return polls found a reason to call into the VM.
984986 // One condition for that is that the top frame is not yet safe to use.
985987 // The following stack watermark barrier poll will catch such situations.
986- StackWatermarkSet::after_unwind (thread () );
988+ StackWatermarkSet::after_unwind (self );
987989
988990 // Process pending operation
989- SafepointMechanism::process_if_requested (thread ());
991+ SafepointMechanism::process_if_requested (self);
992+ self->check_and_handle_async_exceptions ();
990993
991994 // restore oop result, if any
992995 if (return_oop) {
@@ -1002,21 +1005,21 @@ void ThreadSafepointState::handle_polling_page_exception() {
10021005 assert (real_return_addr == caller_fr.pc (), " must match" );
10031006
10041007 // Process pending operation
1005- SafepointMechanism::process_if_requested (thread () );
1008+ SafepointMechanism::process_if_requested (self );
10061009 set_at_poll_safepoint (false );
10071010
10081011 // If we have a pending async exception deoptimize the frame
10091012 // as otherwise we may never deliver it.
1010- if (thread () ->has_async_condition ()) {
1011- ThreadInVMfromJavaNoAsyncException __tiv (thread () );
1012- Deoptimization::deoptimize_frame (thread () , caller_fr.id ());
1013+ if (self ->has_async_condition ()) {
1014+ ThreadInVMfromJavaNoAsyncException __tiv (self );
1015+ Deoptimization::deoptimize_frame (self , caller_fr.id ());
10131016 }
10141017
10151018 // If an exception has been installed we must check for a pending deoptimization
10161019 // Deoptimize frame if exception has been thrown.
10171020
1018- if (thread () ->has_pending_exception () ) {
1019- RegisterMap map (thread () , true , false );
1021+ if (self ->has_pending_exception () ) {
1022+ RegisterMap map (self , true , false );
10201023 frame caller_fr = stub_fr.sender (&map);
10211024 if (caller_fr.is_deoptimized_frame ()) {
10221025 // The exception patch will destroy registers that are still
0 commit comments