diff options
author | 2019-06-28 12:46:33 +0100 | |
---|---|---|
committer | 2019-07-01 12:07:09 +0000 | |
commit | 05b41c40c62078664fa3bcfbe5fc935d20a6e92c (patch) | |
tree | de80d697ee6781439162a06891956ca64b6db896 | |
parent | 3a614eaa58542169f2047ea6efeb5d6ece867be6 (diff) |
Prepare for sharing JIT code after fork.
Only encode classes/strings/methods that are in a boot image.
Bug: 119800099
Test: boot
Change-Id: I7ed8ce2ce876ad1c6c1678939cafe4808a67bef4
-rw-r--r-- | compiler/optimizing/sharpening.cc | 1 | ||||
-rw-r--r-- | runtime/jit/jit.cc | 35 | ||||
-rw-r--r-- | runtime/jit/jit.h | 3 |
3 files changed, 22 insertions, 17 deletions
diff --git a/compiler/optimizing/sharpening.cc b/compiler/optimizing/sharpening.cc index 3e22edc773..03d277f648 100644 --- a/compiler/optimizing/sharpening.cc +++ b/compiler/optimizing/sharpening.cc @@ -100,6 +100,7 @@ HInvokeStaticOrDirect::DispatchInfo HSharpening::SharpenInvokeStaticOrDirect( } code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod; } else if (Runtime::Current()->UseJitCompilation()) { + ScopedObjectAccess soa(Thread::Current()); if (Runtime::Current()->GetJit()->CanEncodeMethod( callee, codegen->GetGraph()->IsCompilingForSharedJitCode())) { diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc index 201f3cee0b..c92630d001 100644 --- a/runtime/jit/jit.cc +++ b/runtime/jit/jit.cc @@ -1073,30 +1073,33 @@ void Jit::PostZygoteFork() { thread_pool_->CreateThreads(); } -bool Jit::CanEncodeMethod(ArtMethod* method ATTRIBUTE_UNUSED, - bool is_for_shared_region ATTRIBUTE_UNUSED) const { - // TODO: For shared region, we should only encode a method of a class - // allocated before any fork. - return true; +bool Jit::CanEncodeMethod(ArtMethod* method, bool is_for_shared_region) const { + return !is_for_shared_region || + Runtime::Current()->GetHeap()->ObjectIsInBootImageSpace(method->GetDeclaringClass()); } bool Jit::CanEncodeClass(ObjPtr<mirror::Class> cls, bool is_for_shared_region) const { - // TODO: For shared region, we should only encode a non-moving class allocated - // before any fork. - return !is_for_shared_region || !Runtime::Current()->GetHeap()->IsMovableObject(cls); + return !is_for_shared_region || Runtime::Current()->GetHeap()->ObjectIsInBootImageSpace(cls); } bool Jit::CanEncodeString(ObjPtr<mirror::String> string, bool is_for_shared_region) const { - // TODO: For shared region, we should only encode a non-moving string allocated - // before any fork. - return !is_for_shared_region || !Runtime::Current()->GetHeap()->IsMovableObject(string); + return !is_for_shared_region || Runtime::Current()->GetHeap()->ObjectIsInBootImageSpace(string); } -bool Jit::CanAssumeInitialized(ObjPtr<mirror::Class> cls, - bool is_for_shared_region ATTRIBUTE_UNUSED) const { - // TODO: For shared region, we should assume initialized if the class is initialized - // before any fork. - return cls->IsInitialized(); +bool Jit::CanAssumeInitialized(ObjPtr<mirror::Class> cls, bool is_for_shared_region) const { + if (!is_for_shared_region) { + return cls->IsInitialized(); + } else { + // Look up the class status in the oat file. + const DexFile& dex_file = *cls->GetDexCache()->GetDexFile(); + const OatDexFile* oat_dex_file = dex_file.GetOatDexFile(); + // In case we run without an image there won't be a backing oat file. + if (oat_dex_file == nullptr || oat_dex_file->GetOatFile() == nullptr) { + return false; + } + uint16_t class_def_index = cls->GetDexClassDefIndex(); + return oat_dex_file->GetOatClass(class_def_index).GetStatus() >= ClassStatus::kInitialized; + } } } // namespace jit diff --git a/runtime/jit/jit.h b/runtime/jit/jit.h index e44e1c94e7..d272a18919 100644 --- a/runtime/jit/jit.h +++ b/runtime/jit/jit.h @@ -326,7 +326,8 @@ class Jit { // Called by the compiler to know whether it can directly encode the // method/class/string. - bool CanEncodeMethod(ArtMethod* method, bool is_for_shared_region) const; + bool CanEncodeMethod(ArtMethod* method, bool is_for_shared_region) const + REQUIRES_SHARED(Locks::mutator_lock_); bool CanEncodeClass(ObjPtr<mirror::Class> cls, bool is_for_shared_region) const REQUIRES_SHARED(Locks::mutator_lock_); bool CanEncodeString(ObjPtr<mirror::String> string, bool is_for_shared_region) const |