Support for local references allocated in SHBs.

Local references passed in the stack handle block by the managed to
native bridge code generated jni_compiler need support for decoding. Add
support and extend jni_compiler_test to check the validity of jobject
arguments in the stack handle block.

Change-Id: Ibba60451c21f6e41023b8d837310f15ea69c44f8
diff --git a/src/thread.cc b/src/thread.cc
index dd333d7..1cb037e 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -135,6 +135,27 @@
   return true;
 }
 
+size_t Thread::NumShbHandles() {
+  size_t count = 0;
+  for (StackHandleBlock* cur = top_shb_; cur; cur = cur->Link()) {
+    count += cur->NumberOfReferences();
+  }
+  return count;
+}
+
+bool Thread::ShbContains(jobject obj) {
+  Object **shb_entry = reinterpret_cast<Object**>(obj);
+  for (StackHandleBlock* cur = top_shb_; cur; cur = cur->Link()) {
+    size_t num_refs = cur->NumberOfReferences();
+    DCHECK_GT(num_refs, 0u); // A SHB should always have a jobject/jclass
+    if ((&cur->Handles()[0] >= shb_entry) &&
+        (shb_entry <= (&cur->Handles()[num_refs-1]))) {
+      return true;
+    }
+  }
+  return false;
+}
+
 void ThrowNewException(Thread* thread, const char* exception_class_name, const char* msg) {
   CHECK(thread != NULL);