Initialize runtime native methods before executing any clinit.
In certain configurations, like coverage, the initialization of core
classes can lead to calling native methods.
Test: setup as described in b/271169261
Bug: 271169261
Change-Id: I9da449e48ede375a7b18854ccc0eb4c5a74d6922
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 86c7772..b84eca8 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -969,6 +969,9 @@
started_ = true;
+ // Before running any clinit, set up the native methods provided by the runtime itself.
+ RegisterRuntimeNativeMethods(self->GetJniEnv());
+
class_linker_->RunEarlyRootClinits(self);
InitializeIntrinsics();
@@ -2181,9 +2184,6 @@
// Must be in the kNative state for calling native methods (JNI_OnLoad code).
CHECK_EQ(self->GetState(), ThreadState::kNative);
- // Set up the native methods provided by the runtime itself.
- RegisterRuntimeNativeMethods(env);
-
// Then set up libjavacore / libopenjdk / libicu_jni ,which are just
// a regular JNI libraries with a regular JNI_OnLoad. Most JNI libraries can
// just use System.loadLibrary, but libcore can't because it's the library