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
diff --git a/dexoptanalyzer/dexoptanalyzer.cc b/dexoptanalyzer/dexoptanalyzer.cc
index e2c159a..fc72bbd 100644
--- a/dexoptanalyzer/dexoptanalyzer.cc
+++ b/dexoptanalyzer/dexoptanalyzer.cc
@@ -97,6 +97,9 @@
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 @@
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 @@
// 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 @@
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 @@
InstructionSet isa_;
CompilerFilter::Filter compiler_filter_;
bool assume_profile_changed_;
+ bool downgrade_;
std::string image_;
};