Add -Xcheck:jni.

I think this is as complete as possible right now. The remaining
two #if 0 sections require:

1. a way to get the Method* of the current native method.
2. a way to get the Class* of the type of a given Field*.

Change-Id: I331586022095fb36ccc10c9ac1890a59a9224d01
diff --git a/src/jni_internal.h b/src/jni_internal.h
index c8a5a39..a4362d3 100644
--- a/src/jni_internal.h
+++ b/src/jni_internal.h
@@ -20,6 +20,8 @@
 class Runtime;
 class Thread;
 
+void JniAbort(const char* jni_function_name);
+
 struct JavaVMExt : public JavaVM {
   JavaVMExt(Runtime* runtime, bool check_jni, bool verbose_jni);
   ~JavaVMExt();
@@ -40,8 +42,12 @@
 
   Runtime* runtime;
 
+  // Used for testing. By default, we'll LOG(FATAL) the reason.
+  void (*check_jni_abort_hook)(const std::string& reason);
+
   bool check_jni;
   bool verbose_jni;
+  bool force_copy;
 
   // Used to hold references to pinned primitive arrays.
   Mutex* pins_lock;
@@ -57,6 +63,9 @@
 
   Mutex* libraries_lock;
   Libraries* libraries;
+
+  // Used by -Xcheck:jni.
+  const JNIInvokeInterface* unchecked_functions;
 };
 
 struct JNIEnvExt : public JNIEnv {
@@ -68,16 +77,22 @@
 
   bool check_jni;
 
-  // Are we in a "critical" JNI call?
-  bool critical;
+  // How many nested "critical" JNI calls are we in?
+  int critical;
 
   // Entered JNI monitors, for bulk exit on thread detach.
   ReferenceTable  monitors;
 
   // JNI local references.
   IndirectReferenceTable locals;
+
+  // Used by -Xcheck:jni.
+  const JNINativeInterface* unchecked_functions;
 };
 
+const JNINativeInterface* GetCheckJniNativeInterface();
+const JNIInvokeInterface* GetCheckJniInvokeInterface();
+
 }  // namespace art
 
 std::ostream& operator<<(std::ostream& os, const jobjectRefType& rhs);