blob: 16d3ce05a5e536025ab59d14c6d517a6f5be9cf1 [file] [log] [blame]
Richard Uhler66d874d2015-01-15 09:37:19 -08001/*
2 * Copyright (C) 2014 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
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070017#include "oat_file_assistant.h"
18
Richard Uhler66d874d2015-01-15 09:37:19 -080019#include <sys/param.h>
20
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070021#include <string>
22#include <vector>
Shubham Ajmerab22dea02017-10-04 18:36:41 -070023#include <fcntl.h>
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070024
Richard Uhler66d874d2015-01-15 09:37:19 -080025#include <gtest/gtest.h>
26
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070027#include "android-base/strings.h"
28
Mathieu Chartierc7853442015-03-27 14:35:38 -070029#include "art_field-inl.h"
David Sehrc431b9d2018-03-02 12:01:51 -080030#include "base/os.h"
31#include "base/utils.h"
Vladimir Marko3481ba22015-04-13 12:22:36 +010032#include "class_linker-inl.h"
Calin Juravle27e0d1f2017-07-26 00:16:07 -070033#include "class_loader_context.h"
Jeff Hao0cb17282017-07-12 14:51:49 -070034#include "common_runtime_test.h"
Calin Juravle36eb3132017-01-13 16:32:38 -080035#include "dexopt_test.h"
David Brazdil32bde992018-05-14 15:24:34 +010036#include "hidden_api.h"
Vladimir Markod3d00c02019-11-07 15:09:07 +000037#include "oat.h"
Calin Juravle27e0d1f2017-07-26 00:16:07 -070038#include "oat_file.h"
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070039#include "oat_file_manager.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070040#include "scoped_thread_state_change-inl.h"
Andreas Gampeb486a982017-06-01 13:45:54 -070041#include "thread-current-inl.h"
Richard Uhler66d874d2015-01-15 09:37:19 -080042
43namespace art {
44
Calin Juravle5f9a8012018-02-12 20:27:46 -080045class OatFileAssistantTest : public DexoptTest {
46 public:
Calin Juravle98071152021-01-27 18:41:58 -080047 void VerifyOptimizationStatus(OatFileAssistant* assistant,
48 const std::string& file,
Calin Juravle5f9a8012018-02-12 20:27:46 -080049 const std::string& expected_filter,
Calin Juravle98071152021-01-27 18:41:58 -080050 const std::string& expected_reason,
51 const std::string& expected_odex_status) {
52 // Verify the static methods (called from PM for dexOptNeeded).
53 std::string compilation_filter1;
54 std::string compilation_reason1;
Calin Juravle5f9a8012018-02-12 20:27:46 -080055
Calin Juravle98071152021-01-27 18:41:58 -080056 OatFileAssistant::GetOptimizationStatus(
57 file, kRuntimeISA, &compilation_filter1, &compilation_reason1);
58
59 ASSERT_EQ(expected_filter, compilation_filter1);
60 ASSERT_EQ(expected_reason, compilation_reason1);
61
62 // Verify the instance methods (called at runtime for systrace).
63 std::string odex_location2; // ignored
64 std::string compilation_filter2;
65 std::string compilation_reason2;
66 std::string odex_status2;
67
68 assistant->GetOptimizationStatus(
69 &odex_location2,
70 &compilation_filter2,
71 &compilation_reason2,
72 &odex_status2);
73
74 ASSERT_EQ(expected_filter, compilation_filter2);
75 ASSERT_EQ(expected_reason, compilation_reason2);
76 ASSERT_EQ(expected_odex_status, odex_status2);
Calin Juravle5f9a8012018-02-12 20:27:46 -080077 }
78
Calin Juravle98071152021-01-27 18:41:58 -080079 void VerifyOptimizationStatus(OatFileAssistant* assistant,
80 const std::string& file,
Calin Juravle5f9a8012018-02-12 20:27:46 -080081 CompilerFilter::Filter expected_filter,
Calin Juravle98071152021-01-27 18:41:58 -080082 const std::string& expected_reason,
83 const std::string& expected_odex_status) {
Calin Juravle5f9a8012018-02-12 20:27:46 -080084 VerifyOptimizationStatus(
Calin Juravle98071152021-01-27 18:41:58 -080085 assistant,
86 file,
87 CompilerFilter::NameOfFilter(expected_filter),
88 expected_reason,
89 expected_odex_status);
Calin Juravle5f9a8012018-02-12 20:27:46 -080090 }
Calin Juravle0a5cad32020-02-14 20:29:26 +000091
Vladimir Markof3d88a82018-12-21 16:38:47 +000092 void InsertNewBootClasspathEntry() {
93 std::string extra_dex_filename = GetMultiDexSrc1();
94 Runtime* runtime = Runtime::Current();
95 runtime->boot_class_path_.push_back(extra_dex_filename);
96 if (!runtime->boot_class_path_locations_.empty()) {
97 runtime->boot_class_path_locations_.push_back(extra_dex_filename);
98 }
99 }
Calin Juravle0a5cad32020-02-14 20:29:26 +0000100
101 int GetDexOptNeeded(OatFileAssistant* assistant,
102 CompilerFilter::Filter compiler_filter,
103 bool profile_changed) {
104 std::vector<int> context_fds;
105 return GetDexOptNeeded(assistant,
106 compiler_filter,
107 ClassLoaderContext::Default(),
108 context_fds,
109 profile_changed,
110 /*downgrade=*/ false);
111 }
112
113 int GetDexOptNeeded(
114 OatFileAssistant* assistant,
115 CompilerFilter::Filter compiler_filter,
116 const std::unique_ptr<ClassLoaderContext>& context = ClassLoaderContext::Default(),
117 const std::vector<int>& context_fds = std::vector<int>(),
118 bool profile_changed = false,
119 bool downgrade = false) {
120 return assistant->GetDexOptNeeded(
121 compiler_filter,
122 context.get(),
123 context_fds,
124 profile_changed,
125 downgrade);
126 }
Calin Juravle5f9a8012018-02-12 20:27:46 -0800127};
Richard Uhler66d874d2015-01-15 09:37:19 -0800128
Calin Juravle357c66d2017-05-04 01:57:17 +0000129class ScopedNonWritable {
130 public:
131 explicit ScopedNonWritable(const std::string& dex_location) {
132 is_valid_ = false;
133 size_t pos = dex_location.rfind('/');
134 if (pos != std::string::npos) {
135 is_valid_ = true;
136 dex_parent_ = dex_location.substr(0, pos);
137 if (chmod(dex_parent_.c_str(), 0555) != 0) {
138 PLOG(ERROR) << "Could not change permissions on " << dex_parent_;
139 }
140 }
141 }
142
143 bool IsSuccessful() { return is_valid_ && (access(dex_parent_.c_str(), W_OK) != 0); }
144
145 ~ScopedNonWritable() {
146 if (is_valid_) {
147 if (chmod(dex_parent_.c_str(), 0777) != 0) {
148 PLOG(ERROR) << "Could not restore permissions on " << dex_parent_;
149 }
150 }
151 }
152
153 private:
154 std::string dex_parent_;
155 bool is_valid_;
156};
157
158static bool IsExecutedAsRoot() {
159 return geteuid() == 0;
160}
Calin Juravle36eb3132017-01-13 16:32:38 -0800161
Nicolas Geoffray3d8a78a2018-08-29 21:10:16 +0000162// Case: We have a MultiDEX file and up-to-date ODEX file for it with relative
163// encoded dex locations.
164// Expect: The oat file status is kNoDexOptNeeded.
165TEST_F(OatFileAssistantTest, RelativeEncodedDexLocation) {
166 std::string dex_location = GetScratchDir() + "/RelativeEncodedDexLocation.jar";
167 std::string odex_location = GetOdexDir() + "/RelativeEncodedDexLocation.odex";
168
169 // Create the dex file
170 Copy(GetMultiDexSrc1(), dex_location);
171
172 // Create the oat file with relative encoded dex location.
173 std::vector<std::string> args = {
174 "--dex-file=" + dex_location,
175 "--dex-location=" + std::string("RelativeEncodedDexLocation.jar"),
176 "--oat-file=" + odex_location,
177 "--compiler-filter=speed"
178 };
179
180 std::string error_msg;
181 ASSERT_TRUE(Dex2Oat(args, &error_msg)) << error_msg;
182
183 // Verify we can load both dex files.
184 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
185
186 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
187 ASSERT_TRUE(oat_file.get() != nullptr);
188 EXPECT_TRUE(oat_file->IsExecutable());
189 std::vector<std::unique_ptr<const DexFile>> dex_files;
190 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
191 EXPECT_EQ(2u, dex_files.size());
192}
193
194TEST_F(OatFileAssistantTest, MakeUpToDateWithContext) {
195 std::string dex_location = GetScratchDir() + "/TestDex.jar";
196 std::string odex_location = GetOdexDir() + "/TestDex.odex";
197 std::string context_location = GetScratchDir() + "/ContextDex.jar";
198 Copy(GetDexSrc1(), dex_location);
199 Copy(GetDexSrc2(), context_location);
200
201 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
202
203 std::string context_str = "PCL[" + context_location + "]";
204 std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(context_str);
205 ASSERT_TRUE(context != nullptr);
Calin Juravle5ff23932020-12-11 18:26:14 -0800206 ASSERT_TRUE(context->OpenDexFiles());
Nicolas Geoffray3d8a78a2018-08-29 21:10:16 +0000207
208 std::string error_msg;
209 std::vector<std::string> args;
210 args.push_back("--dex-file=" + dex_location);
211 args.push_back("--oat-file=" + odex_location);
212 args.push_back("--class-loader-context=" + context_str);
213 ASSERT_TRUE(Dex2Oat(args, &error_msg)) << error_msg;
214
215 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
216 EXPECT_NE(nullptr, oat_file.get());
217 EXPECT_EQ(context->EncodeContextForOatFile(""),
218 oat_file->GetOatHeader().GetStoreValueByKey(OatHeader::kClassPathKey));
219}
220
221TEST_F(OatFileAssistantTest, GetDexOptNeededWithUpToDateContextRelative) {
222 std::string dex_location = GetScratchDir() + "/TestDex.jar";
223 std::string odex_location = GetOdexDir() + "/TestDex.odex";
224 std::string context_location = GetScratchDir() + "/ContextDex.jar";
225 Copy(GetDexSrc1(), dex_location);
226 Copy(GetDexSrc2(), context_location);
227
228 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
229
230 std::string context_str = "PCL[" + context_location + "]";
231 std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(context_str);
232 ASSERT_TRUE(context != nullptr);
Calin Juravle5ff23932020-12-11 18:26:14 -0800233 ASSERT_TRUE(context->OpenDexFiles());
Nicolas Geoffray3d8a78a2018-08-29 21:10:16 +0000234
235 std::string error_msg;
236 std::vector<std::string> args;
237 args.push_back("--dex-file=" + dex_location);
238 args.push_back("--oat-file=" + odex_location);
239 args.push_back("--class-loader-context=" + context_str);
240 ASSERT_TRUE(Dex2Oat(args, &error_msg)) << error_msg;
241
242 // A relative context simulates a dependent split context.
243 std::unique_ptr<ClassLoaderContext> relative_context =
244 ClassLoaderContext::Create("PCL[ContextDex.jar]");
245 EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000246 GetDexOptNeeded(&oat_file_assistant,
Nicolas Geoffray3d8a78a2018-08-29 21:10:16 +0000247 CompilerFilter::kDefaultCompilerFilter,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000248 relative_context));
Nicolas Geoffray3d8a78a2018-08-29 21:10:16 +0000249}
250
Richard Uhler66d874d2015-01-15 09:37:19 -0800251// Case: We have a DEX file, but no OAT file for it.
Richard Uhler95abd042015-03-24 09:51:28 -0700252// Expect: The status is kDex2OatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800253TEST_F(OatFileAssistantTest, DexNoOat) {
254 std::string dex_location = GetScratchDir() + "/DexNoOat.jar";
255 Copy(GetDexSrc1(), dex_location);
256
Richard Uhlerd1472a22016-04-15 15:18:56 -0700257 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Richard Uhler66d874d2015-01-15 09:37:19 -0800258
Richard Uhler7225a8d2016-11-22 10:12:03 +0000259 EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000260 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract));
Richard Uhler7225a8d2016-11-22 10:12:03 +0000261 EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch,
Nicolas Geoffrayf50975a2020-10-15 13:34:55 +0000262 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify));
Richard Uhler7225a8d2016-11-22 10:12:03 +0000263 EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000264 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeedProfile));
Richard Uhler7225a8d2016-11-22 10:12:03 +0000265 EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000266 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -0800267
268 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Richard Uhler03bc6592016-11-22 09:42:04 +0000269 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus());
270 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100271 EXPECT_TRUE(oat_file_assistant.HasDexFiles());
Calin Juravle5f9a8012018-02-12 20:27:46 -0800272
Calin Juravle98071152021-01-27 18:41:58 -0800273 VerifyOptimizationStatus(
274 &oat_file_assistant,
275 dex_location,
276 "run-from-apk",
277 "unknown",
278 "io-error-no-oat");
Richard Uhler66d874d2015-01-15 09:37:19 -0800279}
280
281// Case: We have no DEX file and no OAT file.
Richard Uhler9b994ea2015-06-24 08:44:19 -0700282// Expect: Status is kNoDexOptNeeded. Loading should fail, but not crash.
Richard Uhler66d874d2015-01-15 09:37:19 -0800283TEST_F(OatFileAssistantTest, NoDexNoOat) {
284 std::string dex_location = GetScratchDir() + "/NoDexNoOat.jar";
285
Richard Uhlerd1472a22016-04-15 15:18:56 -0700286 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler66d874d2015-01-15 09:37:19 -0800287
Andreas Gampe29d38e72016-03-23 15:31:51 +0000288 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000289 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100290 EXPECT_FALSE(oat_file_assistant.HasDexFiles());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700291
Richard Uhler9b994ea2015-06-24 08:44:19 -0700292 // Trying to get the best oat file should fail, but not crash.
Richard Uhler66d874d2015-01-15 09:37:19 -0800293 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
294 EXPECT_EQ(nullptr, oat_file.get());
295}
296
Vladimir Markoe0669322018-09-03 15:44:54 +0100297// Case: We have a DEX file and an ODEX file, but no OAT file.
298// Expect: The status is kNoDexOptNeeded.
Calin Juravle357c66d2017-05-04 01:57:17 +0000299TEST_F(OatFileAssistantTest, OdexUpToDate) {
300 std::string dex_location = GetScratchDir() + "/OdexUpToDate.jar";
301 std::string odex_location = GetOdexDir() + "/OdexUpToDate.odex";
302 Copy(GetDexSrc1(), dex_location);
Vladimir Markoe0669322018-09-03 15:44:54 +0100303 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed, "install");
Calin Juravle357c66d2017-05-04 01:57:17 +0000304
Vladimir Markof3d88a82018-12-21 16:38:47 +0000305 // Force the use of oat location by making the dex parent not writable.
306 OatFileAssistant oat_file_assistant(
307 dex_location.c_str(), kRuntimeISA, /*load_executable=*/ false);
Calin Juravle357c66d2017-05-04 01:57:17 +0000308
309 EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000310 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Calin Juravle357c66d2017-05-04 01:57:17 +0000311 EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded,
Nicolas Geoffrayf50975a2020-10-15 13:34:55 +0000312 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify));
Calin Juravle357c66d2017-05-04 01:57:17 +0000313 EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000314 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract));
Calin Juravle357c66d2017-05-04 01:57:17 +0000315 EXPECT_EQ(-OatFileAssistant::kDex2OatForFilter,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000316 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kEverything));
Vladimir Markof3d88a82018-12-21 16:38:47 +0000317
318 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
319 EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OdexFileStatus());
320 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100321 EXPECT_TRUE(oat_file_assistant.HasDexFiles());
Vladimir Markof3d88a82018-12-21 16:38:47 +0000322
Calin Juravle98071152021-01-27 18:41:58 -0800323 VerifyOptimizationStatus(
324 &oat_file_assistant,
325 dex_location,
326 CompilerFilter::kSpeed,
327 "install",
328 "up-to-date");
Vladimir Markof3d88a82018-12-21 16:38:47 +0000329}
330
331// Case: We have an ODEX file compiled against partial boot image.
332// Expect: The status is kNoDexOptNeeded.
333TEST_F(OatFileAssistantTest, OdexUpToDatePartialBootImage) {
334 std::string dex_location = GetScratchDir() + "/OdexUpToDate.jar";
335 std::string odex_location = GetOdexDir() + "/OdexUpToDate.odex";
336 Copy(GetDexSrc1(), dex_location);
337 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed, "install");
338
339 // Insert an extra dex file to the boot class path.
340 InsertNewBootClasspathEntry();
341
342 // Force the use of oat location by making the dex parent not writable.
343 OatFileAssistant oat_file_assistant(
344 dex_location.c_str(), kRuntimeISA, /*load_executable=*/ false);
345
346 EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000347 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Vladimir Markof3d88a82018-12-21 16:38:47 +0000348 EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded,
Nicolas Geoffrayf50975a2020-10-15 13:34:55 +0000349 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify));
Vladimir Markof3d88a82018-12-21 16:38:47 +0000350 EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000351 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract));
Vladimir Markof3d88a82018-12-21 16:38:47 +0000352 EXPECT_EQ(-OatFileAssistant::kDex2OatForFilter,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000353 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kEverything));
Calin Juravle357c66d2017-05-04 01:57:17 +0000354
355 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
356 EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OdexFileStatus());
357 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100358 EXPECT_TRUE(oat_file_assistant.HasDexFiles());
Calin Juravle5f9a8012018-02-12 20:27:46 -0800359
Calin Juravle98071152021-01-27 18:41:58 -0800360 VerifyOptimizationStatus(
361 &oat_file_assistant,
362 dex_location,
363 CompilerFilter::kSpeed,
364 "install",
365 "up-to-date");
Calin Juravle357c66d2017-05-04 01:57:17 +0000366}
367
368// Case: We have a DEX file and a PIC ODEX file, but no OAT file. We load the dex
369// file via a symlink.
Vladimir Markoe0669322018-09-03 15:44:54 +0100370// Expect: The status is kNoDexOptNeeded.
Calin Juravle357c66d2017-05-04 01:57:17 +0000371TEST_F(OatFileAssistantTest, OdexUpToDateSymLink) {
372 std::string scratch_dir = GetScratchDir();
373 std::string dex_location = GetScratchDir() + "/OdexUpToDate.jar";
374 std::string odex_location = GetOdexDir() + "/OdexUpToDate.odex";
375
376 Copy(GetDexSrc1(), dex_location);
Vladimir Markoe0669322018-09-03 15:44:54 +0100377 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
Calin Juravle357c66d2017-05-04 01:57:17 +0000378
379 // Now replace the dex location with a symlink.
380 std::string link = scratch_dir + "/link";
381 ASSERT_EQ(0, symlink(scratch_dir.c_str(), link.c_str()));
382 dex_location = link + "/OdexUpToDate.jar";
383
384 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
385
386 EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000387 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Calin Juravle357c66d2017-05-04 01:57:17 +0000388 EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded,
Nicolas Geoffrayf50975a2020-10-15 13:34:55 +0000389 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify));
Calin Juravle357c66d2017-05-04 01:57:17 +0000390 EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000391 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract));
Calin Juravle357c66d2017-05-04 01:57:17 +0000392 EXPECT_EQ(-OatFileAssistant::kDex2OatForFilter,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000393 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kEverything));
Calin Juravle357c66d2017-05-04 01:57:17 +0000394
395 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
396 EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OdexFileStatus());
397 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100398 EXPECT_TRUE(oat_file_assistant.HasDexFiles());
Calin Juravle357c66d2017-05-04 01:57:17 +0000399}
400
Richard Uhler66d874d2015-01-15 09:37:19 -0800401// Case: We have a DEX file and up-to-date OAT file for it.
Richard Uhler95abd042015-03-24 09:51:28 -0700402// Expect: The status is kNoDexOptNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -0800403TEST_F(OatFileAssistantTest, OatUpToDate) {
Calin Juravle357c66d2017-05-04 01:57:17 +0000404 if (IsExecutedAsRoot()) {
405 // We cannot simulate non writable locations when executed as root: b/38000545.
406 LOG(ERROR) << "Test skipped because it's running as root";
407 return;
408 }
409
Richard Uhler66d874d2015-01-15 09:37:19 -0800410 std::string dex_location = GetScratchDir() + "/OatUpToDate.jar";
411 Copy(GetDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000412 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800413
Vladimir Markof3d88a82018-12-21 16:38:47 +0000414 // Force the use of oat location by making the dex parent not writable.
Calin Juravle357c66d2017-05-04 01:57:17 +0000415 ScopedNonWritable scoped_non_writable(dex_location);
416 ASSERT_TRUE(scoped_non_writable.IsSuccessful());
417
418 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
419
420 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000421 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Calin Juravle357c66d2017-05-04 01:57:17 +0000422 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Nicolas Geoffrayf50975a2020-10-15 13:34:55 +0000423 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify));
Calin Juravle357c66d2017-05-04 01:57:17 +0000424 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000425 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract));
Calin Juravle357c66d2017-05-04 01:57:17 +0000426 EXPECT_EQ(OatFileAssistant::kDex2OatForFilter,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000427 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kEverything));
Calin Juravle357c66d2017-05-04 01:57:17 +0000428
429 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
430 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus());
431 EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OatFileStatus());
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100432 EXPECT_TRUE(oat_file_assistant.HasDexFiles());
Calin Juravle5f9a8012018-02-12 20:27:46 -0800433
Calin Juravle98071152021-01-27 18:41:58 -0800434 VerifyOptimizationStatus(
435 &oat_file_assistant,
436 dex_location,
437 CompilerFilter::kSpeed,
438 "unknown",
439 "up-to-date");
Calin Juravle357c66d2017-05-04 01:57:17 +0000440}
441
Vladimir Markoe0669322018-09-03 15:44:54 +0100442// Case: Passing valid file descriptors of updated odex/vdex files along with the dex file.
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700443// Expect: The status is kNoDexOptNeeded.
444TEST_F(OatFileAssistantTest, GetDexOptNeededWithFd) {
445 std::string dex_location = GetScratchDir() + "/OatUpToDate.jar";
446 std::string odex_location = GetScratchDir() + "/OatUpToDate.odex";
447 std::string vdex_location = GetScratchDir() + "/OatUpToDate.vdex";
448
449 Copy(GetDexSrc1(), dex_location);
450 GenerateOatForTest(dex_location.c_str(),
451 odex_location.c_str(),
452 CompilerFilter::kSpeed,
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700453 /* with_alternate_image= */ false);
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700454
Andreas Gampedfcd82c2018-10-16 20:22:37 -0700455 android::base::unique_fd odex_fd(open(odex_location.c_str(), O_RDONLY | O_CLOEXEC));
456 android::base::unique_fd vdex_fd(open(vdex_location.c_str(), O_RDONLY | O_CLOEXEC));
457 android::base::unique_fd zip_fd(open(dex_location.c_str(), O_RDONLY | O_CLOEXEC));
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700458
459 OatFileAssistant oat_file_assistant(dex_location.c_str(),
460 kRuntimeISA,
461 false,
Nicolas Geoffray29742602017-12-14 10:09:03 +0000462 false,
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700463 vdex_fd.get(),
Shubham Ajmerac12bf4c2017-10-24 16:59:42 -0700464 odex_fd.get(),
465 zip_fd.get());
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700466 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000467 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700468 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Nicolas Geoffrayf50975a2020-10-15 13:34:55 +0000469 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify));
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700470 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000471 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract));
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700472 EXPECT_EQ(-OatFileAssistant::kDex2OatForFilter,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000473 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kEverything));
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700474
475 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
476 EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OdexFileStatus());
477 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100478 EXPECT_TRUE(oat_file_assistant.HasDexFiles());
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700479}
480
Shubham Ajmerac12bf4c2017-10-24 16:59:42 -0700481// Case: Passing invalid odex fd and valid vdex and zip fds.
482// Expect: The status should be kDex2OatForBootImage.
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700483TEST_F(OatFileAssistantTest, GetDexOptNeededWithInvalidOdexFd) {
484 std::string dex_location = GetScratchDir() + "/OatUpToDate.jar";
485 std::string odex_location = GetScratchDir() + "/OatUpToDate.odex";
486 std::string vdex_location = GetScratchDir() + "/OatUpToDate.vdex";
487
488 Copy(GetDexSrc1(), dex_location);
489 GenerateOatForTest(dex_location.c_str(),
490 odex_location.c_str(),
491 CompilerFilter::kSpeed,
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700492 /* with_alternate_image= */ false);
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700493
Andreas Gampedfcd82c2018-10-16 20:22:37 -0700494 android::base::unique_fd vdex_fd(open(vdex_location.c_str(), O_RDONLY | O_CLOEXEC));
495 android::base::unique_fd zip_fd(open(dex_location.c_str(), O_RDONLY | O_CLOEXEC));
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700496
497 OatFileAssistant oat_file_assistant(dex_location.c_str(),
498 kRuntimeISA,
499 false,
Nicolas Geoffray29742602017-12-14 10:09:03 +0000500 false,
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700501 vdex_fd.get(),
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700502 /* oat_fd= */ -1,
Shubham Ajmerac12bf4c2017-10-24 16:59:42 -0700503 zip_fd.get());
Nicolas Geoffray16f60dc2021-02-16 15:35:16 +0000504 EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded,
505 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify));
506 EXPECT_EQ(-OatFileAssistant::kDex2OatForFilter,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000507 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Nicolas Geoffray16f60dc2021-02-16 15:35:16 +0000508 EXPECT_EQ(-OatFileAssistant::kDex2OatForFilter,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000509 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kEverything));
Shubham Ajmerac12bf4c2017-10-24 16:59:42 -0700510
511 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Nicolas Geoffray16f60dc2021-02-16 15:35:16 +0000512 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus());
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700513 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100514 EXPECT_TRUE(oat_file_assistant.HasDexFiles());
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700515}
516
Shubham Ajmerac12bf4c2017-10-24 16:59:42 -0700517// Case: Passing invalid vdex fd and valid odex and zip fds.
518// Expect: The status should be kDex2OatFromScratch.
519TEST_F(OatFileAssistantTest, GetDexOptNeededWithInvalidVdexFd) {
520 std::string dex_location = GetScratchDir() + "/OatUpToDate.jar";
521 std::string odex_location = GetScratchDir() + "/OatUpToDate.odex";
522
523 Copy(GetDexSrc1(), dex_location);
524 GenerateOatForTest(dex_location.c_str(),
525 odex_location.c_str(),
526 CompilerFilter::kSpeed,
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700527 /* with_alternate_image= */ false);
Shubham Ajmerac12bf4c2017-10-24 16:59:42 -0700528
Andreas Gampedfcd82c2018-10-16 20:22:37 -0700529 android::base::unique_fd odex_fd(open(odex_location.c_str(), O_RDONLY | O_CLOEXEC));
530 android::base::unique_fd zip_fd(open(dex_location.c_str(), O_RDONLY | O_CLOEXEC));
Shubham Ajmerac12bf4c2017-10-24 16:59:42 -0700531
532 OatFileAssistant oat_file_assistant(dex_location.c_str(),
533 kRuntimeISA,
534 false,
Nicolas Geoffray29742602017-12-14 10:09:03 +0000535 false,
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700536 /* vdex_fd= */ -1,
Shubham Ajmerac12bf4c2017-10-24 16:59:42 -0700537 odex_fd.get(),
538 zip_fd.get());
539
540 EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000541 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Shubham Ajmerac12bf4c2017-10-24 16:59:42 -0700542 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
543 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus());
544 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100545 EXPECT_TRUE(oat_file_assistant.HasDexFiles());
Shubham Ajmerac12bf4c2017-10-24 16:59:42 -0700546}
547
548// Case: Passing invalid vdex and odex fd with valid zip fd.
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700549// Expect: The status is kDex2oatFromScratch.
550TEST_F(OatFileAssistantTest, GetDexOptNeededWithInvalidOdexVdexFd) {
551 std::string dex_location = GetScratchDir() + "/OatUpToDate.jar";
552
553 Copy(GetDexSrc1(), dex_location);
554
Andreas Gampedfcd82c2018-10-16 20:22:37 -0700555 android::base::unique_fd zip_fd(open(dex_location.c_str(), O_RDONLY | O_CLOEXEC));
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700556 OatFileAssistant oat_file_assistant(dex_location.c_str(),
557 kRuntimeISA,
558 false,
Nicolas Geoffray29742602017-12-14 10:09:03 +0000559 false,
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700560 /* vdex_fd= */ -1,
561 /* oat_fd= */ -1,
Shubham Ajmerac12bf4c2017-10-24 16:59:42 -0700562 zip_fd);
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700563 EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000564 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700565 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus());
566 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
567}
568
Nicolas Geoffray16f60dc2021-02-16 15:35:16 +0000569// Case: We have a DEX file and up-to-date VDEX file for it, but no
Richard Uhler2f27abd2017-01-31 14:02:34 +0000570// ODEX file.
571TEST_F(OatFileAssistantTest, VdexUpToDateNoOdex) {
Richard Uhler2f27abd2017-01-31 14:02:34 +0000572 std::string dex_location = GetScratchDir() + "/VdexUpToDateNoOdex.jar";
Calin Juravle357c66d2017-05-04 01:57:17 +0000573 std::string odex_location = GetOdexDir() + "/VdexUpToDateNoOdex.oat";
Richard Uhler2f27abd2017-01-31 14:02:34 +0000574
Richard Uhler9a37efc2016-08-05 16:32:55 -0700575 Copy(GetDexSrc1(), dex_location);
576
Richard Uhler2f27abd2017-01-31 14:02:34 +0000577 // Generating and deleting the oat file should have the side effect of
578 // creating an up-to-date vdex file.
Calin Juravle357c66d2017-05-04 01:57:17 +0000579 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
580 ASSERT_EQ(0, unlink(odex_location.c_str()));
Richard Uhler2f27abd2017-01-31 14:02:34 +0000581
Calin Juravle357c66d2017-05-04 01:57:17 +0000582 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Richard Uhler2f27abd2017-01-31 14:02:34 +0000583
Nicolas Geoffray16f60dc2021-02-16 15:35:16 +0000584 EXPECT_EQ(-OatFileAssistant::kNoDexOptNeeded,
585 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify));
586 EXPECT_EQ(-OatFileAssistant::kDex2OatForFilter,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000587 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Richard Uhler2f27abd2017-01-31 14:02:34 +0000588
589 // Make sure we don't crash in this case when we dump the status. We don't
590 // care what the actual dumped value is.
591 oat_file_assistant.GetStatusDump();
Calin Juravle5f9a8012018-02-12 20:27:46 -0800592
Calin Juravle98071152021-01-27 18:41:58 -0800593 VerifyOptimizationStatus(
594 &oat_file_assistant,
595 dex_location,
Nicolas Geoffray16f60dc2021-02-16 15:35:16 +0000596 "verify",
Calin Juravle98071152021-01-27 18:41:58 -0800597 "unknown",
Nicolas Geoffray16f60dc2021-02-16 15:35:16 +0000598 "up-to-date");
Richard Uhler2f27abd2017-01-31 14:02:34 +0000599}
600
601// Case: We have a DEX file and empty VDEX and ODEX files.
602TEST_F(OatFileAssistantTest, EmptyVdexOdex) {
603 std::string dex_location = GetScratchDir() + "/EmptyVdexOdex.jar";
604 std::string odex_location = GetOdexDir() + "/EmptyVdexOdex.oat";
605 std::string vdex_location = GetOdexDir() + "/EmptyVdexOdex.vdex";
606
607 Copy(GetDexSrc1(), dex_location);
Richard Uhler5cd59292017-02-01 12:54:23 +0000608 ScratchFile vdex_file(vdex_location.c_str());
609 ScratchFile odex_file(odex_location.c_str());
Richard Uhler2f27abd2017-01-31 14:02:34 +0000610
611 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
612 EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000613 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Richard Uhler2f27abd2017-01-31 14:02:34 +0000614}
615
616// Case: We have a DEX file and up-to-date (OAT) VDEX file for it, but no OAT
617// file.
618TEST_F(OatFileAssistantTest, VdexUpToDateNoOat) {
Calin Juravle357c66d2017-05-04 01:57:17 +0000619 if (IsExecutedAsRoot()) {
620 // We cannot simulate non writable locations when executed as root: b/38000545.
621 LOG(ERROR) << "Test skipped because it's running as root";
622 return;
623 }
Richard Uhler2f27abd2017-01-31 14:02:34 +0000624
625 std::string dex_location = GetScratchDir() + "/VdexUpToDateNoOat.jar";
626 std::string oat_location;
627 std::string error_msg;
628 ASSERT_TRUE(OatFileAssistant::DexLocationToOatFilename(
629 dex_location, kRuntimeISA, &oat_location, &error_msg)) << error_msg;
630
631 Copy(GetDexSrc1(), dex_location);
632 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
633 ASSERT_EQ(0, unlink(oat_location.c_str()));
634
Calin Juravle357c66d2017-05-04 01:57:17 +0000635 ScopedNonWritable scoped_non_writable(dex_location);
636 ASSERT_TRUE(scoped_non_writable.IsSuccessful());
Richard Uhler9a37efc2016-08-05 16:32:55 -0700637 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
638
Nicolas Geoffray16f60dc2021-02-16 15:35:16 +0000639 EXPECT_EQ(OatFileAssistant::kDex2OatForFilter,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000640 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Richard Uhler9a37efc2016-08-05 16:32:55 -0700641}
642
Andreas Gampe29d38e72016-03-23 15:31:51 +0000643// Case: We have a DEX file and speed-profile OAT file for it.
Richard Uhlerd1472a22016-04-15 15:18:56 -0700644// Expect: The status is kNoDexOptNeeded if the profile hasn't changed, but
645// kDex2Oat if the profile has changed.
Andreas Gampe29d38e72016-03-23 15:31:51 +0000646TEST_F(OatFileAssistantTest, ProfileOatUpToDate) {
Calin Juravle357c66d2017-05-04 01:57:17 +0000647 if (IsExecutedAsRoot()) {
648 // We cannot simulate non writable locations when executed as root: b/38000545.
649 LOG(ERROR) << "Test skipped because it's running as root";
650 return;
651 }
652
Andreas Gampe29d38e72016-03-23 15:31:51 +0000653 std::string dex_location = GetScratchDir() + "/ProfileOatUpToDate.jar";
654 Copy(GetDexSrc1(), dex_location);
655 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeedProfile);
656
Calin Juravle357c66d2017-05-04 01:57:17 +0000657 ScopedNonWritable scoped_non_writable(dex_location);
658 ASSERT_TRUE(scoped_non_writable.IsSuccessful());
659
Richard Uhlerd1472a22016-04-15 15:18:56 -0700660 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000661
662 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000663 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeedProfile, false));
Andreas Gampe29d38e72016-03-23 15:31:51 +0000664 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Nicolas Geoffrayf50975a2020-10-15 13:34:55 +0000665 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify, false));
Richard Uhler7225a8d2016-11-22 10:12:03 +0000666 EXPECT_EQ(OatFileAssistant::kDex2OatForFilter,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000667 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeedProfile, true));
Richard Uhler7225a8d2016-11-22 10:12:03 +0000668 EXPECT_EQ(OatFileAssistant::kDex2OatForFilter,
Nicolas Geoffrayf50975a2020-10-15 13:34:55 +0000669 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify, true));
Andreas Gampe29d38e72016-03-23 15:31:51 +0000670
671 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Richard Uhler03bc6592016-11-22 09:42:04 +0000672 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus());
Andreas Gampe29d38e72016-03-23 15:31:51 +0000673 EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OatFileStatus());
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100674 EXPECT_TRUE(oat_file_assistant.HasDexFiles());
Andreas Gampe29d38e72016-03-23 15:31:51 +0000675}
676
Richard Uhler66d874d2015-01-15 09:37:19 -0800677// Case: We have a MultiDEX file and up-to-date OAT file for it.
Richard Uhler95abd042015-03-24 09:51:28 -0700678// Expect: The status is kNoDexOptNeeded and we load all dex files.
Richard Uhler66d874d2015-01-15 09:37:19 -0800679TEST_F(OatFileAssistantTest, MultiDexOatUpToDate) {
Calin Juravle357c66d2017-05-04 01:57:17 +0000680 if (IsExecutedAsRoot()) {
681 // We cannot simulate non writable locations when executed as root: b/38000545.
682 LOG(ERROR) << "Test skipped because it's running as root";
683 return;
684 }
685
Richard Uhler66d874d2015-01-15 09:37:19 -0800686 std::string dex_location = GetScratchDir() + "/MultiDexOatUpToDate.jar";
687 Copy(GetMultiDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000688 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800689
Calin Juravle357c66d2017-05-04 01:57:17 +0000690 ScopedNonWritable scoped_non_writable(dex_location);
691 ASSERT_TRUE(scoped_non_writable.IsSuccessful());
692
Richard Uhlerd1472a22016-04-15 15:18:56 -0700693 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000694 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000695 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100696 EXPECT_TRUE(oat_file_assistant.HasDexFiles());
Richard Uhler95abd042015-03-24 09:51:28 -0700697
698 // Verify we can load both dex files.
Richard Uhlere5fed032015-03-18 08:21:11 -0700699 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
Richard Uhler66d874d2015-01-15 09:37:19 -0800700 ASSERT_TRUE(oat_file.get() != nullptr);
701 EXPECT_TRUE(oat_file->IsExecutable());
702 std::vector<std::unique_ptr<const DexFile>> dex_files;
Richard Uhlere5fed032015-03-18 08:21:11 -0700703 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
704 EXPECT_EQ(2u, dex_files.size());
705}
706
Richard Uhler69bcf2c2017-01-24 10:25:21 +0000707// Case: We have a MultiDEX file where the non-main multdex entry is out of date.
Richard Uhler67ff7d12015-05-14 13:21:13 -0700708// Expect: The status is kDex2OatNeeded.
Richard Uhler69bcf2c2017-01-24 10:25:21 +0000709TEST_F(OatFileAssistantTest, MultiDexNonMainOutOfDate) {
Calin Juravle357c66d2017-05-04 01:57:17 +0000710 if (IsExecutedAsRoot()) {
711 // We cannot simulate non writable locations when executed as root: b/38000545.
712 LOG(ERROR) << "Test skipped because it's running as root";
713 return;
714 }
715
Richard Uhler69bcf2c2017-01-24 10:25:21 +0000716 std::string dex_location = GetScratchDir() + "/MultiDexNonMainOutOfDate.jar";
Richard Uhler67ff7d12015-05-14 13:21:13 -0700717
718 // Compile code for GetMultiDexSrc1.
719 Copy(GetMultiDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000720 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler67ff7d12015-05-14 13:21:13 -0700721
Richard Uhler69bcf2c2017-01-24 10:25:21 +0000722 // Now overwrite the dex file with GetMultiDexSrc2 so the non-main checksum
Richard Uhler67ff7d12015-05-14 13:21:13 -0700723 // is out of date.
724 Copy(GetMultiDexSrc2(), dex_location);
725
Calin Juravle357c66d2017-05-04 01:57:17 +0000726 ScopedNonWritable scoped_non_writable(dex_location);
727 ASSERT_TRUE(scoped_non_writable.IsSuccessful());
728
Richard Uhlerd1472a22016-04-15 15:18:56 -0700729 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler7225a8d2016-11-22 10:12:03 +0000730 EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000731 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100732 EXPECT_TRUE(oat_file_assistant.HasDexFiles());
Richard Uhler69bcf2c2017-01-24 10:25:21 +0000733}
734
Richard Uhler03bc6592016-11-22 09:42:04 +0000735// Case: We have a DEX file and an OAT file out of date with respect to the
736// dex checksum.
737TEST_F(OatFileAssistantTest, OatDexOutOfDate) {
Calin Juravle357c66d2017-05-04 01:57:17 +0000738 if (IsExecutedAsRoot()) {
739 // We cannot simulate non writable locations when executed as root: b/38000545.
740 LOG(ERROR) << "Test skipped because it's running as root";
741 return;
742 }
743
Richard Uhler03bc6592016-11-22 09:42:04 +0000744 std::string dex_location = GetScratchDir() + "/OatDexOutOfDate.jar";
Richard Uhler66d874d2015-01-15 09:37:19 -0800745
746 // We create a dex, generate an oat for it, then overwrite the dex with a
747 // different dex to make the oat out of date.
748 Copy(GetDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000749 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800750 Copy(GetDexSrc2(), dex_location);
751
Calin Juravle357c66d2017-05-04 01:57:17 +0000752 ScopedNonWritable scoped_non_writable(dex_location);
753 ASSERT_TRUE(scoped_non_writable.IsSuccessful());
754
Richard Uhlerd1472a22016-04-15 15:18:56 -0700755 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Richard Uhler7225a8d2016-11-22 10:12:03 +0000756 EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000757 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract));
Richard Uhler7225a8d2016-11-22 10:12:03 +0000758 EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000759 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -0800760
761 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Richard Uhler03bc6592016-11-22 09:42:04 +0000762 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus());
763 EXPECT_EQ(OatFileAssistant::kOatDexOutOfDate, oat_file_assistant.OatFileStatus());
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100764 EXPECT_TRUE(oat_file_assistant.HasDexFiles());
Calin Juravle98071152021-01-27 18:41:58 -0800765
766 VerifyOptimizationStatus(
767 &oat_file_assistant,
768 dex_location,
769 "run-from-apk-fallback",
770 "unknown",
771 "apk-more-recent");
Richard Uhler03bc6592016-11-22 09:42:04 +0000772}
773
Richard Uhler2f27abd2017-01-31 14:02:34 +0000774// Case: We have a DEX file and an (ODEX) VDEX file out of date with respect
775// to the dex checksum, but no ODEX file.
776TEST_F(OatFileAssistantTest, VdexDexOutOfDate) {
Richard Uhler2f27abd2017-01-31 14:02:34 +0000777 std::string dex_location = GetScratchDir() + "/VdexDexOutOfDate.jar";
Calin Juravle357c66d2017-05-04 01:57:17 +0000778 std::string odex_location = GetOdexDir() + "/VdexDexOutOfDate.oat";
Richard Uhler2f27abd2017-01-31 14:02:34 +0000779
780 Copy(GetDexSrc1(), dex_location);
Calin Juravle357c66d2017-05-04 01:57:17 +0000781 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
782 ASSERT_EQ(0, unlink(odex_location.c_str()));
Richard Uhler2f27abd2017-01-31 14:02:34 +0000783 Copy(GetDexSrc2(), dex_location);
784
Calin Juravle357c66d2017-05-04 01:57:17 +0000785 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Richard Uhler2f27abd2017-01-31 14:02:34 +0000786
787 EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000788 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Richard Uhler2f27abd2017-01-31 14:02:34 +0000789}
790
Richard Uhler69bcf2c2017-01-24 10:25:21 +0000791// Case: We have a MultiDEX (ODEX) VDEX file where the non-main multidex entry
792// is out of date and there is no corresponding ODEX file.
793TEST_F(OatFileAssistantTest, VdexMultiDexNonMainOutOfDate) {
Richard Uhler69bcf2c2017-01-24 10:25:21 +0000794 std::string dex_location = GetScratchDir() + "/VdexMultiDexNonMainOutOfDate.jar";
Calin Juravle357c66d2017-05-04 01:57:17 +0000795 std::string odex_location = GetOdexDir() + "/VdexMultiDexNonMainOutOfDate.odex";
Richard Uhler2f27abd2017-01-31 14:02:34 +0000796
797 Copy(GetMultiDexSrc1(), dex_location);
Calin Juravle357c66d2017-05-04 01:57:17 +0000798 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
799 ASSERT_EQ(0, unlink(odex_location.c_str()));
Richard Uhler2f27abd2017-01-31 14:02:34 +0000800 Copy(GetMultiDexSrc2(), dex_location);
801
Calin Juravle357c66d2017-05-04 01:57:17 +0000802 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Richard Uhler2f27abd2017-01-31 14:02:34 +0000803
804 EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000805 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Richard Uhler2f27abd2017-01-31 14:02:34 +0000806}
807
Richard Uhler03bc6592016-11-22 09:42:04 +0000808// Case: We have a DEX file and an OAT file out of date with respect to the
809// boot image.
810TEST_F(OatFileAssistantTest, OatImageOutOfDate) {
Calin Juravle357c66d2017-05-04 01:57:17 +0000811 if (IsExecutedAsRoot()) {
812 // We cannot simulate non writable locations when executed as root: b/38000545.
813 LOG(ERROR) << "Test skipped because it's running as root";
814 return;
815 }
816
Richard Uhler03bc6592016-11-22 09:42:04 +0000817 std::string dex_location = GetScratchDir() + "/OatImageOutOfDate.jar";
818
819 Copy(GetDexSrc1(), dex_location);
820 GenerateOatForTest(dex_location.c_str(),
821 CompilerFilter::kSpeed,
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700822 /* with_alternate_image= */ true);
Richard Uhler03bc6592016-11-22 09:42:04 +0000823
Calin Juravle357c66d2017-05-04 01:57:17 +0000824 ScopedNonWritable scoped_non_writable(dex_location);
825 ASSERT_TRUE(scoped_non_writable.IsSuccessful());
826
Richard Uhler03bc6592016-11-22 09:42:04 +0000827 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Nicolas Geoffray16f60dc2021-02-16 15:35:16 +0000828 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000829 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract));
Nicolas Geoffray16f60dc2021-02-16 15:35:16 +0000830 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Nicolas Geoffrayf50975a2020-10-15 13:34:55 +0000831 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify));
Nicolas Geoffray16f60dc2021-02-16 15:35:16 +0000832 EXPECT_EQ(OatFileAssistant::kDex2OatForFilter,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000833 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Richard Uhler03bc6592016-11-22 09:42:04 +0000834
835 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
836 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus());
837 EXPECT_EQ(OatFileAssistant::kOatBootImageOutOfDate, oat_file_assistant.OatFileStatus());
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100838 EXPECT_TRUE(oat_file_assistant.HasDexFiles());
Calin Juravle98071152021-01-27 18:41:58 -0800839
840 VerifyOptimizationStatus(
841 &oat_file_assistant,
842 dex_location,
Nicolas Geoffray16f60dc2021-02-16 15:35:16 +0000843 "verify",
Calin Juravle98071152021-01-27 18:41:58 -0800844 "unknown",
Nicolas Geoffray16f60dc2021-02-16 15:35:16 +0000845 "up-to-date");
Richard Uhler03bc6592016-11-22 09:42:04 +0000846}
847
848// Case: We have a DEX file and a verify-at-runtime OAT file out of date with
849// respect to the boot image.
850// It shouldn't matter that the OAT file is out of date, because it is
851// verify-at-runtime.
852TEST_F(OatFileAssistantTest, OatVerifyAtRuntimeImageOutOfDate) {
Calin Juravle357c66d2017-05-04 01:57:17 +0000853 if (IsExecutedAsRoot()) {
854 // We cannot simulate non writable locations when executed as root: b/38000545.
855 LOG(ERROR) << "Test skipped because it's running as root";
856 return;
857 }
858
Richard Uhler03bc6592016-11-22 09:42:04 +0000859 std::string dex_location = GetScratchDir() + "/OatVerifyAtRuntimeImageOutOfDate.jar";
860
861 Copy(GetDexSrc1(), dex_location);
862 GenerateOatForTest(dex_location.c_str(),
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100863 CompilerFilter::kExtract,
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700864 /* with_alternate_image= */ true);
Richard Uhler03bc6592016-11-22 09:42:04 +0000865
Calin Juravle357c66d2017-05-04 01:57:17 +0000866 ScopedNonWritable scoped_non_writable(dex_location);
867 ASSERT_TRUE(scoped_non_writable.IsSuccessful());
868
Richard Uhler03bc6592016-11-22 09:42:04 +0000869 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
870 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000871 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract));
Richard Uhler7225a8d2016-11-22 10:12:03 +0000872 EXPECT_EQ(OatFileAssistant::kDex2OatForFilter,
Nicolas Geoffrayf50975a2020-10-15 13:34:55 +0000873 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify));
Richard Uhler03bc6592016-11-22 09:42:04 +0000874
875 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
876 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus());
877 EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OatFileStatus());
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100878 EXPECT_TRUE(oat_file_assistant.HasDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800879}
880
881// Case: We have a DEX file and an ODEX file, but no OAT file.
Richard Uhler66d874d2015-01-15 09:37:19 -0800882TEST_F(OatFileAssistantTest, DexOdexNoOat) {
883 std::string dex_location = GetScratchDir() + "/DexOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700884 std::string odex_location = GetOdexDir() + "/DexOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -0800885
886 // Create the dex and odex files
887 Copy(GetDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000888 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800889
890 // Verify the status.
Richard Uhlerd1472a22016-04-15 15:18:56 -0700891 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Richard Uhler66d874d2015-01-15 09:37:19 -0800892
Andreas Gampe29d38e72016-03-23 15:31:51 +0000893 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000894 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract));
Vladimir Markoe0669322018-09-03 15:44:54 +0100895 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000896 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -0800897
898 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Vladimir Markoe0669322018-09-03 15:44:54 +0100899 EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OdexFileStatus());
Richard Uhler03bc6592016-11-22 09:42:04 +0000900 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100901 EXPECT_TRUE(oat_file_assistant.HasDexFiles());
Richard Uhler5f946da2015-07-17 12:28:32 -0700902
903 // We should still be able to get the non-executable odex file to run from.
904 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
905 ASSERT_TRUE(oat_file.get() != nullptr);
Richard Uhler66d874d2015-01-15 09:37:19 -0800906}
907
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100908// Case: We have a resource-only DEX file, no ODEX file and no
Richard Uhler9b994ea2015-06-24 08:44:19 -0700909// OAT file. Expect: The status is kNoDexOptNeeded.
910TEST_F(OatFileAssistantTest, ResourceOnlyDex) {
911 std::string dex_location = GetScratchDir() + "/ResourceOnlyDex.jar";
912
Calin Juravle5ff23932020-12-11 18:26:14 -0800913 Copy(GetResourceOnlySrc1(), dex_location);
Richard Uhler9b994ea2015-06-24 08:44:19 -0700914
915 // Verify the status.
Richard Uhlerd1472a22016-04-15 15:18:56 -0700916 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler9b994ea2015-06-24 08:44:19 -0700917
Andreas Gampe29d38e72016-03-23 15:31:51 +0000918 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000919 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Andreas Gampe29d38e72016-03-23 15:31:51 +0000920 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000921 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract));
Andreas Gampe29d38e72016-03-23 15:31:51 +0000922 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Nicolas Geoffrayf50975a2020-10-15 13:34:55 +0000923 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kVerify));
Richard Uhler9b994ea2015-06-24 08:44:19 -0700924
925 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Richard Uhler03bc6592016-11-22 09:42:04 +0000926 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus());
927 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100928 EXPECT_FALSE(oat_file_assistant.HasDexFiles());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700929
Andreas Gampe29d38e72016-03-23 15:31:51 +0000930 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000931 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Richard Uhler9b994ea2015-06-24 08:44:19 -0700932
933 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Richard Uhler03bc6592016-11-22 09:42:04 +0000934 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus());
935 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100936 EXPECT_FALSE(oat_file_assistant.HasDexFiles());
Richard Uhler9b994ea2015-06-24 08:44:19 -0700937}
938
Vladimir Markoe0669322018-09-03 15:44:54 +0100939// Case: We have a DEX file, an ODEX file and an OAT file.
940// Expect: It shouldn't crash. We should load the odex file executable.
Richard Uhler66d874d2015-01-15 09:37:19 -0800941TEST_F(OatFileAssistantTest, OdexOatOverlap) {
942 std::string dex_location = GetScratchDir() + "/OdexOatOverlap.jar";
Richard Uhler63434112015-03-16 14:32:16 -0700943 std::string odex_location = GetOdexDir() + "/OdexOatOverlap.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -0800944
Calin Juravle357c66d2017-05-04 01:57:17 +0000945 // Create the dex, the odex and the oat files.
Richard Uhler66d874d2015-01-15 09:37:19 -0800946 Copy(GetDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +0000947 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
Vladimir Markoe0669322018-09-03 15:44:54 +0100948 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -0800949
950 // Verify things don't go bad.
Calin Juravle357c66d2017-05-04 01:57:17 +0000951 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler66d874d2015-01-15 09:37:19 -0800952
Vladimir Markoe0669322018-09-03 15:44:54 +0100953 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000954 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -0800955
956 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Vladimir Markoe0669322018-09-03 15:44:54 +0100957 EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OdexFileStatus());
958 EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OatFileStatus());
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100959 EXPECT_TRUE(oat_file_assistant.HasDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -0800960
Richard Uhler66d874d2015-01-15 09:37:19 -0800961 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
962 ASSERT_TRUE(oat_file.get() != nullptr);
Richard Uhlerf16d5722015-05-11 09:32:47 -0700963
Vladimir Markoe0669322018-09-03 15:44:54 +0100964 EXPECT_TRUE(oat_file->IsExecutable());
Richard Uhler66d874d2015-01-15 09:37:19 -0800965 std::vector<std::unique_ptr<const DexFile>> dex_files;
966 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
967 EXPECT_EQ(1u, dex_files.size());
968}
969
Andreas Gampe29d38e72016-03-23 15:31:51 +0000970// Case: We have a DEX file and a VerifyAtRuntime ODEX file, but no OAT file.
971// Expect: The status is kNoDexOptNeeded, because VerifyAtRuntime contains no code.
972TEST_F(OatFileAssistantTest, DexVerifyAtRuntimeOdexNoOat) {
973 std::string dex_location = GetScratchDir() + "/DexVerifyAtRuntimeOdexNoOat.jar";
974 std::string odex_location = GetOdexDir() + "/DexVerifyAtRuntimeOdexNoOat.odex";
David Brazdilce4b0ba2016-01-28 15:05:49 +0000975
976 // Create the dex and odex files
977 Copy(GetDexSrc1(), dex_location);
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100978 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kExtract);
David Brazdilce4b0ba2016-01-28 15:05:49 +0000979
980 // Verify the status.
Richard Uhlerd1472a22016-04-15 15:18:56 -0700981 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
David Brazdilce4b0ba2016-01-28 15:05:49 +0000982
Andreas Gampe29d38e72016-03-23 15:31:51 +0000983 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000984 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kExtract));
Richard Uhler7225a8d2016-11-22 10:12:03 +0000985 EXPECT_EQ(-OatFileAssistant::kDex2OatForFilter,
Calin Juravle0a5cad32020-02-14 20:29:26 +0000986 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
David Brazdilce4b0ba2016-01-28 15:05:49 +0000987
988 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Richard Uhler3e580bc2016-11-08 16:23:07 +0000989 EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OdexFileStatus());
Richard Uhler03bc6592016-11-22 09:42:04 +0000990 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +0100991 EXPECT_TRUE(oat_file_assistant.HasDexFiles());
David Brazdilce4b0ba2016-01-28 15:05:49 +0000992}
993
Richard Uhler66d874d2015-01-15 09:37:19 -0800994// Case: We have a DEX file and up-to-date OAT file for it.
995// Expect: We should load an executable dex file.
996TEST_F(OatFileAssistantTest, LoadOatUpToDate) {
Calin Juravle357c66d2017-05-04 01:57:17 +0000997 if (IsExecutedAsRoot()) {
998 // We cannot simulate non writable locations when executed as root: b/38000545.
999 LOG(ERROR) << "Test skipped because it's running as root";
1000 return;
1001 }
1002
Richard Uhler66d874d2015-01-15 09:37:19 -08001003 std::string dex_location = GetScratchDir() + "/LoadOatUpToDate.jar";
1004
1005 Copy(GetDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +00001006 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -08001007
Calin Juravle357c66d2017-05-04 01:57:17 +00001008 ScopedNonWritable scoped_non_writable(dex_location);
1009 ASSERT_TRUE(scoped_non_writable.IsSuccessful());
1010
Richard Uhler66d874d2015-01-15 09:37:19 -08001011 // Load the oat using an oat file assistant.
Richard Uhlerd1472a22016-04-15 15:18:56 -07001012 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Andreas Gampe29d38e72016-03-23 15:31:51 +00001013
1014 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
1015 ASSERT_TRUE(oat_file.get() != nullptr);
1016 EXPECT_TRUE(oat_file->IsExecutable());
1017 std::vector<std::unique_ptr<const DexFile>> dex_files;
1018 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
1019 EXPECT_EQ(1u, dex_files.size());
1020}
1021
Nicolas Geoffray49cda062017-04-21 13:08:25 +01001022// Case: We have a DEX file and up-to-date quicken OAT file for it.
Andreas Gampe29d38e72016-03-23 15:31:51 +00001023// Expect: We should still load the oat file as executable.
1024TEST_F(OatFileAssistantTest, LoadExecInterpretOnlyOatUpToDate) {
Calin Juravle357c66d2017-05-04 01:57:17 +00001025 if (IsExecutedAsRoot()) {
1026 // We cannot simulate non writable locations when executed as root: b/38000545.
1027 LOG(ERROR) << "Test skipped because it's running as root";
1028 return;
1029 }
1030
Andreas Gampe29d38e72016-03-23 15:31:51 +00001031 std::string dex_location = GetScratchDir() + "/LoadExecInterpretOnlyOatUpToDate.jar";
1032
1033 Copy(GetDexSrc1(), dex_location);
Nicolas Geoffrayf50975a2020-10-15 13:34:55 +00001034 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kVerify);
Andreas Gampe29d38e72016-03-23 15:31:51 +00001035
Calin Juravle357c66d2017-05-04 01:57:17 +00001036 ScopedNonWritable scoped_non_writable(dex_location);
1037 ASSERT_TRUE(scoped_non_writable.IsSuccessful());
1038
Andreas Gampe29d38e72016-03-23 15:31:51 +00001039 // Load the oat using an oat file assistant.
Richard Uhlerd1472a22016-04-15 15:18:56 -07001040 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler66d874d2015-01-15 09:37:19 -08001041
1042 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
1043 ASSERT_TRUE(oat_file.get() != nullptr);
1044 EXPECT_TRUE(oat_file->IsExecutable());
1045 std::vector<std::unique_ptr<const DexFile>> dex_files;
1046 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
1047 EXPECT_EQ(1u, dex_files.size());
1048}
1049
1050// Case: We have a DEX file and up-to-date OAT file for it.
1051// Expect: Loading non-executable should load the oat non-executable.
1052TEST_F(OatFileAssistantTest, LoadNoExecOatUpToDate) {
Calin Juravle357c66d2017-05-04 01:57:17 +00001053 if (IsExecutedAsRoot()) {
1054 // We cannot simulate non writable locations when executed as root: b/38000545.
1055 LOG(ERROR) << "Test skipped because it's running as root";
1056 return;
1057 }
1058
Richard Uhler66d874d2015-01-15 09:37:19 -08001059 std::string dex_location = GetScratchDir() + "/LoadNoExecOatUpToDate.jar";
1060
1061 Copy(GetDexSrc1(), dex_location);
Calin Juravle357c66d2017-05-04 01:57:17 +00001062
1063 ScopedNonWritable scoped_non_writable(dex_location);
1064 ASSERT_TRUE(scoped_non_writable.IsSuccessful());
1065
Andreas Gampe29d38e72016-03-23 15:31:51 +00001066 GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -08001067
1068 // Load the oat using an oat file assistant.
Richard Uhlerd1472a22016-04-15 15:18:56 -07001069 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Richard Uhler66d874d2015-01-15 09:37:19 -08001070
1071 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
1072 ASSERT_TRUE(oat_file.get() != nullptr);
1073 EXPECT_FALSE(oat_file->IsExecutable());
1074 std::vector<std::unique_ptr<const DexFile>> dex_files;
1075 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
1076 EXPECT_EQ(1u, dex_files.size());
1077}
1078
Richard Uhler66d874d2015-01-15 09:37:19 -08001079// Turn an absolute path into a path relative to the current working
1080// directory.
Andreas Gampeca620d72016-11-08 08:09:33 -08001081static std::string MakePathRelative(const std::string& target) {
Richard Uhler66d874d2015-01-15 09:37:19 -08001082 char buf[MAXPATHLEN];
1083 std::string cwd = getcwd(buf, MAXPATHLEN);
1084
1085 // Split the target and cwd paths into components.
1086 std::vector<std::string> target_path;
1087 std::vector<std::string> cwd_path;
1088 Split(target, '/', &target_path);
1089 Split(cwd, '/', &cwd_path);
1090
1091 // Reverse the path components, so we can use pop_back().
1092 std::reverse(target_path.begin(), target_path.end());
1093 std::reverse(cwd_path.begin(), cwd_path.end());
1094
1095 // Drop the common prefix of the paths. Because we reversed the path
1096 // components, this becomes the common suffix of target_path and cwd_path.
1097 while (!target_path.empty() && !cwd_path.empty()
1098 && target_path.back() == cwd_path.back()) {
1099 target_path.pop_back();
1100 cwd_path.pop_back();
1101 }
1102
1103 // For each element of the remaining cwd_path, add '..' to the beginning
1104 // of the target path. Because we reversed the path components, we add to
1105 // the end of target_path.
1106 for (unsigned int i = 0; i < cwd_path.size(); i++) {
1107 target_path.push_back("..");
1108 }
1109
1110 // Reverse again to get the right path order, and join to get the result.
1111 std::reverse(target_path.begin(), target_path.end());
Andreas Gampe9186ced2016-12-12 14:28:21 -08001112 return android::base::Join(target_path, '/');
Richard Uhler66d874d2015-01-15 09:37:19 -08001113}
1114
1115// Case: Non-absolute path to Dex location.
1116// Expect: Not sure, but it shouldn't crash.
1117TEST_F(OatFileAssistantTest, NonAbsoluteDexLocation) {
1118 std::string abs_dex_location = GetScratchDir() + "/NonAbsoluteDexLocation.jar";
1119 Copy(GetDexSrc1(), abs_dex_location);
1120
1121 std::string dex_location = MakePathRelative(abs_dex_location);
Richard Uhlerd1472a22016-04-15 15:18:56 -07001122 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler66d874d2015-01-15 09:37:19 -08001123
1124 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Richard Uhler7225a8d2016-11-22 10:12:03 +00001125 EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch,
Calin Juravle0a5cad32020-02-14 20:29:26 +00001126 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Richard Uhler03bc6592016-11-22 09:42:04 +00001127 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus());
1128 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
Richard Uhler66d874d2015-01-15 09:37:19 -08001129}
1130
1131// Case: Very short, non-existent Dex location.
Richard Uhler9b994ea2015-06-24 08:44:19 -07001132// Expect: kNoDexOptNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -08001133TEST_F(OatFileAssistantTest, ShortDexLocation) {
1134 std::string dex_location = "/xx";
1135
Richard Uhlerd1472a22016-04-15 15:18:56 -07001136 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler66d874d2015-01-15 09:37:19 -08001137
1138 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Andreas Gampe29d38e72016-03-23 15:31:51 +00001139 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +00001140 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Richard Uhler03bc6592016-11-22 09:42:04 +00001141 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus());
1142 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +01001143 EXPECT_FALSE(oat_file_assistant.HasDexFiles());
Richard Uhler66d874d2015-01-15 09:37:19 -08001144}
1145
1146// Case: Non-standard extension for dex file.
Richard Uhler95abd042015-03-24 09:51:28 -07001147// Expect: The status is kDex2OatNeeded.
Richard Uhler66d874d2015-01-15 09:37:19 -08001148TEST_F(OatFileAssistantTest, LongDexExtension) {
1149 std::string dex_location = GetScratchDir() + "/LongDexExtension.jarx";
1150 Copy(GetDexSrc1(), dex_location);
1151
Richard Uhlerd1472a22016-04-15 15:18:56 -07001152 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
Richard Uhler66d874d2015-01-15 09:37:19 -08001153
Richard Uhler7225a8d2016-11-22 10:12:03 +00001154 EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch,
Calin Juravle0a5cad32020-02-14 20:29:26 +00001155 GetDexOptNeeded(&oat_file_assistant, CompilerFilter::kSpeed));
Richard Uhler66d874d2015-01-15 09:37:19 -08001156
1157 EXPECT_FALSE(oat_file_assistant.IsInBootClassPath());
Richard Uhler03bc6592016-11-22 09:42:04 +00001158 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus());
1159 EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
Richard Uhler66d874d2015-01-15 09:37:19 -08001160}
1161
1162// A task to generate a dex location. Used by the RaceToGenerate test.
1163class RaceGenerateTask : public Task {
1164 public:
Vladimir Markob9c29f62019-03-20 14:22:51 +00001165 RaceGenerateTask(OatFileAssistantTest& test,
1166 const std::string& dex_location,
Nicolas Geoffray1e76d7a2018-09-03 13:23:34 +01001167 const std::string& oat_location,
1168 Mutex* lock)
Vladimir Markob9c29f62019-03-20 14:22:51 +00001169 : test_(test),
1170 dex_location_(dex_location),
Nicolas Geoffray1e76d7a2018-09-03 13:23:34 +01001171 oat_location_(oat_location),
1172 lock_(lock),
1173 loaded_oat_file_(nullptr)
Richard Uhler66d874d2015-01-15 09:37:19 -08001174 {}
1175
Andreas Gampefa6a1b02018-09-07 08:11:55 -07001176 void Run(Thread* self ATTRIBUTE_UNUSED) override {
Richard Uhler66d874d2015-01-15 09:37:19 -08001177 // Load the dex files, and save a pointer to the loaded oat file, so that
1178 // we can verify only one oat file was loaded for the dex location.
Richard Uhler66d874d2015-01-15 09:37:19 -08001179 std::vector<std::unique_ptr<const DexFile>> dex_files;
1180 std::vector<std::string> error_msgs;
Mathieu Chartiere58991b2015-10-13 07:59:34 -07001181 const OatFile* oat_file = nullptr;
Nicolas Geoffray3d8a78a2018-08-29 21:10:16 +00001182 {
Nicolas Geoffray1e76d7a2018-09-03 13:23:34 +01001183 MutexLock mu(Thread::Current(), *lock_);
Nicolas Geoffray3d8a78a2018-08-29 21:10:16 +00001184 // Create the oat file.
1185 std::vector<std::string> args;
1186 args.push_back("--dex-file=" + dex_location_);
1187 args.push_back("--oat-file=" + oat_location_);
1188 std::string error_msg;
Vladimir Markob9c29f62019-03-20 14:22:51 +00001189 ASSERT_TRUE(test_.Dex2Oat(args, &error_msg)) << error_msg;
Nicolas Geoffray3d8a78a2018-08-29 21:10:16 +00001190 }
1191
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -07001192 dex_files = Runtime::Current()->GetOatFileManager().OpenDexFilesFromOat(
1193 dex_location_.c_str(),
Jeff Hao0cb17282017-07-12 14:51:49 -07001194 Runtime::Current()->GetSystemClassLoader(),
Andreas Gampe98ea9d92018-10-19 14:06:15 -07001195 /*dex_elements=*/nullptr,
Mathieu Chartiere58991b2015-10-13 07:59:34 -07001196 &oat_file,
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -07001197 &error_msgs);
Andreas Gampe9186ced2016-12-12 14:28:21 -08001198 CHECK(!dex_files.empty()) << android::base::Join(error_msgs, '\n');
Nicolas Geoffray3d8a78a2018-08-29 21:10:16 +00001199 if (dex_files[0]->GetOatDexFile() != nullptr) {
1200 loaded_oat_file_ = dex_files[0]->GetOatDexFile()->GetOatFile();
1201 }
Mathieu Chartiere58991b2015-10-13 07:59:34 -07001202 CHECK_EQ(loaded_oat_file_, oat_file);
Richard Uhler66d874d2015-01-15 09:37:19 -08001203 }
1204
1205 const OatFile* GetLoadedOatFile() const {
1206 return loaded_oat_file_;
1207 }
1208
1209 private:
Vladimir Markob9c29f62019-03-20 14:22:51 +00001210 OatFileAssistantTest& test_;
Richard Uhler66d874d2015-01-15 09:37:19 -08001211 std::string dex_location_;
1212 std::string oat_location_;
Nicolas Geoffray1e76d7a2018-09-03 13:23:34 +01001213 Mutex* lock_;
Richard Uhler66d874d2015-01-15 09:37:19 -08001214 const OatFile* loaded_oat_file_;
1215};
1216
Nicolas Geoffray3d8a78a2018-08-29 21:10:16 +00001217// Test the case where dex2oat invocations race with multiple processes trying to
1218// load the oat file.
Richard Uhler66d874d2015-01-15 09:37:19 -08001219TEST_F(OatFileAssistantTest, RaceToGenerate) {
1220 std::string dex_location = GetScratchDir() + "/RaceToGenerate.jar";
Richard Uhler63434112015-03-16 14:32:16 -07001221 std::string oat_location = GetOdexDir() + "/RaceToGenerate.oat";
Richard Uhler66d874d2015-01-15 09:37:19 -08001222
Jeff Hao0cb17282017-07-12 14:51:49 -07001223 // Start the runtime to initialize the system's class loader.
1224 Thread::Current()->TransitionFromSuspendedToRunnable();
1225 runtime_->Start();
1226
Richard Uhler66d874d2015-01-15 09:37:19 -08001227 // We use the lib core dex file, because it's large, and hopefully should
1228 // take a while to generate.
Narayan Kamathd1ef4362015-11-12 11:49:06 +00001229 Copy(GetLibCoreDexFileNames()[0], dex_location);
Richard Uhler66d874d2015-01-15 09:37:19 -08001230
Nicolas Geoffray3d8a78a2018-08-29 21:10:16 +00001231 const size_t kNumThreads = 32;
Richard Uhler66d874d2015-01-15 09:37:19 -08001232 Thread* self = Thread::Current();
1233 ThreadPool thread_pool("Oat file assistant test thread pool", kNumThreads);
1234 std::vector<std::unique_ptr<RaceGenerateTask>> tasks;
Nicolas Geoffray1e76d7a2018-09-03 13:23:34 +01001235 Mutex lock("RaceToGenerate");
Nicolas Geoffray3d8a78a2018-08-29 21:10:16 +00001236 for (size_t i = 0; i < kNumThreads; i++) {
Vladimir Markob9c29f62019-03-20 14:22:51 +00001237 std::unique_ptr<RaceGenerateTask> task(
1238 new RaceGenerateTask(*this, dex_location, oat_location, &lock));
Richard Uhler66d874d2015-01-15 09:37:19 -08001239 thread_pool.AddTask(self, task.get());
1240 tasks.push_back(std::move(task));
1241 }
1242 thread_pool.StartWorkers(self);
Andreas Gampe98ea9d92018-10-19 14:06:15 -07001243 thread_pool.Wait(self, /* do_work= */ true, /* may_hold_locks= */ false);
Richard Uhler66d874d2015-01-15 09:37:19 -08001244
Nicolas Geoffray3d8a78a2018-08-29 21:10:16 +00001245 // Verify that tasks which got an oat file got a unique one.
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -07001246 std::set<const OatFile*> oat_files;
Richard Uhler66d874d2015-01-15 09:37:19 -08001247 for (auto& task : tasks) {
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -07001248 const OatFile* oat_file = task->GetLoadedOatFile();
Nicolas Geoffray3d8a78a2018-08-29 21:10:16 +00001249 if (oat_file != nullptr) {
1250 EXPECT_TRUE(oat_files.find(oat_file) == oat_files.end());
1251 oat_files.insert(oat_file);
1252 }
Richard Uhler66d874d2015-01-15 09:37:19 -08001253 }
1254}
1255
Nicolas Geoffray3d8a78a2018-08-29 21:10:16 +00001256// Case: We have a DEX file and an ODEX file, and no OAT file,
Vladimir Markoe0669322018-09-03 15:44:54 +01001257// Expect: We should load the odex file executable.
Nicolas Geoffray3d8a78a2018-08-29 21:10:16 +00001258TEST_F(DexoptTest, LoadDexOdexNoOat) {
Richard Uhler66d874d2015-01-15 09:37:19 -08001259 std::string dex_location = GetScratchDir() + "/LoadDexOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -07001260 std::string odex_location = GetOdexDir() + "/LoadDexOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -08001261
1262 // Create the dex and odex files
1263 Copy(GetDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +00001264 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -08001265
1266 // Load the oat using an executable oat file assistant.
Richard Uhlerd1472a22016-04-15 15:18:56 -07001267 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler66d874d2015-01-15 09:37:19 -08001268
1269 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
1270 ASSERT_TRUE(oat_file.get() != nullptr);
Vladimir Markoe0669322018-09-03 15:44:54 +01001271 EXPECT_TRUE(oat_file->IsExecutable());
Richard Uhler66d874d2015-01-15 09:37:19 -08001272 std::vector<std::unique_ptr<const DexFile>> dex_files;
1273 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
1274 EXPECT_EQ(1u, dex_files.size());
1275}
1276
Nicolas Geoffray3d8a78a2018-08-29 21:10:16 +00001277// Case: We have a MultiDEX file and an ODEX file, and no OAT file.
Vladimir Markoe0669322018-09-03 15:44:54 +01001278// Expect: We should load the odex file executable.
Nicolas Geoffray3d8a78a2018-08-29 21:10:16 +00001279TEST_F(DexoptTest, LoadMultiDexOdexNoOat) {
Richard Uhler66d874d2015-01-15 09:37:19 -08001280 std::string dex_location = GetScratchDir() + "/LoadMultiDexOdexNoOat.jar";
Richard Uhler63434112015-03-16 14:32:16 -07001281 std::string odex_location = GetOdexDir() + "/LoadMultiDexOdexNoOat.odex";
Richard Uhler66d874d2015-01-15 09:37:19 -08001282
1283 // Create the dex and odex files
1284 Copy(GetMultiDexSrc1(), dex_location);
Andreas Gampe29d38e72016-03-23 15:31:51 +00001285 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
Richard Uhler66d874d2015-01-15 09:37:19 -08001286
1287 // Load the oat using an executable oat file assistant.
Richard Uhlerd1472a22016-04-15 15:18:56 -07001288 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true);
Richard Uhler66d874d2015-01-15 09:37:19 -08001289
1290 std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
1291 ASSERT_TRUE(oat_file.get() != nullptr);
Vladimir Markoe0669322018-09-03 15:44:54 +01001292 EXPECT_TRUE(oat_file->IsExecutable());
Richard Uhler66d874d2015-01-15 09:37:19 -08001293 std::vector<std::unique_ptr<const DexFile>> dex_files;
1294 dex_files = oat_file_assistant.LoadDexFiles(*oat_file, dex_location.c_str());
1295 EXPECT_EQ(2u, dex_files.size());
1296}
1297
Richard Uhlerb81881d2016-04-19 13:08:04 -07001298TEST(OatFileAssistantUtilsTest, DexLocationToOdexFilename) {
Richard Uhler66d874d2015-01-15 09:37:19 -08001299 std::string error_msg;
1300 std::string odex_file;
1301
Richard Uhlerb81881d2016-04-19 13:08:04 -07001302 EXPECT_TRUE(OatFileAssistant::DexLocationToOdexFilename(
Vladimir Marko33bff252017-11-01 14:35:42 +00001303 "/foo/bar/baz.jar", InstructionSet::kArm, &odex_file, &error_msg)) << error_msg;
Richard Uhler63434112015-03-16 14:32:16 -07001304 EXPECT_EQ("/foo/bar/oat/arm/baz.odex", odex_file);
Richard Uhler66d874d2015-01-15 09:37:19 -08001305
Richard Uhlerb81881d2016-04-19 13:08:04 -07001306 EXPECT_TRUE(OatFileAssistant::DexLocationToOdexFilename(
Vladimir Marko33bff252017-11-01 14:35:42 +00001307 "/foo/bar/baz.funnyext", InstructionSet::kArm, &odex_file, &error_msg)) << error_msg;
Richard Uhler63434112015-03-16 14:32:16 -07001308 EXPECT_EQ("/foo/bar/oat/arm/baz.odex", odex_file);
Richard Uhler66d874d2015-01-15 09:37:19 -08001309
Richard Uhlerb81881d2016-04-19 13:08:04 -07001310 EXPECT_FALSE(OatFileAssistant::DexLocationToOdexFilename(
Vladimir Marko33bff252017-11-01 14:35:42 +00001311 "nopath.jar", InstructionSet::kArm, &odex_file, &error_msg));
Richard Uhlerb81881d2016-04-19 13:08:04 -07001312 EXPECT_FALSE(OatFileAssistant::DexLocationToOdexFilename(
Vladimir Marko33bff252017-11-01 14:35:42 +00001313 "/foo/bar/baz_noext", InstructionSet::kArm, &odex_file, &error_msg));
Richard Uhler66d874d2015-01-15 09:37:19 -08001314}
1315
Richard Uhler23cedd22015-04-08 13:17:29 -07001316// Verify the dexopt status values from dalvik.system.DexFile
1317// match the OatFileAssistant::DexOptStatus values.
1318TEST_F(OatFileAssistantTest, DexOptStatusValues) {
Richard Uhler7225a8d2016-11-22 10:12:03 +00001319 std::pair<OatFileAssistant::DexOptNeeded, const char*> mapping[] = {
1320 {OatFileAssistant::kNoDexOptNeeded, "NO_DEXOPT_NEEDED"},
1321 {OatFileAssistant::kDex2OatFromScratch, "DEX2OAT_FROM_SCRATCH"},
1322 {OatFileAssistant::kDex2OatForBootImage, "DEX2OAT_FOR_BOOT_IMAGE"},
1323 {OatFileAssistant::kDex2OatForFilter, "DEX2OAT_FOR_FILTER"},
Richard Uhler7225a8d2016-11-22 10:12:03 +00001324 };
1325
Richard Uhler23cedd22015-04-08 13:17:29 -07001326 ScopedObjectAccess soa(Thread::Current());
1327 StackHandleScope<1> hs(soa.Self());
1328 ClassLinker* linker = Runtime::Current()->GetClassLinker();
1329 Handle<mirror::Class> dexfile(
1330 hs.NewHandle(linker->FindSystemClass(soa.Self(), "Ldalvik/system/DexFile;")));
Andreas Gampefa4333d2017-02-14 11:10:34 -08001331 ASSERT_FALSE(dexfile == nullptr);
Richard Uhler23cedd22015-04-08 13:17:29 -07001332 linker->EnsureInitialized(soa.Self(), dexfile, true, true);
1333
Richard Uhler7225a8d2016-11-22 10:12:03 +00001334 for (std::pair<OatFileAssistant::DexOptNeeded, const char*> field : mapping) {
1335 ArtField* art_field = mirror::Class::FindStaticField(
Vladimir Marko19a4d372016-12-08 14:41:46 +00001336 soa.Self(), dexfile.Get(), field.second, "I");
Richard Uhler7225a8d2016-11-22 10:12:03 +00001337 ASSERT_FALSE(art_field == nullptr);
1338 EXPECT_EQ(art_field->GetTypeAsPrimitiveType(), Primitive::kPrimInt);
1339 EXPECT_EQ(field.first, art_field->GetInt(dexfile.Get()));
1340 }
Richard Uhler23cedd22015-04-08 13:17:29 -07001341}
Richard Uhler66d874d2015-01-15 09:37:19 -08001342
Calin Juravle44e5efa2017-09-12 00:54:26 -07001343TEST_F(OatFileAssistantTest, GetDexOptNeededWithOutOfDateContext) {
1344 std::string dex_location = GetScratchDir() + "/TestDex.jar";
Calin Juravleaf322422020-02-11 13:45:53 -08001345 std::string odex_location = GetOdexDir() + "/TestDex.odex";
1346
Calin Juravle44e5efa2017-09-12 00:54:26 -07001347 std::string context_location = GetScratchDir() + "/ContextDex.jar";
1348 Copy(GetDexSrc1(), dex_location);
1349 Copy(GetDexSrc2(), context_location);
1350
Calin Juravle44e5efa2017-09-12 00:54:26 -07001351 std::string context_str = "PCL[" + context_location + "]";
Calin Juravleaf322422020-02-11 13:45:53 -08001352
Calin Juravle44e5efa2017-09-12 00:54:26 -07001353 std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(context_str);
1354 ASSERT_TRUE(context != nullptr);
Calin Juravle5ff23932020-12-11 18:26:14 -08001355 ASSERT_TRUE(context->OpenDexFiles());
Calin Juravle44e5efa2017-09-12 00:54:26 -07001356
Calin Juravleaf322422020-02-11 13:45:53 -08001357 std::string error_msg;
1358 std::vector<std::string> args;
1359 args.push_back("--dex-file=" + dex_location);
1360 args.push_back("--oat-file=" + odex_location);
1361 args.push_back("--class-loader-context=" + context_str);
1362 ASSERT_TRUE(Dex2Oat(args, &error_msg)) << error_msg;
1363
Calin Juravle44e5efa2017-09-12 00:54:26 -07001364 // Update the context by overriding the jar file.
1365 Copy(GetMultiDexSrc2(), context_location);
Calin Juravleaf322422020-02-11 13:45:53 -08001366
1367 {
Calin Juravle0a5cad32020-02-14 20:29:26 +00001368 std::unique_ptr<ClassLoaderContext> updated_context = ClassLoaderContext::Create(context_str);
1369 ASSERT_TRUE(updated_context != nullptr);
Calin Juravleaf322422020-02-11 13:45:53 -08001370 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
1371 // DexOptNeeded should advise compilation from scratch when the context changes.
1372 EXPECT_EQ(OatFileAssistant::kDex2OatFromScratch,
Calin Juravle0a5cad32020-02-14 20:29:26 +00001373 GetDexOptNeeded(&oat_file_assistant,
Calin Juravleaf322422020-02-11 13:45:53 -08001374 CompilerFilter::kDefaultCompilerFilter,
Calin Juravle0a5cad32020-02-14 20:29:26 +00001375 updated_context));
Calin Juravleaf322422020-02-11 13:45:53 -08001376 }
1377 {
Calin Juravle0a5cad32020-02-14 20:29:26 +00001378 std::unique_ptr<ClassLoaderContext> updated_context = ClassLoaderContext::Create(context_str);
1379 ASSERT_TRUE(updated_context != nullptr);
Calin Juravleaf322422020-02-11 13:45:53 -08001380 OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, false);
1381 // Now check that DexOptNeeded does not advise compilation if we only extracted the file.
1382 args.push_back("--compiler-filter=extract");
1383 ASSERT_TRUE(Dex2Oat(args, &error_msg)) << error_msg;
1384 EXPECT_EQ(OatFileAssistant::kNoDexOptNeeded,
Calin Juravle0a5cad32020-02-14 20:29:26 +00001385 GetDexOptNeeded(&oat_file_assistant,
Calin Juravleaf322422020-02-11 13:45:53 -08001386 CompilerFilter::kExtract,
Calin Juravle0a5cad32020-02-14 20:29:26 +00001387 updated_context));
Calin Juravleaf322422020-02-11 13:45:53 -08001388 }
Nicolas Geoffray29742602017-12-14 10:09:03 +00001389}
1390
Nicolas Geoffraye3e0f702019-03-12 07:02:02 +00001391// Test that GetLocation of a dex file is the same whether the dex
1392// filed is backed by an oat file or not.
1393TEST_F(OatFileAssistantTest, GetDexLocation) {
1394 std::string dex_location = GetScratchDir() + "/TestDex.jar";
1395 std::string oat_location = GetOdexDir() + "/TestDex.odex";
Eric Holkbc89ed42020-04-29 19:59:24 +00001396 std::string art_location = GetOdexDir() + "/TestDex.art";
Nicolas Geoffraye3e0f702019-03-12 07:02:02 +00001397
1398 // Start the runtime to initialize the system's class loader.
1399 Thread::Current()->TransitionFromSuspendedToRunnable();
1400 runtime_->Start();
1401
1402 Copy(GetDexSrc1(), dex_location);
1403
1404 std::vector<std::unique_ptr<const DexFile>> dex_files;
1405 std::vector<std::string> error_msgs;
1406 const OatFile* oat_file = nullptr;
1407
1408 dex_files = Runtime::Current()->GetOatFileManager().OpenDexFilesFromOat(
1409 dex_location.c_str(),
1410 Runtime::Current()->GetSystemClassLoader(),
1411 /*dex_elements=*/nullptr,
1412 &oat_file,
1413 &error_msgs);
Vladimir Markob7bf8432019-12-03 13:18:50 +00001414 ASSERT_EQ(dex_files.size(), 1u) << android::base::Join(error_msgs, "\n");
Nicolas Geoffraye3e0f702019-03-12 07:02:02 +00001415 EXPECT_EQ(oat_file, nullptr);
1416 std::string stored_dex_location = dex_files[0]->GetLocation();
1417 {
1418 // Create the oat file.
1419 std::vector<std::string> args;
1420 args.push_back("--dex-file=" + dex_location);
1421 args.push_back("--dex-location=TestDex.jar");
1422 args.push_back("--oat-file=" + oat_location);
Eric Holkbc89ed42020-04-29 19:59:24 +00001423 args.push_back("--app-image-file=" + art_location);
Nicolas Geoffraye3e0f702019-03-12 07:02:02 +00001424 std::string error_msg;
1425 ASSERT_TRUE(DexoptTest::Dex2Oat(args, &error_msg)) << error_msg;
1426 }
1427 dex_files = Runtime::Current()->GetOatFileManager().OpenDexFilesFromOat(
1428 dex_location.c_str(),
1429 Runtime::Current()->GetSystemClassLoader(),
1430 /*dex_elements=*/nullptr,
1431 &oat_file,
1432 &error_msgs);
Vladimir Markob7bf8432019-12-03 13:18:50 +00001433 ASSERT_EQ(dex_files.size(), 1u) << android::base::Join(error_msgs, "\n");
1434 ASSERT_NE(oat_file, nullptr);
Nicolas Geoffraye3e0f702019-03-12 07:02:02 +00001435 std::string oat_stored_dex_location = dex_files[0]->GetLocation();
1436 EXPECT_EQ(oat_stored_dex_location, stored_dex_location);
1437}
1438
1439// Test that a dex file on the platform location gets the right hiddenapi domain,
1440// regardless of whether it has a backing oat file.
1441TEST_F(OatFileAssistantTest, SystemFrameworkDir) {
1442 std::string filebase = "OatFileAssistantTestSystemFrameworkDir";
1443 std::string dex_location = GetAndroidRoot() + "/framework/" + filebase + ".jar";
1444 Copy(GetDexSrc1(), dex_location);
1445
1446 std::string odex_dir = GetAndroidRoot() + "/framework/oat/";
1447 mkdir(odex_dir.c_str(), 0700);
1448 odex_dir = odex_dir + std::string(GetInstructionSetString(kRuntimeISA));
1449 mkdir(odex_dir.c_str(), 0700);
1450 std::string oat_location = odex_dir + "/" + filebase + ".odex";
Nicolas Geoffray16f60dc2021-02-16 15:35:16 +00001451 std::string vdex_location = odex_dir + "/" + filebase + ".vdex";
Eric Holkbc89ed42020-04-29 19:59:24 +00001452 std::string art_location = odex_dir + "/" + filebase + ".art";
Nicolas Geoffraye3e0f702019-03-12 07:02:02 +00001453 // Clean up in case previous run crashed.
1454 remove(oat_location.c_str());
Nicolas Geoffray16f60dc2021-02-16 15:35:16 +00001455 remove(vdex_location.c_str());
1456 remove(art_location.c_str());
Nicolas Geoffraye3e0f702019-03-12 07:02:02 +00001457
1458 // Start the runtime to initialize the system's class loader.
1459 Thread::Current()->TransitionFromSuspendedToRunnable();
1460 runtime_->Start();
1461
1462 std::vector<std::unique_ptr<const DexFile>> dex_files_first;
1463 std::vector<std::unique_ptr<const DexFile>> dex_files_second;
1464 std::vector<std::string> error_msgs;
1465 const OatFile* oat_file = nullptr;
1466
1467 dex_files_first = Runtime::Current()->GetOatFileManager().OpenDexFilesFromOat(
1468 dex_location.c_str(),
1469 Runtime::Current()->GetSystemClassLoader(),
1470 /*dex_elements=*/nullptr,
1471 &oat_file,
1472 &error_msgs);
Vladimir Markob7bf8432019-12-03 13:18:50 +00001473 ASSERT_EQ(dex_files_first.size(), 1u) << android::base::Join(error_msgs, "\n");
Nicolas Geoffraye3e0f702019-03-12 07:02:02 +00001474 EXPECT_EQ(oat_file, nullptr) << dex_location;
1475 EXPECT_EQ(dex_files_first[0]->GetOatDexFile(), nullptr);
1476
1477 // Register the dex file to get a domain.
1478 {
1479 ScopedObjectAccess soa(Thread::Current());
1480 Runtime::Current()->GetClassLinker()->RegisterDexFile(
1481 *dex_files_first[0],
1482 soa.Decode<mirror::ClassLoader>(Runtime::Current()->GetSystemClassLoader()));
1483 }
1484 std::string stored_dex_location = dex_files_first[0]->GetLocation();
1485 EXPECT_EQ(dex_files_first[0]->GetHiddenapiDomain(), hiddenapi::Domain::kPlatform);
1486 {
1487 // Create the oat file.
1488 std::vector<std::string> args;
1489 args.push_back("--dex-file=" + dex_location);
1490 args.push_back("--dex-location=" + filebase + ".jar");
1491 args.push_back("--oat-file=" + oat_location);
Eric Holkbc89ed42020-04-29 19:59:24 +00001492 args.push_back("--app-image-file=" + art_location);
Nicolas Geoffraye3e0f702019-03-12 07:02:02 +00001493 std::string error_msg;
1494 ASSERT_TRUE(DexoptTest::Dex2Oat(args, &error_msg)) << error_msg;
1495 }
1496 dex_files_second = Runtime::Current()->GetOatFileManager().OpenDexFilesFromOat(
1497 dex_location.c_str(),
1498 Runtime::Current()->GetSystemClassLoader(),
1499 /*dex_elements=*/nullptr,
1500 &oat_file,
1501 &error_msgs);
Vladimir Markob7bf8432019-12-03 13:18:50 +00001502 ASSERT_EQ(dex_files_second.size(), 1u) << android::base::Join(error_msgs, "\n");
1503 ASSERT_NE(oat_file, nullptr);
Nicolas Geoffraye3e0f702019-03-12 07:02:02 +00001504 EXPECT_NE(dex_files_second[0]->GetOatDexFile(), nullptr);
1505 EXPECT_NE(dex_files_second[0]->GetOatDexFile()->GetOatFile(), nullptr);
1506
1507 // Register the dex file to get a domain.
1508 {
1509 ScopedObjectAccess soa(Thread::Current());
1510 Runtime::Current()->GetClassLinker()->RegisterDexFile(
1511 *dex_files_second[0],
1512 soa.Decode<mirror::ClassLoader>(Runtime::Current()->GetSystemClassLoader()));
1513 }
1514 std::string oat_stored_dex_location = dex_files_second[0]->GetLocation();
1515 EXPECT_EQ(oat_stored_dex_location, stored_dex_location);
1516 EXPECT_EQ(dex_files_second[0]->GetHiddenapiDomain(), hiddenapi::Domain::kPlatform);
1517 EXPECT_EQ(0, remove(oat_location.c_str()));
1518}
1519
Eric Holkbc89ed42020-04-29 19:59:24 +00001520// Make sure OAT files that require app images are not loaded as executable.
1521TEST_F(OatFileAssistantTest, LoadOatNoArt) {
1522 std::string dex_location = GetScratchDir() + "/TestDex.jar";
1523 std::string odex_location = GetOdexDir() + "/TestDex.odex";
1524 std::string art_location = GetOdexDir() + "/TestDex.art";
1525 Copy(GetDexSrc1(), dex_location);
1526 GenerateOdexForTest(dex_location,
1527 odex_location,
1528 CompilerFilter::kSpeed,
1529 "install",
1530 {
1531 "--app-image-file=" + art_location,
1532 });
1533
1534 unlink(art_location.c_str());
1535
1536 std::vector<std::string> error_msgs;
1537 const OatFile* oat_file = nullptr;
1538
1539 // Start the runtime to initialize the system's class loader.
1540 Thread::Current()->TransitionFromSuspendedToRunnable();
1541 runtime_->Start();
1542
1543 const auto dex_files = Runtime::Current()->GetOatFileManager().OpenDexFilesFromOat(
1544 dex_location.c_str(),
1545 Runtime::Current()->GetSystemClassLoader(),
1546 /*dex_elements=*/nullptr,
1547 &oat_file,
1548 &error_msgs);
1549
1550 EXPECT_FALSE(dex_files.empty());
Nicolas Geoffray90a18cf2020-06-25 15:12:59 +01001551 ASSERT_NE(oat_file, nullptr);
Eric Holkbc89ed42020-04-29 19:59:24 +00001552 EXPECT_FALSE(oat_file->IsExecutable());
1553}
1554
Richard Uhler66d874d2015-01-15 09:37:19 -08001555// TODO: More Tests:
1556// * Test class linker falls back to unquickened dex for DexNoOat
1557// * Test class linker falls back to unquickened dex for MultiDexNoOat
Richard Uhler66d874d2015-01-15 09:37:19 -08001558// * Test using secondary isa
Richard Uhler66d874d2015-01-15 09:37:19 -08001559// * Test for status of oat while oat is being generated (how?)
1560// * Test case where 32 and 64 bit boot class paths differ,
1561// and we ask IsInBootClassPath for a class in exactly one of the 32 or
1562// 64 bit boot class paths.
1563// * Test unexpected scenarios (?):
1564// - Dex is stripped, don't have odex.
1565// - Oat file corrupted after status check, before reload unexecutable
1566// because it's unrelocated and no dex2oat
Richard Uhler66d874d2015-01-15 09:37:19 -08001567} // namespace art