From d1472a27e856ec68ab5a27abaaebe9c61d91d343 Mon Sep 17 00:00:00 2001 From: Richard Uhler Date: Fri, 15 Apr 2016 15:18:56 -0700 Subject: [PATCH] profile_changed should not effect GetBestOatFile. This change moves the check for whether a profile changed from GetBestOatFile to GetDexOptStatus, because profile_changed should not effect what oat files are loaded. Test: OatFileAssistantTest.ProfileOatUpToDate Change-Id: Iafd12677f20d2844809337d1d83b688f17461cc0 --- dex2oat/dex2oat.cc | 2 +- runtime/native/dalvik_system_DexFile.cc | 7 +- runtime/oat_file_assistant.cc | 54 +++++++------- runtime/oat_file_assistant.h | 30 ++++---- runtime/oat_file_assistant_test.cc | 127 +++++++++++++------------------- runtime/oat_file_manager.cc | 3 +- 6 files changed, 100 insertions(+), 123 deletions(-) diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc index c13398023..8d20e5bff 100644 --- a/dex2oat/dex2oat.cc +++ b/dex2oat/dex2oat.cc @@ -2038,7 +2038,7 @@ class Dex2Oat FINAL { location.c_str(), location.c_str(), kVerifyChecksum, &error_msg, opened_dex_files)) { // If we fail to open the dex file because it's been stripped, try to open the dex file // from its corresponding oat file. - OatFileAssistant oat_file_assistant(location.c_str(), isa, false, false); + OatFileAssistant oat_file_assistant(location.c_str(), isa, false); std::unique_ptr oat_file(oat_file_assistant.GetBestOatFile()); if (oat_file == nullptr) { LOG(WARNING) << "Failed to open dex file and associated oat file for '" << location diff --git a/runtime/native/dalvik_system_DexFile.cc b/runtime/native/dalvik_system_DexFile.cc index 46be5e6c8..d4ad0ea0b 100644 --- a/runtime/native/dalvik_system_DexFile.cc +++ b/runtime/native/dalvik_system_DexFile.cc @@ -378,13 +378,13 @@ static jint GetDexOptNeeded(JNIEnv* env, // TODO: Verify the dex location is well formed, and throw an IOException if // not? - OatFileAssistant oat_file_assistant(filename, target_instruction_set, profile_changed, false); + OatFileAssistant oat_file_assistant(filename, target_instruction_set, false); // Always treat elements of the bootclasspath as up-to-date. if (oat_file_assistant.IsInBootClassPath()) { return OatFileAssistant::kNoDexOptNeeded; } - return oat_file_assistant.GetDexOptNeeded(filter); + return oat_file_assistant.GetDexOptNeeded(filter, profile_changed); } static jstring DexFile_getDexFileStatus(JNIEnv* env, @@ -411,7 +411,6 @@ static jstring DexFile_getDexFileStatus(JNIEnv* env, } OatFileAssistant oat_file_assistant(filename.c_str(), target_instruction_set, - false /* profile_changed */, false /* load_executable */); std::ostringstream status; @@ -486,7 +485,7 @@ static jboolean DexFile_isDexOptNeeded(JNIEnv* env, jclass, jstring javaFilename return JNI_FALSE; } - OatFileAssistant oat_file_assistant(filename, kRuntimeISA, false, false); + OatFileAssistant oat_file_assistant(filename, kRuntimeISA, false); return oat_file_assistant.IsUpToDate() ? JNI_FALSE : JNI_TRUE; } diff --git a/runtime/oat_file_assistant.cc b/runtime/oat_file_assistant.cc index 57c7d4ced..a70d65ade 100644 --- a/runtime/oat_file_assistant.cc +++ b/runtime/oat_file_assistant.cc @@ -64,17 +64,15 @@ std::ostream& operator << (std::ostream& stream, const OatFileAssistant::OatStat OatFileAssistant::OatFileAssistant(const char* dex_location, const InstructionSet isa, - bool profile_changed, bool load_executable) - : OatFileAssistant(dex_location, nullptr, isa, profile_changed, load_executable) + : OatFileAssistant(dex_location, nullptr, isa, load_executable) { } OatFileAssistant::OatFileAssistant(const char* dex_location, const char* oat_location, const InstructionSet isa, - bool profile_changed, bool load_executable) - : isa_(isa), profile_changed_(profile_changed), load_executable_(load_executable) { + : isa_(isa), load_executable_(load_executable) { CHECK(dex_location != nullptr) << "OatFileAssistant: null dex location"; dex_location_.assign(dex_location); @@ -134,29 +132,43 @@ bool OatFileAssistant::Lock(std::string* error_msg) { return true; } -bool OatFileAssistant::OatFileCompilerFilterIsOkay(CompilerFilter::Filter target) { +static bool GivenOatFileCompilerFilterIsOkay(const OatFile& oat_file, + CompilerFilter::Filter target, + bool profile_changed) { + CompilerFilter::Filter current = oat_file.GetCompilerFilter(); + + if (profile_changed && CompilerFilter::DependsOnProfile(current)) { + VLOG(oat) << "Compiler filter not okay because Profile changed"; + return false; + } + return CompilerFilter::IsAsGoodAs(current, target); +} + +bool OatFileAssistant::OatFileCompilerFilterIsOkay(CompilerFilter::Filter target, + bool profile_changed) { const OatFile* oat_file = GetOatFile(); if (oat_file != nullptr) { - CompilerFilter::Filter current = oat_file->GetCompilerFilter(); - return CompilerFilter::IsAsGoodAs(current, target); + return GivenOatFileCompilerFilterIsOkay(*oat_file, target, profile_changed); } return false; } -bool OatFileAssistant::OdexFileCompilerFilterIsOkay(CompilerFilter::Filter target) { +bool OatFileAssistant::OdexFileCompilerFilterIsOkay(CompilerFilter::Filter target, + bool profile_changed) { const OatFile* odex_file = GetOdexFile(); if (odex_file != nullptr) { - CompilerFilter::Filter current = odex_file->GetCompilerFilter(); - return CompilerFilter::IsAsGoodAs(current, target); + return GivenOatFileCompilerFilterIsOkay(*odex_file, target, profile_changed); } return false; } -OatFileAssistant::DexOptNeeded OatFileAssistant::GetDexOptNeeded(CompilerFilter::Filter target) { +OatFileAssistant::DexOptNeeded +OatFileAssistant::GetDexOptNeeded(CompilerFilter::Filter target, + bool profile_changed) { bool compilation_desired = CompilerFilter::IsBytecodeCompilationEnabled(target); // See if the oat file is in good shape as is. - bool oat_okay = OatFileCompilerFilterIsOkay(target); + bool oat_okay = OatFileCompilerFilterIsOkay(target, profile_changed); if (oat_okay) { if (compilation_desired) { if (OatFileIsUpToDate()) { @@ -170,7 +182,7 @@ OatFileAssistant::DexOptNeeded OatFileAssistant::GetDexOptNeeded(CompilerFilter: } // See if the odex file is in good shape as is. - bool odex_okay = OdexFileCompilerFilterIsOkay(target); + bool odex_okay = OdexFileCompilerFilterIsOkay(target, profile_changed); if (odex_okay) { if (compilation_desired) { if (OdexFileIsUpToDate()) { @@ -225,13 +237,13 @@ bool OatFileAssistant::IsUpToDate() { } OatFileAssistant::ResultOfAttemptToUpdate -OatFileAssistant::MakeUpToDate(std::string* error_msg) { +OatFileAssistant::MakeUpToDate(bool profile_changed, std::string* error_msg) { CompilerFilter::Filter target; if (!GetRuntimeCompilerFilterOption(&target, error_msg)) { return kUpdateNotAttempted; } - switch (GetDexOptNeeded(target)) { + switch (GetDexOptNeeded(target, profile_changed)) { case kNoDexOptNeeded: return kUpdateSucceeded; case kDex2OatNeeded: return GenerateOatFile(error_msg); case kPatchOatNeeded: return RelocateOatFile(OdexFileName(), error_msg); @@ -578,18 +590,6 @@ bool OatFileAssistant::GivenOatFileIsOutOfDate(const OatFile& file) { VLOG(oat) << "Image checksum test skipped for compiler filter " << current_compiler_filter; } - // Verify the profile hasn't changed recently. - // TODO: Move this check to OatFileCompilerFilterIsOkay? Nothing bad should - // happen if we use an oat file compiled with an out-of-date profile. - if (CompilerFilter::DependsOnProfile(current_compiler_filter)) { - if (profile_changed_) { - VLOG(oat) << "The profile has changed recently."; - return true; - } - } else { - VLOG(oat) << "Profile check skipped for compiler filter " << current_compiler_filter; - } - // Everything looks good; the dex file is not out of date. return false; } diff --git a/runtime/oat_file_assistant.h b/runtime/oat_file_assistant.h index 88bbaba02..b8fea8290 100644 --- a/runtime/oat_file_assistant.h +++ b/runtime/oat_file_assistant.h @@ -101,14 +101,10 @@ class OatFileAssistant { // device. For example, on an arm device, use arm or arm64. An oat file can // be loaded executable only if the ISA matches the current runtime. // - // profile_changed should be true if the profile has recently changed - // for this dex location. - // // load_executable should be true if the caller intends to try and load // executable code for this dex location. OatFileAssistant(const char* dex_location, const InstructionSet isa, - bool profile_changed, bool load_executable); // Constructs an OatFileAssistant, providing an explicit target oat_location @@ -116,7 +112,6 @@ class OatFileAssistant { OatFileAssistant(const char* dex_location, const char* oat_location, const InstructionSet isa, - bool profile_changed, bool load_executable); ~OatFileAssistant(); @@ -145,8 +140,10 @@ class OatFileAssistant { // Return what action needs to be taken to produce up-to-date code for this // dex location that is at least as good as an oat file generated with the - // given compiler filter. - DexOptNeeded GetDexOptNeeded(CompilerFilter::Filter target_compiler_filter); + // given compiler filter. profile_changed should be true to indicate the + // profile has recently changed for this dex location. + DexOptNeeded GetDexOptNeeded(CompilerFilter::Filter target_compiler_filter, + bool profile_changed = false); // Returns true if there is up-to-date code for this dex location, // irrespective of the compiler filter of the up-to-date code. @@ -164,11 +161,15 @@ class OatFileAssistant { // Attempts to generate or relocate the oat file as needed to make it up to // date based on the current runtime and compiler options. + // profile_changed should be true to indicate the profile has recently + // changed for this dex location. + // + // Returns the result of attempting to update the code. // // If the result is not kUpdateSucceeded, the value of error_msg will be set // to a string describing why there was a failure or the update was not // attempted. error_msg must not be null. - ResultOfAttemptToUpdate MakeUpToDate(std::string* error_msg); + ResultOfAttemptToUpdate MakeUpToDate(bool profile_changed, std::string* error_msg); // Returns an oat file that can be used for loading dex files. // Returns null if no suitable oat file was found. @@ -321,8 +322,9 @@ class OatFileAssistant { const OatFile* GetOdexFile(); // Returns true if the compiler filter used to generate the odex file is at - // least as good as the given target filter. - bool OdexFileCompilerFilterIsOkay(CompilerFilter::Filter target); + // least as good as the given target filter. profile_changed should be true + // to indicate the profile has recently changed for this dex location. + bool OdexFileCompilerFilterIsOkay(CompilerFilter::Filter target, bool profile_changed); // Returns true if the odex file is opened executable. bool OdexFileIsExecutable(); @@ -340,8 +342,9 @@ class OatFileAssistant { const OatFile* GetOatFile(); // Returns true if the compiler filter used to generate the oat file is at - // least as good as the given target filter. - bool OatFileCompilerFilterIsOkay(CompilerFilter::Filter target); + // least as good as the given target filter. profile_changed should be true + // to indicate the profile has recently changed for this dex location. + bool OatFileCompilerFilterIsOkay(CompilerFilter::Filter target, bool profile_changed); // Returns true if the oat file is opened executable. bool OatFileIsExecutable(); @@ -372,9 +375,6 @@ class OatFileAssistant { // the 32 or 64 bit variant for the current device. const InstructionSet isa_ = kNone; - // Whether the profile has recently changed. - bool profile_changed_ = false; - // Whether we will attempt to load oat files executable. bool load_executable_ = false; diff --git a/runtime/oat_file_assistant_test.cc b/runtime/oat_file_assistant_test.cc index a1d3ed924..6bccea677 100644 --- a/runtime/oat_file_assistant_test.cc +++ b/runtime/oat_file_assistant_test.cc @@ -213,7 +213,7 @@ class OatFileAssistantNoDex2OatTest : public OatFileAssistantTest { // generation of oat files. static void GenerateOatForTest(const char* dex_location, CompilerFilter::Filter filter) { // Use an oat file assistant to find the proper oat location. - OatFileAssistant ofa(dex_location, kRuntimeISA, false, false); + OatFileAssistant ofa(dex_location, kRuntimeISA, false); const std::string* oat_location = ofa.OatFileName(); ASSERT_TRUE(oat_location != nullptr); @@ -245,7 +245,7 @@ TEST_F(OatFileAssistantTest, DexNoOat) { std::string dex_location = GetScratchDir() + "/DexNoOat.jar"; Copy(GetDexSrc1(), dex_location); - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false); EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime)); @@ -275,7 +275,7 @@ TEST_F(OatFileAssistantTest, DexNoOat) { TEST_F(OatFileAssistantTest, NoDexNoOat) { std::string dex_location = GetScratchDir() + "/NoDexNoOat.jar"; - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true); EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); @@ -283,7 +283,7 @@ TEST_F(OatFileAssistantTest, NoDexNoOat) { // Trying to make the oat file up to date should not fail or crash. std::string error_msg; - EXPECT_EQ(OatFileAssistant::kUpdateSucceeded, oat_file_assistant.MakeUpToDate(&error_msg)); + EXPECT_EQ(OatFileAssistant::kUpdateSucceeded, oat_file_assistant.MakeUpToDate(false, &error_msg)); // Trying to get the best oat file should fail, but not crash. std::unique_ptr oat_file = oat_file_assistant.GetBestOatFile(); @@ -297,7 +297,7 @@ TEST_F(OatFileAssistantTest, OatUpToDate) { Copy(GetDexSrc1(), dex_location); GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false); EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); @@ -321,18 +321,23 @@ TEST_F(OatFileAssistantTest, OatUpToDate) { } // Case: We have a DEX file and speed-profile OAT file for it. -// Expect: The status is kNoDexOptNeeded if the profile hasn't changed. +// Expect: The status is kNoDexOptNeeded if the profile hasn't changed, but +// kDex2Oat if the profile has changed. TEST_F(OatFileAssistantTest, ProfileOatUpToDate) { std::string dex_location = GetScratchDir() + "/ProfileOatUpToDate.jar"; Copy(GetDexSrc1(), dex_location); GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeedProfile); - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false); EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, - oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeedProfile)); + oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeedProfile, false)); EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, - oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly)); + oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly, false)); + EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, + oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeedProfile, true)); + EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, + oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly, true)); EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); EXPECT_FALSE(oat_file_assistant.OdexFileExists()); @@ -346,32 +351,6 @@ TEST_F(OatFileAssistantTest, ProfileOatUpToDate) { EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles()); } -// Case: We have a DEX file and speed-profile OAT file for it. -// Expect: The status is kNoDex2OatNeeded if the profile has changed. -TEST_F(OatFileAssistantTest, ProfileOatOutOfDate) { - std::string dex_location = GetScratchDir() + "/ProfileOatOutOfDate.jar"; - Copy(GetDexSrc1(), dex_location); - GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeedProfile); - - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true, false); - - EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, - oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeedProfile)); - EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, - oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly)); - - EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); - EXPECT_FALSE(oat_file_assistant.OdexFileExists()); - EXPECT_TRUE(oat_file_assistant.OdexFileIsOutOfDate()); - EXPECT_FALSE(oat_file_assistant.OdexFileIsUpToDate()); - EXPECT_TRUE(oat_file_assistant.OatFileExists()); - EXPECT_TRUE(oat_file_assistant.OatFileIsOutOfDate()); - EXPECT_FALSE(oat_file_assistant.OatFileNeedsRelocation()); - EXPECT_FALSE(oat_file_assistant.OatFileIsUpToDate()); - EXPECT_EQ(OatFileAssistant::kOatOutOfDate, oat_file_assistant.OatFileStatus()); - EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles()); -} - // Case: We have a MultiDEX file and up-to-date OAT file for it. // Expect: The status is kNoDexOptNeeded and we load all dex files. TEST_F(OatFileAssistantTest, MultiDexOatUpToDate) { @@ -379,9 +358,9 @@ TEST_F(OatFileAssistantTest, MultiDexOatUpToDate) { Copy(GetMultiDexSrc1(), dex_location); GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true); EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, - oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); + oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed, false)); EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles()); // Verify we can load both dex files. @@ -406,9 +385,9 @@ TEST_F(OatFileAssistantTest, MultiDexSecondaryOutOfDate) { // is out of date. Copy(GetMultiDexSrc2(), dex_location); - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true); EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, - oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); + oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed, false)); EXPECT_TRUE(oat_file_assistant.HasOriginalDexFiles()); } @@ -435,7 +414,7 @@ TEST_F(OatFileAssistantTest, RelativeEncodedDexLocation) { // Verify we can load both dex files. OatFileAssistant oat_file_assistant(dex_location.c_str(), oat_location.c_str(), - kRuntimeISA, false, true); + kRuntimeISA, true); std::unique_ptr oat_file = oat_file_assistant.GetBestOatFile(); ASSERT_TRUE(oat_file.get() != nullptr); EXPECT_TRUE(oat_file->IsExecutable()); @@ -455,7 +434,7 @@ TEST_F(OatFileAssistantTest, OatOutOfDate) { GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); Copy(GetDexSrc2(), dex_location); - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false); EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime)); EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, @@ -482,7 +461,7 @@ TEST_F(OatFileAssistantTest, DexOdexNoOat) { GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); // Verify the status. - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false); EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime)); @@ -518,7 +497,7 @@ TEST_F(OatFileAssistantTest, StrippedDexOdexNoOat) { Copy(GetStrippedDexSrc1(), dex_location); // Verify the status. - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true); EXPECT_EQ(OatFileAssistant::kPatchOatNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); @@ -536,7 +515,7 @@ TEST_F(OatFileAssistantTest, StrippedDexOdexNoOat) { std::string error_msg; Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); ASSERT_EQ(OatFileAssistant::kUpdateSucceeded, - oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg; + oat_file_assistant.MakeUpToDate(false, &error_msg)) << error_msg; EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); @@ -577,7 +556,7 @@ TEST_F(OatFileAssistantTest, StrippedDexOdexOat) { Copy(GetStrippedDexSrc1(), dex_location); // Verify the status. - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true); EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime)); @@ -600,7 +579,7 @@ TEST_F(OatFileAssistantTest, StrippedDexOdexOat) { std::string error_msg; Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); ASSERT_EQ(OatFileAssistant::kUpdateSucceeded, - oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg; + oat_file_assistant.MakeUpToDate(false, &error_msg)) << error_msg; EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); @@ -635,7 +614,7 @@ TEST_F(OatFileAssistantTest, ResourceOnlyDex) { Copy(GetStrippedDexSrc1(), dex_location); // Verify the status. - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true); EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); @@ -658,7 +637,7 @@ TEST_F(OatFileAssistantTest, ResourceOnlyDex) { std::string error_msg; Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); EXPECT_EQ(OatFileAssistant::kUpdateSucceeded, - oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg; + oat_file_assistant.MakeUpToDate(false, &error_msg)) << error_msg; EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); @@ -686,7 +665,7 @@ TEST_F(OatFileAssistantTest, SelfRelocation) { GenerateOdexForTest(dex_location, oat_location, CompilerFilter::kSpeed); OatFileAssistant oat_file_assistant(dex_location.c_str(), - oat_location.c_str(), kRuntimeISA, false, true); + oat_location.c_str(), kRuntimeISA, true); EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly)); @@ -710,7 +689,7 @@ TEST_F(OatFileAssistantTest, SelfRelocation) { std::string error_msg; Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); ASSERT_EQ(OatFileAssistant::kUpdateSucceeded, - oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg; + oat_file_assistant.MakeUpToDate(false, &error_msg)) << error_msg; EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); @@ -746,7 +725,7 @@ TEST_F(OatFileAssistantTest, NoSelfRelocation) { GenerateNoPatchOdexForTest(dex_location, oat_location, CompilerFilter::kSpeed); OatFileAssistant oat_file_assistant(dex_location.c_str(), - oat_location.c_str(), kRuntimeISA, false, true); + oat_location.c_str(), kRuntimeISA, true); EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); @@ -755,7 +734,7 @@ TEST_F(OatFileAssistantTest, NoSelfRelocation) { std::string error_msg; Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); ASSERT_EQ(OatFileAssistant::kUpdateSucceeded, - oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg; + oat_file_assistant.MakeUpToDate(false, &error_msg)) << error_msg; EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); @@ -785,7 +764,7 @@ TEST_F(OatFileAssistantTest, OdexOatOverlap) { // Verify things don't go bad. OatFileAssistant oat_file_assistant(dex_location.c_str(), - oat_location.c_str(), kRuntimeISA, false, true); + oat_location.c_str(), kRuntimeISA, true); EXPECT_EQ(OatFileAssistant::kPatchOatNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); @@ -820,7 +799,7 @@ TEST_F(OatFileAssistantTest, DexPicOdexNoOat) { GeneratePicOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); // Verify the status. - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false); EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); @@ -848,7 +827,7 @@ TEST_F(OatFileAssistantTest, DexVerifyAtRuntimeOdexNoOat) { GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kVerifyAtRuntime); // Verify the status. - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false); EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kVerifyAtRuntime)); @@ -874,7 +853,7 @@ TEST_F(OatFileAssistantTest, LoadOatUpToDate) { GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); // Load the oat using an oat file assistant. - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true); std::unique_ptr oat_file = oat_file_assistant.GetBestOatFile(); ASSERT_TRUE(oat_file.get() != nullptr); @@ -893,7 +872,7 @@ TEST_F(OatFileAssistantTest, LoadExecInterpretOnlyOatUpToDate) { GenerateOatForTest(dex_location.c_str(), CompilerFilter::kInterpretOnly); // Load the oat using an oat file assistant. - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true); std::unique_ptr oat_file = oat_file_assistant.GetBestOatFile(); ASSERT_TRUE(oat_file.get() != nullptr); @@ -912,7 +891,7 @@ TEST_F(OatFileAssistantTest, LoadNoExecOatUpToDate) { GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); // Load the oat using an oat file assistant. - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false); std::unique_ptr oat_file = oat_file_assistant.GetBestOatFile(); ASSERT_TRUE(oat_file.get() != nullptr); @@ -932,11 +911,11 @@ TEST_F(OatFileAssistantTest, LoadDexNoAlternateOat) { Copy(GetDexSrc1(), dex_location); OatFileAssistant oat_file_assistant( - dex_location.c_str(), oat_location.c_str(), kRuntimeISA, false, true); + dex_location.c_str(), oat_location.c_str(), kRuntimeISA, true); std::string error_msg; Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); ASSERT_EQ(OatFileAssistant::kUpdateSucceeded, - oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg; + oat_file_assistant.MakeUpToDate(false, &error_msg)) << error_msg; std::unique_ptr oat_file = oat_file_assistant.GetBestOatFile(); ASSERT_TRUE(oat_file.get() != nullptr); @@ -948,7 +927,7 @@ TEST_F(OatFileAssistantTest, LoadDexNoAlternateOat) { EXPECT_TRUE(OS::FileExists(oat_location.c_str())); // Verify it didn't create an oat in the default location. - OatFileAssistant ofm(dex_location.c_str(), kRuntimeISA, false, false); + OatFileAssistant ofm(dex_location.c_str(), kRuntimeISA, false); EXPECT_FALSE(ofm.OatFileExists()); } @@ -964,11 +943,11 @@ TEST_F(OatFileAssistantTest, LoadDexUnwriteableAlternateOat) { Copy(GetDexSrc1(), dex_location); OatFileAssistant oat_file_assistant( - dex_location.c_str(), oat_location.c_str(), kRuntimeISA, false, true); + dex_location.c_str(), oat_location.c_str(), kRuntimeISA, true); std::string error_msg; Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); ASSERT_EQ(OatFileAssistant::kUpdateNotAttempted, - oat_file_assistant.MakeUpToDate(&error_msg)); + oat_file_assistant.MakeUpToDate(false, &error_msg)); std::unique_ptr oat_file = oat_file_assistant.GetBestOatFile(); ASSERT_TRUE(oat_file.get() == nullptr); @@ -981,7 +960,7 @@ TEST_F(OatFileAssistantTest, GenNoDex) { std::string oat_location = GetScratchDir() + "/GenNoDex.oat"; OatFileAssistant oat_file_assistant( - dex_location.c_str(), oat_location.c_str(), kRuntimeISA, false, true); + dex_location.c_str(), oat_location.c_str(), kRuntimeISA, true); std::string error_msg; Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); EXPECT_EQ(OatFileAssistant::kUpdateNotAttempted, @@ -1031,7 +1010,7 @@ TEST_F(OatFileAssistantTest, NonAbsoluteDexLocation) { Copy(GetDexSrc1(), abs_dex_location); std::string dex_location = MakePathRelative(abs_dex_location); - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true); EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, @@ -1049,7 +1028,7 @@ TEST_F(OatFileAssistantTest, NonAbsoluteDexLocation) { TEST_F(OatFileAssistantTest, ShortDexLocation) { std::string dex_location = "/xx"; - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true); EXPECT_FALSE(oat_file_assistant.IsInBootClassPath()); EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, @@ -1066,7 +1045,7 @@ TEST_F(OatFileAssistantTest, ShortDexLocation) { std::string error_msg; Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); EXPECT_EQ(OatFileAssistant::kUpdateSucceeded, - oat_file_assistant.MakeUpToDate(&error_msg)); + oat_file_assistant.MakeUpToDate(false, &error_msg)); EXPECT_TRUE(error_msg.empty()); } @@ -1076,7 +1055,7 @@ TEST_F(OatFileAssistantTest, LongDexExtension) { std::string dex_location = GetScratchDir() + "/LongDexExtension.jarx"; Copy(GetDexSrc1(), dex_location); - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false); EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kSpeed)); @@ -1173,7 +1152,7 @@ TEST_F(OatFileAssistantNoDex2OatTest, LoadDexOdexNoOat) { GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); // Load the oat using an executable oat file assistant. - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true); std::unique_ptr oat_file = oat_file_assistant.GetBestOatFile(); ASSERT_TRUE(oat_file.get() != nullptr); @@ -1195,7 +1174,7 @@ TEST_F(OatFileAssistantNoDex2OatTest, LoadMultiDexOdexNoOat) { GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); // Load the oat using an executable oat file assistant. - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, true); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true); std::unique_ptr oat_file = oat_file_assistant.GetBestOatFile(); ASSERT_TRUE(oat_file.get() != nullptr); @@ -1209,12 +1188,12 @@ TEST_F(OatFileAssistantTest, RuntimeCompilerFilterOptionUsed) { std::string dex_location = GetScratchDir() + "/RuntimeCompilerFilterOptionUsed.jar"; Copy(GetDexSrc1(), dex_location); - OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false, false); + OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false); std::string error_msg; Runtime::Current()->AddCompilerOption("--compiler-filter=interpret-only"); EXPECT_EQ(OatFileAssistant::kUpdateSucceeded, - oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg; + oat_file_assistant.MakeUpToDate(false, &error_msg)) << error_msg; EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly)); EXPECT_EQ(OatFileAssistant::kDex2OatNeeded, @@ -1222,7 +1201,7 @@ TEST_F(OatFileAssistantTest, RuntimeCompilerFilterOptionUsed) { Runtime::Current()->AddCompilerOption("--compiler-filter=speed"); EXPECT_EQ(OatFileAssistant::kUpdateSucceeded, - oat_file_assistant.MakeUpToDate(&error_msg)) << error_msg; + oat_file_assistant.MakeUpToDate(false, &error_msg)) << error_msg; EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, oat_file_assistant.GetDexOptNeeded(CompilerFilter::kInterpretOnly)); EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded, @@ -1230,7 +1209,7 @@ TEST_F(OatFileAssistantTest, RuntimeCompilerFilterOptionUsed) { Runtime::Current()->AddCompilerOption("--compiler-filter=bogus"); EXPECT_EQ(OatFileAssistant::kUpdateNotAttempted, - oat_file_assistant.MakeUpToDate(&error_msg)); + oat_file_assistant.MakeUpToDate(false, &error_msg)); } TEST(OatFileAssistantUtilsTest, DexFilenameToOdexFilename) { diff --git a/runtime/oat_file_manager.cc b/runtime/oat_file_manager.cc index b7e604036..768051766 100644 --- a/runtime/oat_file_manager.cc +++ b/runtime/oat_file_manager.cc @@ -558,7 +558,6 @@ std::vector> OatFileManager::OpenDexFilesFromOat( OatFileAssistant oat_file_assistant(dex_location, oat_location, kRuntimeISA, - /*profile_changed*/false, !runtime->IsAotCompiler()); // Lock the target oat location to avoid races generating and loading the @@ -576,7 +575,7 @@ std::vector> OatFileManager::OpenDexFilesFromOat( // Update the oat file on disk if we can, based on the --compiler-filter // option derived from the current runtime options. // This may fail, but that's okay. Best effort is all that matters here. - switch (oat_file_assistant.MakeUpToDate(/*out*/ &error_msg)) { + switch (oat_file_assistant.MakeUpToDate(/*profile_changed*/false, /*out*/ &error_msg)) { case OatFileAssistant::kUpdateFailed: LOG(WARNING) << error_msg; break; -- 2.11.0