Minor nio cleanup.

Remove an unused cached jmethodID from "Jni.c", and change "CheckJni.c" to
use the same direct field access that "Jni.c" was already using. (I noticed
this when removing the otherwise unused PlatformAddress.toLong method from
libcore.)

Also remove the now-meaningless double check that the direct field access
works.

Change-Id: I9ef3d5a0e2fd4feafc3925004cacb46fa9f28c17
diff --git a/vm/CheckJni.c b/vm/CheckJni.c
index 59d34eb..e111187 100644
--- a/vm/CheckJni.c
+++ b/vm/CheckJni.c
@@ -184,8 +184,6 @@
 #define BASE_ENV(_env)  (((JNIEnvExt*)_env)->baseFuncTable)
 #define BASE_VM(_vm)    (((JavaVMExt*)_vm)->baseFuncTable)
 
-#define kRedundantDirectBufferTest false
-
 /*
  * Flags passed into checkThread().
  */
@@ -2374,59 +2372,6 @@
     CHECK_OBJECT(env, buf);
     void* result = BASE_ENV(env)->GetDirectBufferAddress(env, buf);
     CHECK_EXIT(env);
-
-    /* optional - check result vs. "safe" implementation */
-    if (kRedundantDirectBufferTest) {
-        jobject platformAddr = NULL;
-        void* checkResult = NULL;
-
-        /*
-         * Start by determining if the object supports the DirectBuffer
-         * interfaces.  Note this does not guarantee that it's a direct buffer.
-         */
-        if (JNI_FALSE == (*env)->IsInstanceOf(env, buf,
-                gDvm.jclassOrgApacheHarmonyNioInternalDirectBuffer))
-        {
-            goto bail;
-        }
-
-        /*
-         * Get the PlatformAddress object.
-         *
-         * If this isn't a direct buffer, platformAddr will be NULL and/or an
-         * exception will have been thrown.
-         */
-        platformAddr = (*env)->CallObjectMethod(env, buf,
-            (jmethodID) gDvm.methOrgApacheHarmonyNioInternalDirectBuffer_getEffectiveAddress);
-
-        if ((*env)->ExceptionCheck(env)) {
-            (*env)->ExceptionClear(env);
-            platformAddr = NULL;
-        }
-        if (platformAddr == NULL) {
-            LOGV("Got request for address of non-direct buffer\n");
-            goto bail;
-        }
-
-        jclass platformAddrClass = (*env)->FindClass(env,
-            "org/apache/harmony/luni/platform/PlatformAddress");
-        jmethodID toLongMethod = (*env)->GetMethodID(env, platformAddrClass,
-            "toLong", "()J");
-        checkResult = (void*)(u4)(*env)->CallLongMethod(env, platformAddr,
-                toLongMethod);
-
-    bail:
-        if (platformAddr != NULL)
-            (*env)->DeleteLocalRef(env, platformAddr);
-
-        if (result != checkResult) {
-            LOGW("JNI WARNING: direct buffer result mismatch (%p vs %p)\n",
-                result, checkResult);
-            abortMaybe();
-            /* keep going */
-        }
-    }
-
     return result;
 }
 
diff --git a/vm/Globals.h b/vm/Globals.h
index d0ad110..10462d3 100644
--- a/vm/Globals.h
+++ b/vm/Globals.h
@@ -223,7 +223,6 @@
     ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMember;
     ClassObject* classOrgApacheHarmonyLangAnnotationAnnotationMemberArray;
     ClassObject* classOrgApacheHarmonyNioInternalDirectBuffer;
-    jclass      jclassOrgApacheHarmonyNioInternalDirectBuffer;
 
     /* synthetic classes for arrays of primitives */
     ClassObject* classArrayBoolean;
@@ -328,7 +327,6 @@
     int         offJavaNioBuffer_capacity;
     int         offJavaNioBuffer_effectiveDirectAddress;
     int         offOrgApacheHarmonyLuniPlatformPlatformAddress_osaddr;
-    int         voffOrgApacheHarmonyLuniPlatformPlatformAddress_toLong;
 
     /*
      * VM-synthesized primitive classes, for arrays.
diff --git a/vm/Jni.c b/vm/Jni.c
index ef0749a..312984e 100644
--- a/vm/Jni.c
+++ b/vm/Jni.c
@@ -362,9 +362,6 @@
     }
     gDvm.classJavaNioReadWriteDirectByteBuffer = readWriteBufferClass;
     gDvm.classOrgApacheHarmonyNioInternalDirectBuffer = directBufferClass;
-    /* need a global reference for extended CheckJNI tests */
-    gDvm.jclassOrgApacheHarmonyNioInternalDirectBuffer =
-        addGlobalReference((Object*) directBufferClass);
 
     /*
      * We need a Method* here rather than a vtable offset, because
@@ -380,15 +377,6 @@
     }
     gDvm.methOrgApacheHarmonyNioInternalDirectBuffer_getEffectiveAddress = meth;
 
-    meth = dvmFindVirtualMethodByDescriptor(platformAddressClass,
-                "toLong", "()J");
-    if (meth == NULL) {
-        LOGE("Unable to find PlatformAddress.toLong\n");
-        return false;
-    }
-    gDvm.voffOrgApacheHarmonyLuniPlatformPlatformAddress_toLong =
-        meth->methodIndex;
-
     meth = dvmFindDirectMethodByDescriptor(platformAddressFactoryClass,
                 "on",
                 "(I)Lorg/apache/harmony/luni/platform/PlatformAddress;");
@@ -3745,7 +3733,7 @@
 
     /*
      * Extract the address from the PlatformAddress object.  Instead of
-     * calling the toLong() method, just grab the field directly.  This
+     * calling the toInt() method, just grab the field directly.  This
      * is faster but more fragile.
      */
     result = (void*) dvmGetFieldInt(platformAddr,