summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Mathieu Chartier <mathieuc@google.com> 2017-07-19 16:55:04 -0700
committer Mathieu Chartier <mathieuc@google.com> 2017-07-20 09:36:26 -0700
commite01b6f674a865a3aef7d66cd91a2d2e226587b50 (patch)
tree1d99c6889746d829a86b375b3d88552f29461b7e
parente8f48da635c4d07bbe431e5819da8e1fad91a8ef (diff)
Move IsVeryLarge check before we create verification results
Otherwise we can end up creating verification results when they are not actually needed (if the compiler filter was >= quicken). Bug: 63467744 Test: test-art-host Change-Id: Ied2a12e0e4c2010f3f660e278c3a5111545ba251
-rw-r--r--compiler/common_compiler_test.cc6
-rw-r--r--compiler/dex/quick_compiler_callbacks.h13
-rw-r--r--compiler/image_test.h7
-rw-r--r--compiler/oat_test.cc4
-rw-r--r--dex2oat/dex2oat.cc44
5 files changed, 43 insertions, 31 deletions
diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc
index 3683695a1b..120389803a 100644
--- a/compiler/common_compiler_test.cc
+++ b/compiler/common_compiler_test.cc
@@ -207,8 +207,10 @@ void CommonCompilerTest::SetUpRuntimeOptions(RuntimeOptions* options) {
compiler_options_.reset(new CompilerOptions);
verification_results_.reset(new VerificationResults(compiler_options_.get()));
- callbacks_.reset(new QuickCompilerCallbacks(verification_results_.get(),
- CompilerCallbacks::CallbackMode::kCompileApp));
+ QuickCompilerCallbacks* callbacks =
+ new QuickCompilerCallbacks(CompilerCallbacks::CallbackMode::kCompileApp);
+ callbacks->SetVerificationResults(verification_results_.get());
+ callbacks_.reset(callbacks);
}
Compiler::Kind CommonCompilerTest::GetCompilerKind() const {
diff --git a/compiler/dex/quick_compiler_callbacks.h b/compiler/dex/quick_compiler_callbacks.h
index 2100522f10..a3a6c0972c 100644
--- a/compiler/dex/quick_compiler_callbacks.h
+++ b/compiler/dex/quick_compiler_callbacks.h
@@ -26,11 +26,8 @@ class VerificationResults;
class QuickCompilerCallbacks FINAL : public CompilerCallbacks {
public:
- QuickCompilerCallbacks(VerificationResults* verification_results,
- CompilerCallbacks::CallbackMode mode)
- : CompilerCallbacks(mode),
- verification_results_(verification_results),
- verifier_deps_(nullptr) {}
+ explicit QuickCompilerCallbacks(CompilerCallbacks::CallbackMode mode)
+ : CompilerCallbacks(mode) {}
~QuickCompilerCallbacks() { }
@@ -52,8 +49,12 @@ class QuickCompilerCallbacks FINAL : public CompilerCallbacks {
verifier_deps_.reset(deps);
}
+ void SetVerificationResults(VerificationResults* verification_results) {
+ verification_results_ = verification_results;
+ }
+
private:
- VerificationResults* const verification_results_;
+ VerificationResults* verification_results_ = nullptr;
std::unique_ptr<verifier::VerifierDeps> verifier_deps_;
};
diff --git a/compiler/image_test.h b/compiler/image_test.h
index fa714ada6c..6c3a89b7a2 100644
--- a/compiler/image_test.h
+++ b/compiler/image_test.h
@@ -84,9 +84,10 @@ class ImageTest : public CommonCompilerTest {
void SetUpRuntimeOptions(RuntimeOptions* options) OVERRIDE {
CommonCompilerTest::SetUpRuntimeOptions(options);
- callbacks_.reset(new QuickCompilerCallbacks(
- verification_results_.get(),
- CompilerCallbacks::CallbackMode::kCompileBootImage));
+ QuickCompilerCallbacks* new_callbacks =
+ new QuickCompilerCallbacks(CompilerCallbacks::CallbackMode::kCompileBootImage);
+ new_callbacks->SetVerificationResults(verification_results_.get());
+ callbacks_.reset(new_callbacks);
options->push_back(std::make_pair("compilercallbacks", callbacks_.get()));
}
diff --git a/compiler/oat_test.cc b/compiler/oat_test.cc
index 910d7a7c54..6f8904979d 100644
--- a/compiler/oat_test.cc
+++ b/compiler/oat_test.cc
@@ -104,8 +104,8 @@ class OatTest : public CommonCompilerTest {
compiler_options_->ParseCompilerOption(option, Usage);
}
verification_results_.reset(new VerificationResults(compiler_options_.get()));
- callbacks_.reset(new QuickCompilerCallbacks(verification_results_.get(),
- CompilerCallbacks::CallbackMode::kCompileApp));
+ callbacks_.reset(new QuickCompilerCallbacks(CompilerCallbacks::CallbackMode::kCompileApp));
+ callbacks_->SetVerificationResults(verification_results_.get());
Runtime::Current()->SetCompilerCallbacks(callbacks_.get());
timer_.reset(new CumulativeLogger("Compilation times"));
compiler_driver_.reset(new CompilerDriver(compiler_options_.get(),
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 0ef496f6c8..ea74f29b78 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -1520,12 +1520,11 @@ class Dex2Oat FINAL {
return dex2oat::ReturnCode::kOther;
}
- if (CompilerFilter::IsAnyCompilationEnabled(compiler_options_->GetCompilerFilter())) {
- // Only modes with compilation require verification results.
- verification_results_.reset(new VerificationResults(compiler_options_.get()));
- }
+ // Verification results are null since we don't know if we will need them yet as the compler
+ // filter may change.
+ // This needs to be done before PrepareRuntimeOptions since the callbacks are passed to the
+ // runtime.
callbacks_.reset(new QuickCompilerCallbacks(
- verification_results_.get(),
IsBootImage() ?
CompilerCallbacks::CallbackMode::kCompileBootImage :
CompilerCallbacks::CallbackMode::kCompileApp));
@@ -1662,6 +1661,28 @@ class Dex2Oat FINAL {
dex_files_ = MakeNonOwningPointerVector(opened_dex_files_);
+ // If we need to downgrade the compiler-filter for size reasons.
+ if (!IsBootImage() && IsVeryLarge(dex_files_)) {
+ if (!CompilerFilter::IsAsGoodAs(kLargeAppFilter, compiler_options_->GetCompilerFilter())) {
+ LOG(INFO) << "Very large app, downgrading to verify.";
+ // Note: this change won't be reflected in the key-value store, as that had to be
+ // finalized before loading the dex files. This setup is currently required
+ // to get the size from the DexFile objects.
+ // TODO: refactor. b/29790079
+ compiler_options_->SetCompilerFilter(kLargeAppFilter);
+ }
+ }
+
+ if (CompilerFilter::IsAnyCompilationEnabled(compiler_options_->GetCompilerFilter())) {
+ // Only modes with compilation require verification results, do this here instead of when we
+ // create the compilation callbacks since the compilation mode may have been changed by the
+ // very large app logic.
+ // Avoiding setting the verification results saves RAM by not adding the dex files later in
+ // the function.
+ verification_results_.reset(new VerificationResults(compiler_options_.get()));
+ callbacks_->SetVerificationResults(verification_results_.get());
+ }
+
// We had to postpone the swap decision till now, as this is the point when we actually
// know about the dex files we're going to use.
@@ -1678,19 +1699,6 @@ class Dex2Oat FINAL {
}
}
// Note that dex2oat won't close the swap_fd_. The compiler driver's swap space will do that.
-
- // If we need to downgrade the compiler-filter for size reasons, do that check now.
- if (!IsBootImage() && IsVeryLarge(dex_files_)) {
- if (!CompilerFilter::IsAsGoodAs(kLargeAppFilter, compiler_options_->GetCompilerFilter())) {
- LOG(INFO) << "Very large app, downgrading to verify.";
- // Note: this change won't be reflected in the key-value store, as that had to be
- // finalized before loading the dex files. This setup is currently required
- // to get the size from the DexFile objects.
- // TODO: refactor. b/29790079
- compiler_options_->SetCompilerFilter(kLargeAppFilter);
- }
- }
-
if (IsBootImage()) {
// For boot image, pass opened dex files to the Runtime::Create().
// Note: Runtime acquires ownership of these dex files.