Remove native code from test 944 for CTS

Replaced native code in test 944 with java reflection based code.

Bug: 32072923
Test: ./test/testrunner/testrunner.py --host -j40 -t 944
Change-Id: I678d805936009a33ce8fe6b8570bfb788a8da72d
diff --git a/test/944-transform-classloaders/classloader.cc b/test/944-transform-classloaders/classloader.cc
deleted file mode 100644
index 766597e..0000000
--- a/test/944-transform-classloaders/classloader.cc
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "android-base/macros.h"
-#include "jni.h"
-#include "jvmti.h"
-#include "mirror/class-inl.h"
-#include "scoped_local_ref.h"
-
-// Test infrastructure
-#include "test_env.h"
-
-namespace art {
-namespace Test944TransformClassloaders {
-
-extern "C" JNIEXPORT jlong JNICALL Java_art_Test944_getDexFilePointer(JNIEnv* env, jclass, jclass klass) {
-  if (Runtime::Current() == nullptr) {
-    env->ThrowNew(env->FindClass("java/lang/Exception"),
-                  "We do not seem to be running in ART! Unable to get dex file.");
-    return 0;
-  }
-  ScopedObjectAccess soa(env);
-  // This sequence of casts must be the same as those done in
-  // runtime/native/dalvik_system_DexFile.cc in order to ensure that we get the same results.
-  return static_cast<jlong>(reinterpret_cast<uintptr_t>(
-      &soa.Decode<mirror::Class>(klass)->GetDexFile()));
-}
-
-}  // namespace Test944TransformClassloaders
-}  // namespace art
diff --git a/test/944-transform-classloaders/src/art/Test944.java b/test/944-transform-classloaders/src/art/Test944.java
index 7aa9131..e7747c2 100644
--- a/test/944-transform-classloaders/src/art/Test944.java
+++ b/test/944-transform-classloaders/src/art/Test944.java
@@ -231,8 +231,6 @@
   }
 
   private static void doTest() throws Exception {
-    art.Main.bindAgentJNIForClass(Test944.class);
-
     Transform t = new Transform();
     Transform2 t2 = new Transform2();
 
@@ -270,7 +268,29 @@
   }
 
   // Gets the 'long' (really a native pointer) that is stored in the ClassLoader representing the
-  // DexFile a class is loaded from. This is converted from the DexFile* in the same way it is done
-  // in runtime/native/dalvik_system_DexFile.cc
-  private static native long getDexFilePointer(Class<?> target);
+  // DexFile a class is loaded from. This is plucked out of the internal DexCache object associated
+  // with the class.
+  private static long getDexFilePointer(Class<?> target) throws Exception {
+    // If all the android BCP classes were available when compiling this test and access checks
+    // weren't a thing this function would be written as follows:
+    //
+    // java.lang.DexCache dexCacheObject = target.dexCache;
+    // if (dexCacheObject == null) {
+    //   return 0;
+    // }
+    // return dexCacheObject.dexFile;
+    Field dexCacheField = Class.class.getDeclaredField("dexCache");
+
+    Class<?> dexCacheClass = Class.forName("java.lang.DexCache");
+    Field dexFileField = dexCacheClass.getDeclaredField("dexFile");
+
+    AccessibleObject.setAccessible(new AccessibleObject[] { dexCacheField, dexFileField }, true);
+
+    Object dexCacheObject = dexCacheField.get(target);
+    if (dexCacheObject == null) {
+      return 0;
+    }
+    checkIsInstance(dexCacheClass, dexCacheObject);
+    return dexFileField.getLong(dexCacheObject);
+  }
 }
diff --git a/test/Android.bp b/test/Android.bp
index 033c4fc..7cf49e2 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -295,7 +295,6 @@
         "909-attach-agent/attach.cc",
         "912-classes/classes.cc",
         "936-search-onload/search_onload.cc",
-        "944-transform-classloaders/classloader.cc",
         "945-obsolete-native/obsolete_native.cc",
         "983-source-transform-verify/source_transform.cc",
         "984-obsolete-invoke/obsolete_invoke.cc",