xref: /aosp_15_r20/frameworks/native/cmds/installd/run_dex2oat.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright (C) 2020 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #ifndef ANDROID_INSTALLD_RUN_DEX2OAT_H
18*38e8c45fSAndroid Build Coastguard Worker #define ANDROID_INSTALLD_RUN_DEX2OAT_H
19*38e8c45fSAndroid Build Coastguard Worker 
20*38e8c45fSAndroid Build Coastguard Worker #include <memory>
21*38e8c45fSAndroid Build Coastguard Worker #include <string>
22*38e8c45fSAndroid Build Coastguard Worker 
23*38e8c45fSAndroid Build Coastguard Worker #include "execv_helper.h"
24*38e8c45fSAndroid Build Coastguard Worker 
25*38e8c45fSAndroid Build Coastguard Worker namespace android {
26*38e8c45fSAndroid Build Coastguard Worker namespace installd {
27*38e8c45fSAndroid Build Coastguard Worker 
28*38e8c45fSAndroid Build Coastguard Worker class UniqueFile;
29*38e8c45fSAndroid Build Coastguard Worker 
30*38e8c45fSAndroid Build Coastguard Worker class RunDex2Oat {
31*38e8c45fSAndroid Build Coastguard Worker   public:
32*38e8c45fSAndroid Build Coastguard Worker     explicit RunDex2Oat(const char* dex2oat_bin, ExecVHelper* execv_helper);
33*38e8c45fSAndroid Build Coastguard Worker     virtual ~RunDex2Oat();
34*38e8c45fSAndroid Build Coastguard Worker 
35*38e8c45fSAndroid Build Coastguard Worker     void Initialize(const UniqueFile& output_oat,
36*38e8c45fSAndroid Build Coastguard Worker                     const UniqueFile& output_vdex,
37*38e8c45fSAndroid Build Coastguard Worker                     const UniqueFile& output_image,
38*38e8c45fSAndroid Build Coastguard Worker                     const UniqueFile& input_dex,
39*38e8c45fSAndroid Build Coastguard Worker                     const UniqueFile& input_vdex,
40*38e8c45fSAndroid Build Coastguard Worker                     const UniqueFile& dex_metadata,
41*38e8c45fSAndroid Build Coastguard Worker                     const UniqueFile& profile,
42*38e8c45fSAndroid Build Coastguard Worker                     const char* class_loader_context,
43*38e8c45fSAndroid Build Coastguard Worker                     const std::string& class_loader_context_fds,
44*38e8c45fSAndroid Build Coastguard Worker                     int swap_fd,
45*38e8c45fSAndroid Build Coastguard Worker                     const char* instruction_set,
46*38e8c45fSAndroid Build Coastguard Worker                     const char* compiler_filter,
47*38e8c45fSAndroid Build Coastguard Worker                     bool debuggable,
48*38e8c45fSAndroid Build Coastguard Worker                     bool post_bootcomplete,
49*38e8c45fSAndroid Build Coastguard Worker                     bool for_restore,
50*38e8c45fSAndroid Build Coastguard Worker                     int target_sdk_version,
51*38e8c45fSAndroid Build Coastguard Worker                     bool enable_hidden_api_checks,
52*38e8c45fSAndroid Build Coastguard Worker                     bool generate_compact_dex,
53*38e8c45fSAndroid Build Coastguard Worker                     bool use_jitzygote,
54*38e8c45fSAndroid Build Coastguard Worker                     bool background_job_compile,
55*38e8c45fSAndroid Build Coastguard Worker                     const char* compilation_reason);
56*38e8c45fSAndroid Build Coastguard Worker 
57*38e8c45fSAndroid Build Coastguard Worker     void Exec(int exit_code);
58*38e8c45fSAndroid Build Coastguard Worker 
59*38e8c45fSAndroid Build Coastguard Worker   protected:
60*38e8c45fSAndroid Build Coastguard Worker     void PrepareBootImageFlags(bool use_jitzygote);
61*38e8c45fSAndroid Build Coastguard Worker     void PrepareInputFileFlags(const UniqueFile& output_oat,
62*38e8c45fSAndroid Build Coastguard Worker                                const UniqueFile& output_vdex,
63*38e8c45fSAndroid Build Coastguard Worker                                const UniqueFile& output_image,
64*38e8c45fSAndroid Build Coastguard Worker                                const UniqueFile& input_dex,
65*38e8c45fSAndroid Build Coastguard Worker                                const UniqueFile& input_vdex,
66*38e8c45fSAndroid Build Coastguard Worker                                const UniqueFile& dex_metadata,
67*38e8c45fSAndroid Build Coastguard Worker                                const UniqueFile& profile,
68*38e8c45fSAndroid Build Coastguard Worker                                int swap_fd,
69*38e8c45fSAndroid Build Coastguard Worker                                const char* class_loader_context,
70*38e8c45fSAndroid Build Coastguard Worker                                const std::string& class_loader_context_fds);
71*38e8c45fSAndroid Build Coastguard Worker     void PrepareCompilerConfigFlags(const UniqueFile& input_vdex,
72*38e8c45fSAndroid Build Coastguard Worker                                     const UniqueFile& output_vdex,
73*38e8c45fSAndroid Build Coastguard Worker                                     const char* instruction_set,
74*38e8c45fSAndroid Build Coastguard Worker                                     const char* compiler_filter,
75*38e8c45fSAndroid Build Coastguard Worker                                     bool debuggable,
76*38e8c45fSAndroid Build Coastguard Worker                                     int target_sdk_version,
77*38e8c45fSAndroid Build Coastguard Worker                                     bool enable_hidden_api_checks,
78*38e8c45fSAndroid Build Coastguard Worker                                     bool generate_compact_dex,
79*38e8c45fSAndroid Build Coastguard Worker                                     const char* compilation_reason);
80*38e8c45fSAndroid Build Coastguard Worker     void PrepareCompilerRuntimeAndPerfConfigFlags(bool post_bootcomplete,
81*38e8c45fSAndroid Build Coastguard Worker                                                   bool for_restore,
82*38e8c45fSAndroid Build Coastguard Worker                                                   bool background_job_compile);
83*38e8c45fSAndroid Build Coastguard Worker 
84*38e8c45fSAndroid Build Coastguard Worker     virtual std::string GetProperty(const std::string& key, const std::string& default_value);
85*38e8c45fSAndroid Build Coastguard Worker     virtual bool GetBoolProperty(const std::string& key, bool default_value);
86*38e8c45fSAndroid Build Coastguard Worker 
87*38e8c45fSAndroid Build Coastguard Worker   private:
88*38e8c45fSAndroid Build Coastguard Worker     void AddArg(const std::string& arg);
89*38e8c45fSAndroid Build Coastguard Worker     void AddRuntimeArg(const std::string& arg);
90*38e8c45fSAndroid Build Coastguard Worker 
91*38e8c45fSAndroid Build Coastguard Worker     std::string MapPropertyToArg(const std::string& property,
92*38e8c45fSAndroid Build Coastguard Worker                                  const std::string& format,
93*38e8c45fSAndroid Build Coastguard Worker                                  const std::string& default_value = "");
94*38e8c45fSAndroid Build Coastguard Worker 
95*38e8c45fSAndroid Build Coastguard Worker     std::string MapPropertyToArgWithBackup(const std::string& property,
96*38e8c45fSAndroid Build Coastguard Worker                                            const std::string& backupProperty,
97*38e8c45fSAndroid Build Coastguard Worker                                            const std::string& format,
98*38e8c45fSAndroid Build Coastguard Worker                                            const std::string& default_value = "");
99*38e8c45fSAndroid Build Coastguard Worker 
100*38e8c45fSAndroid Build Coastguard Worker     const std::string dex2oat_bin_;
101*38e8c45fSAndroid Build Coastguard Worker     ExecVHelper* execv_helper_;  // not owned
102*38e8c45fSAndroid Build Coastguard Worker };
103*38e8c45fSAndroid Build Coastguard Worker 
104*38e8c45fSAndroid Build Coastguard Worker }  // namespace installd
105*38e8c45fSAndroid Build Coastguard Worker }  // namespace android
106*38e8c45fSAndroid Build Coastguard Worker 
107*38e8c45fSAndroid Build Coastguard Worker #endif  // ANDROID_INSTALLD_RUN_DEX2OAT_H
108