Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <gtest/gtest.h> |
| 18 | |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 19 | #include <string> |
| 20 | |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 21 | #include "arch/instruction_set.h" |
Eric Holk | c7ac91b | 2021-02-04 21:44:01 +0000 | [diff] [blame] | 22 | #include "base/compiler_filter.h" |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 23 | #include "dexopt_test.h" |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 24 | #include "dexoptanalyzer.h" |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 25 | |
| 26 | namespace art { |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 27 | namespace dexoptanalyzer { |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 28 | |
| 29 | class DexoptAnalyzerTest : public DexoptTest { |
| 30 | protected: |
| 31 | std::string GetDexoptAnalyzerCmd() { |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 32 | std::string file_path = GetArtBinDir() + "/dexoptanalyzer"; |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 33 | if (kIsDebugBuild) { |
Roland Levillain | fb6a5c0 | 2019-03-29 20:20:16 +0000 | [diff] [blame] | 34 | file_path += 'd'; |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 35 | } |
| 36 | EXPECT_TRUE(OS::FileExists(file_path.c_str())) << file_path << " should be a valid file path"; |
| 37 | return file_path; |
| 38 | } |
| 39 | |
| 40 | int Analyze(const std::string& dex_file, |
| 41 | CompilerFilter::Filter compiler_filter, |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 42 | ProfileAnalysisResult profile_analysis_result, |
| 43 | const char* class_loader_context, |
| 44 | bool downgrade = false) { |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 45 | std::string dexoptanalyzer_cmd = GetDexoptAnalyzerCmd(); |
| 46 | std::vector<std::string> argv_str; |
| 47 | argv_str.push_back(dexoptanalyzer_cmd); |
| 48 | argv_str.push_back("--dex-file=" + dex_file); |
| 49 | argv_str.push_back("--isa=" + std::string(GetInstructionSetString(kRuntimeISA))); |
| 50 | argv_str.push_back("--compiler-filter=" + CompilerFilter::NameOfFilter(compiler_filter)); |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 51 | argv_str.push_back("--profile-analysis-result=" + |
| 52 | std::to_string(static_cast<int>(profile_analysis_result))); |
| 53 | if (downgrade) { |
| 54 | argv_str.push_back("--downgrade"); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 55 | } |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 56 | |
Vladimir Marko | 7a85e70 | 2018-12-03 18:47:23 +0000 | [diff] [blame] | 57 | argv_str.push_back("--runtime-arg"); |
| 58 | argv_str.push_back(GetClassPathOption("-Xbootclasspath:", GetLibCoreDexFileNames())); |
| 59 | argv_str.push_back("--runtime-arg"); |
| 60 | argv_str.push_back(GetClassPathOption("-Xbootclasspath-locations:", GetLibCoreDexLocations())); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 61 | argv_str.push_back("--image=" + GetImageLocation()); |
| 62 | argv_str.push_back("--android-data=" + android_data_); |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 63 | if (class_loader_context != nullptr) { |
| 64 | argv_str.push_back("--class-loader-context=" + std::string(class_loader_context)); |
Nicolas Geoffray | 35de14b | 2019-01-10 13:10:36 +0000 | [diff] [blame] | 65 | } |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 66 | |
| 67 | std::string error; |
| 68 | return ExecAndReturnCode(argv_str, &error); |
| 69 | } |
| 70 | |
| 71 | int DexoptanalyzerToOatFileAssistant(int dexoptanalyzerResult) { |
| 72 | switch (dexoptanalyzerResult) { |
| 73 | case 0: return OatFileAssistant::kNoDexOptNeeded; |
| 74 | case 1: return OatFileAssistant::kDex2OatFromScratch; |
| 75 | case 2: return OatFileAssistant::kDex2OatForBootImage; |
| 76 | case 3: return OatFileAssistant::kDex2OatForFilter; |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 77 | case 4: return -OatFileAssistant::kDex2OatForBootImage; |
| 78 | case 5: return -OatFileAssistant::kDex2OatForFilter; |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 79 | default: return dexoptanalyzerResult; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | // Verify that the output of dexoptanalyzer for the given arguments is the same |
| 84 | // as the output of OatFileAssistant::GetDexOptNeeded. |
| 85 | void Verify(const std::string& dex_file, |
| 86 | CompilerFilter::Filter compiler_filter, |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 87 | ProfileAnalysisResult profile_analysis_result = |
| 88 | ProfileAnalysisResult::kDontOptimizeSmallDelta, |
Nicolas Geoffray | 35de14b | 2019-01-10 13:10:36 +0000 | [diff] [blame] | 89 | bool downgrade = false, |
Calin Juravle | 0a5cad3 | 2020-02-14 20:29:26 +0000 | [diff] [blame] | 90 | const char* class_loader_context = "PCL[]") { |
David Srbecky | 656fdcd | 2021-04-17 16:47:01 +0000 | [diff] [blame] | 91 | std::unique_ptr<ClassLoaderContext> context = class_loader_context == nullptr |
| 92 | ? nullptr |
| 93 | : ClassLoaderContext::Create(class_loader_context); |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 94 | if (context != nullptr) { |
| 95 | std::vector<int> context_fds; |
| 96 | ASSERT_TRUE(context->OpenDexFiles("", context_fds, /*only_read_checksums*/ true)); |
| 97 | } |
David Srbecky | 656fdcd | 2021-04-17 16:47:01 +0000 | [diff] [blame] | 98 | |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 99 | int dexoptanalyzerResult = Analyze( |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 100 | dex_file, compiler_filter, profile_analysis_result, class_loader_context, downgrade); |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 101 | dexoptanalyzerResult = DexoptanalyzerToOatFileAssistant(dexoptanalyzerResult); |
| 102 | OatFileAssistant oat_file_assistant(dex_file.c_str(), |
| 103 | kRuntimeISA, |
| 104 | context.get(), |
| 105 | /*load_executable=*/ false); |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 106 | bool assume_profile_changed = profile_analysis_result == ProfileAnalysisResult::kOptimize; |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 107 | int assistantResult = oat_file_assistant.GetDexOptNeeded( |
Nicolas Geoffray | 525fa42 | 2021-04-19 07:50:35 +0000 | [diff] [blame] | 108 | compiler_filter, assume_profile_changed, downgrade); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 109 | EXPECT_EQ(assistantResult, dexoptanalyzerResult); |
| 110 | } |
| 111 | }; |
| 112 | |
| 113 | // The tests below exercise the same test case from oat_file_assistant_test.cc. |
| 114 | |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 115 | // Case: We have a DEX file, but no ODEX file for it. |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 116 | TEST_F(DexoptAnalyzerTest, DexNoOat) { |
| 117 | std::string dex_location = GetScratchDir() + "/DexNoOat.jar"; |
| 118 | Copy(GetDexSrc1(), dex_location); |
| 119 | |
| 120 | Verify(dex_location, CompilerFilter::kSpeed); |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 121 | Verify(dex_location, CompilerFilter::kExtract); |
Nicolas Geoffray | f50975a | 2020-10-15 13:34:55 +0000 | [diff] [blame] | 122 | Verify(dex_location, CompilerFilter::kVerify); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 123 | Verify(dex_location, CompilerFilter::kSpeedProfile); |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 124 | Verify(dex_location, CompilerFilter::kSpeed, |
| 125 | ProfileAnalysisResult::kDontOptimizeSmallDelta, false, nullptr); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 126 | } |
| 127 | |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 128 | // Case: We have a DEX file and up-to-date ODEX file for it. |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 129 | TEST_F(DexoptAnalyzerTest, OatUpToDate) { |
| 130 | std::string dex_location = GetScratchDir() + "/OatUpToDate.jar"; |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 131 | std::string odex_location = GetOdexDir() + "/OatUpToDate.odex"; |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 132 | Copy(GetDexSrc1(), dex_location); |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 133 | GenerateOdexForTest(dex_location.c_str(), odex_location.c_str(), CompilerFilter::kSpeed); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 134 | |
| 135 | Verify(dex_location, CompilerFilter::kSpeed); |
Nicolas Geoffray | f50975a | 2020-10-15 13:34:55 +0000 | [diff] [blame] | 136 | Verify(dex_location, CompilerFilter::kVerify); |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 137 | Verify(dex_location, CompilerFilter::kExtract); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 138 | Verify(dex_location, CompilerFilter::kEverything); |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 139 | Verify(dex_location, CompilerFilter::kSpeed, |
| 140 | ProfileAnalysisResult::kDontOptimizeSmallDelta, false, nullptr); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 141 | } |
| 142 | |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 143 | // Case: We have a DEX file and speed-profile ODEX file for it. |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 144 | TEST_F(DexoptAnalyzerTest, ProfileOatUpToDate) { |
| 145 | std::string dex_location = GetScratchDir() + "/ProfileOatUpToDate.jar"; |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 146 | std::string odex_location = GetOdexDir() + "/ProfileOatUpToDate.odex"; |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 147 | Copy(GetDexSrc1(), dex_location); |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 148 | GenerateOdexForTest(dex_location.c_str(), odex_location.c_str(), CompilerFilter::kSpeedProfile); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 149 | |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 150 | Verify(dex_location, CompilerFilter::kSpeedProfile, |
| 151 | ProfileAnalysisResult::kDontOptimizeSmallDelta); |
| 152 | Verify(dex_location, CompilerFilter::kVerify, ProfileAnalysisResult::kDontOptimizeSmallDelta); |
| 153 | Verify(dex_location, CompilerFilter::kSpeedProfile, ProfileAnalysisResult::kOptimize); |
| 154 | Verify(dex_location, CompilerFilter::kVerify, ProfileAnalysisResult::kOptimize); |
| 155 | } |
| 156 | |
| 157 | // Case: We have a DEX file, verify odex file for it, and we ask if it's up to date |
| 158 | // when the profiles are empty or full. |
| 159 | TEST_F(DexoptAnalyzerTest, VerifyAndEmptyProfiles) { |
| 160 | std::string dex_location = GetScratchDir() + "/VerifyAndEmptyProfiles.jar"; |
| 161 | std::string odex_location = GetOdexDir() + "/VerifyAndEmptyProfiles.odex"; |
| 162 | Copy(GetDexSrc1(), dex_location); |
| 163 | |
| 164 | GenerateOdexForTest(dex_location.c_str(), odex_location.c_str(), CompilerFilter::kVerify); |
| 165 | |
| 166 | // If we want to speed-profile something that was verified, do it even if |
| 167 | // the profile analysis returns kDontOptimizeSmallDelta (it means that we do have profile data, |
| 168 | // so a transition verify -> speed-profile is still worth). |
| 169 | ASSERT_EQ( |
| 170 | static_cast<int>(ReturnCode::kDex2OatForFilterOdex), |
| 171 | Analyze(dex_location, CompilerFilter::kSpeedProfile, |
| 172 | ProfileAnalysisResult::kDontOptimizeSmallDelta, "PCL[]")); |
| 173 | // If we want to speed-profile something that was verified but the profiles are empty, |
| 174 | // don't do it - there will be no gain. |
| 175 | ASSERT_EQ( |
| 176 | static_cast<int>(ReturnCode::kNoDexOptNeeded), |
| 177 | Analyze(dex_location, CompilerFilter::kSpeedProfile, |
| 178 | ProfileAnalysisResult::kDontOptimizeEmptyProfiles, "PCL[]")); |
| 179 | // Standard case where we need to re-compile a speed-profile because of sufficient new |
| 180 | // information in the profile. |
| 181 | ASSERT_EQ( |
| 182 | static_cast<int>(ReturnCode::kDex2OatForFilterOdex), |
| 183 | Analyze(dex_location, CompilerFilter::kSpeedProfile, |
| 184 | ProfileAnalysisResult::kOptimize, "PCL[]")); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 185 | } |
| 186 | |
Shubham Ajmera | e4e812a | 2017-05-25 20:09:58 -0700 | [diff] [blame] | 187 | TEST_F(DexoptAnalyzerTest, Downgrade) { |
| 188 | std::string dex_location = GetScratchDir() + "/Downgrade.jar"; |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 189 | std::string odex_location = GetOdexDir() + "/Downgrade.odex"; |
Shubham Ajmera | e4e812a | 2017-05-25 20:09:58 -0700 | [diff] [blame] | 190 | Copy(GetDexSrc1(), dex_location); |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 191 | GenerateOdexForTest(dex_location.c_str(), odex_location.c_str(), CompilerFilter::kVerify); |
Shubham Ajmera | e4e812a | 2017-05-25 20:09:58 -0700 | [diff] [blame] | 192 | |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 193 | Verify(dex_location, CompilerFilter::kSpeedProfile, |
| 194 | ProfileAnalysisResult::kDontOptimizeSmallDelta, true); |
| 195 | Verify(dex_location, CompilerFilter::kVerify, |
| 196 | ProfileAnalysisResult::kDontOptimizeSmallDelta, true); |
| 197 | Verify(dex_location, CompilerFilter::kExtract, |
| 198 | ProfileAnalysisResult::kDontOptimizeSmallDelta, true); |
Shubham Ajmera | e4e812a | 2017-05-25 20:09:58 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 201 | // Case: We have a MultiDEX file and up-to-date ODEX file for it. |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 202 | TEST_F(DexoptAnalyzerTest, MultiDexOatUpToDate) { |
| 203 | std::string dex_location = GetScratchDir() + "/MultiDexOatUpToDate.jar"; |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 204 | std::string odex_location = GetOdexDir() + "/MultiDexOatUpToDate.odex"; |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 205 | |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 206 | Copy(GetMultiDexSrc1(), dex_location); |
| 207 | GenerateOdexForTest(dex_location.c_str(), odex_location.c_str(), CompilerFilter::kSpeed); |
| 208 | |
| 209 | Verify(dex_location, CompilerFilter::kSpeed, ProfileAnalysisResult::kDontOptimizeSmallDelta); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | // Case: We have a MultiDEX file where the secondary dex file is out of date. |
| 213 | TEST_F(DexoptAnalyzerTest, MultiDexSecondaryOutOfDate) { |
| 214 | std::string dex_location = GetScratchDir() + "/MultiDexSecondaryOutOfDate.jar"; |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 215 | std::string odex_location = GetOdexDir() + "/MultiDexSecondaryOutOfDate.odex"; |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 216 | |
| 217 | // Compile code for GetMultiDexSrc1. |
| 218 | Copy(GetMultiDexSrc1(), dex_location); |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 219 | GenerateOdexForTest(dex_location.c_str(), odex_location.c_str(), CompilerFilter::kSpeed); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 220 | |
| 221 | // Now overwrite the dex file with GetMultiDexSrc2 so the secondary checksum |
| 222 | // is out of date. |
| 223 | Copy(GetMultiDexSrc2(), dex_location); |
| 224 | |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 225 | Verify(dex_location, CompilerFilter::kSpeed, ProfileAnalysisResult::kDontOptimizeSmallDelta); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 228 | // Case: We have a DEX file and an ODEX file out of date with respect to the |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 229 | // dex checksum. |
| 230 | TEST_F(DexoptAnalyzerTest, OatDexOutOfDate) { |
| 231 | std::string dex_location = GetScratchDir() + "/OatDexOutOfDate.jar"; |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 232 | std::string odex_location = GetOdexDir() + "/OatDexOutOfDate.odex"; |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 233 | |
| 234 | // We create a dex, generate an oat for it, then overwrite the dex with a |
| 235 | // different dex to make the oat out of date. |
| 236 | Copy(GetDexSrc1(), dex_location); |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 237 | GenerateOdexForTest(dex_location.c_str(), odex_location.c_str(), CompilerFilter::kSpeed); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 238 | Copy(GetDexSrc2(), dex_location); |
| 239 | |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 240 | Verify(dex_location, CompilerFilter::kExtract); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 241 | Verify(dex_location, CompilerFilter::kSpeed); |
| 242 | } |
| 243 | |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 244 | // Case: We have a DEX file and an ODEX file out of date with respect to the |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 245 | // boot image. |
| 246 | TEST_F(DexoptAnalyzerTest, OatImageOutOfDate) { |
| 247 | std::string dex_location = GetScratchDir() + "/OatImageOutOfDate.jar"; |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 248 | std::string odex_location = GetOdexDir() + "/OatImageOutOfDate.odex"; |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 249 | |
| 250 | Copy(GetDexSrc1(), dex_location); |
| 251 | GenerateOatForTest(dex_location.c_str(), |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 252 | odex_location.c_str(), |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 253 | CompilerFilter::kSpeed, |
Andreas Gampe | 9b031f7 | 2018-10-04 11:03:34 -0700 | [diff] [blame] | 254 | /*with_alternate_image=*/true); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 255 | |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 256 | Verify(dex_location, CompilerFilter::kExtract); |
Nicolas Geoffray | f50975a | 2020-10-15 13:34:55 +0000 | [diff] [blame] | 257 | Verify(dex_location, CompilerFilter::kVerify); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 258 | Verify(dex_location, CompilerFilter::kSpeed); |
| 259 | } |
| 260 | |
| 261 | // Case: We have a DEX file and a verify-at-runtime OAT file out of date with |
| 262 | // respect to the boot image. |
| 263 | // It shouldn't matter that the OAT file is out of date, because it is |
| 264 | // verify-at-runtime. |
| 265 | TEST_F(DexoptAnalyzerTest, OatVerifyAtRuntimeImageOutOfDate) { |
| 266 | std::string dex_location = GetScratchDir() + "/OatVerifyAtRuntimeImageOutOfDate.jar"; |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 267 | std::string odex_location = GetOdexDir() + "/OatVerifyAtRuntimeImageOutOfDate.odex"; |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 268 | |
| 269 | Copy(GetDexSrc1(), dex_location); |
| 270 | GenerateOatForTest(dex_location.c_str(), |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 271 | odex_location.c_str(), |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 272 | CompilerFilter::kExtract, |
Andreas Gampe | 9b031f7 | 2018-10-04 11:03:34 -0700 | [diff] [blame] | 273 | /*with_alternate_image=*/true); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 274 | |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 275 | Verify(dex_location, CompilerFilter::kExtract); |
Nicolas Geoffray | f50975a | 2020-10-15 13:34:55 +0000 | [diff] [blame] | 276 | Verify(dex_location, CompilerFilter::kVerify); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | // Case: We have a DEX file and an ODEX file, but no OAT file. |
| 280 | TEST_F(DexoptAnalyzerTest, DexOdexNoOat) { |
| 281 | std::string dex_location = GetScratchDir() + "/DexOdexNoOat.jar"; |
| 282 | std::string odex_location = GetOdexDir() + "/DexOdexNoOat.odex"; |
| 283 | |
| 284 | Copy(GetDexSrc1(), dex_location); |
| 285 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); |
| 286 | |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 287 | Verify(dex_location, CompilerFilter::kExtract); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 288 | Verify(dex_location, CompilerFilter::kSpeed); |
Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 289 | Verify(dex_location, CompilerFilter::kEverything); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 290 | } |
| 291 | |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 292 | // Case: We have a stripped (or resource-only) DEX file, no ODEX file and no |
| 293 | // OAT file. Expect: The status is kNoDexOptNeeded. |
| 294 | TEST_F(DexoptAnalyzerTest, ResourceOnlyDex) { |
| 295 | std::string dex_location = GetScratchDir() + "/ResourceOnlyDex.jar"; |
| 296 | |
Calin Juravle | 5ff2393 | 2020-12-11 18:26:14 -0800 | [diff] [blame] | 297 | Copy(GetResourceOnlySrc1(), dex_location); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 298 | |
| 299 | Verify(dex_location, CompilerFilter::kSpeed); |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 300 | Verify(dex_location, CompilerFilter::kExtract); |
Nicolas Geoffray | f50975a | 2020-10-15 13:34:55 +0000 | [diff] [blame] | 301 | Verify(dex_location, CompilerFilter::kVerify); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 304 | // Case: We have a DEX file, an ODEX file and an OAT file. |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 305 | TEST_F(DexoptAnalyzerTest, OdexOatOverlap) { |
| 306 | std::string dex_location = GetScratchDir() + "/OdexOatOverlap.jar"; |
| 307 | std::string odex_location = GetOdexDir() + "/OdexOatOverlap.odex"; |
| 308 | std::string oat_location = GetOdexDir() + "/OdexOatOverlap.oat"; |
| 309 | |
| 310 | Copy(GetDexSrc1(), dex_location); |
| 311 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); |
| 312 | |
| 313 | // Create the oat file by copying the odex so they are located in the same |
| 314 | // place in memory. |
| 315 | Copy(odex_location, oat_location); |
| 316 | |
| 317 | Verify(dex_location, CompilerFilter::kSpeed); |
| 318 | } |
| 319 | |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 320 | // Case: We have a DEX file and a VerifyAtRuntime ODEX file, but no OAT file.. |
| 321 | TEST_F(DexoptAnalyzerTest, DexVerifyAtRuntimeOdexNoOat) { |
| 322 | std::string dex_location = GetScratchDir() + "/DexVerifyAtRuntimeOdexNoOat.jar"; |
| 323 | std::string odex_location = GetOdexDir() + "/DexVerifyAtRuntimeOdexNoOat.odex"; |
| 324 | |
| 325 | Copy(GetDexSrc1(), dex_location); |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 326 | GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kExtract); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 327 | |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 328 | Verify(dex_location, CompilerFilter::kExtract); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 329 | Verify(dex_location, CompilerFilter::kSpeed); |
| 330 | } |
| 331 | |
| 332 | // Case: Non-standard extension for dex file. |
| 333 | TEST_F(DexoptAnalyzerTest, LongDexExtension) { |
| 334 | std::string dex_location = GetScratchDir() + "/LongDexExtension.jarx"; |
| 335 | Copy(GetDexSrc1(), dex_location); |
| 336 | |
| 337 | Verify(dex_location, CompilerFilter::kSpeed); |
| 338 | } |
| 339 | |
| 340 | // Case: Very short, non-existent Dex location. |
| 341 | TEST_F(DexoptAnalyzerTest, ShortDexLocation) { |
| 342 | std::string dex_location = "/xx"; |
| 343 | |
| 344 | Verify(dex_location, CompilerFilter::kSpeed); |
| 345 | } |
| 346 | |
Nicolas Geoffray | 35de14b | 2019-01-10 13:10:36 +0000 | [diff] [blame] | 347 | // Case: We have a DEX file and up-to-date OAT file for it, and we check with |
| 348 | // a class loader context. |
| 349 | TEST_F(DexoptAnalyzerTest, ClassLoaderContext) { |
| 350 | std::string dex_location1 = GetScratchDir() + "/DexToAnalyze.jar"; |
| 351 | std::string odex_location1 = GetOdexDir() + "/DexToAnalyze.odex"; |
| 352 | std::string dex_location2 = GetScratchDir() + "/DexInContext.jar"; |
| 353 | Copy(GetDexSrc1(), dex_location1); |
| 354 | Copy(GetDexSrc2(), dex_location2); |
| 355 | |
| 356 | std::string class_loader_context = "PCL[" + dex_location2 + "]"; |
| 357 | std::string class_loader_context_option = "--class-loader-context=PCL[" + dex_location2 + "]"; |
| 358 | |
| 359 | // Generate the odex to get the class loader context also open the dex files. |
| 360 | GenerateOdexForTest(dex_location1, odex_location1, CompilerFilter::kSpeed, /* compilation_reason= */ nullptr, /* extra_args= */ { class_loader_context_option }); |
| 361 | |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 362 | Verify(dex_location1, CompilerFilter::kSpeed, ProfileAnalysisResult::kDontOptimizeSmallDelta, |
| 363 | false, class_loader_context.c_str()); |
Nicolas Geoffray | 35de14b | 2019-01-10 13:10:36 +0000 | [diff] [blame] | 364 | } |
Calin Juravle | 1737409 | 2021-06-08 13:45:09 -0700 | [diff] [blame] | 365 | |
| 366 | } // namespace dexoptanalyzer |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 367 | } // namespace art |