Touch up changes related to cross-dex compiling
* Added exaplanatory comments
* Used IsBootStrapClassLoaded to avoid a read barrier
* Use the new multi-image from CompilerOptions
Bug: 154012332
Test: art/test/testrunner/testrunner.py --host --64 --optimizing -b
Change-Id: I10a4ed0f9d5b2e796102846564a54dc90f297068
diff --git a/compiler/driver/compiler_options.h b/compiler/driver/compiler_options.h
index 0034306..1bffdb1 100644
--- a/compiler/driver/compiler_options.h
+++ b/compiler/driver/compiler_options.h
@@ -26,6 +26,7 @@
#include "base/globals.h"
#include "base/hash_set.h"
#include "base/macros.h"
+#include "base/stl_util.h"
#include "base/utils.h"
#include "optimizing/register_allocator.h"
@@ -377,9 +378,9 @@
return initialize_app_image_classes_;
}
+ // Returns true if `dex_file` is within an oat file we're producing right now.
bool WithinOatFile(const DexFile* dex_file) const {
- return std::find(GetDexFilesForOatFile().begin(), GetDexFilesForOatFile().end(), dex_file) !=
- GetDexFilesForOatFile().end();
+ return ContainsElement(GetDexFilesForOatFile(), dex_file);
}
private:
diff --git a/compiler/optimizing/inliner.cc b/compiler/optimizing/inliner.cc
index 741e6df..8b41205 100644
--- a/compiler/optimizing/inliner.cc
+++ b/compiler/optimizing/inliner.cc
@@ -1744,13 +1744,11 @@
// Inline across dexfiles if the callee's DexFile is:
// 1) in the bootclasspath, or
- if (callee->GetDeclaringClass()->GetClassLoader() == nullptr) {
+ if (callee->GetDeclaringClass()->IsBootStrapClassLoaded()) {
// In multi-image, each BCP DexFile has their own OatWriter. Since they don't cooperate with
// each other, we request the BSS check for them.
- // TODO(solanes): Add .bss support for BCP multi-image.
- const bool is_multi_image = codegen->GetCompilerOptions().IsBootImage() ||
- codegen->GetCompilerOptions().IsBootImageExtension();
- *out_needs_bss_check = is_multi_image;
+ // TODO(solanes, 154012332): Add .bss support for BCP multi-image.
+ *out_needs_bss_check = codegen->GetCompilerOptions().IsMultiImage();
return true;
}
@@ -1939,13 +1937,14 @@
return false;
}
- // We currently don't have support for inlining across dex files if the inlined method needs a
- // .bss entry. This only happens when we are:
+ // We currently don't have support for inlining across dex files if we are:
// 1) In AoT,
- // 2) cross-dex inlining, and
- // 3) have an instruction that needs a bss entry, which will always be
- // 3)b) an instruction that needs an environment.
- // TODO(solanes, 154012332): Add this support.
+ // 2) cross-dex inlining,
+ // 3) the callee is a BCP DexFile,
+ // 4) we are compiling multi image, and
+ // 5) have an instruction that needs a bss entry, which will always be
+ // 5)b) an instruction that needs an environment.
+ // 1) - 4) are encoded in `needs_bss_check` (see CanEncodeInlinedMethodInStackMap).
if (needs_bss_check && current->NeedsBss()) {
DCHECK(current->NeedsEnvironment());
LOG_FAIL(stats_, MethodCompilationStat::kNotInlinedBss)
diff --git a/compiler/optimizing/stack_map_stream.cc b/compiler/optimizing/stack_map_stream.cc
index 7317bdf..f55bbee 100644
--- a/compiler/optimizing/stack_map_stream.cc
+++ b/compiler/optimizing/stack_map_stream.cc
@@ -224,7 +224,7 @@
ScopedObjectAccess soa(Thread::Current());
const DexFile* dex_file = method->GetDexFile();
if (!IsSameDexFile(*outer_dex_file, *dex_file)) {
- if (method->GetDeclaringClass()->GetClassLoader() == nullptr) {
+ if (method->GetDeclaringClass()->IsBootStrapClassLoaded()) {
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
const std::vector<const DexFile*>& boot_class_path = class_linker->GetBootClassPath();
auto it = std::find_if(
@@ -269,7 +269,7 @@
ScopedObjectAccess soa(Thread::Current());
if (inline_info.GetDexPc() != static_cast<uint32_t>(-1) &&
!IsSameDexFile(*outer_dex_file, *method->GetDexFile())) {
- if (method->GetDeclaringClass()->GetClassLoader() == nullptr) {
+ if (method->GetDeclaringClass()->IsBootStrapClassLoaded()) {
CHECK_EQ(method_info.GetDexFileIndexKind(), MethodInfo::kKindBCP);
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
const std::vector<const DexFile*>& boot_class_path = class_linker->GetBootClassPath();
diff --git a/runtime/hidden_api.cc b/runtime/hidden_api.cc
index e1d0f70..54acbb4 100644
--- a/runtime/hidden_api.cc
+++ b/runtime/hidden_api.cc
@@ -684,7 +684,7 @@
// The check only applies to boot classpaths dex files.
Runtime* runtime = Runtime::Current();
if (UNLIKELY(runtime->IsAotCompiler())) {
- if (member->GetDeclaringClass()->GetClassLoader() == nullptr &&
+ if (member->GetDeclaringClass()->IsBootStrapClassLoaded() &&
runtime->GetClassLinker()->DenyAccessBasedOnPublicSdk(member)) {
return true;
}
diff --git a/runtime/jit/jit_code_cache.cc b/runtime/jit/jit_code_cache.cc
index e6be531..0b34688 100644
--- a/runtime/jit/jit_code_cache.cc
+++ b/runtime/jit/jit_code_cache.cc
@@ -326,7 +326,7 @@
const void* JitCodeCache::GetSavedEntryPointOfPreCompiledMethod(ArtMethod* method) {
if (method->IsPreCompiled()) {
const void* code_ptr = nullptr;
- if (method->GetDeclaringClass()->GetClassLoader() == nullptr) {
+ if (method->GetDeclaringClass()->IsBootStrapClassLoaded()) {
code_ptr = zygote_map_.GetCodeFor(method);
} else {
MutexLock mu(Thread::Current(), *Locks::jit_lock_);