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 #define LOG_TAG "installd"
17*38e8c45fSAndroid Build Coastguard Worker
18*38e8c45fSAndroid Build Coastguard Worker #include "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 #include <vector>
23*38e8c45fSAndroid Build Coastguard Worker
24*38e8c45fSAndroid Build Coastguard Worker #include <android-base/file.h>
25*38e8c45fSAndroid Build Coastguard Worker #include <android-base/logging.h>
26*38e8c45fSAndroid Build Coastguard Worker #include <android-base/properties.h>
27*38e8c45fSAndroid Build Coastguard Worker #include <android-base/scopeguard.h>
28*38e8c45fSAndroid Build Coastguard Worker #include <android-base/stringprintf.h>
29*38e8c45fSAndroid Build Coastguard Worker #include <android-base/strings.h>
30*38e8c45fSAndroid Build Coastguard Worker #include <log/log.h>
31*38e8c45fSAndroid Build Coastguard Worker #include <server_configurable_flags/get_flags.h>
32*38e8c45fSAndroid Build Coastguard Worker
33*38e8c45fSAndroid Build Coastguard Worker #include "unique_file.h"
34*38e8c45fSAndroid Build Coastguard Worker
35*38e8c45fSAndroid Build Coastguard Worker using android::base::Basename;
36*38e8c45fSAndroid Build Coastguard Worker using android::base::StringPrintf;
37*38e8c45fSAndroid Build Coastguard Worker
38*38e8c45fSAndroid Build Coastguard Worker namespace android {
39*38e8c45fSAndroid Build Coastguard Worker namespace installd {
40*38e8c45fSAndroid Build Coastguard Worker
41*38e8c45fSAndroid Build Coastguard Worker namespace {
42*38e8c45fSAndroid Build Coastguard Worker
43*38e8c45fSAndroid Build Coastguard Worker // Should minidebug info be included in compiled artifacts? Even if this value is
44*38e8c45fSAndroid Build Coastguard Worker // "true," usage might still be conditional to other constraints, e.g., system
45*38e8c45fSAndroid Build Coastguard Worker // property overrides.
46*38e8c45fSAndroid Build Coastguard Worker static constexpr bool kEnableMinidebugInfo = true;
47*38e8c45fSAndroid Build Coastguard Worker
48*38e8c45fSAndroid Build Coastguard Worker static constexpr const char* kMinidebugInfoSystemProperty = "dalvik.vm.dex2oat-minidebuginfo";
49*38e8c45fSAndroid Build Coastguard Worker static constexpr bool kMinidebugInfoSystemPropertyDefault = false;
50*38e8c45fSAndroid Build Coastguard Worker static constexpr const char* kMinidebugDex2oatFlag = "--generate-mini-debug-info";
51*38e8c45fSAndroid Build Coastguard Worker static constexpr const char* kDisableCompactDexFlag = "--compact-dex-level=none";
52*38e8c45fSAndroid Build Coastguard Worker
SplitBySpaces(const std::string & str)53*38e8c45fSAndroid Build Coastguard Worker std::vector<std::string> SplitBySpaces(const std::string& str) {
54*38e8c45fSAndroid Build Coastguard Worker if (str.empty()) {
55*38e8c45fSAndroid Build Coastguard Worker return {};
56*38e8c45fSAndroid Build Coastguard Worker }
57*38e8c45fSAndroid Build Coastguard Worker return android::base::Split(str, " ");
58*38e8c45fSAndroid Build Coastguard Worker }
59*38e8c45fSAndroid Build Coastguard Worker
60*38e8c45fSAndroid Build Coastguard Worker } // namespace
61*38e8c45fSAndroid Build Coastguard Worker
RunDex2Oat(const char * dex2oat_bin,ExecVHelper * execv_helper)62*38e8c45fSAndroid Build Coastguard Worker RunDex2Oat::RunDex2Oat(const char* dex2oat_bin, ExecVHelper* execv_helper)
63*38e8c45fSAndroid Build Coastguard Worker : dex2oat_bin_(dex2oat_bin), execv_helper_(execv_helper) {}
64*38e8c45fSAndroid Build Coastguard Worker
Initialize(const UniqueFile & output_oat,const UniqueFile & output_vdex,const UniqueFile & output_image,const UniqueFile & input_dex,const UniqueFile & input_vdex,const UniqueFile & dex_metadata,const UniqueFile & profile,const char * class_loader_context,const std::string & class_loader_context_fds,int swap_fd,const char * instruction_set,const char * compiler_filter,bool debuggable,bool post_bootcomplete,bool for_restore,int target_sdk_version,bool enable_hidden_api_checks,bool generate_compact_dex,bool use_jitzygote,bool background_job_compile,const char * compilation_reason)65*38e8c45fSAndroid Build Coastguard Worker void RunDex2Oat::Initialize(const UniqueFile& output_oat,
66*38e8c45fSAndroid Build Coastguard Worker const UniqueFile& output_vdex,
67*38e8c45fSAndroid Build Coastguard Worker const UniqueFile& output_image,
68*38e8c45fSAndroid Build Coastguard Worker const UniqueFile& input_dex,
69*38e8c45fSAndroid Build Coastguard Worker const UniqueFile& input_vdex,
70*38e8c45fSAndroid Build Coastguard Worker const UniqueFile& dex_metadata,
71*38e8c45fSAndroid Build Coastguard Worker const UniqueFile& profile,
72*38e8c45fSAndroid Build Coastguard Worker const char* class_loader_context,
73*38e8c45fSAndroid Build Coastguard Worker const std::string& class_loader_context_fds,
74*38e8c45fSAndroid Build Coastguard Worker int swap_fd,
75*38e8c45fSAndroid Build Coastguard Worker const char* instruction_set,
76*38e8c45fSAndroid Build Coastguard Worker const char* compiler_filter,
77*38e8c45fSAndroid Build Coastguard Worker bool debuggable,
78*38e8c45fSAndroid Build Coastguard Worker bool post_bootcomplete,
79*38e8c45fSAndroid Build Coastguard Worker bool for_restore,
80*38e8c45fSAndroid Build Coastguard Worker int target_sdk_version,
81*38e8c45fSAndroid Build Coastguard Worker bool enable_hidden_api_checks,
82*38e8c45fSAndroid Build Coastguard Worker bool generate_compact_dex,
83*38e8c45fSAndroid Build Coastguard Worker bool use_jitzygote,
84*38e8c45fSAndroid Build Coastguard Worker bool background_job_compile,
85*38e8c45fSAndroid Build Coastguard Worker const char* compilation_reason) {
86*38e8c45fSAndroid Build Coastguard Worker PrepareBootImageFlags(use_jitzygote);
87*38e8c45fSAndroid Build Coastguard Worker
88*38e8c45fSAndroid Build Coastguard Worker PrepareInputFileFlags(output_oat, output_vdex, output_image, input_dex, input_vdex,
89*38e8c45fSAndroid Build Coastguard Worker dex_metadata, profile, swap_fd, class_loader_context,
90*38e8c45fSAndroid Build Coastguard Worker class_loader_context_fds);
91*38e8c45fSAndroid Build Coastguard Worker
92*38e8c45fSAndroid Build Coastguard Worker PrepareCompilerConfigFlags(input_vdex, output_vdex, instruction_set, compiler_filter,
93*38e8c45fSAndroid Build Coastguard Worker debuggable, target_sdk_version, enable_hidden_api_checks,
94*38e8c45fSAndroid Build Coastguard Worker generate_compact_dex, compilation_reason);
95*38e8c45fSAndroid Build Coastguard Worker
96*38e8c45fSAndroid Build Coastguard Worker PrepareCompilerRuntimeAndPerfConfigFlags(post_bootcomplete, for_restore,
97*38e8c45fSAndroid Build Coastguard Worker background_job_compile);
98*38e8c45fSAndroid Build Coastguard Worker
99*38e8c45fSAndroid Build Coastguard Worker const std::string dex2oat_flags = GetProperty("dalvik.vm.dex2oat-flags", "");
100*38e8c45fSAndroid Build Coastguard Worker std::vector<std::string> dex2oat_flags_args = SplitBySpaces(dex2oat_flags);
101*38e8c45fSAndroid Build Coastguard Worker ALOGV("dalvik.vm.dex2oat-flags=%s\n", dex2oat_flags.c_str());
102*38e8c45fSAndroid Build Coastguard Worker
103*38e8c45fSAndroid Build Coastguard Worker // Do not add args after dex2oat_flags, they should override others for debugging.
104*38e8c45fSAndroid Build Coastguard Worker for (auto it = dex2oat_flags_args.begin(); it != dex2oat_flags_args.end(); ++it) {
105*38e8c45fSAndroid Build Coastguard Worker AddArg(*it);
106*38e8c45fSAndroid Build Coastguard Worker }
107*38e8c45fSAndroid Build Coastguard Worker
108*38e8c45fSAndroid Build Coastguard Worker execv_helper_->PrepareArgs(dex2oat_bin_);
109*38e8c45fSAndroid Build Coastguard Worker }
110*38e8c45fSAndroid Build Coastguard Worker
~RunDex2Oat()111*38e8c45fSAndroid Build Coastguard Worker RunDex2Oat::~RunDex2Oat() {}
112*38e8c45fSAndroid Build Coastguard Worker
PrepareBootImageFlags(bool use_jitzygote)113*38e8c45fSAndroid Build Coastguard Worker void RunDex2Oat::PrepareBootImageFlags(bool use_jitzygote) {
114*38e8c45fSAndroid Build Coastguard Worker if (use_jitzygote) {
115*38e8c45fSAndroid Build Coastguard Worker // Don't pass a boot image because JIT Zygote should decide which image to use. Typically,
116*38e8c45fSAndroid Build Coastguard Worker // it does not use any boot image on disk.
117*38e8c45fSAndroid Build Coastguard Worker AddArg("--force-jit-zygote");
118*38e8c45fSAndroid Build Coastguard Worker } else {
119*38e8c45fSAndroid Build Coastguard Worker AddArg(MapPropertyToArg("dalvik.vm.boot-image", "--boot-image=%s"));
120*38e8c45fSAndroid Build Coastguard Worker }
121*38e8c45fSAndroid Build Coastguard Worker }
122*38e8c45fSAndroid Build Coastguard Worker
PrepareInputFileFlags(const UniqueFile & output_oat,const UniqueFile & output_vdex,const UniqueFile & output_image,const UniqueFile & input_dex,const UniqueFile & input_vdex,const UniqueFile & dex_metadata,const UniqueFile & profile,int swap_fd,const char * class_loader_context,const std::string & class_loader_context_fds)123*38e8c45fSAndroid Build Coastguard Worker void RunDex2Oat::PrepareInputFileFlags(const UniqueFile& output_oat,
124*38e8c45fSAndroid Build Coastguard Worker const UniqueFile& output_vdex,
125*38e8c45fSAndroid Build Coastguard Worker const UniqueFile& output_image,
126*38e8c45fSAndroid Build Coastguard Worker const UniqueFile& input_dex,
127*38e8c45fSAndroid Build Coastguard Worker const UniqueFile& input_vdex,
128*38e8c45fSAndroid Build Coastguard Worker const UniqueFile& dex_metadata,
129*38e8c45fSAndroid Build Coastguard Worker const UniqueFile& profile,
130*38e8c45fSAndroid Build Coastguard Worker int swap_fd,
131*38e8c45fSAndroid Build Coastguard Worker const char* class_loader_context,
132*38e8c45fSAndroid Build Coastguard Worker const std::string& class_loader_context_fds) {
133*38e8c45fSAndroid Build Coastguard Worker std::string input_basename = Basename(input_dex.path());
134*38e8c45fSAndroid Build Coastguard Worker LOG(VERBOSE) << "Running " << dex2oat_bin_ << " in=" << input_basename << " out="
135*38e8c45fSAndroid Build Coastguard Worker << output_oat.path();
136*38e8c45fSAndroid Build Coastguard Worker
137*38e8c45fSAndroid Build Coastguard Worker AddArg(StringPrintf("--zip-fd=%d", input_dex.fd()));
138*38e8c45fSAndroid Build Coastguard Worker AddArg(StringPrintf("--zip-location=%s", input_basename.c_str()));
139*38e8c45fSAndroid Build Coastguard Worker AddArg(StringPrintf("--oat-fd=%d", output_oat.fd()));
140*38e8c45fSAndroid Build Coastguard Worker AddArg(StringPrintf("--oat-location=%s", output_oat.path().c_str()));
141*38e8c45fSAndroid Build Coastguard Worker AddArg(StringPrintf("--input-vdex-fd=%d", input_vdex.fd()));
142*38e8c45fSAndroid Build Coastguard Worker AddArg(StringPrintf("--output-vdex-fd=%d", output_vdex.fd()));
143*38e8c45fSAndroid Build Coastguard Worker
144*38e8c45fSAndroid Build Coastguard Worker if (output_image.fd() >= 0) {
145*38e8c45fSAndroid Build Coastguard Worker AddArg(StringPrintf("--app-image-fd=%d", output_image.fd()));
146*38e8c45fSAndroid Build Coastguard Worker AddArg(MapPropertyToArg("dalvik.vm.appimageformat", "--image-format=%s"));
147*38e8c45fSAndroid Build Coastguard Worker }
148*38e8c45fSAndroid Build Coastguard Worker if (dex_metadata.fd() > -1) {
149*38e8c45fSAndroid Build Coastguard Worker AddArg("--dm-fd=" + std::to_string(dex_metadata.fd()));
150*38e8c45fSAndroid Build Coastguard Worker }
151*38e8c45fSAndroid Build Coastguard Worker if (profile.fd() != -1) {
152*38e8c45fSAndroid Build Coastguard Worker AddArg(StringPrintf("--profile-file-fd=%d", profile.fd()));
153*38e8c45fSAndroid Build Coastguard Worker }
154*38e8c45fSAndroid Build Coastguard Worker if (swap_fd >= 0) {
155*38e8c45fSAndroid Build Coastguard Worker AddArg(StringPrintf("--swap-fd=%d", swap_fd));
156*38e8c45fSAndroid Build Coastguard Worker }
157*38e8c45fSAndroid Build Coastguard Worker
158*38e8c45fSAndroid Build Coastguard Worker // Get the directory of the apk to pass as a base classpath directory.
159*38e8c45fSAndroid Build Coastguard Worker {
160*38e8c45fSAndroid Build Coastguard Worker std::string apk_dir(input_dex.path());
161*38e8c45fSAndroid Build Coastguard Worker size_t dir_index = apk_dir.rfind('/');
162*38e8c45fSAndroid Build Coastguard Worker if (dir_index != std::string::npos) {
163*38e8c45fSAndroid Build Coastguard Worker apk_dir = apk_dir.substr(0, dir_index);
164*38e8c45fSAndroid Build Coastguard Worker AddArg(StringPrintf("--classpath-dir=%s", apk_dir.c_str()));
165*38e8c45fSAndroid Build Coastguard Worker }
166*38e8c45fSAndroid Build Coastguard Worker }
167*38e8c45fSAndroid Build Coastguard Worker
168*38e8c45fSAndroid Build Coastguard Worker if (class_loader_context != nullptr) {
169*38e8c45fSAndroid Build Coastguard Worker AddArg(StringPrintf("--class-loader-context=%s", class_loader_context));
170*38e8c45fSAndroid Build Coastguard Worker if (!class_loader_context_fds.empty()) {
171*38e8c45fSAndroid Build Coastguard Worker AddArg(StringPrintf("--class-loader-context-fds=%s",
172*38e8c45fSAndroid Build Coastguard Worker class_loader_context_fds.c_str()));
173*38e8c45fSAndroid Build Coastguard Worker }
174*38e8c45fSAndroid Build Coastguard Worker }
175*38e8c45fSAndroid Build Coastguard Worker }
176*38e8c45fSAndroid Build Coastguard Worker
PrepareCompilerConfigFlags(const UniqueFile & input_vdex,const UniqueFile & output_vdex,const char * instruction_set,const char * compiler_filter,bool debuggable,int target_sdk_version,bool enable_hidden_api_checks,bool generate_compact_dex,const char * compilation_reason)177*38e8c45fSAndroid Build Coastguard Worker void RunDex2Oat::PrepareCompilerConfigFlags(const UniqueFile& input_vdex,
178*38e8c45fSAndroid Build Coastguard Worker const UniqueFile& output_vdex,
179*38e8c45fSAndroid Build Coastguard Worker const char* instruction_set,
180*38e8c45fSAndroid Build Coastguard Worker const char* compiler_filter,
181*38e8c45fSAndroid Build Coastguard Worker bool debuggable,
182*38e8c45fSAndroid Build Coastguard Worker int target_sdk_version,
183*38e8c45fSAndroid Build Coastguard Worker bool enable_hidden_api_checks,
184*38e8c45fSAndroid Build Coastguard Worker bool generate_compact_dex,
185*38e8c45fSAndroid Build Coastguard Worker const char* compilation_reason) {
186*38e8c45fSAndroid Build Coastguard Worker // Disable cdex if update input vdex is true since this combination of options is not
187*38e8c45fSAndroid Build Coastguard Worker // supported.
188*38e8c45fSAndroid Build Coastguard Worker const bool disable_cdex = !generate_compact_dex || (input_vdex.fd() == output_vdex.fd());
189*38e8c45fSAndroid Build Coastguard Worker if (disable_cdex) {
190*38e8c45fSAndroid Build Coastguard Worker AddArg(kDisableCompactDexFlag);
191*38e8c45fSAndroid Build Coastguard Worker }
192*38e8c45fSAndroid Build Coastguard Worker
193*38e8c45fSAndroid Build Coastguard Worker // ISA related
194*38e8c45fSAndroid Build Coastguard Worker {
195*38e8c45fSAndroid Build Coastguard Worker AddArg(StringPrintf("--instruction-set=%s", instruction_set));
196*38e8c45fSAndroid Build Coastguard Worker
197*38e8c45fSAndroid Build Coastguard Worker const std::string dex2oat_isa_features_key =
198*38e8c45fSAndroid Build Coastguard Worker StringPrintf("dalvik.vm.isa.%s.features", instruction_set);
199*38e8c45fSAndroid Build Coastguard Worker std::string instruction_set_features_arg =
200*38e8c45fSAndroid Build Coastguard Worker MapPropertyToArg(dex2oat_isa_features_key, "--instruction-set-features=%s");
201*38e8c45fSAndroid Build Coastguard Worker AddArg(instruction_set_features_arg);
202*38e8c45fSAndroid Build Coastguard Worker
203*38e8c45fSAndroid Build Coastguard Worker const std::string dex2oat_isa_variant_key =
204*38e8c45fSAndroid Build Coastguard Worker StringPrintf("dalvik.vm.isa.%s.variant", instruction_set);
205*38e8c45fSAndroid Build Coastguard Worker std::string instruction_set_variant_arg =
206*38e8c45fSAndroid Build Coastguard Worker MapPropertyToArg(dex2oat_isa_variant_key, "--instruction-set-variant=%s");
207*38e8c45fSAndroid Build Coastguard Worker AddArg(instruction_set_variant_arg);
208*38e8c45fSAndroid Build Coastguard Worker }
209*38e8c45fSAndroid Build Coastguard Worker
210*38e8c45fSAndroid Build Coastguard Worker // Compute compiler filter.
211*38e8c45fSAndroid Build Coastguard Worker if (compiler_filter != nullptr) {
212*38e8c45fSAndroid Build Coastguard Worker AddArg(StringPrintf("--compiler-filter=%s", compiler_filter));
213*38e8c45fSAndroid Build Coastguard Worker } else {
214*38e8c45fSAndroid Build Coastguard Worker AddArg(MapPropertyToArg("dalvik.vm.dex2oat-filter", "--compiler-filter=%s"));
215*38e8c45fSAndroid Build Coastguard Worker }
216*38e8c45fSAndroid Build Coastguard Worker if (compilation_reason != nullptr) {
217*38e8c45fSAndroid Build Coastguard Worker AddArg(std::string("--compilation-reason=") + compilation_reason);
218*38e8c45fSAndroid Build Coastguard Worker }
219*38e8c45fSAndroid Build Coastguard Worker
220*38e8c45fSAndroid Build Coastguard Worker AddArg(MapPropertyToArg("dalvik.vm.dex2oat-max-image-block-size",
221*38e8c45fSAndroid Build Coastguard Worker "--max-image-block-size=%s"));
222*38e8c45fSAndroid Build Coastguard Worker
223*38e8c45fSAndroid Build Coastguard Worker AddArg(MapPropertyToArg("dalvik.vm.dex2oat-very-large",
224*38e8c45fSAndroid Build Coastguard Worker "--very-large-app-threshold=%s"));
225*38e8c45fSAndroid Build Coastguard Worker
226*38e8c45fSAndroid Build Coastguard Worker std::string resolve_startup_string_arg = MapPropertyToArg(
227*38e8c45fSAndroid Build Coastguard Worker "persist.device_config.runtime.dex2oat_resolve_startup_strings",
228*38e8c45fSAndroid Build Coastguard Worker "--resolve-startup-const-strings=%s");
229*38e8c45fSAndroid Build Coastguard Worker if (resolve_startup_string_arg.empty()) {
230*38e8c45fSAndroid Build Coastguard Worker // If empty, fall back to system property.
231*38e8c45fSAndroid Build Coastguard Worker resolve_startup_string_arg =
232*38e8c45fSAndroid Build Coastguard Worker MapPropertyToArg("dalvik.vm.dex2oat-resolve-startup-strings",
233*38e8c45fSAndroid Build Coastguard Worker "--resolve-startup-const-strings=%s");
234*38e8c45fSAndroid Build Coastguard Worker }
235*38e8c45fSAndroid Build Coastguard Worker AddArg(resolve_startup_string_arg);
236*38e8c45fSAndroid Build Coastguard Worker
237*38e8c45fSAndroid Build Coastguard Worker // Debug related
238*38e8c45fSAndroid Build Coastguard Worker {
239*38e8c45fSAndroid Build Coastguard Worker // Check whether all apps should be compiled debuggable.
240*38e8c45fSAndroid Build Coastguard Worker if (!debuggable) {
241*38e8c45fSAndroid Build Coastguard Worker debuggable = GetProperty("dalvik.vm.always_debuggable", "") == "1";
242*38e8c45fSAndroid Build Coastguard Worker }
243*38e8c45fSAndroid Build Coastguard Worker if (debuggable) {
244*38e8c45fSAndroid Build Coastguard Worker AddArg("--debuggable");
245*38e8c45fSAndroid Build Coastguard Worker }
246*38e8c45fSAndroid Build Coastguard Worker
247*38e8c45fSAndroid Build Coastguard Worker const bool generate_debug_info = GetBoolProperty("debug.generate-debug-info", false);
248*38e8c45fSAndroid Build Coastguard Worker if (generate_debug_info) {
249*38e8c45fSAndroid Build Coastguard Worker AddArg("--generate-debug-info");
250*38e8c45fSAndroid Build Coastguard Worker }
251*38e8c45fSAndroid Build Coastguard Worker {
252*38e8c45fSAndroid Build Coastguard Worker bool generate_minidebug_info = kEnableMinidebugInfo &&
253*38e8c45fSAndroid Build Coastguard Worker GetBoolProperty(kMinidebugInfoSystemProperty,
254*38e8c45fSAndroid Build Coastguard Worker kMinidebugInfoSystemPropertyDefault);
255*38e8c45fSAndroid Build Coastguard Worker if (generate_minidebug_info) {
256*38e8c45fSAndroid Build Coastguard Worker AddArg(kMinidebugDex2oatFlag);
257*38e8c45fSAndroid Build Coastguard Worker }
258*38e8c45fSAndroid Build Coastguard Worker }
259*38e8c45fSAndroid Build Coastguard Worker }
260*38e8c45fSAndroid Build Coastguard Worker
261*38e8c45fSAndroid Build Coastguard Worker // On-device signing related. odsign sets the system property odsign.verification.success if
262*38e8c45fSAndroid Build Coastguard Worker // AOT artifacts have the expected signatures.
263*38e8c45fSAndroid Build Coastguard Worker const bool trust_art_apex_data_files = GetBoolProperty("odsign.verification.success", false);
264*38e8c45fSAndroid Build Coastguard Worker if (!trust_art_apex_data_files) {
265*38e8c45fSAndroid Build Coastguard Worker AddRuntimeArg("-Xdeny-art-apex-data-files");
266*38e8c45fSAndroid Build Coastguard Worker }
267*38e8c45fSAndroid Build Coastguard Worker
268*38e8c45fSAndroid Build Coastguard Worker if (target_sdk_version != 0) {
269*38e8c45fSAndroid Build Coastguard Worker AddRuntimeArg(StringPrintf("-Xtarget-sdk-version:%d", target_sdk_version));
270*38e8c45fSAndroid Build Coastguard Worker }
271*38e8c45fSAndroid Build Coastguard Worker
272*38e8c45fSAndroid Build Coastguard Worker if (enable_hidden_api_checks) {
273*38e8c45fSAndroid Build Coastguard Worker AddRuntimeArg("-Xhidden-api-policy:enabled");
274*38e8c45fSAndroid Build Coastguard Worker }
275*38e8c45fSAndroid Build Coastguard Worker }
276*38e8c45fSAndroid Build Coastguard Worker
PrepareCompilerRuntimeAndPerfConfigFlags(bool post_bootcomplete,bool for_restore,bool background_job_compile)277*38e8c45fSAndroid Build Coastguard Worker void RunDex2Oat::PrepareCompilerRuntimeAndPerfConfigFlags(bool post_bootcomplete,
278*38e8c45fSAndroid Build Coastguard Worker bool for_restore,
279*38e8c45fSAndroid Build Coastguard Worker bool background_job_compile) {
280*38e8c45fSAndroid Build Coastguard Worker // CPU set
281*38e8c45fSAndroid Build Coastguard Worker {
282*38e8c45fSAndroid Build Coastguard Worker std::string cpu_set_format = "--cpu-set=%s";
283*38e8c45fSAndroid Build Coastguard Worker std::string dex2oat_cpu_set_arg = post_bootcomplete
284*38e8c45fSAndroid Build Coastguard Worker ? (for_restore
285*38e8c45fSAndroid Build Coastguard Worker ? MapPropertyToArgWithBackup(
286*38e8c45fSAndroid Build Coastguard Worker "dalvik.vm.restore-dex2oat-cpu-set",
287*38e8c45fSAndroid Build Coastguard Worker "dalvik.vm.dex2oat-cpu-set",
288*38e8c45fSAndroid Build Coastguard Worker cpu_set_format)
289*38e8c45fSAndroid Build Coastguard Worker : (background_job_compile
290*38e8c45fSAndroid Build Coastguard Worker ? MapPropertyToArgWithBackup(
291*38e8c45fSAndroid Build Coastguard Worker "dalvik.vm.background-dex2oat-cpu-set",
292*38e8c45fSAndroid Build Coastguard Worker "dalvik.vm.dex2oat-cpu-set",
293*38e8c45fSAndroid Build Coastguard Worker cpu_set_format)
294*38e8c45fSAndroid Build Coastguard Worker : MapPropertyToArg("dalvik.vm.dex2oat-cpu-set", cpu_set_format)))
295*38e8c45fSAndroid Build Coastguard Worker : MapPropertyToArg("dalvik.vm.boot-dex2oat-cpu-set", cpu_set_format);
296*38e8c45fSAndroid Build Coastguard Worker AddArg(dex2oat_cpu_set_arg);
297*38e8c45fSAndroid Build Coastguard Worker }
298*38e8c45fSAndroid Build Coastguard Worker
299*38e8c45fSAndroid Build Coastguard Worker // Number of threads
300*38e8c45fSAndroid Build Coastguard Worker {
301*38e8c45fSAndroid Build Coastguard Worker std::string threads_format = "-j%s";
302*38e8c45fSAndroid Build Coastguard Worker std::string dex2oat_threads_arg = post_bootcomplete
303*38e8c45fSAndroid Build Coastguard Worker ? (for_restore
304*38e8c45fSAndroid Build Coastguard Worker ? MapPropertyToArgWithBackup(
305*38e8c45fSAndroid Build Coastguard Worker "dalvik.vm.restore-dex2oat-threads",
306*38e8c45fSAndroid Build Coastguard Worker "dalvik.vm.dex2oat-threads",
307*38e8c45fSAndroid Build Coastguard Worker threads_format)
308*38e8c45fSAndroid Build Coastguard Worker : (background_job_compile
309*38e8c45fSAndroid Build Coastguard Worker ? MapPropertyToArgWithBackup(
310*38e8c45fSAndroid Build Coastguard Worker "dalvik.vm.background-dex2oat-threads",
311*38e8c45fSAndroid Build Coastguard Worker "dalvik.vm.dex2oat-threads",
312*38e8c45fSAndroid Build Coastguard Worker threads_format)
313*38e8c45fSAndroid Build Coastguard Worker : MapPropertyToArg("dalvik.vm.dex2oat-threads", threads_format)))
314*38e8c45fSAndroid Build Coastguard Worker : MapPropertyToArg("dalvik.vm.boot-dex2oat-threads", threads_format);
315*38e8c45fSAndroid Build Coastguard Worker AddArg(dex2oat_threads_arg);
316*38e8c45fSAndroid Build Coastguard Worker }
317*38e8c45fSAndroid Build Coastguard Worker
318*38e8c45fSAndroid Build Coastguard Worker AddRuntimeArg(MapPropertyToArg("dalvik.vm.dex2oat-Xms", "-Xms%s"));
319*38e8c45fSAndroid Build Coastguard Worker AddRuntimeArg(MapPropertyToArg("dalvik.vm.dex2oat-Xmx", "-Xmx%s"));
320*38e8c45fSAndroid Build Coastguard Worker
321*38e8c45fSAndroid Build Coastguard Worker // Enable compiling dex files in isolation on low ram devices.
322*38e8c45fSAndroid Build Coastguard Worker // It takes longer but reduces the memory footprint.
323*38e8c45fSAndroid Build Coastguard Worker if (GetBoolProperty("ro.config.low_ram", false)) {
324*38e8c45fSAndroid Build Coastguard Worker AddArg("--compile-individually");
325*38e8c45fSAndroid Build Coastguard Worker }
326*38e8c45fSAndroid Build Coastguard Worker }
327*38e8c45fSAndroid Build Coastguard Worker
Exec(int exit_code)328*38e8c45fSAndroid Build Coastguard Worker void RunDex2Oat::Exec(int exit_code) {
329*38e8c45fSAndroid Build Coastguard Worker execv_helper_->Exec(exit_code);
330*38e8c45fSAndroid Build Coastguard Worker }
331*38e8c45fSAndroid Build Coastguard Worker
AddArg(const std::string & arg)332*38e8c45fSAndroid Build Coastguard Worker void RunDex2Oat::AddArg(const std::string& arg) {
333*38e8c45fSAndroid Build Coastguard Worker execv_helper_->AddArg(arg);
334*38e8c45fSAndroid Build Coastguard Worker }
335*38e8c45fSAndroid Build Coastguard Worker
AddRuntimeArg(const std::string & arg)336*38e8c45fSAndroid Build Coastguard Worker void RunDex2Oat::AddRuntimeArg(const std::string& arg) {
337*38e8c45fSAndroid Build Coastguard Worker execv_helper_->AddRuntimeArg(arg);
338*38e8c45fSAndroid Build Coastguard Worker }
339*38e8c45fSAndroid Build Coastguard Worker
GetProperty(const std::string & key,const std::string & default_value)340*38e8c45fSAndroid Build Coastguard Worker std::string RunDex2Oat::GetProperty(const std::string& key,
341*38e8c45fSAndroid Build Coastguard Worker const std::string& default_value) {
342*38e8c45fSAndroid Build Coastguard Worker return android::base::GetProperty(key, default_value);
343*38e8c45fSAndroid Build Coastguard Worker }
344*38e8c45fSAndroid Build Coastguard Worker
GetBoolProperty(const std::string & key,bool default_value)345*38e8c45fSAndroid Build Coastguard Worker bool RunDex2Oat::GetBoolProperty(const std::string& key, bool default_value) {
346*38e8c45fSAndroid Build Coastguard Worker return android::base::GetBoolProperty(key, default_value);
347*38e8c45fSAndroid Build Coastguard Worker }
348*38e8c45fSAndroid Build Coastguard Worker
MapPropertyToArg(const std::string & property,const std::string & format,const std::string & default_value)349*38e8c45fSAndroid Build Coastguard Worker std::string RunDex2Oat::MapPropertyToArg(const std::string& property,
350*38e8c45fSAndroid Build Coastguard Worker const std::string& format,
351*38e8c45fSAndroid Build Coastguard Worker const std::string& default_value) {
352*38e8c45fSAndroid Build Coastguard Worker std::string prop = GetProperty(property, default_value);
353*38e8c45fSAndroid Build Coastguard Worker if (!prop.empty()) {
354*38e8c45fSAndroid Build Coastguard Worker return StringPrintf(format.c_str(), prop.c_str());
355*38e8c45fSAndroid Build Coastguard Worker }
356*38e8c45fSAndroid Build Coastguard Worker return "";
357*38e8c45fSAndroid Build Coastguard Worker }
358*38e8c45fSAndroid Build Coastguard Worker
MapPropertyToArgWithBackup(const std::string & property,const std::string & backupProperty,const std::string & format,const std::string & default_value)359*38e8c45fSAndroid Build Coastguard Worker std::string RunDex2Oat::MapPropertyToArgWithBackup(
360*38e8c45fSAndroid Build Coastguard Worker const std::string& property,
361*38e8c45fSAndroid Build Coastguard Worker const std::string& backupProperty,
362*38e8c45fSAndroid Build Coastguard Worker const std::string& format,
363*38e8c45fSAndroid Build Coastguard Worker const std::string& default_value) {
364*38e8c45fSAndroid Build Coastguard Worker std::string value = GetProperty(property, default_value);
365*38e8c45fSAndroid Build Coastguard Worker if (!value.empty()) {
366*38e8c45fSAndroid Build Coastguard Worker return StringPrintf(format.c_str(), value.c_str());
367*38e8c45fSAndroid Build Coastguard Worker }
368*38e8c45fSAndroid Build Coastguard Worker return MapPropertyToArg(backupProperty, format, default_value);
369*38e8c45fSAndroid Build Coastguard Worker }
370*38e8c45fSAndroid Build Coastguard Worker
371*38e8c45fSAndroid Build Coastguard Worker } // namespace installd
372*38e8c45fSAndroid Build Coastguard Worker } // namespace android
373