Fix exception caught listeners and frame type for deopt.

Change-Id: I5792ebe9a7772d068b6ec556b4fc27ddd44d7ca1
diff --git a/src/debugger.cc b/src/debugger.cc
index 9bd1eb5..0712c93 100644
--- a/src/debugger.cc
+++ b/src/debugger.cc
@@ -538,7 +538,8 @@
   runtime->GetInstrumentation()->AddListener(&gDebugInstrumentationListener,
                                              instrumentation::Instrumentation::kMethodEntered |
                                              instrumentation::Instrumentation::kMethodExited |
-                                             instrumentation::Instrumentation::kDexPcMoved);
+                                             instrumentation::Instrumentation::kDexPcMoved |
+                                             instrumentation::Instrumentation::kExceptionCaught);
   gDebuggerActive = true;
   CHECK_EQ(self->SetStateUnsafe(old_state), kRunnable);
   runtime->GetThreadList()->ResumeAll();
@@ -561,7 +562,8 @@
   runtime->GetInstrumentation()->RemoveListener(&gDebugInstrumentationListener,
                                                 instrumentation::Instrumentation::kMethodEntered |
                                                 instrumentation::Instrumentation::kMethodExited |
-                                                instrumentation::Instrumentation::kDexPcMoved);
+                                                instrumentation::Instrumentation::kDexPcMoved |
+                                                instrumentation::Instrumentation::kExceptionCaught);
   gDebuggerActive = false;
   gRegistry->Clear();
   gDebuggerConnected = false;
diff --git a/src/instrumentation.cc b/src/instrumentation.cc
index 55e93cb..982af29 100644
--- a/src/instrumentation.cc
+++ b/src/instrumentation.cc
@@ -274,6 +274,10 @@
     require_interpreter = true;
     have_dex_pc_listeners_ = true;
   }
+  if ((events & kExceptionCaught) != 0) {
+    exception_caught_listeners_.push_back(listener);
+    have_exception_caught_listeners_ = true;
+  }
   ConfigureStubs(require_entry_exit_stubs, require_interpreter);
 }
 
@@ -312,6 +316,10 @@
     have_dex_pc_listeners_ = dex_pc_listeners_.size() > 0;
     require_interpreter |= have_dex_pc_listeners_;
   }
+  if ((events & kExceptionCaught) != 0) {
+    exception_caught_listeners_.remove(listener);
+    have_exception_caught_listeners_ = exception_caught_listeners_.size() > 0;
+  }
   ConfigureStubs(require_entry_exit_stubs, require_interpreter);
 }
 
diff --git a/src/oat/runtime/arm/runtime_support_arm.S b/src/oat/runtime/arm/runtime_support_arm.S
index 96b3980..0e34d40 100644
--- a/src/oat/runtime/arm/runtime_support_arm.S
+++ b/src/oat/runtime/arm/runtime_support_arm.S
@@ -1019,7 +1019,7 @@
      */
     .extern artDeoptimize
 ENTRY art_quick_deoptimize
-    SETUP_REF_ONLY_CALLEE_SAVE_FRAME
+    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
     mov    r0, r9         @ Set up args.
     mov    r1, sp
     blx    artDeoptimize  @ artDeoptimize(Thread*, SP)
diff --git a/src/oat/runtime/mips/runtime_support_mips.S b/src/oat/runtime/mips/runtime_support_mips.S
index 529fd0d..31b1846 100644
--- a/src/oat/runtime/mips/runtime_support_mips.S
+++ b/src/oat/runtime/mips/runtime_support_mips.S
@@ -1030,7 +1030,7 @@
     .extern artEnterInterpreterFromDeoptimize
 ENTRY art_quick_deoptimize
     GENERATE_GLOBAL_POINTER
-    SETUP_REF_ONLY_CALLEE_SAVE_FRAME
+    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
     move     $a0, rSELF     # pass Thread::current
     jal      artDeoptimize  # artDeoptimize(Thread*, SP)
                             # Returns caller method's frame size.
diff --git a/src/oat/runtime/support_deoptimize.cc b/src/oat/runtime/support_deoptimize.cc
index 0b0a7c3..43fc9d2 100644
--- a/src/oat/runtime/support_deoptimize.cc
+++ b/src/oat/runtime/support_deoptimize.cc
@@ -30,7 +30,7 @@
 
 extern "C" void artDeoptimize(Thread* self, mirror::AbstractMethod** sp)
     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
-  FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly);
+  FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
   self->SetException(ThrowLocation(), reinterpret_cast<mirror::Throwable*>(-1));
   self->QuickDeliverException();
 }