Fix delivering async exception while in compiled code.

Change artInstrumentationMethodExitFromCode() to check
for async exceptions.

Also fix kDebugExceptionDelivery = true causing stale
ObjPtr<> use.

Test: run-test --jit -runtime-option -Xjitthreshold:0 \
      1934-jvmti-signal-thread
Test: Repeat with kDebugExceptionDelivery = true.
Bug: 74583459
Change-Id: Ia2e777cc3ccef4eba549aa290f8bc12608eafe44
diff --git a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
index ac67bb3..e9a0808 100644
--- a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
@@ -1169,7 +1169,7 @@
   instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
   TwoWordReturn return_or_deoptimize_pc = instrumentation->PopInstrumentationStackFrame(
       self, return_pc, gpr_result, fpr_result);
-  if (self->IsExceptionPending()) {
+  if (self->IsExceptionPending() || self->ObserveAsyncException()) {
     return GetTwoWordFailureValue();
   }
   return return_or_deoptimize_pc;
diff --git a/runtime/quick_exception_handler.cc b/runtime/quick_exception_handler.cc
index 006405f..077aa33 100644
--- a/runtime/quick_exception_handler.cc
+++ b/runtime/quick_exception_handler.cc
@@ -143,14 +143,14 @@
 
 void QuickExceptionHandler::FindCatch(ObjPtr<mirror::Throwable> exception) {
   DCHECK(!is_deoptimization_);
-  if (kDebugExceptionDelivery) {
-    mirror::String* msg = exception->GetDetailMessage();
-    std::string str_msg(msg != nullptr ? msg->ToModifiedUtf8() : "");
-    self_->DumpStack(LOG_STREAM(INFO) << "Delivering exception: " << exception->PrettyTypeOf()
-                     << ": " << str_msg << "\n");
-  }
   StackHandleScope<1> hs(self_);
   Handle<mirror::Throwable> exception_ref(hs.NewHandle(exception));
+  if (kDebugExceptionDelivery) {
+    ObjPtr<mirror::String> msg = exception_ref->GetDetailMessage();
+    std::string str_msg(msg != nullptr ? msg->ToModifiedUtf8() : "");
+    self_->DumpStack(LOG_STREAM(INFO) << "Delivering exception: " << exception_ref->PrettyTypeOf()
+                     << ": " << str_msg << "\n");
+  }
 
   // Walk the stack to find catch handler.
   CatchBlockStackVisitor visitor(self_, context_, &exception_ref, this);