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/jni_internal_test.cc b/src/jni_internal_test.cc
index 95e22ba..ddd39b5 100644
--- a/src/jni_internal_test.cc
+++ b/src/jni_internal_test.cc
@@ -7,6 +7,7 @@
 #include <cmath>
 
 #include "common_test.h"
+#include "ScopedLocalRef.h"
 
 namespace art {
 
@@ -22,11 +23,19 @@
 
     env_ = Thread::Current()->GetJniEnv();
 
-    aioobe_ = env_->FindClass("java/lang/ArrayIndexOutOfBoundsException");
-    CHECK(aioobe_ != NULL);
+    ScopedLocalRef<jclass> aioobe(env_, env_->FindClass("java/lang/ArrayIndexOutOfBoundsException"));
+    CHECK(aioobe.get() != NULL);
+    aioobe_ = reinterpret_cast<jclass>(env_->NewGlobalRef(aioobe.get()));
 
-    sioobe_ = env_->FindClass("java/lang/StringIndexOutOfBoundsException");
-    CHECK(sioobe_ != NULL);
+    ScopedLocalRef<jclass> sioobe(env_, env_->FindClass("java/lang/StringIndexOutOfBoundsException"));
+    CHECK(sioobe.get() != NULL);
+    sioobe_ = reinterpret_cast<jclass>(env_->NewGlobalRef(sioobe.get()));
+  }
+
+  virtual void TearDown() {
+    env_->DeleteGlobalRef(aioobe_);
+    env_->DeleteGlobalRef(sioobe_);
+    CommonTest::TearDown();
   }
 
   JavaVMExt* vm_;