Try to avoid expensive stack walk in QuickDeliverException

Stack popping is a debug feature. We can skip the
stack walk if no stack pops have been requested.
This makes PMD benchmark about 10% faster.

Bug: 136438735
Test: test.py -b --host --64 --interpreter
Test: run-libjdwp-tests.sh '--mode=host' '--variant=X64'
Change-Id: I09b9a444c110434d9bb7253776128bd3fe9c28ab
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 27d1038..463023a 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -3548,8 +3548,8 @@
   // instrumentation trampolines (for example with DDMS tracing). That forces us to do deopt later
   // and see every frame being popped. We don't need to handle it any differently.
   ShadowFrame* cf;
-  bool force_deopt;
-  {
+  bool force_deopt = false;
+  if (Runtime::Current()->AreNonStandardExitsEnabled() || kIsDebugBuild) {
     NthCallerVisitor visitor(this, 0, false);
     visitor.WalkStack();
     cf = visitor.GetCurrentShadowFrame();
@@ -3559,6 +3559,7 @@
     bool force_frame_pop = cf != nullptr && cf->GetForcePopFrame();
     bool force_retry_instr = cf != nullptr && cf->GetForceRetryInstruction();
     if (kIsDebugBuild && force_frame_pop) {
+      DCHECK(Runtime::Current()->AreNonStandardExitsEnabled());
       NthCallerVisitor penultimate_visitor(this, 1, false);
       penultimate_visitor.WalkStack();
       ShadowFrame* penultimate_frame = penultimate_visitor.GetCurrentShadowFrame();
@@ -3566,6 +3567,9 @@
         penultimate_frame = FindDebuggerShadowFrame(penultimate_visitor.GetFrameId());
       }
     }
+    if (force_retry_instr) {
+      DCHECK(Runtime::Current()->AreNonStandardExitsEnabled());
+    }
     force_deopt = force_frame_pop || force_retry_instr;
   }
   if (Dbg::IsForcedInterpreterNeededForException(this) || force_deopt || IsForceInterpreter()) {