diff options
Diffstat (limited to 'runtime/class_linker.cc')
-rw-r--r-- | runtime/class_linker.cc | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 838d6c1a80..151abeb3db 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -2405,6 +2405,10 @@ void ClassLinker::VisitClassRoots(RootVisitor* visitor, VisitRootFlags flags) { // enabling tracing requires the mutator lock, there are no race conditions here. const bool tracing_enabled = Trace::IsTracingEnabled(); Thread* const self = Thread::Current(); + // For simplicity, if there is JIT activity, we'll trace all class loaders. + // This prevents class unloading while a method is being compiled or is going + // to be compiled. + const bool is_jit_active = jit::Jit::IsActive(self); WriterMutexLock mu(self, *Locks::classlinker_classes_lock_); if (gUseReadBarrier) { // We do not track new roots for CC. @@ -2435,8 +2439,8 @@ void ClassLinker::VisitClassRoots(RootVisitor* visitor, VisitRootFlags flags) { // these objects. UnbufferedRootVisitor root_visitor(visitor, RootInfo(kRootStickyClass)); boot_class_table_->VisitRoots(root_visitor); - // If tracing is enabled, then mark all the class loaders to prevent unloading. - if ((flags & kVisitRootFlagClassLoader) != 0 || tracing_enabled) { + // If tracing is enabled or jit is active, mark all the class loaders to prevent unloading. + if ((flags & kVisitRootFlagClassLoader) != 0 || tracing_enabled || is_jit_active) { for (const ClassLoaderData& data : class_loaders_) { GcRoot<mirror::Object> root(GcRoot<mirror::Object>(self->DecodeJObject(data.weak_root))); root.VisitRoot(visitor, RootInfo(kRootVMInternal)); |