diff options
author | 2020-02-27 21:51:29 +0000 | |
---|---|---|
committer | 2020-02-28 08:36:58 +0000 | |
commit | 6cf7a9b0ecce7057758a55d8a2a2a5f1ca4653dc (patch) | |
tree | e460c6d1a599ba65e540951f5687227779e81a87 | |
parent | e248b023113308862520ba8d42f882c6a1016dbd (diff) |
Revert "Revert "If generating an image, run initialization and other optimizations.""
This reverts commit bbec8a6fc720ee5ce572d3fb63617fb0af6addc7.
Reason for revert: Fix vdex compilation with app images.
Test: 628-vdex
Bug: 150193586
Change-Id: Ic4d0445f277caf9405c18938c1f39ee08b9bf2fd
-rw-r--r-- | compiler/driver/compiler_options.h | 4 | ||||
-rw-r--r-- | dex2oat/dex2oat.cc | 6 | ||||
-rw-r--r-- | dex2oat/driver/compiler_driver.cc | 97 | ||||
-rw-r--r-- | dex2oat/driver/compiler_driver_test.cc | 2 |
4 files changed, 59 insertions, 50 deletions
diff --git a/compiler/driver/compiler_options.h b/compiler/driver/compiler_options.h index 747205e4e5..79ba1c27c9 100644 --- a/compiler/driver/compiler_options.h +++ b/compiler/driver/compiler_options.h @@ -195,6 +195,10 @@ class CompilerOptions final { return implicit_suspend_checks_; } + bool IsGeneratingImage() const { + return IsBootImage() || IsBootImageExtension() || IsAppImage(); + } + // Are we compiling a boot image? bool IsBootImage() const { return image_type_ == ImageType::kBootImage; diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc index 0fcc6cccaa..a71dcb462b 100644 --- a/dex2oat/dex2oat.cc +++ b/dex2oat/dex2oat.cc @@ -1654,8 +1654,10 @@ class Dex2Oat final { } } - if (CompilerFilter::IsAnyCompilationEnabled(compiler_options_->GetCompilerFilter())) { - // Only modes with compilation require verification results, do this here instead of when we + if (CompilerFilter::IsAnyCompilationEnabled(compiler_options_->GetCompilerFilter()) || + IsImage()) { + // Only modes with compilation or image generation 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 diff --git a/dex2oat/driver/compiler_driver.cc b/dex2oat/driver/compiler_driver.cc index 6792a595a9..344f8009e1 100644 --- a/dex2oat/driver/compiler_driver.cc +++ b/dex2oat/driver/compiler_driver.cc @@ -887,55 +887,56 @@ void CompilerDriver::PreCompile(jobject class_loader, if (compiler_options_->AssumeClassesAreVerified()) { VLOG(compiler) << "Verify none mode specified, skipping verification."; SetVerified(class_loader, dex_files, timings); - } - - if (!compiler_options_->IsVerificationEnabled()) { - return; - } - - Verify(class_loader, dex_files, timings, verification_results); - VLOG(compiler) << "Verify: " << GetMemoryUsageString(false); - - if (GetCompilerOptions().IsForceDeterminism() && - (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension())) { - // Resolve strings from const-string. Do this now to have a deterministic image. - ResolveConstStrings(dex_files, /*only_startup_strings=*/ false, timings); - VLOG(compiler) << "Resolve const-strings: " << GetMemoryUsageString(false); - } else if (GetCompilerOptions().ResolveStartupConstStrings()) { - ResolveConstStrings(dex_files, /*only_startup_strings=*/ true, timings); - } - - if (had_hard_verifier_failure_ && GetCompilerOptions().AbortOnHardVerifierFailure()) { - // Avoid dumping threads. Even if we shut down the thread pools, there will still be three - // instances of this thread's stack. - LOG(FATAL_WITHOUT_ABORT) << "Had a hard failure verifying all classes, and was asked to abort " - << "in such situations. Please check the log."; - _exit(1); - } else if (number_of_soft_verifier_failures_ > 0 && - GetCompilerOptions().AbortOnSoftVerifierFailure()) { - LOG(FATAL_WITHOUT_ABORT) << "Had " << number_of_soft_verifier_failures_ << " soft failure(s) " - << "verifying all classes, and was asked to abort in such situations. " - << "Please check the log."; - _exit(1); - } - - if (compiler_options_->IsAnyCompilationEnabled()) { - if (kIsDebugBuild) { - EnsureVerifiedOrVerifyAtRuntime(class_loader, dex_files); + } else if (compiler_options_->IsVerificationEnabled()) { + Verify(class_loader, dex_files, timings, verification_results); + VLOG(compiler) << "Verify: " << GetMemoryUsageString(false); + + if (GetCompilerOptions().IsForceDeterminism() && + (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension())) { + // Resolve strings from const-string. Do this now to have a deterministic image. + ResolveConstStrings(dex_files, /*only_startup_strings=*/ false, timings); + VLOG(compiler) << "Resolve const-strings: " << GetMemoryUsageString(false); + } else if (GetCompilerOptions().ResolveStartupConstStrings()) { + ResolveConstStrings(dex_files, /*only_startup_strings=*/ true, timings); + } + + if (had_hard_verifier_failure_ && GetCompilerOptions().AbortOnHardVerifierFailure()) { + // Avoid dumping threads. Even if we shut down the thread pools, there will still be three + // instances of this thread's stack. + LOG(FATAL_WITHOUT_ABORT) << "Had a hard failure verifying all classes, and was asked to abort " + << "in such situations. Please check the log."; + _exit(1); + } else if (number_of_soft_verifier_failures_ > 0 && + GetCompilerOptions().AbortOnSoftVerifierFailure()) { + LOG(FATAL_WITHOUT_ABORT) << "Had " << number_of_soft_verifier_failures_ << " soft failure(s) " + << "verifying all classes, and was asked to abort in such situations. " + << "Please check the log."; + _exit(1); + } + } + + if (GetCompilerOptions().IsGeneratingImage()) { + // We can only initialize classes when their verification bit is set. + if (compiler_options_->AssumeClassesAreVerified() || + compiler_options_->IsVerificationEnabled()) { + if (kIsDebugBuild) { + EnsureVerifiedOrVerifyAtRuntime(class_loader, dex_files); + } + InitializeClasses(class_loader, dex_files, timings); + VLOG(compiler) << "InitializeClasses: " << GetMemoryUsageString(false); } - InitializeClasses(class_loader, dex_files, timings); - VLOG(compiler) << "InitializeClasses: " << GetMemoryUsageString(false); - } - UpdateImageClasses(timings, image_classes); - VLOG(compiler) << "UpdateImageClasses: " << GetMemoryUsageString(false); + UpdateImageClasses(timings, image_classes); + VLOG(compiler) << "UpdateImageClasses: " << GetMemoryUsageString(false); - if (kBitstringSubtypeCheckEnabled && - GetCompilerOptions().IsForceDeterminism() && GetCompilerOptions().IsBootImage()) { - // Initialize type check bit string used by check-cast and instanceof. - // Do this now to have a deterministic image. - // Note: This is done after UpdateImageClasses() at it relies on the image classes to be final. - InitializeTypeCheckBitstrings(this, dex_files, timings); + if (kBitstringSubtypeCheckEnabled && + GetCompilerOptions().IsForceDeterminism() && GetCompilerOptions().IsBootImage()) { + // Initialize type check bit string used by check-cast and instanceof. + // Do this now to have a deterministic image. + // Note: This is done after UpdateImageClasses() at it relies on the image + // classes to be final. + InitializeTypeCheckBitstrings(this, dex_files, timings); + } } } @@ -1785,7 +1786,9 @@ bool CompilerDriver::FastVerify(jobject jclass_loader, return false; } - bool compiler_only_verifies = !GetCompilerOptions().IsAnyCompilationEnabled(); + bool compiler_only_verifies = + !GetCompilerOptions().IsAnyCompilationEnabled() && + !GetCompilerOptions().IsGeneratingImage(); // We successfully validated the dependencies, now update class status // of verified classes. Note that the dependencies also record which classes diff --git a/dex2oat/driver/compiler_driver_test.cc b/dex2oat/driver/compiler_driver_test.cc index 0a9702b330..50cb292a4d 100644 --- a/dex2oat/driver/compiler_driver_test.cc +++ b/dex2oat/driver/compiler_driver_test.cc @@ -308,7 +308,7 @@ class CompilerDriverVerifyTest : public CompilerDriverTest { bool found = compiler_driver_->GetCompiledClass( ClassReference(&klass->GetDexFile(), klass->GetDexTypeIndex().index_), &status); ASSERT_TRUE(found); - EXPECT_EQ(status, ClassStatus::kVerified); + EXPECT_GE(status, ClassStatus::kVerified); } }; |