@@ -583,24 +583,6 @@ bool Runtime::Start() {
583583
584584 started_ = true ;
585585
586- // Create the JIT either if we have to use JIT compilation or save profiling info.
587- // TODO(calin): We use the JIT class as a proxy for JIT compilation and for
588- // recoding profiles. Maybe we should consider changing the name to be more clear it's
589- // not only about compiling. b/28295073.
590- if (jit_options_->UseJitCompilation () || jit_options_->GetSaveProfilingInfo ()) {
591- std::string error_msg;
592- if (!IsZygote ()) {
593- // If we are the zygote then we need to wait until after forking to create the code cache
594- // due to SELinux restrictions on r/w/x memory regions.
595- CreateJit ();
596- } else if (jit_options_->UseJitCompilation ()) {
597- if (!jit::Jit::LoadCompilerLibrary (&error_msg)) {
598- // Try to load compiler pre zygote to reduce PSS. b/27744947
599- LOG (WARNING) << " Failed to load JIT compiler with error " << error_msg;
600- }
601- }
602- }
603-
604586 if (!IsImageDex2OatEnabled () || !GetHeap ()->HasBootImageSpace ()) {
605587 ScopedObjectAccess soa (self);
606588 StackHandleScope<2 > hs (soa.Self ());
@@ -625,6 +607,27 @@ bool Runtime::Start() {
625607
626608 Thread::FinishStartup ();
627609
610+ // Create the JIT either if we have to use JIT compilation or save profiling info. This is
611+ // done after FinishStartup as the JIT pool needs Java thread peers, which require the main
612+ // ThreadGroup to exist.
613+ //
614+ // TODO(calin): We use the JIT class as a proxy for JIT compilation and for
615+ // recoding profiles. Maybe we should consider changing the name to be more clear it's
616+ // not only about compiling. b/28295073.
617+ if (jit_options_->UseJitCompilation () || jit_options_->GetSaveProfilingInfo ()) {
618+ std::string error_msg;
619+ if (!IsZygote ()) {
620+ // If we are the zygote then we need to wait until after forking to create the code cache
621+ // due to SELinux restrictions on r/w/x memory regions.
622+ CreateJit ();
623+ } else if (jit_options_->UseJitCompilation ()) {
624+ if (!jit::Jit::LoadCompilerLibrary (&error_msg)) {
625+ // Try to load compiler pre zygote to reduce PSS. b/27744947
626+ LOG (WARNING) << " Failed to load JIT compiler with error " << error_msg;
627+ }
628+ }
629+ }
630+
628631 system_class_loader_ = CreateSystemClassLoader (this );
629632
630633 if (is_zygote_) {
0 commit comments