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.h b/src/thread.h
index 66b5e28..ac332e0 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -80,6 +80,10 @@
     return link_;
   }
 
+  Object** Handles() {
+    return handles_;
+  }
+
   // Offset of length within SHB, used by generated code
   static size_t NumberOfReferencesOffset() {
     return OFFSETOF_MEMBER(StackHandleBlock, number_of_references_);
@@ -96,6 +100,9 @@
   size_t number_of_references_;
   StackHandleBlock* link_;
 
+  // Fake array, really allocated and filled in by jni_compiler.
+  Object* handles_[0];
+
   DISALLOW_COPY_AND_ASSIGN(StackHandleBlock);
 };
 
@@ -216,13 +223,10 @@
   }
 
   // Number of references allocated in StackHandleBlocks on this thread
-  size_t NumShbHandles() {
-    size_t count = 0;
-    for (StackHandleBlock* cur = top_shb_; cur; cur = cur->Link()) {
-      count += cur->NumberOfReferences();
-    }
-    return count;
-  }
+  size_t NumShbHandles();
+
+  // Is the given obj in this thread's stack handle blocks?
+  bool ShbContains(jobject obj);
 
   // Offset of exception_entry_point_ within Thread, used by generated code
   static ThreadOffset ExceptionEntryPointOffset() {