Fix crash in stack walking.

Bug: 8537133

The G+ app throws an exception which leads to a crash when walking the stack.
The cause is the compiled code tries to set the top of quick stack while the
current managed stack is shadow frame based.

This CL adds the missing "pop" of the shadow frame and also some checks enabled
in debug only.

Change-Id: Iac04993b287abadee7a3c240e2e9cf1a07e50ce5
diff --git a/src/oat/runtime/support_interpreter.cc b/src/oat/runtime/support_interpreter.cc
index ada19a3..2b23bd7 100644
--- a/src/oat/runtime/support_interpreter.cc
+++ b/src/oat/runtime/support_interpreter.cc
@@ -97,6 +97,7 @@
     if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(method->GetDeclaringClass(),
                                                                  true, true)) {
       DCHECK(Thread::Current()->IsExceptionPending());
+      self->PopManagedStackFragment(fragment);
       return 0;
     }
   }
diff --git a/src/stack.h b/src/stack.h
index 18a2101..e0cb28e 100644
--- a/src/stack.h
+++ b/src/stack.h
@@ -278,6 +278,7 @@
   }
 
   void SetTopQuickFrame(mirror::AbstractMethod** top) {
+    DCHECK(top_shadow_frame_ == NULL);
     top_quick_frame_ = top;
   }
 
@@ -286,6 +287,7 @@
   }
 
   void SetTopQuickFramePc(uintptr_t pc) {
+    DCHECK(top_shadow_frame_ == NULL);
     top_quick_frame_pc_ = pc;
   }
 
@@ -298,6 +300,7 @@
   }
 
   ShadowFrame* PushShadowFrame(ShadowFrame* new_top_frame) {
+    DCHECK(top_quick_frame_ == NULL);
     ShadowFrame* old_frame = top_shadow_frame_;
     top_shadow_frame_ = new_top_frame;
     new_top_frame->SetLink(old_frame);
@@ -305,6 +308,7 @@
   }
 
   ShadowFrame* PopShadowFrame() {
+    DCHECK(top_quick_frame_ == NULL);
     CHECK(top_shadow_frame_ != NULL);
     ShadowFrame* frame = top_shadow_frame_;
     top_shadow_frame_ = frame->GetLink();
@@ -316,6 +320,7 @@
   }
 
   void SetTopShadowFrame(ShadowFrame* top) {
+    DCHECK(top_quick_frame_ == NULL);
     top_shadow_frame_ = top;
   }