Don't run managed code until the runtime has started.
Previously we ended up running managed code because JNI was
triggering class initializers to run. This was triggered by
both Thread::CreatePeer() and InitBoxingMethods().
When these initializers were prevented from running, other
code broke:
- Creating the peer for the main thread was relying on
ThreadGroup.<clinit> to assign the built-in thread groups.
- Creating the boxed methods caused class initialization of
the primitive wrapper classes; these need to be initialized
before Thread.<clinit> is run to avoid a crash in its own
initializer.
This change works around those breaks by splitting thread peer
creation into two parts (allocation and running <init>) and
by calling InitBoxingMethods() during runtime start.
Change-Id: I44be7170ce08451adf876ee73cba0f1f66d5a59e
diff --git a/src/runtime.cc b/src/runtime.cc
index 083e3ae..d5b9562 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -439,15 +439,10 @@
InitNativeMethods();
- Thread::FinishStartup();
-
- class_linker_->RunRootClinits();
-
- // Class::AllocObject asserts that all objects allocated better be
- // initialized after Runtime::IsStarted is true, so this needs to
- // come after ClassLinker::RunRootClinits.
started_ = true;
+ Thread::FinishStartup();
+
if (!is_zygote_) {
DidForkFromZygote();
}