Turn upcall argument type checking on with CheckJNI.

Change-Id: I97f17ad6bcabd1d72acf76f95c6f3ed341bd867c
diff --git a/src/jni_internal.cc b/src/jni_internal.cc
index 80576a9..12c3c00 100644
--- a/src/jni_internal.cc
+++ b/src/jni_internal.cc
@@ -278,8 +278,6 @@
   return reinterpret_cast<T>(ts.Self()->DecodeJObject(obj));
 }
 
-// TODO: can we make this available in non-debug builds if CheckJNI is on, or is it too expensive?
-#if !defined(NDEBUG)
 static void CheckMethodArguments(Method* m, JValue* args) {
   MethodHelper mh(m);
   ObjectArray<Class>* parameter_types = mh.GetParameterTypes();
@@ -287,6 +285,7 @@
   size_t error_count = 0;
   for (int i = 0; i < parameter_types->GetLength(); ++i) {
     Class* parameter_type = parameter_types->Get(i);
+    // TODO: check primitives are in range.
     if (!parameter_type->IsPrimitive()) {
       Object* argument = args[i].GetL();
       if (argument != NULL && !argument->InstanceOf(parameter_type)) {
@@ -302,13 +301,12 @@
     JniAbort(NULL);
   }
 }
-#else
-static void CheckMethodArguments(Method*, JValue*) { }
-#endif
 
 static JValue InvokeWithArgArray(JNIEnv* public_env, Object* receiver, Method* method, JValue* args) {
-  CheckMethodArguments(method, args);
   JNIEnvExt* env = reinterpret_cast<JNIEnvExt*>(public_env);
+  if (UNLIKELY(env->check_jni)) {
+    CheckMethodArguments(method, args);
+  }
   JValue result;
   method->Invoke(env->self, receiver, args, &result);
   return result;