Finish the OutOfMemoryError implementation.

This copes with the double-OOME case.

Also check that I don't leave local references in a newly-attached thread's
local reference table, and fix the leaks this discovered.

Also fix the code that implements fillInNativeStackTrace to cope with the
situation where we're not able to allocate (because we're throwing
OutOfMemoryError and there's not enough space left for our arrays).

Also fix the order of checking for a pending exception and popping the
local references in the JNI native method invocation stub. (This fixes
the warnings we'd been seeing from the IndirectReferenceTable in test 064.)

Also improve some -Xcheck:jni output.

This fixes test 061.

Change-Id: Icc04a2c06339bd28d6772190350a86abfc5734b8
diff --git a/src/indirect_reference_table.cc b/src/indirect_reference_table.cc
index e78b362..4283b83 100644
--- a/src/indirect_reference_table.cc
+++ b/src/indirect_reference_table.cc
@@ -158,6 +158,13 @@
   return result;
 }
 
+void IndirectReferenceTable::AssertEmpty() {
+  if (begin() != end()) {
+    Dump();
+    LOG(FATAL) << "Internal Error: non-empty local reference table";
+  }
+}
+
 /*
  * Verify that the indirect table lookup is valid.
  *
@@ -250,15 +257,15 @@
   }
 
   if (idx < bottomIndex) {
-    /* wrong segment */
-    LOG(INFO) << "Attempt to remove index outside index area (" << idx
-              << " vs " << bottomIndex << "-" << topIndex << ")";
+    // Wrong segment.
+    LOG(WARNING) << "Attempt to remove index outside index area (" << idx
+                 << " vs " << bottomIndex << "-" << topIndex << ")";
     return false;
   }
   if (idx >= topIndex) {
-    /* bad -- stale reference? */
-    LOG(INFO) << "Attempt to remove invalid index " << idx
-              << " (bottom=" << bottomIndex << " top=" << topIndex << ")";
+    // Bad --- stale reference?
+    LOG(WARNING) << "Attempt to remove invalid index " << idx
+                 << " (bottom=" << bottomIndex << " top=" << topIndex << ")";
     return false;
   }