blob: 1c9ef6433530b9a7bc87d0c62da39dc24755a4d6 [file] [log] [blame]
Brian Carlstromced4bff2013-11-14 23:44:56 -08001####################################
2# dexpreopt support for ART
3#
4####################################
5
Colin Crossb8901d72018-12-14 11:49:49 -08006# Default to debug version to help find bugs.
7# Set USE_DEX2OAT_DEBUG to false for only building non-debug versions.
8ifeq ($(USE_DEX2OAT_DEBUG),false)
9DEX2OAT := $(HOST_OUT_EXECUTABLES)/dex2oat$(HOST_EXECUTABLE_SUFFIX)
10else
11DEX2OAT := $(HOST_OUT_EXECUTABLES)/dex2oatd$(HOST_EXECUTABLE_SUFFIX)
12endif
13
14DEX2OAT_DEPENDENCY += $(DEX2OAT)
15
16# Use the first preloaded-classes file in PRODUCT_COPY_FILES.
17PRELOADED_CLASSES := $(call word-colon,1,$(firstword \
18 $(filter %system/etc/preloaded-classes,$(PRODUCT_COPY_FILES))))
19
20# Use the first dirty-image-objects file in PRODUCT_COPY_FILES.
21DIRTY_IMAGE_OBJECTS := $(call word-colon,1,$(firstword \
22 $(filter %system/etc/dirty-image-objects,$(PRODUCT_COPY_FILES))))
23
24define get-product-default-property
25$(strip \
26 $(eval _prop := $(patsubst $(1)=%,%,$(filter $(1)=%,$(PRODUCT_DEFAULT_PROPERTY_OVERRIDES))))\
27 $(if $(_prop),$(_prop),$(patsubst $(1)=%,%,$(filter $(1)=%,$(PRODUCT_SYSTEM_DEFAULT_PROPERTIES)))))
28endef
29
30DEX2OAT_IMAGE_XMS := $(call get-product-default-property,dalvik.vm.image-dex2oat-Xms)
31DEX2OAT_IMAGE_XMX := $(call get-product-default-property,dalvik.vm.image-dex2oat-Xmx)
32DEX2OAT_XMS := $(call get-product-default-property,dalvik.vm.dex2oat-Xms)
33DEX2OAT_XMX := $(call get-product-default-property,dalvik.vm.dex2oat-Xmx)
34
35ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64))
36# MIPS specific overrides.
37# For MIPS the ART image is loaded at a lower address. This causes issues
38# with the image overlapping with memory on the host cross-compiling and
39# building the image. We therefore limit the Xmx value. This isn't done
40# via a property as we want the larger Xmx value if we're running on a
41# MIPS device.
42DEX2OAT_XMX := 128m
43endif
44
Brian Carlstromced4bff2013-11-14 23:44:56 -080045########################################################################
46# The full system boot classpath
47
Colin Crossb8901d72018-12-14 11:49:49 -080048# Returns the path to the .odex file
49# $(1): the arch name.
50# $(2): the full path (including file name) of the corresponding .jar or .apk.
51define get-odex-file-path
52$(dir $(2))oat/$(1)/$(basename $(notdir $(2))).odex
53endef
54
55# Returns the full path to the installed .odex file.
56# This handles BOARD_USES_SYSTEM_OTHER_ODEX to install odex files into another
57# partition.
58# $(1): the arch name.
59# $(2): the full install path (including file name) of the corresponding .apk.
60ifeq ($(BOARD_USES_SYSTEM_OTHER_ODEX),true)
61define get-odex-installed-file-path
62$(if $(call install-on-system-other, $(2)),
63 $(call get-odex-file-path,$(1),$(patsubst $(TARGET_OUT)/%,$(TARGET_OUT_SYSTEM_OTHER)/%,$(2))),
64 $(call get-odex-file-path,$(1),$(2)))
65endef
66else
67get-odex-installed-file-path = $(get-odex-file-path)
68endif
69
70# Returns the path to the image file (such as "/system/framework/<arch>/boot.art"
71# $(1): the arch name (such as "arm")
72# $(2): the image location (such as "/system/framework/boot.art")
73define get-image-file-path
74$(dir $(2))$(1)/$(notdir $(2))
75endef
76
Neil Fuller9fb70172018-08-28 13:18:25 +010077LIBART_TARGET_BOOT_JARS := $(DEXPREOPT_BOOT_JARS_MODULES)
Brian Carlstromced4bff2013-11-14 23:44:56 -080078LIBART_TARGET_BOOT_DEX_LOCATIONS := $(foreach jar,$(LIBART_TARGET_BOOT_JARS),/$(DEXPREOPT_BOOT_JAR_DIR)/$(jar).jar)
79LIBART_TARGET_BOOT_DEX_FILES := $(foreach jar,$(LIBART_TARGET_BOOT_JARS),$(call intermediates-dir-for,JAVA_LIBRARIES,$(jar),,COMMON)/javalib.jar)
80
Colin Cross52dcb2f2016-03-08 13:21:49 -080081# dex preopt on the bootclasspath produces multiple files. The first dex file
82# is converted into to boot.art (to match the legacy assumption that boot.art
83# exists), and the rest are converted to boot-<name>.art.
84# In addition, each .art file has an associated .oat file.
Vladimir Markoe47795b2018-09-26 12:57:21 +010085LIBART_TARGET_BOOT_ART_EXTRA_FILES := $(foreach jar,$(wordlist 2,999,$(LIBART_TARGET_BOOT_JARS)),boot-$(jar).art boot-$(jar).oat)
86LIBART_TARGET_BOOT_ART_EXTRA_FILES += boot.oat
bowen_lai4570fdb2017-08-16 16:28:05 +080087LIBART_TARGET_BOOT_ART_VDEX_FILES := $(foreach jar,$(wordlist 2,999,$(LIBART_TARGET_BOOT_JARS)),boot-$(jar).vdex)
88LIBART_TARGET_BOOT_ART_VDEX_FILES += boot.vdex
Colin Cross52dcb2f2016-03-08 13:21:49 -080089
Mathieu Chartiera61acf62017-06-28 18:23:37 -070090# If we use a boot image profile.
91my_use_profile_for_boot_image := $(PRODUCT_USE_PROFILE_FOR_BOOT_IMAGE)
92ifeq (,$(my_use_profile_for_boot_image))
Mathieu Chartier8fd29b32017-10-24 15:22:57 -070093# If not set, set the default to true if we are not a PDK build. PDK builds
94# can't build the profile since they don't have frameworks/base.
95ifneq (true,$(TARGET_BUILD_PDK))
Mathieu Chartierce944942017-08-28 18:42:02 -070096my_use_profile_for_boot_image := true
Mathieu Chartiera61acf62017-06-28 18:23:37 -070097endif
Mathieu Chartier8fd29b32017-10-24 15:22:57 -070098endif
Dan Willemsen406418d2018-06-19 23:03:34 -070099ifeq (,$(strip $(LIBART_TARGET_BOOT_DEX_FILES)))
100my_use_profile_for_boot_image := false
101endif
Mathieu Chartiera61acf62017-06-28 18:23:37 -0700102
103ifeq (true,$(my_use_profile_for_boot_image))
104
Shibin George9dd9e682018-07-02 16:21:49 +0530105boot_image_profiles := $(PRODUCT_DEX_PREOPT_BOOT_IMAGE_PROFILE_LOCATION)
106
107ifeq (,$(boot_image_profiles))
Mathieu Chartiera61acf62017-06-28 18:23:37 -0700108# If not set, use the default.
Shibin George9dd9e682018-07-02 16:21:49 +0530109boot_image_profiles := frameworks/base/config/boot-image-profile.txt
Mathieu Chartiera61acf62017-06-28 18:23:37 -0700110endif
111
Shibin George9dd9e682018-07-02 16:21:49 +0530112# Location of text based profile for the boot image.
113my_boot_image_profile_location := $(PRODUCT_OUT)/dex_bootjars/boot-image-profile.txt
114
115$(my_boot_image_profile_location): $(boot_image_profiles)
116 @echo 'Generating $@ for profman'
117 @rm -rf $@
118 $(hide) cat $^ > $@
119
Mathieu Chartiera61acf62017-06-28 18:23:37 -0700120# Code to create the boot image profile, not in dex_preopt_libart_boot.mk since the profile is the same for all archs.
121my_out_boot_image_profile_location := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/boot.prof
122$(my_out_boot_image_profile_location): PRIVATE_PROFILE_INPUT_LOCATION := $(my_boot_image_profile_location)
123$(my_out_boot_image_profile_location): $(PROFMAN) $(LIBART_TARGET_BOOT_DEX_FILES) $(my_boot_image_profile_location)
124 @echo "target profman: $@"
125 @mkdir -p $(dir $@)
126 ANDROID_LOG_TAGS="*:e" $(PROFMAN) \
127 --create-profile-from=$(PRIVATE_PROFILE_INPUT_LOCATION) \
128 $(addprefix --apk=,$(LIBART_TARGET_BOOT_DEX_FILES)) \
129 $(addprefix --dex-location=,$(LIBART_TARGET_BOOT_DEX_LOCATIONS)) \
130 --reference-profile-file=$@
131
132# We want to install the profile even if we are not using preopt since it is required to generate
133# the image on the device.
134my_installed_profile := $(TARGET_OUT)/etc/boot-image.prof
135$(eval $(call copy-one-file,$(my_out_boot_image_profile_location),$(my_installed_profile)))
136ALL_DEFAULT_INSTALLED_MODULES += $(my_installed_profile)
137
138endif
139
bowen_lai4570fdb2017-08-16 16:28:05 +0800140LIBART_TARGET_BOOT_ART_VDEX_INSTALLED_SHARED_FILES := $(addprefix $(PRODUCT_OUT)/$(DEXPREOPT_BOOT_JAR_DIR)/,$(LIBART_TARGET_BOOT_ART_VDEX_FILES))
141
Ying Wangb9aa5d42014-05-13 13:57:28 -0700142my_2nd_arch_prefix :=
143include $(BUILD_SYSTEM)/dex_preopt_libart_boot.mk
Brian Carlstromced4bff2013-11-14 23:44:56 -0800144
Ying Wang87538e42016-03-16 19:53:19 -0700145ifneq ($(TARGET_TRANSLATE_2ND_ARCH),true)
Ying Wangb9aa5d42014-05-13 13:57:28 -0700146ifdef TARGET_2ND_ARCH
147my_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
148include $(BUILD_SYSTEM)/dex_preopt_libart_boot.mk
Ying Wangb9aa5d42014-05-13 13:57:28 -0700149endif
Ying Wang87538e42016-03-16 19:53:19 -0700150endif
Brian Carlstromced4bff2013-11-14 23:44:56 -0800151
bowen_lai4570fdb2017-08-16 16:28:05 +0800152# Copy shared vdex to the directory and create corresponding symlinks in primary and secondary arch.
153$(LIBART_TARGET_BOOT_ART_VDEX_INSTALLED_SHARED_FILES) : PRIMARY_ARCH_DIR := $(dir $(DEFAULT_DEX_PREOPT_INSTALLED_IMAGE))
154$(LIBART_TARGET_BOOT_ART_VDEX_INSTALLED_SHARED_FILES) : SECOND_ARCH_DIR := $(dir $($(my_2nd_arch_prefix)DEFAULT_DEX_PREOPT_INSTALLED_IMAGE))
155$(LIBART_TARGET_BOOT_ART_VDEX_INSTALLED_SHARED_FILES) : $(DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME)
156 @echo "Install: $@"
157 @mkdir -p $(dir $@)
158 @rm -f $@
159 $(hide) cp "$(dir $<)$(notdir $@)" "$@"
160 # Make symlink for both the archs. In the case its single arch the symlink will just get overridden.
161 @mkdir -p $(PRIMARY_ARCH_DIR)
162 $(hide) ln -sf /$(DEXPREOPT_BOOT_JAR_DIR)/$(notdir $@) $(PRIMARY_ARCH_DIR)$(notdir $@)
163 @mkdir -p $(SECOND_ARCH_DIR)
164 $(hide) ln -sf /$(DEXPREOPT_BOOT_JAR_DIR)/$(notdir $@) $(SECOND_ARCH_DIR)$(notdir $@)
165
166my_2nd_arch_prefix :=
Colin Crossb8901d72018-12-14 11:49:49 -0800167
168########################################################################
169# For a single jar or APK
170
171# $(1): the input .jar or .apk file
172# $(2): the output .odex file
173# In the case where LOCAL_ENFORCE_USES_LIBRARIES is true, PRIVATE_DEX2OAT_CLASS_LOADER_CONTEXT
174# contains the normalized path list of the libraries. This makes it easier to conditionally prepend
175# org.apache.http.legacy.impl based on the SDK level if required.
176#
177# Pass --avoid-storing-invocation to make the output deterministics between
178# different products that may have different paths on the command line.
179define dex2oat-one-file
180$(hide) rm -f $(2)
181$(hide) mkdir -p $(dir $(2))
182stored_class_loader_context_libs=$(PRIVATE_DEX2OAT_STORED_CLASS_LOADER_CONTEXT_LIBS) && \
183class_loader_context_arg=--class-loader-context=$(PRIVATE_DEX2OAT_CLASS_LOADER_CONTEXT) && \
184class_loader_context=$(PRIVATE_DEX2OAT_CLASS_LOADER_CONTEXT) && \
185stored_class_loader_context_arg="" && \
186uses_library_names="$(PRIVATE_USES_LIBRARY_NAMES)" && \
187optional_uses_library_names="$(PRIVATE_OPTIONAL_USES_LIBRARY_NAMES)" && \
188aapt_binary="$(AAPT)" && \
189$(if $(filter true,$(PRIVATE_ENFORCE_USES_LIBRARIES)), \
190source build/make/core/verify_uses_libraries.sh "$(1)" && \
191source build/make/core/construct_context.sh "$(PRIVATE_CONDITIONAL_USES_LIBRARIES_HOST)" "$(PRIVATE_CONDITIONAL_USES_LIBRARIES_TARGET)" && \
192,) \
193ANDROID_LOG_TAGS="*:e" $(DEX2OAT) \
194 --avoid-storing-invocation \
195 --runtime-arg -Xms$(DEX2OAT_XMS) --runtime-arg -Xmx$(DEX2OAT_XMX) \
196 $${class_loader_context_arg} \
197 $${stored_class_loader_context_arg} \
198 --boot-image=$(PRIVATE_DEX_PREOPT_IMAGE_LOCATION) \
199 --dex-file=$(1) \
200 --dex-location=$(PRIVATE_DEX_LOCATION) \
201 --oat-file=$(2) \
202 --android-root=$(PRODUCT_OUT)/system \
203 --instruction-set=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_ARCH) \
204 --instruction-set-variant=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_CPU_VARIANT) \
205 --instruction-set-features=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES) \
206 --no-generate-debug-info --generate-build-id \
207 --abort-on-hard-verifier-error \
208 --force-determinism \
209 --no-inline-from=core-oj.jar \
210 $(PRIVATE_DEX_PREOPT_FLAGS) \
211 $(PRIVATE_ART_FILE_PREOPT_FLAGS) \
212 $(PRIVATE_PROFILE_PREOPT_FLAGS) \
213 $(GLOBAL_DEXPREOPT_FLAGS)
214endef