diff options
| author | Shubham Ajmera <shubhamajmera@google.com> | 2017-05-25 20:09:58 -0700 |
|---|---|---|
| committer | Shubham Ajmera <shubhamajmera@google.com> | 2017-07-19 00:15:56 +0000 |
| commit | e4e812a917345a3cb9ac955c8a84f64dfc26b5d9 (patch) | |
| tree | bf830d83f8d7ade1d875903ed5d8529d706d3b11 /dexoptanalyzer | |
| parent | 2f0ac4fb4486e7d9e5c1545d45a2b9b818a80dc3 (diff) | |
| download | art-e4e812a917345a3cb9ac955c8a84f64dfc26b5d9.tar.gz art-e4e812a917345a3cb9ac955c8a84f64dfc26b5d9.tar.bz2 art-e4e812a917345a3cb9ac955c8a84f64dfc26b5d9.zip | |
Allow DexFile#getDexOptNeeded to check case when downgrading is required
The change in the API will allow comparison of compiler filter in case when
downgrade is required. Previously, it used to only consider cases of compiler
filter upgrades.
Test: make & boot
Bug: 36598475
(cherry-picked from commit cf3d122a9234414b7cd2aab340d1450f3e9da213)
Change-Id: Ice292ef4f16c373297821c40e39987f3de914c67
Diffstat (limited to 'dexoptanalyzer')
| -rw-r--r-- | dexoptanalyzer/dexoptanalyzer.cc | 16 | ||||
| -rw-r--r-- | dexoptanalyzer/dexoptanalyzer_test.cc | 15 |
2 files changed, 24 insertions, 7 deletions
diff --git a/dexoptanalyzer/dexoptanalyzer.cc b/dexoptanalyzer/dexoptanalyzer.cc index e2c159aa5c..fc72bbdb87 100644 --- a/dexoptanalyzer/dexoptanalyzer.cc +++ b/dexoptanalyzer/dexoptanalyzer.cc @@ -97,6 +97,9 @@ NO_RETURN static void Usage(const char *fmt, ...) { UsageError(" --android-data=<directory>: optional, the directory which should be used as"); UsageError(" android-data. By default ANDROID_DATA env variable is used."); UsageError(""); + UsageError(" --downgrade: optional, if the purpose of dexopt is to downgrade the dex file"); + UsageError(" By default, dexopt considers upgrade case."); + UsageError(""); UsageError("Return code:"); UsageError(" To make it easier to integrate with the internal tools this command will make"); UsageError(" available its result (dexoptNeeded) as the exit/return code. i.e. it will not"); @@ -121,7 +124,9 @@ NO_RETURN static void Usage(const char *fmt, ...) { class DexoptAnalyzer FINAL { public: - DexoptAnalyzer() : assume_profile_changed_(false) {} + DexoptAnalyzer() : + assume_profile_changed_(false), + downgrade_(false) {} void ParseArgs(int argc, char **argv) { original_argc = argc; @@ -160,9 +165,9 @@ class DexoptAnalyzer FINAL { // compute dalvik-cache folder). This is mostly used in tests. std::string new_android_data = option.substr(strlen("--android-data=")).ToString(); setenv("ANDROID_DATA", new_android_data.c_str(), 1); - } else { - Usage("Unknown argument '%s'", option.data()); - } + } else if (option.starts_with("--downgrade")) { + downgrade_ = true; + } else { Usage("Unknown argument '%s'", option.data()); } } if (image_.empty()) { @@ -225,7 +230,7 @@ class DexoptAnalyzer FINAL { return kNoDexOptNeeded; } int dexoptNeeded = oat_file_assistant.GetDexOptNeeded( - compiler_filter_, assume_profile_changed_); + compiler_filter_, assume_profile_changed_, downgrade_); // Convert OatFileAssitant codes to dexoptanalyzer codes. switch (dexoptNeeded) { @@ -249,6 +254,7 @@ class DexoptAnalyzer FINAL { InstructionSet isa_; CompilerFilter::Filter compiler_filter_; bool assume_profile_changed_; + bool downgrade_; std::string image_; }; diff --git a/dexoptanalyzer/dexoptanalyzer_test.cc b/dexoptanalyzer/dexoptanalyzer_test.cc index 1703ff4cbc..1cbf5461a4 100644 --- a/dexoptanalyzer/dexoptanalyzer_test.cc +++ b/dexoptanalyzer/dexoptanalyzer_test.cc @@ -71,12 +71,13 @@ class DexoptAnalyzerTest : public DexoptTest { // as the output of OatFileAssistant::GetDexOptNeeded. void Verify(const std::string& dex_file, CompilerFilter::Filter compiler_filter, - bool assume_profile_changed = false) { + bool assume_profile_changed = false, + bool downgrade = false) { int dexoptanalyzerResult = Analyze(dex_file, compiler_filter, assume_profile_changed); dexoptanalyzerResult = DexoptanalyzerToOatFileAssistant(dexoptanalyzerResult); OatFileAssistant oat_file_assistant(dex_file.c_str(), kRuntimeISA, /*load_executable*/ false); int assistantResult = oat_file_assistant.GetDexOptNeeded( - compiler_filter, assume_profile_changed); + compiler_filter, assume_profile_changed, downgrade); EXPECT_EQ(assistantResult, dexoptanalyzerResult); } }; @@ -118,6 +119,16 @@ TEST_F(DexoptAnalyzerTest, ProfileOatUpToDate) { Verify(dex_location, CompilerFilter::kQuicken, true); } +TEST_F(DexoptAnalyzerTest, Downgrade) { + std::string dex_location = GetScratchDir() + "/Downgrade.jar"; + Copy(GetDexSrc1(), dex_location); + GenerateOatForTest(dex_location.c_str(), CompilerFilter::kQuicken); + + Verify(dex_location, CompilerFilter::kSpeedProfile, false, true); + Verify(dex_location, CompilerFilter::kQuicken, false, true); + Verify(dex_location, CompilerFilter::kVerify, false, true); +} + // Case: We have a MultiDEX file and up-to-date OAT file for it. TEST_F(DexoptAnalyzerTest, MultiDexOatUpToDate) { std::string dex_location = GetScratchDir() + "/MultiDexOatUpToDate.jar"; |
