Move dex_files_for_oat_file_ to CompilerOptions.
A step toward removing the CompilerDriver dependency from
several classes, including HSharpening and ImageWriter.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Change-Id: I364ef66511fdf855cb11b12c818a40572b037727
diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc
index 7491173..52c767f 100644
--- a/compiler/common_compiler_test.cc
+++ b/compiler/common_compiler_test.cc
@@ -40,6 +40,7 @@
#include "oat_quick_method_header.h"
#include "scoped_thread_state_change-inl.h"
#include "thread-current-inl.h"
+#include "utils/atomic_dex_ref_map-inl.h"
namespace art {
@@ -332,4 +333,10 @@
image_reservation_.reset();
}
+void CommonCompilerTest::SetDexFilesForOatFile(const std::vector<const DexFile*>& dex_files) {
+ compiler_options_->dex_files_for_oat_file_ = dex_files;
+ compiler_driver_->compiled_classes_.AddDexFiles(dex_files);
+ compiler_driver_->dex_to_dex_compiler_.SetDexFiles(dex_files);
+}
+
} // namespace art
diff --git a/compiler/common_compiler_test.h b/compiler/common_compiler_test.h
index 46b59a3..f070bbb 100644
--- a/compiler/common_compiler_test.h
+++ b/compiler/common_compiler_test.h
@@ -33,6 +33,7 @@
class CompilerDriver;
class CompilerOptions;
class CumulativeLogger;
+class DexFile;
class ProfileCompilationInfo;
class VerificationResults;
@@ -93,6 +94,8 @@
void UnreserveImageSpace();
+ void SetDexFilesForOatFile(const std::vector<const DexFile*>& dex_files);
+
Compiler::Kind compiler_kind_ = Compiler::kOptimizing;
std::unique_ptr<CompilerOptions> compiler_options_;
std::unique_ptr<VerificationResults> verification_results_;
diff --git a/compiler/dex/dex_to_dex_decompiler_test.cc b/compiler/dex/dex_to_dex_decompiler_test.cc
index 76250d2..4f83d60 100644
--- a/compiler/dex/dex_to_dex_decompiler_test.cc
+++ b/compiler/dex/dex_to_dex_decompiler_test.cc
@@ -47,7 +47,7 @@
// the results for all the dex files, not just the results for the current dex file.
down_cast<QuickCompilerCallbacks*>(Runtime::Current()->GetCompilerCallbacks())->SetVerifierDeps(
new verifier::VerifierDeps(GetDexFiles(class_loader)));
- compiler_driver_->SetDexFilesForOatFile(GetDexFiles(class_loader));
+ SetDexFilesForOatFile(GetDexFiles(class_loader));
compiler_driver_->CompileAll(class_loader, GetDexFiles(class_loader), &timings);
}
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index ed4fb6f..66a8a57 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -885,8 +885,12 @@
const std::vector<const DexFile*>& dex_files,
TimingLogger* timings) {
CheckThreadPools();
+
VLOG(compiler) << "Before precompile " << GetMemoryUsageString(false);
+ compiled_classes_.AddDexFiles(GetCompilerOptions().GetDexFilesForOatFile());
+ dex_to_dex_compiler_.SetDexFiles(GetCompilerOptions().GetDexFilesForOatFile());
+
// Precompile:
// 1) Load image classes.
// 2) Resolve all classes.
@@ -1948,7 +1952,8 @@
// Create per-thread VerifierDeps to avoid contention on the main one.
// We will merge them after verification.
for (ThreadPoolWorker* worker : parallel_thread_pool_->GetWorkers()) {
- worker->GetThread()->SetVerifierDeps(new verifier::VerifierDeps(dex_files_for_oat_file_));
+ worker->GetThread()->SetVerifierDeps(
+ new verifier::VerifierDeps(GetCompilerOptions().GetDexFilesForOatFile()));
}
}
@@ -1973,7 +1978,7 @@
for (ThreadPoolWorker* worker : parallel_thread_pool_->GetWorkers()) {
verifier::VerifierDeps* thread_deps = worker->GetThread()->GetVerifierDeps();
worker->GetThread()->SetVerifierDeps(nullptr);
- verifier_deps->MergeWith(*thread_deps, dex_files_for_oat_file_);
+ verifier_deps->MergeWith(*thread_deps, GetCompilerOptions().GetDexFilesForOatFile());
delete thread_deps;
}
Thread::Current()->SetVerifierDeps(nullptr);
@@ -2846,7 +2851,7 @@
if (kIsDebugBuild) {
// Check to make sure it's not a dex file for an oat file we are compiling since these
// should always succeed. These do not include classes in for used libraries.
- for (const DexFile* dex_file : GetDexFilesForOatFile()) {
+ for (const DexFile* dex_file : GetCompilerOptions().GetDexFilesForOatFile()) {
CHECK_NE(ref.dex_file, dex_file) << ref.dex_file->GetLocation();
}
}
@@ -2945,17 +2950,6 @@
return oss.str();
}
-bool CompilerDriver::MayInlineInternal(const DexFile* inlined_from,
- const DexFile* inlined_into) const {
- // We're not allowed to inline across dex files if we're the no-inline-from dex file.
- if (inlined_from != inlined_into &&
- ContainsElement(compiler_options_->GetNoInlineFromDexFile(), inlined_from)) {
- return false;
- }
-
- return true;
-}
-
void CompilerDriver::InitializeThreadPools() {
size_t parallel_count = parallel_thread_count_ > 0 ? parallel_thread_count_ - 1 : 0;
parallel_thread_pool_.reset(
@@ -2968,12 +2962,6 @@
single_thread_pool_.reset();
}
-void CompilerDriver::SetDexFilesForOatFile(const std::vector<const DexFile*>& dex_files) {
- dex_files_for_oat_file_ = dex_files;
- compiled_classes_.AddDexFiles(dex_files);
- dex_to_dex_compiler_.SetDexFiles(dex_files);
-}
-
void CompilerDriver::SetClasspathDexFiles(const std::vector<const DexFile*>& dex_files) {
classpath_classes_.AddDexFiles(dex_files);
}
diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h
index 36e93a8..54e1f37 100644
--- a/compiler/driver/compiler_driver.h
+++ b/compiler/driver/compiler_driver.h
@@ -106,17 +106,9 @@
~CompilerDriver();
- // Set dex files associated with the oat file being compiled.
- void SetDexFilesForOatFile(const std::vector<const DexFile*>& dex_files);
-
// Set dex files classpath.
void SetClasspathDexFiles(const std::vector<const DexFile*>& dex_files);
- // Get dex files associated with the the oat file being compiled.
- ArrayRef<const DexFile* const> GetDexFilesForOatFile() const {
- return ArrayRef<const DexFile* const>(dex_files_for_oat_file_);
- }
-
void CompileAll(jobject class_loader,
const std::vector<const DexFile*>& dex_files,
TimingLogger* timings)
@@ -354,13 +346,6 @@
bool CanAssumeClassIsLoaded(mirror::Class* klass)
REQUIRES_SHARED(Locks::mutator_lock_);
- bool MayInline(const DexFile* inlined_from, const DexFile* inlined_into) const {
- if (!kIsTargetBuild) {
- return MayInlineInternal(inlined_from, inlined_into);
- }
- return true;
- }
-
const ProfileCompilationInfo* GetProfileCompilationInfo() const {
return profile_compilation_info_;
}
@@ -454,8 +439,6 @@
const std::vector<const DexFile*>& dex_files,
TimingLogger* timings);
- bool MayInlineInternal(const DexFile* inlined_from, const DexFile* inlined_into) const;
-
void InitializeThreadPools();
void FreeThreadPools();
void CheckThreadPools();
@@ -525,9 +508,6 @@
bool support_boot_image_fixup_;
- // List of dex files associates with the oat file.
- std::vector<const DexFile*> dex_files_for_oat_file_;
-
CompiledMethodStorage compiled_method_storage_;
// Info for profile guided compilation.
diff --git a/compiler/driver/compiler_driver_test.cc b/compiler/driver/compiler_driver_test.cc
index 491e61f..2eeb439 100644
--- a/compiler/driver/compiler_driver_test.cc
+++ b/compiler/driver/compiler_driver_test.cc
@@ -46,7 +46,7 @@
TimingLogger timings("CompilerDriverTest::CompileAll", false, false);
TimingLogger::ScopedTiming t(__FUNCTION__, &timings);
dex_files_ = GetDexFiles(class_loader);
- compiler_driver_->SetDexFilesForOatFile(dex_files_);;
+ SetDexFilesForOatFile(dex_files_);
compiler_driver_->CompileAll(class_loader, dex_files_, &timings);
t.NewTiming("MakeAllExecutable");
MakeAllExecutable(class_loader);
@@ -331,7 +331,7 @@
ASSERT_GT(dex_files.size(), 0u);
dex_file = dex_files.front();
}
- compiler_driver_->SetDexFilesForOatFile(dex_files);
+ SetDexFilesForOatFile(dex_files);
callbacks_->SetDoesClassUnloading(true, compiler_driver_.get());
ClassReference ref(dex_file, 0u);
// Test that the status is read from the compiler driver as expected.
diff --git a/compiler/driver/compiler_options.cc b/compiler/driver/compiler_options.cc
index 3d37b68..cc1af3e 100644
--- a/compiler/driver/compiler_options.cc
+++ b/compiler/driver/compiler_options.cc
@@ -38,6 +38,7 @@
num_dex_methods_threshold_(kDefaultNumDexMethodsThreshold),
inline_max_code_units_(kUnsetInlineMaxCodeUnits),
no_inline_from_(),
+ dex_files_for_oat_file_(),
image_classes_(),
boot_image_(false),
core_image_(false),
diff --git a/compiler/driver/compiler_options.h b/compiler/driver/compiler_options.h
index 0709faf..908ff33 100644
--- a/compiler/driver/compiler_options.h
+++ b/compiler/driver/compiler_options.h
@@ -235,6 +235,10 @@
return no_inline_from_;
}
+ const std::vector<const DexFile*>& GetDexFilesForOatFile() const {
+ return dex_files_for_oat_file_;
+ }
+
const HashSet<std::string>& GetImageClasses() const {
return image_classes_;
}
@@ -313,6 +317,9 @@
// prefer vector<> over a lookup-oriented container, such as set<>.
std::vector<const DexFile*> no_inline_from_;
+ // List of dex files associated with the oat file, empty for JIT.
+ std::vector<const DexFile*> dex_files_for_oat_file_;
+
// Image classes, specifies the classes that will be included in the image if creating an image.
// Must not be empty for real boot image, only for tests pretending to compile boot image.
HashSet<std::string> image_classes_;
diff --git a/compiler/optimizing/inliner.cc b/compiler/optimizing/inliner.cc
index 7dd756e..72d53d2 100644
--- a/compiler/optimizing/inliner.cc
+++ b/compiler/optimizing/inliner.cc
@@ -126,7 +126,7 @@
}
bool HInliner::Run() {
- if (compiler_driver_->GetCompilerOptions().GetInlineMaxCodeUnits() == 0) {
+ if (codegen_->GetCompilerOptions().GetInlineMaxCodeUnits() == 0) {
// Inlining effectively disabled.
return false;
} else if (graph_->IsDebuggable()) {
@@ -731,7 +731,7 @@
offline_profile.dex_references.size());
for (size_t i = 0; i < offline_profile.dex_references.size(); i++) {
bool found = false;
- for (const DexFile* dex_file : compiler_driver_->GetDexFilesForOatFile()) {
+ for (const DexFile* dex_file : codegen_->GetCompilerOptions().GetDexFilesForOatFile()) {
if (offline_profile.dex_references[i].MatchesDex(dex_file)) {
dex_profile_index_to_dex_cache[i] =
caller_compilation_unit_.GetClassLinker()->FindDexCache(self, *dex_file);
@@ -1418,6 +1418,22 @@
return count;
}
+static inline bool MayInline(const CompilerOptions& compiler_options,
+ const DexFile& inlined_from,
+ const DexFile& inlined_into) {
+ if (kIsTargetBuild) {
+ return true;
+ }
+
+ // We're not allowed to inline across dex files if we're the no-inline-from dex file.
+ if (!IsSameDexFile(inlined_from, inlined_into) &&
+ ContainsElement(compiler_options.GetNoInlineFromDexFile(), &inlined_from)) {
+ return false;
+ }
+
+ return true;
+}
+
bool HInliner::TryBuildAndInline(HInvoke* invoke_instruction,
ArtMethod* method,
ReferenceTypeInfo receiver_type,
@@ -1439,8 +1455,9 @@
// Check whether we're allowed to inline. The outermost compilation unit is the relevant
// dex file here (though the transitivity of an inline chain would allow checking the calller).
- if (!compiler_driver_->MayInline(method->GetDexFile(),
- outer_compilation_unit_.GetDexFile())) {
+ if (!MayInline(codegen_->GetCompilerOptions(),
+ *method->GetDexFile(),
+ *outer_compilation_unit_.GetDexFile())) {
if (TryPatternSubstitution(invoke_instruction, method, return_replacement)) {
LOG_SUCCESS() << "Successfully replaced pattern of invoke "
<< method->PrettyMethod();
@@ -1465,7 +1482,7 @@
return false;
}
- size_t inline_max_code_units = compiler_driver_->GetCompilerOptions().GetInlineMaxCodeUnits();
+ size_t inline_max_code_units = codegen_->GetCompilerOptions().GetInlineMaxCodeUnits();
if (accessor.InsnsSizeInCodeUnits() > inline_max_code_units) {
LOG_FAIL(stats_, MethodCompilationStat::kNotInlinedCodeItem)
<< "Method " << method->PrettyMethod()
diff --git a/compiler/optimizing/sharpening.cc b/compiler/optimizing/sharpening.cc
index ebac3f6..1e29c21 100644
--- a/compiler/optimizing/sharpening.cc
+++ b/compiler/optimizing/sharpening.cc
@@ -191,14 +191,14 @@
desired_load_kind = HLoadClass::LoadKind::kBootImageLinkTimePcRelative;
} else {
// Not a boot image class.
- DCHECK(ContainsElement(compiler_driver->GetDexFilesForOatFile(), &dex_file));
+ DCHECK(ContainsElement(compiler_options.GetDexFilesForOatFile(), &dex_file));
desired_load_kind = HLoadClass::LoadKind::kBssEntry;
}
} else {
is_in_boot_image = (klass != nullptr) &&
runtime->GetHeap()->ObjectIsInBootImageSpace(klass.Get());
if (runtime->UseJitCompilation()) {
- DCHECK(!codegen->GetCompilerOptions().GetCompilePic());
+ DCHECK(!compiler_options.GetCompilePic());
if (is_in_boot_image) {
// TODO: Use direct pointers for all non-moving spaces, not just boot image. Bug: 29530787
desired_load_kind = HLoadClass::LoadKind::kBootImageAddress;
@@ -331,14 +331,15 @@
: hs.NewHandle(class_linker->FindDexCache(soa.Self(), dex_file));
ObjPtr<mirror::String> string = nullptr;
- if (codegen->GetCompilerOptions().IsBootImage()) {
+ const CompilerOptions& compiler_options = codegen->GetCompilerOptions();
+ if (compiler_options.IsBootImage()) {
// Compiling boot image. Resolve the string and allocate it if needed, to ensure
// the string will be added to the boot image.
DCHECK(!runtime->UseJitCompilation());
string = class_linker->ResolveString(string_index, dex_cache);
CHECK(string != nullptr);
if (compiler_driver->GetSupportBootImageFixup()) {
- DCHECK(ContainsElement(compiler_driver->GetDexFilesForOatFile(), &dex_file));
+ DCHECK(ContainsElement(compiler_options.GetDexFilesForOatFile(), &dex_file));
desired_load_kind = HLoadString::LoadKind::kBootImageLinkTimePcRelative;
} else {
// compiler_driver_test. Do not sharpen.
diff --git a/compiler/verifier_deps_test.cc b/compiler/verifier_deps_test.cc
index 3fe2ec0..c223549 100644
--- a/compiler/verifier_deps_test.cc
+++ b/compiler/verifier_deps_test.cc
@@ -129,7 +129,7 @@
for (const DexFile* dex_file : dex_files_) {
compiler_driver_->GetVerificationResults()->AddDexFile(dex_file);
}
- compiler_driver_->SetDexFilesForOatFile(dex_files_);
+ SetDexFilesForOatFile(dex_files_);
}
void LoadDexFile(ScopedObjectAccess& soa) REQUIRES_SHARED(Locks::mutator_lock_) {