Fix dlsym lookup trampoline for @CriticalNative.

For @CriticalNative we do not have the JniEnv* argument to
retrieve the Thread*, we must use the thread register.

The test 178-app-image-native-method was supposed to cover
this but the profile was missing the necessary references.
We add those references and add $noinline$opt$ tags to make
sure the test actually runs the way it was supposed to and
add extra calls to the critical methods as they can take
different paths on subsequent execution.

Also add an extra test for class initialization checks that
ensures correct behavior for planned direct calls from
compiled managed code to registered @CriticalNative code.

Test: testrunner.py --target --optimizing -t 178
Bug: 112189621
Change-Id: I6a63d990bc08236ebaac7dacb0f5979d835ee321
diff --git a/test/178-app-image-native-method/native_methods.cc b/test/178-app-image-native-method/native_methods.cc
index becda81..0669deb 100644
--- a/test/178-app-image-native-method/native_methods.cc
+++ b/test/178-app-image-native-method/native_methods.cc
@@ -609,4 +609,33 @@
   return 42;
 }
 
+extern "C" JNIEXPORT jint JNICALL Java_CriticalClinitCheck_nativeMethodVoid() {
+  return 42;
+}
+
+extern "C" JNIEXPORT jint JNICALL Java_CriticalClinitCheck_nativeMethod(jint i) {
+  return i;
+}
+
+extern "C" JNIEXPORT jint JNICALL Java_CriticalClinitCheck_nativeMethodWithManyParameters(
+    jint i1, jlong l1, jfloat f1, jdouble d1,
+    jint i2, jlong l2, jfloat f2, jdouble d2,
+    jint i3, jlong l3, jfloat f3, jdouble d3,
+    jint i4, jlong l4, jfloat f4, jdouble d4,
+    jint i5, jlong l5, jfloat f5, jdouble d5,
+    jint i6, jlong l6, jfloat f6, jdouble d6,
+    jint i7, jlong l7, jfloat f7, jdouble d7,
+    jint i8, jlong l8, jfloat f8, jdouble d8) {
+  bool ok = VerifyManyParameters(
+      i1, l1, f1, d1,
+      i2, l2, f2, d2,
+      i3, l3, f3, d3,
+      i4, l4, f4, d4,
+      i5, l5, f5, d5,
+      i6, l6, f6, d6,
+      i7, l7, f7, d7,
+      i8, l8, f8, d8);
+  return ok ? 42 : -1;
+}
+
 }  // namespace art