xref: /aosp_15_r20/art/runtime/oat/oat_file_assistant.h (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2014 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker #ifndef ART_RUNTIME_OAT_OAT_FILE_ASSISTANT_H_
18*795d594fSAndroid Build Coastguard Worker #define ART_RUNTIME_OAT_OAT_FILE_ASSISTANT_H_
19*795d594fSAndroid Build Coastguard Worker 
20*795d594fSAndroid Build Coastguard Worker #include <cstdint>
21*795d594fSAndroid Build Coastguard Worker #include <memory>
22*795d594fSAndroid Build Coastguard Worker #include <optional>
23*795d594fSAndroid Build Coastguard Worker #include <sstream>
24*795d594fSAndroid Build Coastguard Worker #include <string>
25*795d594fSAndroid Build Coastguard Worker #include <string_view>
26*795d594fSAndroid Build Coastguard Worker #include <variant>
27*795d594fSAndroid Build Coastguard Worker 
28*795d594fSAndroid Build Coastguard Worker #include "arch/instruction_set.h"
29*795d594fSAndroid Build Coastguard Worker #include "base/compiler_filter.h"
30*795d594fSAndroid Build Coastguard Worker #include "base/macros.h"
31*795d594fSAndroid Build Coastguard Worker #include "base/os.h"
32*795d594fSAndroid Build Coastguard Worker #include "base/scoped_flock.h"
33*795d594fSAndroid Build Coastguard Worker #include "base/unix_file/fd_file.h"
34*795d594fSAndroid Build Coastguard Worker #include "class_loader_context.h"
35*795d594fSAndroid Build Coastguard Worker #include "oat_file.h"
36*795d594fSAndroid Build Coastguard Worker #include "oat_file_assistant_context.h"
37*795d594fSAndroid Build Coastguard Worker 
38*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN {
39*795d594fSAndroid Build Coastguard Worker 
40*795d594fSAndroid Build Coastguard Worker namespace gc {
41*795d594fSAndroid Build Coastguard Worker namespace space {
42*795d594fSAndroid Build Coastguard Worker class ImageSpace;
43*795d594fSAndroid Build Coastguard Worker }  // namespace space
44*795d594fSAndroid Build Coastguard Worker }  // namespace gc
45*795d594fSAndroid Build Coastguard Worker 
46*795d594fSAndroid Build Coastguard Worker // Class for assisting with oat file management.
47*795d594fSAndroid Build Coastguard Worker //
48*795d594fSAndroid Build Coastguard Worker // This class collects common utilities for determining the status of an oat
49*795d594fSAndroid Build Coastguard Worker // file on the device, updating the oat file, and loading the oat file.
50*795d594fSAndroid Build Coastguard Worker //
51*795d594fSAndroid Build Coastguard Worker // The oat file assistant is intended to be used with dex locations not on the
52*795d594fSAndroid Build Coastguard Worker // boot class path. See the IsInBootClassPath method for a way to check if the
53*795d594fSAndroid Build Coastguard Worker // dex location is in the boot class path.
54*795d594fSAndroid Build Coastguard Worker class OatFileAssistant {
55*795d594fSAndroid Build Coastguard Worker  public:
56*795d594fSAndroid Build Coastguard Worker   enum DexOptNeeded {
57*795d594fSAndroid Build Coastguard Worker     // No dexopt should (or can) be done to update the apk/jar.
58*795d594fSAndroid Build Coastguard Worker     // Matches Java: dalvik.system.DexFile.NO_DEXOPT_NEEDED = 0
59*795d594fSAndroid Build Coastguard Worker     kNoDexOptNeeded = 0,
60*795d594fSAndroid Build Coastguard Worker 
61*795d594fSAndroid Build Coastguard Worker     // dex2oat should be run to update the apk/jar from scratch.
62*795d594fSAndroid Build Coastguard Worker     // Matches Java: dalvik.system.DexFile.DEX2OAT_FROM_SCRATCH = 1
63*795d594fSAndroid Build Coastguard Worker     kDex2OatFromScratch = 1,
64*795d594fSAndroid Build Coastguard Worker 
65*795d594fSAndroid Build Coastguard Worker     // dex2oat should be run to update the apk/jar because the existing code
66*795d594fSAndroid Build Coastguard Worker     // is out of date with respect to the boot image.
67*795d594fSAndroid Build Coastguard Worker     // Matches Java: dalvik.system.DexFile.DEX2OAT_FOR_BOOT_IMAGE
68*795d594fSAndroid Build Coastguard Worker     kDex2OatForBootImage = 2,
69*795d594fSAndroid Build Coastguard Worker 
70*795d594fSAndroid Build Coastguard Worker     // dex2oat should be run to update the apk/jar because the existing code
71*795d594fSAndroid Build Coastguard Worker     // is out of date with respect to the target compiler filter.
72*795d594fSAndroid Build Coastguard Worker     // Matches Java: dalvik.system.DexFile.DEX2OAT_FOR_FILTER
73*795d594fSAndroid Build Coastguard Worker     kDex2OatForFilter = 3,
74*795d594fSAndroid Build Coastguard Worker   };
75*795d594fSAndroid Build Coastguard Worker 
76*795d594fSAndroid Build Coastguard Worker   enum OatStatus {
77*795d594fSAndroid Build Coastguard Worker     // kOatCannotOpen - The oat file cannot be opened, because it does not
78*795d594fSAndroid Build Coastguard Worker     // exist, is unreadable, or otherwise corrupted.
79*795d594fSAndroid Build Coastguard Worker     kOatCannotOpen,
80*795d594fSAndroid Build Coastguard Worker 
81*795d594fSAndroid Build Coastguard Worker     // kOatDexOutOfDate - The oat file is out of date with respect to the dex file.
82*795d594fSAndroid Build Coastguard Worker     kOatDexOutOfDate,
83*795d594fSAndroid Build Coastguard Worker 
84*795d594fSAndroid Build Coastguard Worker     // kOatBootImageOutOfDate - The oat file is up to date with respect to the
85*795d594fSAndroid Build Coastguard Worker     // dex file, but is out of date with respect to the boot image.
86*795d594fSAndroid Build Coastguard Worker     kOatBootImageOutOfDate,
87*795d594fSAndroid Build Coastguard Worker 
88*795d594fSAndroid Build Coastguard Worker     // kOatContextOutOfDate - The context in the oat file is out of date with
89*795d594fSAndroid Build Coastguard Worker     // respect to the class loader context.
90*795d594fSAndroid Build Coastguard Worker     kOatContextOutOfDate,
91*795d594fSAndroid Build Coastguard Worker 
92*795d594fSAndroid Build Coastguard Worker     // kOatUpToDate - The oat file is completely up to date with respect to
93*795d594fSAndroid Build Coastguard Worker     // the dex file and boot image.
94*795d594fSAndroid Build Coastguard Worker     kOatUpToDate,
95*795d594fSAndroid Build Coastguard Worker   };
96*795d594fSAndroid Build Coastguard Worker 
97*795d594fSAndroid Build Coastguard Worker   // A bit field to represent the conditions where dexopt should be performed.
98*795d594fSAndroid Build Coastguard Worker   struct DexOptTrigger {
99*795d594fSAndroid Build Coastguard Worker     // Dexopt should be performed if the target compiler filter is better than the current compiler
100*795d594fSAndroid Build Coastguard Worker     // filter. See `CompilerFilter::IsBetter`.
101*795d594fSAndroid Build Coastguard Worker     bool targetFilterIsBetter : 1;
102*795d594fSAndroid Build Coastguard Worker     // Dexopt should be performed if the target compiler filter is the same as the current compiler
103*795d594fSAndroid Build Coastguard Worker     // filter.
104*795d594fSAndroid Build Coastguard Worker     bool targetFilterIsSame : 1;
105*795d594fSAndroid Build Coastguard Worker     // Dexopt should be performed if the target compiler filter is worse than the current compiler
106*795d594fSAndroid Build Coastguard Worker     // filter. See `CompilerFilter::IsBetter`.
107*795d594fSAndroid Build Coastguard Worker     bool targetFilterIsWorse : 1;
108*795d594fSAndroid Build Coastguard Worker     // Dexopt should be performed if the current oat file was compiled without a primary image,
109*795d594fSAndroid Build Coastguard Worker     // and the runtime is now running with a primary image loaded from disk.
110*795d594fSAndroid Build Coastguard Worker     bool primaryBootImageBecomesUsable : 1;
111*795d594fSAndroid Build Coastguard Worker     // Dexopt should be performed if the APK is compressed and the current oat/vdex file doesn't
112*795d594fSAndroid Build Coastguard Worker     // contain dex code.
113*795d594fSAndroid Build Coastguard Worker     bool needExtraction : 1;
114*795d594fSAndroid Build Coastguard Worker   };
115*795d594fSAndroid Build Coastguard Worker 
116*795d594fSAndroid Build Coastguard Worker   // Represents the location of the current oat file and/or vdex file.
117*795d594fSAndroid Build Coastguard Worker   enum Location {
118*795d594fSAndroid Build Coastguard Worker     // Does not exist, or an error occurs.
119*795d594fSAndroid Build Coastguard Worker     kLocationNoneOrError = 0,
120*795d594fSAndroid Build Coastguard Worker     // In the global "dalvik-cache" folder.
121*795d594fSAndroid Build Coastguard Worker     kLocationOat = 1,
122*795d594fSAndroid Build Coastguard Worker     // In the "oat" folder next to the dex file.
123*795d594fSAndroid Build Coastguard Worker     kLocationOdex = 2,
124*795d594fSAndroid Build Coastguard Worker     // In the DM file. This means the only usable file is the vdex file.
125*795d594fSAndroid Build Coastguard Worker     kLocationDm = 3,
126*795d594fSAndroid Build Coastguard Worker   };
127*795d594fSAndroid Build Coastguard Worker 
128*795d594fSAndroid Build Coastguard Worker   // Represents the status of the current oat file and/or vdex file.
129*795d594fSAndroid Build Coastguard Worker   class DexOptStatus {
130*795d594fSAndroid Build Coastguard Worker    public:
GetLocation()131*795d594fSAndroid Build Coastguard Worker     Location GetLocation() { return location_; }
IsVdexUsable()132*795d594fSAndroid Build Coastguard Worker     bool IsVdexUsable() { return location_ != kLocationNoneOrError; }
133*795d594fSAndroid Build Coastguard Worker 
134*795d594fSAndroid Build Coastguard Worker    private:
135*795d594fSAndroid Build Coastguard Worker     Location location_ = kLocationNoneOrError;
136*795d594fSAndroid Build Coastguard Worker     friend class OatFileAssistant;
137*795d594fSAndroid Build Coastguard Worker   };
138*795d594fSAndroid Build Coastguard Worker 
139*795d594fSAndroid Build Coastguard Worker   // Constructs an OatFileAssistant object to assist the oat file
140*795d594fSAndroid Build Coastguard Worker   // corresponding to the given dex location with the target instruction set.
141*795d594fSAndroid Build Coastguard Worker   //
142*795d594fSAndroid Build Coastguard Worker   // The dex_location must not be null and should remain available and
143*795d594fSAndroid Build Coastguard Worker   // unchanged for the duration of the lifetime of the OatFileAssistant object.
144*795d594fSAndroid Build Coastguard Worker   // Typically the dex_location is the absolute path to the original,
145*795d594fSAndroid Build Coastguard Worker   // un-optimized dex file.
146*795d594fSAndroid Build Coastguard Worker   //
147*795d594fSAndroid Build Coastguard Worker   // Note: Currently the dex_location must have an extension.
148*795d594fSAndroid Build Coastguard Worker   // TODO: Relax this restriction?
149*795d594fSAndroid Build Coastguard Worker   //
150*795d594fSAndroid Build Coastguard Worker   // The isa should be either the 32 bit or 64 bit variant for the current
151*795d594fSAndroid Build Coastguard Worker   // device. For example, on an arm device, use arm or arm64. An oat file can
152*795d594fSAndroid Build Coastguard Worker   // be loaded executable only if the ISA matches the current runtime.
153*795d594fSAndroid Build Coastguard Worker   //
154*795d594fSAndroid Build Coastguard Worker   // context should be the class loader context to check against, or null to skip the check.
155*795d594fSAndroid Build Coastguard Worker   //
156*795d594fSAndroid Build Coastguard Worker   // load_executable should be true if the caller intends to try and load
157*795d594fSAndroid Build Coastguard Worker   // executable code for this dex location.
158*795d594fSAndroid Build Coastguard Worker   //
159*795d594fSAndroid Build Coastguard Worker   // only_load_trusted_executable should be true if the caller intends to have
160*795d594fSAndroid Build Coastguard Worker   // only oat files from trusted locations loaded executable. See IsTrustedLocation() for
161*795d594fSAndroid Build Coastguard Worker   // details on trusted locations.
162*795d594fSAndroid Build Coastguard Worker   //
163*795d594fSAndroid Build Coastguard Worker   // runtime_options should be provided with all the required fields filled if the caller intends to
164*795d594fSAndroid Build Coastguard Worker   // use OatFileAssistant without a runtime.
165*795d594fSAndroid Build Coastguard Worker   EXPORT OatFileAssistant(const char* dex_location,
166*795d594fSAndroid Build Coastguard Worker                           const InstructionSet isa,
167*795d594fSAndroid Build Coastguard Worker                           ClassLoaderContext* context,
168*795d594fSAndroid Build Coastguard Worker                           bool load_executable,
169*795d594fSAndroid Build Coastguard Worker                           bool only_load_trusted_executable = false,
170*795d594fSAndroid Build Coastguard Worker                           OatFileAssistantContext* ofa_context = nullptr);
171*795d594fSAndroid Build Coastguard Worker 
172*795d594fSAndroid Build Coastguard Worker   // Similar to this(const char*, const InstructionSet, bool), however, if a valid zip_fd is
173*795d594fSAndroid Build Coastguard Worker   // provided, vdex, oat, and zip files will be read from vdex_fd, oat_fd and zip_fd respectively.
174*795d594fSAndroid Build Coastguard Worker   // Otherwise, dex_location will be used to construct necessary filenames.
175*795d594fSAndroid Build Coastguard Worker   EXPORT OatFileAssistant(const char* dex_location,
176*795d594fSAndroid Build Coastguard Worker                           const InstructionSet isa,
177*795d594fSAndroid Build Coastguard Worker                           ClassLoaderContext* context,
178*795d594fSAndroid Build Coastguard Worker                           bool load_executable,
179*795d594fSAndroid Build Coastguard Worker                           bool only_load_trusted_executable,
180*795d594fSAndroid Build Coastguard Worker                           OatFileAssistantContext* ofa_context,
181*795d594fSAndroid Build Coastguard Worker                           int vdex_fd,
182*795d594fSAndroid Build Coastguard Worker                           int oat_fd,
183*795d594fSAndroid Build Coastguard Worker                           int zip_fd);
184*795d594fSAndroid Build Coastguard Worker 
185*795d594fSAndroid Build Coastguard Worker   // A convenient factory function that accepts ISA, class loader context, and compiler filter in
186*795d594fSAndroid Build Coastguard Worker   // strings. Returns the created instance and ClassLoaderContext on success, or returns nullptr and
187*795d594fSAndroid Build Coastguard Worker   // outputs an error message if it fails to parse the input strings.
188*795d594fSAndroid Build Coastguard Worker   // The returned ClassLoaderContext must live at least as long as the OatFileAssistant.
189*795d594fSAndroid Build Coastguard Worker   EXPORT static std::unique_ptr<OatFileAssistant> Create(
190*795d594fSAndroid Build Coastguard Worker       const std::string& filename,
191*795d594fSAndroid Build Coastguard Worker       const std::string& isa_str,
192*795d594fSAndroid Build Coastguard Worker       const std::optional<std::string>& context_str,
193*795d594fSAndroid Build Coastguard Worker       bool load_executable,
194*795d594fSAndroid Build Coastguard Worker       bool only_load_trusted_executable,
195*795d594fSAndroid Build Coastguard Worker       OatFileAssistantContext* ofa_context,
196*795d594fSAndroid Build Coastguard Worker       /*out*/ std::unique_ptr<ClassLoaderContext>* context,
197*795d594fSAndroid Build Coastguard Worker       /*out*/ std::string* error_msg);
198*795d594fSAndroid Build Coastguard Worker 
199*795d594fSAndroid Build Coastguard Worker   // Returns true if the dex location refers to an element of the boot class
200*795d594fSAndroid Build Coastguard Worker   // path.
201*795d594fSAndroid Build Coastguard Worker   EXPORT bool IsInBootClassPath();
202*795d594fSAndroid Build Coastguard Worker 
203*795d594fSAndroid Build Coastguard Worker   // Return what action needs to be taken to produce up-to-date code for this
204*795d594fSAndroid Build Coastguard Worker   // dex location. If "downgrade" is set to false, it verifies if the current
205*795d594fSAndroid Build Coastguard Worker   // compiler filter is at least as good as an oat file generated with the
206*795d594fSAndroid Build Coastguard Worker   // given compiler filter otherwise, if its set to true, it checks whether
207*795d594fSAndroid Build Coastguard Worker   // the oat file generated with the target filter will be downgraded as
208*795d594fSAndroid Build Coastguard Worker   // compared to the current state. For example, if the current compiler filter is verify and the
209*795d594fSAndroid Build Coastguard Worker   // target filter is speed profile it will recommend to keep it in its current state.
210*795d594fSAndroid Build Coastguard Worker   // profile_changed should be true to indicate the profile has recently changed
211*795d594fSAndroid Build Coastguard Worker   // for this dex location.
212*795d594fSAndroid Build Coastguard Worker   // If the purpose of the dexopt is to downgrade the compiler filter,
213*795d594fSAndroid Build Coastguard Worker   // set downgrade to true.
214*795d594fSAndroid Build Coastguard Worker   // Returns a positive status code if the status refers to the oat file in
215*795d594fSAndroid Build Coastguard Worker   // the oat location. Returns a negative status code if the status refers to
216*795d594fSAndroid Build Coastguard Worker   // the oat file in the odex location.
217*795d594fSAndroid Build Coastguard Worker   //
218*795d594fSAndroid Build Coastguard Worker   // Deprecated. Use the other overload.
219*795d594fSAndroid Build Coastguard Worker   EXPORT int GetDexOptNeeded(CompilerFilter::Filter target_compiler_filter,
220*795d594fSAndroid Build Coastguard Worker                              bool profile_changed = false,
221*795d594fSAndroid Build Coastguard Worker                              bool downgrade = false);
222*795d594fSAndroid Build Coastguard Worker 
223*795d594fSAndroid Build Coastguard Worker   // Returns true if dexopt needs to be performed with respect to the given target compilation
224*795d594fSAndroid Build Coastguard Worker   // filter and dexopt trigger. Also returns the status of the current oat file and/or vdex file.
225*795d594fSAndroid Build Coastguard Worker   EXPORT bool GetDexOptNeeded(CompilerFilter::Filter target_compiler_filter,
226*795d594fSAndroid Build Coastguard Worker                               const DexOptTrigger dexopt_trigger,
227*795d594fSAndroid Build Coastguard Worker                               /*out*/ DexOptStatus* dexopt_status);
228*795d594fSAndroid Build Coastguard Worker 
229*795d594fSAndroid Build Coastguard Worker   // Returns true if there is up-to-date code for this dex location,
230*795d594fSAndroid Build Coastguard Worker   // irrespective of the compiler filter of the up-to-date code.
231*795d594fSAndroid Build Coastguard Worker   bool IsUpToDate();
232*795d594fSAndroid Build Coastguard Worker 
233*795d594fSAndroid Build Coastguard Worker   // Returns an oat file that can be used for loading dex files.
234*795d594fSAndroid Build Coastguard Worker   // Returns null if no suitable oat file was found.
235*795d594fSAndroid Build Coastguard Worker   //
236*795d594fSAndroid Build Coastguard Worker   // After this call, no other methods of the OatFileAssistant should be
237*795d594fSAndroid Build Coastguard Worker   // called, because access to the loaded oat file has been taken away from
238*795d594fSAndroid Build Coastguard Worker   // the OatFileAssistant object.
239*795d594fSAndroid Build Coastguard Worker   std::unique_ptr<OatFile> GetBestOatFile();
240*795d594fSAndroid Build Coastguard Worker 
241*795d594fSAndroid Build Coastguard Worker   // Returns a human readable description of the status of the code for the
242*795d594fSAndroid Build Coastguard Worker   // dex file. The returned description is for debugging purposes only.
243*795d594fSAndroid Build Coastguard Worker   std::string GetStatusDump();
244*795d594fSAndroid Build Coastguard Worker 
245*795d594fSAndroid Build Coastguard Worker   // Computes the optimization status of the given dex file. The result is
246*795d594fSAndroid Build Coastguard Worker   // returned via the two output parameters.
247*795d594fSAndroid Build Coastguard Worker   //   - out_odex_location: the location of the (best) odex that will be used
248*795d594fSAndroid Build Coastguard Worker   //        for loading. See GetBestInfo().
249*795d594fSAndroid Build Coastguard Worker   //   - out_compilation_filter: the level of optimizations (compiler filter)
250*795d594fSAndroid Build Coastguard Worker   //   - out_compilation_reason: the optimization reason. The reason might
251*795d594fSAndroid Build Coastguard Worker   //        be "unknown" if the compiler artifacts were not annotated during optimizations.
252*795d594fSAndroid Build Coastguard Worker   //   - out_odex_status: a human readable refined status of the validity of the odex file.
253*795d594fSAndroid Build Coastguard Worker   //        Possible values are: "up-to-date", "apk-more-recent", and "io-error-no-oat".
254*795d594fSAndroid Build Coastguard Worker   //
255*795d594fSAndroid Build Coastguard Worker   // This method will try to mimic the runtime effect of loading the dex file.
256*795d594fSAndroid Build Coastguard Worker   // For example, if there is no usable oat file, the compiler filter will be set
257*795d594fSAndroid Build Coastguard Worker   // to "run-from-apk".
258*795d594fSAndroid Build Coastguard Worker   EXPORT void GetOptimizationStatus(std::string* out_odex_location,
259*795d594fSAndroid Build Coastguard Worker                                     std::string* out_compilation_filter,
260*795d594fSAndroid Build Coastguard Worker                                     std::string* out_compilation_reason,
261*795d594fSAndroid Build Coastguard Worker                                     std::string* out_odex_status,
262*795d594fSAndroid Build Coastguard Worker                                     Location* out_location);
263*795d594fSAndroid Build Coastguard Worker 
264*795d594fSAndroid Build Coastguard Worker   static void GetOptimizationStatus(const std::string& filename,
265*795d594fSAndroid Build Coastguard Worker                                     InstructionSet isa,
266*795d594fSAndroid Build Coastguard Worker                                     std::string* out_compilation_filter,
267*795d594fSAndroid Build Coastguard Worker                                     std::string* out_compilation_reason,
268*795d594fSAndroid Build Coastguard Worker                                     OatFileAssistantContext* ofa_context = nullptr);
269*795d594fSAndroid Build Coastguard Worker 
270*795d594fSAndroid Build Coastguard Worker   // Open and returns an image space associated with the oat file.
271*795d594fSAndroid Build Coastguard Worker   static std::unique_ptr<gc::space::ImageSpace> OpenImageSpace(const OatFile* oat_file);
272*795d594fSAndroid Build Coastguard Worker 
273*795d594fSAndroid Build Coastguard Worker   // Loads the dex files in the given oat file for the given dex location.
274*795d594fSAndroid Build Coastguard Worker   // The oat file should be up to date for the given dex location.
275*795d594fSAndroid Build Coastguard Worker   // This loads multiple dex files in the case of multidex.
276*795d594fSAndroid Build Coastguard Worker   // Returns an empty vector if no dex files for that location could be loaded
277*795d594fSAndroid Build Coastguard Worker   // from the oat file.
278*795d594fSAndroid Build Coastguard Worker   //
279*795d594fSAndroid Build Coastguard Worker   // The caller is responsible for freeing the dex_files returned, if any. The
280*795d594fSAndroid Build Coastguard Worker   // dex_files will only remain valid as long as the oat_file is valid.
281*795d594fSAndroid Build Coastguard Worker   static std::vector<std::unique_ptr<const DexFile>> LoadDexFiles(
282*795d594fSAndroid Build Coastguard Worker       const OatFile& oat_file, const char* dex_location);
283*795d594fSAndroid Build Coastguard Worker 
284*795d594fSAndroid Build Coastguard Worker   // Same as `std::vector<std::unique_ptr<const DexFile>> LoadDexFiles(...)` with the difference:
285*795d594fSAndroid Build Coastguard Worker   //   - puts the dex files in the given vector
286*795d594fSAndroid Build Coastguard Worker   //   - returns whether or not all dex files were successfully opened
287*795d594fSAndroid Build Coastguard Worker   static bool LoadDexFiles(const OatFile& oat_file,
288*795d594fSAndroid Build Coastguard Worker                            const std::string& dex_location,
289*795d594fSAndroid Build Coastguard Worker                            std::vector<std::unique_ptr<const DexFile>>* out_dex_files);
290*795d594fSAndroid Build Coastguard Worker 
291*795d594fSAndroid Build Coastguard Worker   // Returns whether this is an apk/zip wit a classes.dex entry, or nullopt if an error occurred.
292*795d594fSAndroid Build Coastguard Worker   EXPORT std::optional<bool> HasDexFiles(std::string* error_msg);
293*795d594fSAndroid Build Coastguard Worker 
294*795d594fSAndroid Build Coastguard Worker   // If the dex file has been installed with a compiled oat file alongside
295*795d594fSAndroid Build Coastguard Worker   // it, the compiled oat file will have the extension .odex, and is referred
296*795d594fSAndroid Build Coastguard Worker   // to as the odex file. It is called odex for legacy reasons; the file is
297*795d594fSAndroid Build Coastguard Worker   // really an oat file. The odex file will often, but not always, have a
298*795d594fSAndroid Build Coastguard Worker   // patch delta of 0 and need to be relocated before use for the purposes of
299*795d594fSAndroid Build Coastguard Worker   // ASLR. The odex file is treated as if it were read-only.
300*795d594fSAndroid Build Coastguard Worker   //
301*795d594fSAndroid Build Coastguard Worker   // Returns the status of the odex file for the dex location.
302*795d594fSAndroid Build Coastguard Worker   OatStatus OdexFileStatus();
303*795d594fSAndroid Build Coastguard Worker 
304*795d594fSAndroid Build Coastguard Worker   // When the dex files is compiled on the target device, the oat file is the
305*795d594fSAndroid Build Coastguard Worker   // result. The oat file will have been relocated to some
306*795d594fSAndroid Build Coastguard Worker   // (possibly-out-of-date) offset for ASLR.
307*795d594fSAndroid Build Coastguard Worker   //
308*795d594fSAndroid Build Coastguard Worker   // Returns the status of the oat file for the dex location.
309*795d594fSAndroid Build Coastguard Worker   OatStatus OatFileStatus();
310*795d594fSAndroid Build Coastguard Worker 
GetBestStatus()311*795d594fSAndroid Build Coastguard Worker   OatStatus GetBestStatus() {
312*795d594fSAndroid Build Coastguard Worker     return GetBestInfo().Status();
313*795d594fSAndroid Build Coastguard Worker   }
314*795d594fSAndroid Build Coastguard Worker 
315*795d594fSAndroid Build Coastguard Worker   // Constructs the odex file name for the given dex location.
316*795d594fSAndroid Build Coastguard Worker   // Returns true on success, in which case odex_filename is set to the odex
317*795d594fSAndroid Build Coastguard Worker   // file name.
318*795d594fSAndroid Build Coastguard Worker   // Returns false on error, in which case error_msg describes the error and
319*795d594fSAndroid Build Coastguard Worker   // odex_filename is not changed.
320*795d594fSAndroid Build Coastguard Worker   // Neither odex_filename nor error_msg may be null.
321*795d594fSAndroid Build Coastguard Worker   EXPORT static bool DexLocationToOdexFilename(const std::string& location,
322*795d594fSAndroid Build Coastguard Worker                                                InstructionSet isa,
323*795d594fSAndroid Build Coastguard Worker                                                std::string* odex_filename,
324*795d594fSAndroid Build Coastguard Worker                                                std::string* error_msg);
325*795d594fSAndroid Build Coastguard Worker 
326*795d594fSAndroid Build Coastguard Worker   // Constructs the oat file name for the given dex location.
327*795d594fSAndroid Build Coastguard Worker   // Returns true on success, in which case oat_filename is set to the oat
328*795d594fSAndroid Build Coastguard Worker   // file name.
329*795d594fSAndroid Build Coastguard Worker   // Returns false on error, in which case error_msg describes the error and
330*795d594fSAndroid Build Coastguard Worker   // oat_filename is not changed.
331*795d594fSAndroid Build Coastguard Worker   // Neither oat_filename nor error_msg may be null.
332*795d594fSAndroid Build Coastguard Worker   //
333*795d594fSAndroid Build Coastguard Worker   // Calling this function requires an active runtime.
334*795d594fSAndroid Build Coastguard Worker   static bool DexLocationToOatFilename(const std::string& location,
335*795d594fSAndroid Build Coastguard Worker                                        InstructionSet isa,
336*795d594fSAndroid Build Coastguard Worker                                        std::string* oat_filename,
337*795d594fSAndroid Build Coastguard Worker                                        std::string* error_msg);
338*795d594fSAndroid Build Coastguard Worker 
339*795d594fSAndroid Build Coastguard Worker   // Same as above, but also takes `deny_art_apex_data_files` from input.
340*795d594fSAndroid Build Coastguard Worker   //
341*795d594fSAndroid Build Coastguard Worker   // Calling this function does not require an active runtime.
342*795d594fSAndroid Build Coastguard Worker   EXPORT static bool DexLocationToOatFilename(const std::string& location,
343*795d594fSAndroid Build Coastguard Worker                                               InstructionSet isa,
344*795d594fSAndroid Build Coastguard Worker                                               bool deny_art_apex_data_files,
345*795d594fSAndroid Build Coastguard Worker                                               std::string* oat_filename,
346*795d594fSAndroid Build Coastguard Worker                                               std::string* error_msg);
347*795d594fSAndroid Build Coastguard Worker 
348*795d594fSAndroid Build Coastguard Worker   // Computes the dex location and vdex filename. If the data directory of the process
349*795d594fSAndroid Build Coastguard Worker   // is known, creates an absolute path in that directory and tries to infer path
350*795d594fSAndroid Build Coastguard Worker   // of a corresponding vdex file. Otherwise only creates a basename dex_location
351*795d594fSAndroid Build Coastguard Worker   // from the combined checksums. Returns true if all out-arguments have been set.
352*795d594fSAndroid Build Coastguard Worker   //
353*795d594fSAndroid Build Coastguard Worker   // Calling this function requires an active runtime.
354*795d594fSAndroid Build Coastguard Worker   static bool AnonymousDexVdexLocation(const std::vector<const DexFile::Header*>& dex_headers,
355*795d594fSAndroid Build Coastguard Worker                                        InstructionSet isa,
356*795d594fSAndroid Build Coastguard Worker                                        /* out */ std::string* dex_location,
357*795d594fSAndroid Build Coastguard Worker                                        /* out */ std::string* vdex_filename);
358*795d594fSAndroid Build Coastguard Worker 
359*795d594fSAndroid Build Coastguard Worker   // Returns true if a filename (given as basename) is a name of a vdex for
360*795d594fSAndroid Build Coastguard Worker   // anonymous dex file(s) created by AnonymousDexVdexLocation.
361*795d594fSAndroid Build Coastguard Worker   EXPORT static bool IsAnonymousVdexBasename(const std::string& basename);
362*795d594fSAndroid Build Coastguard Worker 
363*795d594fSAndroid Build Coastguard Worker   bool ClassLoaderContextIsOkay(const OatFile& oat_file) const;
364*795d594fSAndroid Build Coastguard Worker 
365*795d594fSAndroid Build Coastguard Worker   // Validates the boot class path checksum of an OatFile.
366*795d594fSAndroid Build Coastguard Worker   EXPORT bool ValidateBootClassPathChecksums(const OatFile& oat_file);
367*795d594fSAndroid Build Coastguard Worker 
368*795d594fSAndroid Build Coastguard Worker   // Validates the given bootclasspath and bootclasspath checksums found in an oat header.
369*795d594fSAndroid Build Coastguard Worker   static bool ValidateBootClassPathChecksums(OatFileAssistantContext* ofa_context,
370*795d594fSAndroid Build Coastguard Worker                                              InstructionSet isa,
371*795d594fSAndroid Build Coastguard Worker                                              std::string_view oat_checksums,
372*795d594fSAndroid Build Coastguard Worker                                              std::string_view oat_boot_class_path,
373*795d594fSAndroid Build Coastguard Worker                                              /*out*/ std::string* error_msg);
374*795d594fSAndroid Build Coastguard Worker 
375*795d594fSAndroid Build Coastguard Worker  private:
376*795d594fSAndroid Build Coastguard Worker   class OatFileInfo {
377*795d594fSAndroid Build Coastguard Worker    public:
378*795d594fSAndroid Build Coastguard Worker     // Initially the info is for no file in particular. It will treat the
379*795d594fSAndroid Build Coastguard Worker     // file as out of date until Reset is called with a real filename to use
380*795d594fSAndroid Build Coastguard Worker     // the cache for.
381*795d594fSAndroid Build Coastguard Worker     // Pass true for is_oat_location if the information associated with this
382*795d594fSAndroid Build Coastguard Worker     // OatFileInfo is for the oat location, as opposed to the odex location.
383*795d594fSAndroid Build Coastguard Worker     OatFileInfo(OatFileAssistant* oat_file_assistant, bool is_oat_location);
384*795d594fSAndroid Build Coastguard Worker 
385*795d594fSAndroid Build Coastguard Worker     bool IsOatLocation();
386*795d594fSAndroid Build Coastguard Worker 
387*795d594fSAndroid Build Coastguard Worker     const std::string* Filename();
388*795d594fSAndroid Build Coastguard Worker 
389*795d594fSAndroid Build Coastguard Worker     const char* DisplayFilename();
390*795d594fSAndroid Build Coastguard Worker 
391*795d594fSAndroid Build Coastguard Worker     // Returns true if this oat file can be used for running code. The oat
392*795d594fSAndroid Build Coastguard Worker     // file can be used for running code as long as it is not out of date with
393*795d594fSAndroid Build Coastguard Worker     // respect to the dex code or boot image. An oat file that is out of date
394*795d594fSAndroid Build Coastguard Worker     // with respect to relocation is considered useable, because it's possible
395*795d594fSAndroid Build Coastguard Worker     // to interpret the dex code rather than run the unrelocated compiled
396*795d594fSAndroid Build Coastguard Worker     // code.
397*795d594fSAndroid Build Coastguard Worker     bool IsUseable();
398*795d594fSAndroid Build Coastguard Worker 
399*795d594fSAndroid Build Coastguard Worker     // Returns the status of this oat file.
400*795d594fSAndroid Build Coastguard Worker     OatStatus Status();
401*795d594fSAndroid Build Coastguard Worker 
402*795d594fSAndroid Build Coastguard Worker     // Return the DexOptNeeded value for this oat file with respect to the given target compilation
403*795d594fSAndroid Build Coastguard Worker     // filter and dexopt trigger.
404*795d594fSAndroid Build Coastguard Worker     DexOptNeeded GetDexOptNeeded(CompilerFilter::Filter target_compiler_filter,
405*795d594fSAndroid Build Coastguard Worker                                  const DexOptTrigger dexopt_trigger);
406*795d594fSAndroid Build Coastguard Worker 
407*795d594fSAndroid Build Coastguard Worker     // Returns the loaded file.
408*795d594fSAndroid Build Coastguard Worker     // Loads the file if needed. Returns null if the file failed to load.
409*795d594fSAndroid Build Coastguard Worker     // The caller shouldn't clean up or free the returned pointer.
410*795d594fSAndroid Build Coastguard Worker     const OatFile* GetFile();
411*795d594fSAndroid Build Coastguard Worker 
412*795d594fSAndroid Build Coastguard Worker     // Returns true if the file is opened executable.
413*795d594fSAndroid Build Coastguard Worker     bool IsExecutable();
414*795d594fSAndroid Build Coastguard Worker 
415*795d594fSAndroid Build Coastguard Worker     // Clear any cached information about the file that depends on the
416*795d594fSAndroid Build Coastguard Worker     // contents of the file. This does not reset the provided filename.
417*795d594fSAndroid Build Coastguard Worker     void Reset();
418*795d594fSAndroid Build Coastguard Worker 
419*795d594fSAndroid Build Coastguard Worker     // Clear any cached information and switch to getting info about the oat
420*795d594fSAndroid Build Coastguard Worker     // file with the given filename.
421*795d594fSAndroid Build Coastguard Worker     void Reset(const std::string& filename,
422*795d594fSAndroid Build Coastguard Worker                bool use_fd,
423*795d594fSAndroid Build Coastguard Worker                int zip_fd = -1,
424*795d594fSAndroid Build Coastguard Worker                int vdex_fd = -1,
425*795d594fSAndroid Build Coastguard Worker                int oat_fd = -1);
426*795d594fSAndroid Build Coastguard Worker 
427*795d594fSAndroid Build Coastguard Worker     // Release the loaded oat file for runtime use.
428*795d594fSAndroid Build Coastguard Worker     // Returns null if the oat file hasn't been loaded or is out of date.
429*795d594fSAndroid Build Coastguard Worker     // Ensures the returned file is not loaded executable if it has unuseable
430*795d594fSAndroid Build Coastguard Worker     // compiled code.
431*795d594fSAndroid Build Coastguard Worker     //
432*795d594fSAndroid Build Coastguard Worker     // After this call, no other methods of the OatFileInfo should be
433*795d594fSAndroid Build Coastguard Worker     // called, because access to the loaded oat file has been taken away from
434*795d594fSAndroid Build Coastguard Worker     // the OatFileInfo object.
435*795d594fSAndroid Build Coastguard Worker     std::unique_ptr<OatFile> ReleaseFileForUse();
436*795d594fSAndroid Build Coastguard Worker 
437*795d594fSAndroid Build Coastguard Worker     // Check if we should reject vdex containing cdex code as part of the cdex
438*795d594fSAndroid Build Coastguard Worker     // deprecation.
439*795d594fSAndroid Build Coastguard Worker     // TODO(b/256664509): Clean this up.
440*795d594fSAndroid Build Coastguard Worker     bool CheckDisableCompactDex();
441*795d594fSAndroid Build Coastguard Worker 
442*795d594fSAndroid Build Coastguard Worker    private:
443*795d594fSAndroid Build Coastguard Worker     // Returns true if the oat file is usable but at least one dexopt trigger is matched. This
444*795d594fSAndroid Build Coastguard Worker     // function should only be called if the oat file is usable.
445*795d594fSAndroid Build Coastguard Worker     bool ShouldRecompileForFilter(CompilerFilter::Filter target,
446*795d594fSAndroid Build Coastguard Worker                                   const DexOptTrigger dexopt_trigger);
447*795d594fSAndroid Build Coastguard Worker 
448*795d594fSAndroid Build Coastguard Worker     // Release the loaded oat file.
449*795d594fSAndroid Build Coastguard Worker     // Returns null if the oat file hasn't been loaded.
450*795d594fSAndroid Build Coastguard Worker     //
451*795d594fSAndroid Build Coastguard Worker     // After this call, no other methods of the OatFileInfo should be
452*795d594fSAndroid Build Coastguard Worker     // called, because access to the loaded oat file has been taken away from
453*795d594fSAndroid Build Coastguard Worker     // the OatFileInfo object.
454*795d594fSAndroid Build Coastguard Worker     std::unique_ptr<OatFile> ReleaseFile();
455*795d594fSAndroid Build Coastguard Worker 
456*795d594fSAndroid Build Coastguard Worker     OatFileAssistant* oat_file_assistant_;
457*795d594fSAndroid Build Coastguard Worker     const bool is_oat_location_;
458*795d594fSAndroid Build Coastguard Worker 
459*795d594fSAndroid Build Coastguard Worker     bool filename_provided_ = false;
460*795d594fSAndroid Build Coastguard Worker     std::string filename_;
461*795d594fSAndroid Build Coastguard Worker 
462*795d594fSAndroid Build Coastguard Worker     int zip_fd_ = -1;
463*795d594fSAndroid Build Coastguard Worker     int oat_fd_ = -1;
464*795d594fSAndroid Build Coastguard Worker     int vdex_fd_ = -1;
465*795d594fSAndroid Build Coastguard Worker     bool use_fd_ = false;
466*795d594fSAndroid Build Coastguard Worker 
467*795d594fSAndroid Build Coastguard Worker     bool load_attempted_ = false;
468*795d594fSAndroid Build Coastguard Worker     std::unique_ptr<OatFile> file_;
469*795d594fSAndroid Build Coastguard Worker 
470*795d594fSAndroid Build Coastguard Worker     bool status_attempted_ = false;
471*795d594fSAndroid Build Coastguard Worker     OatStatus status_ = OatStatus::kOatCannotOpen;
472*795d594fSAndroid Build Coastguard Worker 
473*795d594fSAndroid Build Coastguard Worker     // For debugging only.
474*795d594fSAndroid Build Coastguard Worker     // If this flag is set, the file has been released to the user and the
475*795d594fSAndroid Build Coastguard Worker     // OatFileInfo object is in a bad state and should no longer be used.
476*795d594fSAndroid Build Coastguard Worker     bool file_released_ = false;
477*795d594fSAndroid Build Coastguard Worker   };
478*795d594fSAndroid Build Coastguard Worker 
479*795d594fSAndroid Build Coastguard Worker   // Return info for the best oat file.
480*795d594fSAndroid Build Coastguard Worker   OatFileInfo& GetBestInfo();
481*795d594fSAndroid Build Coastguard Worker 
482*795d594fSAndroid Build Coastguard Worker   // Returns true when vdex/oat/odex files should be read from file descriptors.
483*795d594fSAndroid Build Coastguard Worker   // The method checks the value of zip_fd_, and if the value is valid, returns
484*795d594fSAndroid Build Coastguard Worker   // true. This is required to have a deterministic behavior around how different
485*795d594fSAndroid Build Coastguard Worker   // files are being read.
486*795d594fSAndroid Build Coastguard Worker   bool UseFdToReadFiles();
487*795d594fSAndroid Build Coastguard Worker 
488*795d594fSAndroid Build Coastguard Worker   // Returns true if the dex checksums in the given oat file are up to date
489*795d594fSAndroid Build Coastguard Worker   // with respect to the dex location. If the dex checksums are not up to
490*795d594fSAndroid Build Coastguard Worker   // date, error_msg is updated with a message describing the problem.
491*795d594fSAndroid Build Coastguard Worker   bool DexChecksumUpToDate(const OatFile& file, std::string* error_msg);
492*795d594fSAndroid Build Coastguard Worker 
493*795d594fSAndroid Build Coastguard Worker   // Return the status for a given opened oat file with respect to the dex
494*795d594fSAndroid Build Coastguard Worker   // location.
495*795d594fSAndroid Build Coastguard Worker   OatStatus GivenOatFileStatus(const OatFile& file);
496*795d594fSAndroid Build Coastguard Worker 
497*795d594fSAndroid Build Coastguard Worker   // Gets the dex checksum required for an up-to-date oat file.
498*795d594fSAndroid Build Coastguard Worker   // Returns cached result from GetMultiDexChecksum.
499*795d594fSAndroid Build Coastguard Worker   bool GetRequiredDexChecksum(std::optional<uint32_t>* checksum, std::string* error);
500*795d594fSAndroid Build Coastguard Worker 
501*795d594fSAndroid Build Coastguard Worker   // Returns whether there is at least one boot image usable.
502*795d594fSAndroid Build Coastguard Worker   bool IsPrimaryBootImageUsable();
503*795d594fSAndroid Build Coastguard Worker 
504*795d594fSAndroid Build Coastguard Worker   // Returns the trigger for the deprecated overload of `GetDexOptNeeded`.
505*795d594fSAndroid Build Coastguard Worker   //
506*795d594fSAndroid Build Coastguard Worker   // Deprecated. Do not use in new code.
507*795d594fSAndroid Build Coastguard Worker   DexOptTrigger GetDexOptTrigger(CompilerFilter::Filter target_compiler_filter,
508*795d594fSAndroid Build Coastguard Worker                                  bool profile_changed,
509*795d594fSAndroid Build Coastguard Worker                                  bool downgrade);
510*795d594fSAndroid Build Coastguard Worker 
511*795d594fSAndroid Build Coastguard Worker   // Returns the pointer to the owned or unowned instance of OatFileAssistantContext.
GetOatFileAssistantContext()512*795d594fSAndroid Build Coastguard Worker   OatFileAssistantContext* GetOatFileAssistantContext() {
513*795d594fSAndroid Build Coastguard Worker     if (std::holds_alternative<OatFileAssistantContext*>(ofa_context_)) {
514*795d594fSAndroid Build Coastguard Worker       return std::get<OatFileAssistantContext*>(ofa_context_);
515*795d594fSAndroid Build Coastguard Worker     } else {
516*795d594fSAndroid Build Coastguard Worker       return std::get<std::unique_ptr<OatFileAssistantContext>>(ofa_context_).get();
517*795d594fSAndroid Build Coastguard Worker     }
518*795d594fSAndroid Build Coastguard Worker   }
519*795d594fSAndroid Build Coastguard Worker 
520*795d594fSAndroid Build Coastguard Worker   // The runtime options taken from the active runtime or the input.
521*795d594fSAndroid Build Coastguard Worker   //
522*795d594fSAndroid Build Coastguard Worker   // All member functions should get runtime options from this variable rather than referencing the
523*795d594fSAndroid Build Coastguard Worker   // active runtime. This is to allow OatFileAssistant to function without an active runtime.
GetRuntimeOptions()524*795d594fSAndroid Build Coastguard Worker   const OatFileAssistantContext::RuntimeOptions& GetRuntimeOptions() {
525*795d594fSAndroid Build Coastguard Worker     return GetOatFileAssistantContext()->GetRuntimeOptions();
526*795d594fSAndroid Build Coastguard Worker   }
527*795d594fSAndroid Build Coastguard Worker 
528*795d594fSAndroid Build Coastguard Worker   // Returns whether the zip file only contains uncompressed dex.
529*795d594fSAndroid Build Coastguard Worker   bool ZipFileOnlyContainsUncompressedDex();
530*795d594fSAndroid Build Coastguard Worker 
531*795d594fSAndroid Build Coastguard Worker   // Returns the location of the given oat file.
532*795d594fSAndroid Build Coastguard Worker   Location GetLocation(OatFileInfo& info);
533*795d594fSAndroid Build Coastguard Worker 
534*795d594fSAndroid Build Coastguard Worker   std::string dex_location_;
535*795d594fSAndroid Build Coastguard Worker 
536*795d594fSAndroid Build Coastguard Worker   // The class loader context to check against, or null representing that the check should be
537*795d594fSAndroid Build Coastguard Worker   // skipped.
538*795d594fSAndroid Build Coastguard Worker   ClassLoaderContext* context_;
539*795d594fSAndroid Build Coastguard Worker 
540*795d594fSAndroid Build Coastguard Worker   // Whether or not the parent directory of the dex file is writable.
541*795d594fSAndroid Build Coastguard Worker   bool dex_parent_writable_ = false;
542*795d594fSAndroid Build Coastguard Worker 
543*795d594fSAndroid Build Coastguard Worker   // In a properly constructed OatFileAssistant object, isa_ should be either
544*795d594fSAndroid Build Coastguard Worker   // the 32 or 64 bit variant for the current device.
545*795d594fSAndroid Build Coastguard Worker   const InstructionSet isa_ = InstructionSet::kNone;
546*795d594fSAndroid Build Coastguard Worker 
547*795d594fSAndroid Build Coastguard Worker   // Whether we will attempt to load oat files executable.
548*795d594fSAndroid Build Coastguard Worker   bool load_executable_ = false;
549*795d594fSAndroid Build Coastguard Worker 
550*795d594fSAndroid Build Coastguard Worker   // Whether only oat files from trusted locations are loaded executable.
551*795d594fSAndroid Build Coastguard Worker   const bool only_load_trusted_executable_ = false;
552*795d594fSAndroid Build Coastguard Worker 
553*795d594fSAndroid Build Coastguard Worker   // Cached value of whether the potential zip file only contains uncompressed dex.
554*795d594fSAndroid Build Coastguard Worker   // This should be accessed only by the ZipFileOnlyContainsUncompressedDex() method.
555*795d594fSAndroid Build Coastguard Worker   bool zip_file_only_contains_uncompressed_dex_ = true;
556*795d594fSAndroid Build Coastguard Worker 
557*795d594fSAndroid Build Coastguard Worker   // Cached value of the required dex checksums.
558*795d594fSAndroid Build Coastguard Worker   // This should be accessed only by the GetRequiredDexChecksums() method.
559*795d594fSAndroid Build Coastguard Worker   std::optional<uint32_t> cached_required_dex_checksums_;
560*795d594fSAndroid Build Coastguard Worker   std::optional<std::string> cached_required_dex_checksums_error_;
561*795d594fSAndroid Build Coastguard Worker   bool required_dex_checksums_attempted_ = false;
562*795d594fSAndroid Build Coastguard Worker 
563*795d594fSAndroid Build Coastguard Worker   // The AOT-compiled file of an app when the APK of the app is in /data.
564*795d594fSAndroid Build Coastguard Worker   OatFileInfo odex_;
565*795d594fSAndroid Build Coastguard Worker   // The AOT-compiled file of an app when the APK of the app is on a read-only partition
566*795d594fSAndroid Build Coastguard Worker   // (for example /system).
567*795d594fSAndroid Build Coastguard Worker   OatFileInfo oat_;
568*795d594fSAndroid Build Coastguard Worker 
569*795d594fSAndroid Build Coastguard Worker   // The vdex-only file next to `odex_` when `odex_' cannot be used (for example
570*795d594fSAndroid Build Coastguard Worker   // it is out of date).
571*795d594fSAndroid Build Coastguard Worker   OatFileInfo vdex_for_odex_;
572*795d594fSAndroid Build Coastguard Worker   // The vdex-only file next to 'oat_` when `oat_' cannot be used (for example
573*795d594fSAndroid Build Coastguard Worker   // it is out of date).
574*795d594fSAndroid Build Coastguard Worker   OatFileInfo vdex_for_oat_;
575*795d594fSAndroid Build Coastguard Worker 
576*795d594fSAndroid Build Coastguard Worker   // The vdex-only file next to the apk.
577*795d594fSAndroid Build Coastguard Worker   OatFileInfo dm_for_odex_;
578*795d594fSAndroid Build Coastguard Worker   OatFileInfo dm_for_oat_;
579*795d594fSAndroid Build Coastguard Worker 
580*795d594fSAndroid Build Coastguard Worker   // File descriptor corresponding to apk, dex file, or zip.
581*795d594fSAndroid Build Coastguard Worker   int zip_fd_;
582*795d594fSAndroid Build Coastguard Worker 
583*795d594fSAndroid Build Coastguard Worker   // Owned or unowned instance of OatFileAssistantContext.
584*795d594fSAndroid Build Coastguard Worker   std::variant<std::unique_ptr<OatFileAssistantContext>, OatFileAssistantContext*> ofa_context_;
585*795d594fSAndroid Build Coastguard Worker 
586*795d594fSAndroid Build Coastguard Worker   friend class OatFileAssistantTest;
587*795d594fSAndroid Build Coastguard Worker 
588*795d594fSAndroid Build Coastguard Worker   DISALLOW_COPY_AND_ASSIGN(OatFileAssistant);
589*795d594fSAndroid Build Coastguard Worker };
590*795d594fSAndroid Build Coastguard Worker 
591*795d594fSAndroid Build Coastguard Worker std::ostream& operator << (std::ostream& stream, const OatFileAssistant::OatStatus status);
592*795d594fSAndroid Build Coastguard Worker 
593*795d594fSAndroid Build Coastguard Worker }  // namespace art
594*795d594fSAndroid Build Coastguard Worker 
595*795d594fSAndroid Build Coastguard Worker #endif  // ART_RUNTIME_OAT_OAT_FILE_ASSISTANT_H_
596