blob: 09c9d3b3cb2b50d33dbfa1f0684779bc8fb21819 [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
17#ifndef ART_RUNTIME_OAT_FILE_ASSISTANT_H_
18#define ART_RUNTIME_OAT_FILE_ASSISTANT_H_
19
20#include <cstdint>
21#include <memory>
Narayan Kamath8943c1d2016-05-02 13:14:48 +010022#include <sstream>
Richard Uhler66d874d2015-01-15 09:37:19 -080023#include <string>
24
25#include "arch/instruction_set.h"
David Sehrc431b9d2018-03-02 12:01:51 -080026#include "base/os.h"
Richard Uhler66d874d2015-01-15 09:37:19 -080027#include "base/scoped_flock.h"
28#include "base/unix_file/fd_file.h"
Andreas Gampe29d38e72016-03-23 15:31:51 +000029#include "compiler_filter.h"
Calin Juravle44e5efa2017-09-12 00:54:26 -070030#include "class_loader_context.h"
Richard Uhler66d874d2015-01-15 09:37:19 -080031#include "oat_file.h"
Richard Uhler66d874d2015-01-15 09:37:19 -080032
33namespace art {
34
Mathieu Chartierfbc31082016-01-24 11:59:56 -080035namespace gc {
36namespace space {
37class ImageSpace;
38} // namespace space
39} // namespace gc
40
Richard Uhler66d874d2015-01-15 09:37:19 -080041// Class for assisting with oat file management.
42//
43// This class collects common utilities for determining the status of an oat
44// file on the device, updating the oat file, and loading the oat file.
45//
46// The oat file assistant is intended to be used with dex locations not on the
47// boot class path. See the IsInBootClassPath method for a way to check if the
48// dex location is in the boot class path.
Richard Uhler66d874d2015-01-15 09:37:19 -080049class OatFileAssistant {
50 public:
Richard Uhler95abd042015-03-24 09:51:28 -070051 enum DexOptNeeded {
Richard Uhler7225a8d2016-11-22 10:12:03 +000052 // No dexopt should (or can) be done to update the apk/jar.
Richard Uhler95abd042015-03-24 09:51:28 -070053 // Matches Java: dalvik.system.DexFile.NO_DEXOPT_NEEDED = 0
54 kNoDexOptNeeded = 0,
Richard Uhler66d874d2015-01-15 09:37:19 -080055
Richard Uhler7225a8d2016-11-22 10:12:03 +000056 // dex2oat should be run to update the apk/jar from scratch.
57 // Matches Java: dalvik.system.DexFile.DEX2OAT_FROM_SCRATCH = 1
58 kDex2OatFromScratch = 1,
Richard Uhler66d874d2015-01-15 09:37:19 -080059
Richard Uhler7225a8d2016-11-22 10:12:03 +000060 // dex2oat should be run to update the apk/jar because the existing code
61 // is out of date with respect to the boot image.
62 // Matches Java: dalvik.system.DexFile.DEX2OAT_FOR_BOOT_IMAGE
63 kDex2OatForBootImage = 2,
Richard Uhler95abd042015-03-24 09:51:28 -070064
Richard Uhler7225a8d2016-11-22 10:12:03 +000065 // dex2oat should be run to update the apk/jar because the existing code
66 // is out of date with respect to the target compiler filter.
67 // Matches Java: dalvik.system.DexFile.DEX2OAT_FOR_FILTER
68 kDex2OatForFilter = 3,
Richard Uhler95abd042015-03-24 09:51:28 -070069 };
70
71 enum OatStatus {
Richard Uhler03bc6592016-11-22 09:42:04 +000072 // kOatCannotOpen - The oat file cannot be opened, because it does not
73 // exist, is unreadable, or otherwise corrupted.
74 kOatCannotOpen,
Richard Uhler95abd042015-03-24 09:51:28 -070075
Richard Uhler03bc6592016-11-22 09:42:04 +000076 // kOatDexOutOfDate - The oat file is out of date with respect to the dex file.
77 kOatDexOutOfDate,
Richard Uhler95abd042015-03-24 09:51:28 -070078
Richard Uhler03bc6592016-11-22 09:42:04 +000079 // kOatBootImageOutOfDate - The oat file is up to date with respect to the
80 // dex file, but is out of date with respect to the boot image.
81 kOatBootImageOutOfDate,
82
Richard Uhler03bc6592016-11-22 09:42:04 +000083 // kOatUpToDate - The oat file is completely up to date with respect to
84 // the dex file and boot image.
Richard Uhler95abd042015-03-24 09:51:28 -070085 kOatUpToDate,
Richard Uhler66d874d2015-01-15 09:37:19 -080086 };
87
88 // Constructs an OatFileAssistant object to assist the oat file
89 // corresponding to the given dex location with the target instruction set.
90 //
Mathieu Chartier2cebb242015-04-21 16:50:40 -070091 // The dex_location must not be null and should remain available and
Richard Uhler66d874d2015-01-15 09:37:19 -080092 // unchanged for the duration of the lifetime of the OatFileAssistant object.
93 // Typically the dex_location is the absolute path to the original,
94 // un-optimized dex file.
95 //
Richard Uhler66d874d2015-01-15 09:37:19 -080096 // Note: Currently the dex_location must have an extension.
97 // TODO: Relax this restriction?
98 //
99 // The isa should be either the 32 bit or 64 bit variant for the current
100 // device. For example, on an arm device, use arm or arm64. An oat file can
101 // be loaded executable only if the ISA matches the current runtime.
Andreas Gampe29d38e72016-03-23 15:31:51 +0000102 //
Andreas Gampe29d38e72016-03-23 15:31:51 +0000103 // load_executable should be true if the caller intends to try and load
104 // executable code for this dex location.
Nicolas Geoffray29742602017-12-14 10:09:03 +0000105 //
106 // only_load_system_executable should be true if the caller intends to have
107 // only oat files from /system loaded executable.
Calin Juravleb077e152016-02-18 18:47:37 +0000108 OatFileAssistant(const char* dex_location,
Calin Juravleb077e152016-02-18 18:47:37 +0000109 const InstructionSet isa,
Nicolas Geoffray29742602017-12-14 10:09:03 +0000110 bool load_executable,
111 bool only_load_system_executable = false);
Shubham Ajmerac12bf4c2017-10-24 16:59:42 -0700112
113 // Similar to this(const char*, const InstructionSet, bool), however, if a valid zip_fd is
114 // provided, vdex, oat, and zip files will be read from vdex_fd, oat_fd and zip_fd respectively.
115 // Otherwise, dex_location will be used to construct necessary filenames.
116 OatFileAssistant(const char* dex_location,
117 const InstructionSet isa,
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700118 bool load_executable,
Nicolas Geoffray29742602017-12-14 10:09:03 +0000119 bool only_load_system_executable,
Shubham Ajmerac12bf4c2017-10-24 16:59:42 -0700120 int vdex_fd,
121 int oat_fd,
122 int zip_fd);
Richard Uhler66d874d2015-01-15 09:37:19 -0800123
Richard Uhler66d874d2015-01-15 09:37:19 -0800124 ~OatFileAssistant();
125
126 // Returns true if the dex location refers to an element of the boot class
127 // path.
128 bool IsInBootClassPath();
129
Richard Uhler95abd042015-03-24 09:51:28 -0700130 // Return what action needs to be taken to produce up-to-date code for this
Shubham Ajmerae4e812a2017-05-25 20:09:58 -0700131 // dex location. If "downgrade" is set to false, it verifies if the current
132 // compiler filter is at least as good as an oat file generated with the
133 // given compiler filter otherwise, if its set to true, it checks whether
134 // the oat file generated with the target filter will be downgraded as
135 // compared to the current state. For example, if the current compiler filter is
136 // quicken, and target filter is verify, it will recommend to dexopt, while
137 // if the target filter is speed profile, it will recommend to keep it in its
138 // current state.
139 // profile_changed should be true to indicate the profile has recently changed
140 // for this dex location.
141 // If the purpose of the dexopt is to downgrade the compiler filter,
142 // set downgrade to true.
Richard Uhler7225a8d2016-11-22 10:12:03 +0000143 // Returns a positive status code if the status refers to the oat file in
144 // the oat location. Returns a negative status code if the status refers to
145 // the oat file in the odex location.
Shubham Ajmerae4e812a2017-05-25 20:09:58 -0700146 int GetDexOptNeeded(CompilerFilter::Filter target_compiler_filter,
147 bool profile_changed = false,
Calin Juravle44e5efa2017-09-12 00:54:26 -0700148 bool downgrade = false,
149 ClassLoaderContext* context = nullptr);
Richard Uhler66d874d2015-01-15 09:37:19 -0800150
Richard Uhler01be6812016-05-17 10:34:52 -0700151 // Returns true if there is up-to-date code for this dex location,
152 // irrespective of the compiler filter of the up-to-date code.
153 bool IsUpToDate();
154
Richard Uhler66d874d2015-01-15 09:37:19 -0800155 // Returns an oat file that can be used for loading dex files.
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700156 // Returns null if no suitable oat file was found.
Richard Uhler66d874d2015-01-15 09:37:19 -0800157 //
158 // After this call, no other methods of the OatFileAssistant should be
159 // called, because access to the loaded oat file has been taken away from
160 // the OatFileAssistant object.
161 std::unique_ptr<OatFile> GetBestOatFile();
162
Richard Uhler46cc64f2016-11-14 14:53:55 +0000163 // Returns a human readable description of the status of the code for the
164 // dex file. The returned description is for debugging purposes only.
165 std::string GetStatusDump();
166
Calin Juravle5f9a8012018-02-12 20:27:46 -0800167 // Computes the optimization status of the given dex file. The result is
168 // returned via the two output parameters.
169 // - out_compilation_filter: the level of optimizations (compiler filter)
170 // - out_compilation_reason: the optimization reason. The reason might
171 // be "unknown" if the compiler artifacts were not annotated during optimizations.
172 //
173 // This method will try to mimic the runtime effect of loading the dex file.
174 // For example, if there is no usable oat file, the compiler filter will be set
175 // to "run-from-apk".
176 static void GetOptimizationStatus(const std::string& filename,
177 InstructionSet isa,
178 std::string* out_compilation_filter,
179 std::string* out_compilation_reason);
180
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800181 // Open and returns an image space associated with the oat file.
Andreas Gampea463b6a2016-08-12 21:53:32 -0700182 static std::unique_ptr<gc::space::ImageSpace> OpenImageSpace(const OatFile* oat_file);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800183
Richard Uhler66d874d2015-01-15 09:37:19 -0800184 // Loads the dex files in the given oat file for the given dex location.
185 // The oat file should be up to date for the given dex location.
186 // This loads multiple dex files in the case of multidex.
187 // Returns an empty vector if no dex files for that location could be loaded
188 // from the oat file.
189 //
190 // The caller is responsible for freeing the dex_files returned, if any. The
191 // dex_files will only remain valid as long as the oat_file is valid.
192 static std::vector<std::unique_ptr<const DexFile>> LoadDexFiles(
193 const OatFile& oat_file, const char* dex_location);
194
Calin Juravle87e2cb62017-06-13 21:48:45 -0700195 // Same as `std::vector<std::unique_ptr<const DexFile>> LoadDexFiles(...)` with the difference:
196 // - puts the dex files in the given vector
197 // - returns whether or not all dex files were successfully opened
198 static bool LoadDexFiles(const OatFile& oat_file,
199 const std::string& dex_location,
200 std::vector<std::unique_ptr<const DexFile>>* out_dex_files);
201
Richard Uhler9b994ea2015-06-24 08:44:19 -0700202 // Returns true if there are dex files in the original dex location that can
203 // be compiled with dex2oat for this dex location.
204 // Returns false if there is no original dex file, or if the original dex
205 // file is an apk/zip without a classes.dex entry.
206 bool HasOriginalDexFiles();
207
Richard Uhler63434112015-03-16 14:32:16 -0700208 // If the dex file has been installed with a compiled oat file alongside
209 // it, the compiled oat file will have the extension .odex, and is referred
210 // to as the odex file. It is called odex for legacy reasons; the file is
211 // really an oat file. The odex file will often, but not always, have a
212 // patch delta of 0 and need to be relocated before use for the purposes of
213 // ASLR. The odex file is treated as if it were read-only.
Richard Uhler03bc6592016-11-22 09:42:04 +0000214 //
215 // Returns the status of the odex file for the dex location.
Richard Uhler95abd042015-03-24 09:51:28 -0700216 OatStatus OdexFileStatus();
Richard Uhler66d874d2015-01-15 09:37:19 -0800217
218 // When the dex files is compiled on the target device, the oat file is the
219 // result. The oat file will have been relocated to some
220 // (possibly-out-of-date) offset for ASLR.
Richard Uhler03bc6592016-11-22 09:42:04 +0000221 //
222 // Returns the status of the oat file for the dex location.
Richard Uhler95abd042015-03-24 09:51:28 -0700223 OatStatus OatFileStatus();
Richard Uhler66d874d2015-01-15 09:37:19 -0800224
Richard Uhler66d874d2015-01-15 09:37:19 -0800225 // Constructs the odex file name for the given dex location.
226 // Returns true on success, in which case odex_filename is set to the odex
227 // file name.
Richard Uhlere8e48ae2016-04-19 12:41:04 -0700228 // Returns false on error, in which case error_msg describes the error and
229 // odex_filename is not changed.
Richard Uhler66d874d2015-01-15 09:37:19 -0800230 // Neither odex_filename nor error_msg may be null.
Richard Uhlerb81881d2016-04-19 13:08:04 -0700231 static bool DexLocationToOdexFilename(const std::string& location,
232 InstructionSet isa,
233 std::string* odex_filename,
234 std::string* error_msg);
235
236 // Constructs the oat file name for the given dex location.
237 // Returns true on success, in which case oat_filename is set to the oat
238 // file name.
239 // Returns false on error, in which case error_msg describes the error and
240 // oat_filename is not changed.
241 // Neither oat_filename nor error_msg may be null.
242 static bool DexLocationToOatFilename(const std::string& location,
243 InstructionSet isa,
244 std::string* oat_filename,
245 std::string* error_msg);
Richard Uhler66d874d2015-01-15 09:37:19 -0800246
247 private:
248 struct ImageInfo {
Andreas Gampefb83d762018-12-13 23:30:25 +0000249 uint32_t boot_image_checksum = 0;
Richard Uhler66d874d2015-01-15 09:37:19 -0800250 std::string location;
Richard Uhler95e09672017-02-22 11:37:41 +0000251
252 static std::unique_ptr<ImageInfo> GetRuntimeImageInfo(InstructionSet isa,
253 std::string* error_msg);
Richard Uhler66d874d2015-01-15 09:37:19 -0800254 };
255
Richard Uhler743bf362016-04-19 15:39:37 -0700256 class OatFileInfo {
257 public:
258 // Initially the info is for no file in particular. It will treat the
259 // file as out of date until Reset is called with a real filename to use
260 // the cache for.
Richard Uhler88bc6732016-11-14 14:38:03 +0000261 // Pass true for is_oat_location if the information associated with this
262 // OatFileInfo is for the oat location, as opposed to the odex location.
263 OatFileInfo(OatFileAssistant* oat_file_assistant, bool is_oat_location);
264
265 bool IsOatLocation();
Richard Uhler743bf362016-04-19 15:39:37 -0700266
267 const std::string* Filename();
Richard Uhler03bc6592016-11-22 09:42:04 +0000268
269 // Returns true if this oat file can be used for running code. The oat
270 // file can be used for running code as long as it is not out of date with
271 // respect to the dex code or boot image. An oat file that is out of date
272 // with respect to relocation is considered useable, because it's possible
273 // to interpret the dex code rather than run the unrelocated compiled
274 // code.
275 bool IsUseable();
276
277 // Returns the status of this oat file.
Richard Uhler743bf362016-04-19 15:39:37 -0700278 OatStatus Status();
Richard Uhler743bf362016-04-19 15:39:37 -0700279
Richard Uhler70a84262016-11-08 16:51:51 +0000280 // Return the DexOptNeeded value for this oat file with respect to the
281 // given target_compilation_filter.
282 // profile_changed should be true to indicate the profile has recently
283 // changed for this dex location.
Shubham Ajmerae4e812a2017-05-25 20:09:58 -0700284 // downgrade should be true if the purpose of dexopt is to downgrade the
285 // compiler filter.
Richard Uhler70a84262016-11-08 16:51:51 +0000286 DexOptNeeded GetDexOptNeeded(CompilerFilter::Filter target_compiler_filter,
Shubham Ajmerae4e812a2017-05-25 20:09:58 -0700287 bool profile_changed,
Calin Juravle44e5efa2017-09-12 00:54:26 -0700288 bool downgrade,
289 ClassLoaderContext* context);
Richard Uhler70a84262016-11-08 16:51:51 +0000290
Richard Uhler743bf362016-04-19 15:39:37 -0700291 // Returns the loaded file.
292 // Loads the file if needed. Returns null if the file failed to load.
293 // The caller shouldn't clean up or free the returned pointer.
294 const OatFile* GetFile();
295
Richard Uhler743bf362016-04-19 15:39:37 -0700296 // Returns true if the file is opened executable.
297 bool IsExecutable();
298
Richard Uhler743bf362016-04-19 15:39:37 -0700299 // Clear any cached information about the file that depends on the
300 // contents of the file. This does not reset the provided filename.
301 void Reset();
302
303 // Clear any cached information and switch to getting info about the oat
304 // file with the given filename.
Nicolas Geoffray30025092018-04-19 14:43:29 +0100305 void Reset(const std::string& filename,
306 bool use_fd,
307 int zip_fd = -1,
308 int vdex_fd = -1,
309 int oat_fd = -1);
Richard Uhler743bf362016-04-19 15:39:37 -0700310
Richard Uhler70a84262016-11-08 16:51:51 +0000311 // Release the loaded oat file for runtime use.
312 // Returns null if the oat file hasn't been loaded or is out of date.
313 // Ensures the returned file is not loaded executable if it has unuseable
314 // compiled code.
315 //
316 // After this call, no other methods of the OatFileInfo should be
317 // called, because access to the loaded oat file has been taken away from
318 // the OatFileInfo object.
319 std::unique_ptr<OatFile> ReleaseFileForUse();
320
321 private:
322 // Returns true if the compiler filter used to generate the file is at
323 // least as good as the given target filter. profile_changed should be
324 // true to indicate the profile has recently changed for this dex
325 // location.
Shubham Ajmerae4e812a2017-05-25 20:09:58 -0700326 // downgrade should be true if the purpose of dexopt is to downgrade the
327 // compiler filter.
328 bool CompilerFilterIsOkay(CompilerFilter::Filter target, bool profile_changed, bool downgrade);
Richard Uhler70a84262016-11-08 16:51:51 +0000329
Calin Juravle44e5efa2017-09-12 00:54:26 -0700330 bool ClassLoaderContextIsOkay(ClassLoaderContext* context);
331
Richard Uhler743bf362016-04-19 15:39:37 -0700332 // Release the loaded oat file.
333 // Returns null if the oat file hasn't been loaded.
334 //
335 // After this call, no other methods of the OatFileInfo should be
336 // called, because access to the loaded oat file has been taken away from
337 // the OatFileInfo object.
338 std::unique_ptr<OatFile> ReleaseFile();
339
Richard Uhler743bf362016-04-19 15:39:37 -0700340 OatFileAssistant* oat_file_assistant_;
Richard Uhler88bc6732016-11-14 14:38:03 +0000341 const bool is_oat_location_;
Richard Uhler743bf362016-04-19 15:39:37 -0700342
343 bool filename_provided_ = false;
344 std::string filename_;
345
Nicolas Geoffray30025092018-04-19 14:43:29 +0100346 int zip_fd_ = -1;
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700347 int oat_fd_ = -1;
348 int vdex_fd_ = -1;
Shubham Ajmerac12bf4c2017-10-24 16:59:42 -0700349 bool use_fd_ = false;
Shubham Ajmerab22dea02017-10-04 18:36:41 -0700350
Richard Uhler743bf362016-04-19 15:39:37 -0700351 bool load_attempted_ = false;
352 std::unique_ptr<OatFile> file_;
353
354 bool status_attempted_ = false;
Andreas Gamped9911ee2017-03-27 13:27:24 -0700355 OatStatus status_ = OatStatus::kOatCannotOpen;
Richard Uhler743bf362016-04-19 15:39:37 -0700356
357 // For debugging only.
358 // If this flag is set, the file has been released to the user and the
359 // OatFileInfo object is in a bad state and should no longer be used.
360 bool file_released_ = false;
361 };
Richard Uhler66d874d2015-01-15 09:37:19 -0800362
Richard Uhler88bc6732016-11-14 14:38:03 +0000363 // Return info for the best oat file.
364 OatFileInfo& GetBestInfo();
365
Shubham Ajmerac12bf4c2017-10-24 16:59:42 -0700366 // Returns true when vdex/oat/odex files should be read from file descriptors.
367 // The method checks the value of zip_fd_, and if the value is valid, returns
368 // true. This is required to have a deterministic behavior around how different
369 // files are being read.
370 bool UseFdToReadFiles();
371
Richard Uhler2f27abd2017-01-31 14:02:34 +0000372 // Returns true if the dex checksums in the given vdex file are up to date
373 // with respect to the dex location. If the dex checksums are not up to
374 // date, error_msg is updated with a message describing the problem.
375 bool DexChecksumUpToDate(const VdexFile& file, std::string* error_msg);
376
377 // Returns true if the dex checksums in the given oat file are up to date
378 // with respect to the dex location. If the dex checksums are not up to
379 // date, error_msg is updated with a message describing the problem.
380 bool DexChecksumUpToDate(const OatFile& file, std::string* error_msg);
381
Richard Uhler03bc6592016-11-22 09:42:04 +0000382 // Return the status for a given opened oat file with respect to the dex
383 // location.
384 OatStatus GivenOatFileStatus(const OatFile& file);
385
Richard Uhler69bcf2c2017-01-24 10:25:21 +0000386 // Gets the dex checksums required for an up-to-date oat file.
387 // Returns cached_required_dex_checksums if the required checksums were
388 // located. Returns null if the required checksums were not found. The
389 // caller shouldn't clean up or free the returned pointer. This sets the
390 // has_original_dex_files_ field to true if the checksums were found for the
391 // dex_location_ dex file.
392 const std::vector<uint32_t>* GetRequiredDexChecksums();
Richard Uhler66d874d2015-01-15 09:37:19 -0800393
Richard Uhler66d874d2015-01-15 09:37:19 -0800394 // Returns the loaded image info.
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700395 // Loads the image info if needed. Returns null if the image info failed
Richard Uhler66d874d2015-01-15 09:37:19 -0800396 // to load.
397 // The caller shouldn't clean up or free the returned pointer.
398 const ImageInfo* GetImageInfo();
399
Richard Uhler66d874d2015-01-15 09:37:19 -0800400 // To implement Lock(), we lock a dummy file where the oat file would go
401 // (adding ".flock" to the target file name) and retain the lock for the
402 // remaining lifetime of the OatFileAssistant object.
Richard Uhler66d874d2015-01-15 09:37:19 -0800403 ScopedFlock flock_;
404
Richard Uhler740eec92015-10-15 15:12:23 -0700405 std::string dex_location_;
Richard Uhler66d874d2015-01-15 09:37:19 -0800406
Calin Juravle357c66d2017-05-04 01:57:17 +0000407 // Whether or not the parent directory of the dex file is writable.
408 bool dex_parent_writable_ = false;
409
Richard Uhler66d874d2015-01-15 09:37:19 -0800410 // In a properly constructed OatFileAssistant object, isa_ should be either
411 // the 32 or 64 bit variant for the current device.
Vladimir Marko33bff252017-11-01 14:35:42 +0000412 const InstructionSet isa_ = InstructionSet::kNone;
Richard Uhler66d874d2015-01-15 09:37:19 -0800413
Richard Uhler66d874d2015-01-15 09:37:19 -0800414 // Whether we will attempt to load oat files executable.
415 bool load_executable_ = false;
416
Nicolas Geoffray29742602017-12-14 10:09:03 +0000417 // Whether only oat files on /system are loaded executable.
418 const bool only_load_system_executable_ = false;
Nicolas Geoffray66ff8a82018-02-28 13:27:55 +0000419 // Whether the potential zip file only contains uncompressed dex.
420 // Will be set during GetRequiredDexChecksums.
421 bool zip_file_only_contains_uncompressed_dex_ = true;
Nicolas Geoffray29742602017-12-14 10:09:03 +0000422
Richard Uhler69bcf2c2017-01-24 10:25:21 +0000423 // Cached value of the required dex checksums.
424 // This should be accessed only by the GetRequiredDexChecksums() method.
425 std::vector<uint32_t> cached_required_dex_checksums_;
426 bool required_dex_checksums_attempted_ = false;
427 bool required_dex_checksums_found_;
Richard Uhler9b994ea2015-06-24 08:44:19 -0700428 bool has_original_dex_files_;
Richard Uhler66d874d2015-01-15 09:37:19 -0800429
Richard Uhler743bf362016-04-19 15:39:37 -0700430 OatFileInfo odex_;
431 OatFileInfo oat_;
Richard Uhler66d874d2015-01-15 09:37:19 -0800432
Shubham Ajmerac12bf4c2017-10-24 16:59:42 -0700433 // File descriptor corresponding to apk, dex file, or zip.
434 int zip_fd_;
435
Richard Uhler66d874d2015-01-15 09:37:19 -0800436 // Cached value of the image info.
437 // Use the GetImageInfo method rather than accessing these directly.
438 // TODO: The image info should probably be moved out of the oat file
439 // assistant to an image file manager.
440 bool image_info_load_attempted_ = false;
Richard Uhler95e09672017-02-22 11:37:41 +0000441 std::unique_ptr<ImageInfo> cached_image_info_;
Richard Uhler66d874d2015-01-15 09:37:19 -0800442
Calin Juravle357c66d2017-05-04 01:57:17 +0000443 friend class OatFileAssistantTest;
444
Richard Uhler66d874d2015-01-15 09:37:19 -0800445 DISALLOW_COPY_AND_ASSIGN(OatFileAssistant);
446};
447
Narayan Kamath8943c1d2016-05-02 13:14:48 +0100448std::ostream& operator << (std::ostream& stream, const OatFileAssistant::OatStatus status);
449
Richard Uhler66d874d2015-01-15 09:37:19 -0800450} // namespace art
451
452#endif // ART_RUNTIME_OAT_FILE_ASSISTANT_H_