Fix UnsatisfiedLinkError in CtsJvmti tests

A few CtsJvmti tests were failing due to the test setup racing with
the process that attaches the agent and loads the native library.
This change registers the native methods to fix the issue.

Bug: 112338190
Test: atest CtsJvmtiRedefineClassesHostTestCases \
            CtsJvmtiTaggingHostTestCases \
            CtsJvmtiTrackingHostTestCases

Change-Id: If2a1e838a4a706d06554a1e2c3674ee901c73229
(cherry picked from commit fa112a05f89055ceae16ab8b007849a9f882759b)
Merged-In: If2a1e838a4a706d06554a1e2c3674ee901c73229
diff --git a/hostsidetests/jvmti/base/jni/tracking.cpp b/hostsidetests/jvmti/base/jni/tracking.cpp
index a07d653..0503e82 100644
--- a/hostsidetests/jvmti/base/jni/tracking.cpp
+++ b/hostsidetests/jvmti/base/jni/tracking.cpp
@@ -21,6 +21,7 @@
 
 #include "android-base/logging.h"
 #include "android-base/stringprintf.h"
+#include "jni_binder.h"
 #include "jvmti_helper.h"
 #include "scoped_local_ref.h"
 #include "scoped_utf_chars.h"
@@ -93,4 +94,30 @@
   return env->NewStringUTF(result.c_str());
 }
 
+static JNINativeMethod gMethods[] = {
+  { "setupObjectAllocCallback", "(Z)V",
+          (void*)Java_android_jvmti_cts_JvmtiTrackingTest_setupObjectAllocCallback },
+
+  { "enableAllocationTracking", "(Ljava/lang/Thread;Z)V",
+          (void*)Java_android_jvmti_cts_JvmtiTrackingTest_enableAllocationTracking },
+
+  { "getAndResetAllocationTrackingString", "()Ljava/lang/String;",
+          (void*)Java_android_jvmti_cts_JvmtiTrackingTest_getAndResetAllocationTrackingString },
+};
+
+void register_android_jvmti_cts_JvmtiTrackingTest(jvmtiEnv* jenv, JNIEnv* env) {
+  ScopedLocalRef<jclass> klass(env, FindClass(jenv, env,
+          "android/jvmti/cts/JvmtiTrackingTest", nullptr));
+  if (env->ExceptionCheck()) {
+    env->ExceptionClear();
+    return;
+  }
+
+  env->RegisterNatives(klass.get(), gMethods, sizeof(gMethods) / sizeof(JNINativeMethod));
+  if (env->ExceptionCheck()) {
+    env->ExceptionClear();
+    LOG(ERROR) << "Could not register natives for JvmtiTrackingTest class";
+  }
+}
+
 }  // namespace art