Refactor CompilerDriver::CompileAll().
Treat verification results and image classes as mutable
only in CompilerDriver::PreCompile(), and treat them as
immutable during compilation, accessed through the
CompilerOptions. This severs the dependency of the inliner
on the CompilerDriver.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Change-Id: I594a0213ca6a5003c19b4bd488af98db4358d51d
diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc
index 66421e2..be6da71 100644
--- a/compiler/common_compiler_test.cc
+++ b/compiler/common_compiler_test.cc
@@ -22,6 +22,7 @@
#include "art_field-inl.h"
#include "art_method-inl.h"
#include "base/callee_save_type.h"
+#include "base/casts.h"
#include "base/enums.h"
#include "base/utils.h"
#include "class_linker.h"
@@ -152,6 +153,10 @@
CreateCompilerDriver();
}
+ // Note: We cannot use MemMap because some tests tear down the Runtime and destroy
+ // the gMaps, so when destroying the MemMap, the test would crash.
+ inaccessible_page_ = mmap(nullptr, kPageSize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ CHECK(inaccessible_page_ != MAP_FAILED) << strerror(errno);
}
void CommonCompilerTest::ApplyInstructionSet() {
@@ -190,9 +195,7 @@
compiler_options_->image_classes_.swap(*GetImageClasses());
compiler_options_->profile_compilation_info_ = GetProfileCompilationInfo();
compiler_driver_.reset(new CompilerDriver(compiler_options_.get(),
- verification_results_.get(),
compiler_kind_,
- &compiler_options_->image_classes_,
number_of_threads_,
/* swap_fd */ -1));
}
@@ -222,6 +225,10 @@
verification_results_.reset();
compiler_options_.reset();
image_reservation_.Reset();
+ if (inaccessible_page_ != nullptr) {
+ munmap(inaccessible_page_, kPageSize);
+ inaccessible_page_ = nullptr;
+ }
CommonRuntimeTest::TearDown();
}
@@ -267,8 +274,16 @@
compiler_driver_->InitializeThreadPools();
- compiler_driver_->PreCompile(class_loader, dex_files, &timings);
+ compiler_driver_->PreCompile(class_loader,
+ dex_files,
+ &timings,
+ &compiler_options_->image_classes_,
+ verification_results_.get());
+ // Verification results in the `callback_` should not be used during compilation.
+ down_cast<QuickCompilerCallbacks*>(callbacks_.get())->SetVerificationResults(
+ reinterpret_cast<VerificationResults*>(inaccessible_page_));
+ compiler_options_->verification_results_ = verification_results_.get();
compiler_driver_->CompileOne(self,
class_loader,
*dex_file,
@@ -279,6 +294,9 @@
code_item,
dex_cache,
h_class_loader);
+ compiler_options_->verification_results_ = nullptr;
+ down_cast<QuickCompilerCallbacks*>(callbacks_.get())->SetVerificationResults(
+ verification_results_.get());
compiler_driver_->FreeThreadPools();
@@ -334,6 +352,32 @@
CHECK(image_reservation_.IsValid()) << error_msg;
}
+void CommonCompilerTest::CompileAll(jobject class_loader,
+ const std::vector<const DexFile*>& dex_files,
+ TimingLogger* timings) {
+ TimingLogger::ScopedTiming t(__FUNCTION__, timings);
+ SetDexFilesForOatFile(dex_files);
+
+ compiler_driver_->InitializeThreadPools();
+
+ compiler_driver_->PreCompile(class_loader,
+ dex_files,
+ timings,
+ &compiler_options_->image_classes_,
+ verification_results_.get());
+
+ // Verification results in the `callback_` should not be used during compilation.
+ down_cast<QuickCompilerCallbacks*>(callbacks_.get())->SetVerificationResults(
+ reinterpret_cast<VerificationResults*>(inaccessible_page_));
+ compiler_options_->verification_results_ = verification_results_.get();
+ compiler_driver_->CompileAll(class_loader, dex_files, timings);
+ compiler_options_->verification_results_ = nullptr;
+ down_cast<QuickCompilerCallbacks*>(callbacks_.get())->SetVerificationResults(
+ verification_results_.get());
+
+ compiler_driver_->FreeThreadPools();
+}
+
void CommonCompilerTest::UnreserveImageSpace() {
image_reservation_.Reset();
}