blob: 3b9e4e13205998677b534d0eabfb64b37e8a5ed7 [file] [log] [blame]
Brian Carlstromced4bff2013-11-14 23:44:56 -08001####################################
2# dexpreopt support for ART
3#
4####################################
5
Fredrik Roubert8a3dd242015-07-27 21:48:39 +02006# 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)
Brian Carlstromced4bff2013-11-14 23:44:56 -08009DEX2OAT := $(HOST_OUT_EXECUTABLES)/dex2oat$(HOST_EXECUTABLE_SUFFIX)
Alex Klyubina1b5dfe2017-11-14 13:29:24 -080010PATCHOAT := $(HOST_OUT_EXECUTABLES)/patchoat$(HOST_EXECUTABLE_SUFFIX)
Fredrik Roubert8a3dd242015-07-27 21:48:39 +020011else
12DEX2OAT := $(HOST_OUT_EXECUTABLES)/dex2oatd$(HOST_EXECUTABLE_SUFFIX)
Alex Klyubina1b5dfe2017-11-14 13:29:24 -080013PATCHOAT := $(HOST_OUT_EXECUTABLES)/patchoatd$(HOST_EXECUTABLE_SUFFIX)
Fredrik Roubert8a3dd242015-07-27 21:48:39 +020014endif
Brian Carlstromced4bff2013-11-14 23:44:56 -080015
Brian Carlstromced4bff2013-11-14 23:44:56 -080016DEX2OAT_DEPENDENCY += $(DEX2OAT)
Alex Klyubina1b5dfe2017-11-14 13:29:24 -080017PATCHOAT_DEPENDENCY += $(PATCHOAT)
Brian Carlstromced4bff2013-11-14 23:44:56 -080018
Ying Wang0c9b3ba2014-11-13 15:19:12 -080019# Use the first preloaded-classes file in PRODUCT_COPY_FILES.
20PRELOADED_CLASSES := $(call word-colon,1,$(firstword \
21 $(filter %system/etc/preloaded-classes,$(PRODUCT_COPY_FILES))))
Brian Carlstromced4bff2013-11-14 23:44:56 -080022
Jeff Haob454ee12017-08-02 16:45:49 -070023# Use the first dirty-image-objects file in PRODUCT_COPY_FILES.
24DIRTY_IMAGE_OBJECTS := $(call word-colon,1,$(firstword \
25 $(filter %system/etc/dirty-image-objects,$(PRODUCT_COPY_FILES))))
26
Colin Crossdd2ff552014-07-09 22:09:50 -070027define get-product-default-property
Jaekyun Seok5fb6a3e2017-11-03 15:33:10 +090028$(strip \
29 $(eval _prop := $(patsubst $(1)=%,%,$(filter $(1)=%,$(PRODUCT_DEFAULT_PROPERTY_OVERRIDES))))\
30 $(if $(_prop),$(_prop),$(patsubst $(1)=%,%,$(filter $(1)=%,$(PRODUCT_SYSTEM_DEFAULT_PROPERTIES)))))
Brian Carlstromcffe2892014-07-08 10:35:29 -070031endef
32
Colin Crossdd2ff552014-07-09 22:09:50 -070033DEX2OAT_IMAGE_XMS := $(call get-product-default-property,dalvik.vm.image-dex2oat-Xms)
34DEX2OAT_IMAGE_XMX := $(call get-product-default-property,dalvik.vm.image-dex2oat-Xmx)
35DEX2OAT_XMS := $(call get-product-default-property,dalvik.vm.dex2oat-Xms)
36DEX2OAT_XMX := $(call get-product-default-property,dalvik.vm.dex2oat-Xmx)
Brian Carlstromcffe2892014-07-08 10:35:29 -070037
Nikola Veljkovica57aaa32014-12-23 13:50:18 +010038ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64))
Ian Rogers7d70f832014-07-16 18:06:02 -070039# MIPS specific overrides.
40# For MIPS the ART image is loaded at a lower address. This causes issues
41# with the image overlapping with memory on the host cross-compiling and
42# building the image. We therefore limit the Xmx value. This isn't done
43# via a property as we want the larger Xmx value if we're running on a
44# MIPS device.
Ian Rogers87f0d002014-07-16 22:25:35 -070045DEX2OAT_XMX := 128m
Ian Rogers7d70f832014-07-16 18:06:02 -070046endif
47
Brian Carlstromced4bff2013-11-14 23:44:56 -080048########################################################################
49# The full system boot classpath
50
Ying Wangb9aa5d42014-05-13 13:57:28 -070051# Returns the path to the .odex file
52# $(1): the arch name.
53# $(2): the full path (including file name) of the corresponding .jar or .apk.
54define get-odex-file-path
Richard Uhler820fe322015-03-16 14:38:17 -070055$(dir $(2))oat/$(1)/$(basename $(notdir $(2))).odex
Ying Wangb9aa5d42014-05-13 13:57:28 -070056endef
57
Alex Light4e358ab2016-06-16 14:47:10 -070058# Returns the full path to the installed .odex file.
59# This handles BOARD_USES_SYSTEM_OTHER_ODEX to install odex files into another
60# partition.
61# $(1): the arch name.
62# $(2): the full install path (including file name) of the corresponding .apk.
63ifeq ($(BOARD_USES_SYSTEM_OTHER_ODEX),true)
64define get-odex-installed-file-path
Nicolas Geoffraycdd43432017-03-24 14:45:59 +000065$(if $(call install-on-system-other, $(2)),
Alex Light4e358ab2016-06-16 14:47:10 -070066 $(call get-odex-file-path,$(1),$(patsubst $(TARGET_OUT)/%,$(TARGET_OUT_SYSTEM_OTHER)/%,$(2))),
67 $(call get-odex-file-path,$(1),$(2)))
68endef
69else
70get-odex-installed-file-path = $(get-odex-file-path)
71endif
72
Ying Wangb9aa5d42014-05-13 13:57:28 -070073# Returns the path to the image file (such as "/system/framework/<arch>/boot.art"
74# $(1): the arch name (such as "arm")
75# $(2): the image location (such as "/system/framework/boot.art")
76define get-image-file-path
77$(dir $(2))$(1)/$(notdir $(2))
78endef
79
Brian Carlstromced4bff2013-11-14 23:44:56 -080080# note we use core-libart.jar in place of core.jar for ART.
81LIBART_TARGET_BOOT_JARS := $(patsubst core, core-libart,$(DEXPREOPT_BOOT_JARS_MODULES))
82LIBART_TARGET_BOOT_DEX_LOCATIONS := $(foreach jar,$(LIBART_TARGET_BOOT_JARS),/$(DEXPREOPT_BOOT_JAR_DIR)/$(jar).jar)
83LIBART_TARGET_BOOT_DEX_FILES := $(foreach jar,$(LIBART_TARGET_BOOT_JARS),$(call intermediates-dir-for,JAVA_LIBRARIES,$(jar),,COMMON)/javalib.jar)
84
Colin Cross52dcb2f2016-03-08 13:21:49 -080085# dex preopt on the bootclasspath produces multiple files. The first dex file
86# is converted into to boot.art (to match the legacy assumption that boot.art
87# exists), and the rest are converted to boot-<name>.art.
88# In addition, each .art file has an associated .oat file.
bowen_lai4570fdb2017-08-16 16:28:05 +080089LIBART_TARGET_BOOT_ART_EXTRA_FILES := $(foreach jar,$(wordlist 2,999,$(LIBART_TARGET_BOOT_JARS)),boot-$(jar).art boot-$(jar).art.rel boot-$(jar).oat)
90LIBART_TARGET_BOOT_ART_EXTRA_FILES += boot.art.rel boot.oat
91LIBART_TARGET_BOOT_ART_VDEX_FILES := $(foreach jar,$(wordlist 2,999,$(LIBART_TARGET_BOOT_JARS)),boot-$(jar).vdex)
92LIBART_TARGET_BOOT_ART_VDEX_FILES += boot.vdex
Colin Cross52dcb2f2016-03-08 13:21:49 -080093
Mathieu Chartiera61acf62017-06-28 18:23:37 -070094# If we use a boot image profile.
95my_use_profile_for_boot_image := $(PRODUCT_USE_PROFILE_FOR_BOOT_IMAGE)
96ifeq (,$(my_use_profile_for_boot_image))
Mathieu Chartier8fd29b32017-10-24 15:22:57 -070097# If not set, set the default to true if we are not a PDK build. PDK builds
98# can't build the profile since they don't have frameworks/base.
99ifneq (true,$(TARGET_BUILD_PDK))
Mathieu Chartierce944942017-08-28 18:42:02 -0700100my_use_profile_for_boot_image := true
Mathieu Chartiera61acf62017-06-28 18:23:37 -0700101endif
Mathieu Chartier8fd29b32017-10-24 15:22:57 -0700102endif
Mathieu Chartiera61acf62017-06-28 18:23:37 -0700103
104ifeq (true,$(my_use_profile_for_boot_image))
105
106# Location of text based profile for the boot image.
107my_boot_image_profile_location := $(PRODUCT_DEX_PREOPT_BOOT_IMAGE_PROFILE_LOCATION)
108ifeq (,$(my_boot_image_profile_location))
109# If not set, use the default.
Mathieu Chartiera2cc65b2017-08-28 18:42:02 -0700110my_boot_image_profile_location := frameworks/base/config/boot-image-profile.txt
Mathieu Chartiera61acf62017-06-28 18:23:37 -0700111endif
112
113# Code to create the boot image profile, not in dex_preopt_libart_boot.mk since the profile is the same for all archs.
114my_out_boot_image_profile_location := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/boot.prof
115$(my_out_boot_image_profile_location): PRIVATE_PROFILE_INPUT_LOCATION := $(my_boot_image_profile_location)
116$(my_out_boot_image_profile_location): $(PROFMAN) $(LIBART_TARGET_BOOT_DEX_FILES) $(my_boot_image_profile_location)
117 @echo "target profman: $@"
118 @mkdir -p $(dir $@)
119 ANDROID_LOG_TAGS="*:e" $(PROFMAN) \
120 --create-profile-from=$(PRIVATE_PROFILE_INPUT_LOCATION) \
121 $(addprefix --apk=,$(LIBART_TARGET_BOOT_DEX_FILES)) \
122 $(addprefix --dex-location=,$(LIBART_TARGET_BOOT_DEX_LOCATIONS)) \
123 --reference-profile-file=$@
124
125# We want to install the profile even if we are not using preopt since it is required to generate
126# the image on the device.
127my_installed_profile := $(TARGET_OUT)/etc/boot-image.prof
128$(eval $(call copy-one-file,$(my_out_boot_image_profile_location),$(my_installed_profile)))
129ALL_DEFAULT_INSTALLED_MODULES += $(my_installed_profile)
130
131endif
132
bowen_lai4570fdb2017-08-16 16:28:05 +0800133LIBART_TARGET_BOOT_ART_VDEX_INSTALLED_SHARED_FILES := $(addprefix $(PRODUCT_OUT)/$(DEXPREOPT_BOOT_JAR_DIR)/,$(LIBART_TARGET_BOOT_ART_VDEX_FILES))
134
Ying Wangb9aa5d42014-05-13 13:57:28 -0700135my_2nd_arch_prefix :=
136include $(BUILD_SYSTEM)/dex_preopt_libart_boot.mk
Brian Carlstromced4bff2013-11-14 23:44:56 -0800137
Ying Wang87538e42016-03-16 19:53:19 -0700138ifneq ($(TARGET_TRANSLATE_2ND_ARCH),true)
Ying Wangb9aa5d42014-05-13 13:57:28 -0700139ifdef TARGET_2ND_ARCH
140my_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
141include $(BUILD_SYSTEM)/dex_preopt_libart_boot.mk
Ying Wangb9aa5d42014-05-13 13:57:28 -0700142endif
Ying Wang87538e42016-03-16 19:53:19 -0700143endif
Brian Carlstromced4bff2013-11-14 23:44:56 -0800144
bowen_lai4570fdb2017-08-16 16:28:05 +0800145# Copy shared vdex to the directory and create corresponding symlinks in primary and secondary arch.
146$(LIBART_TARGET_BOOT_ART_VDEX_INSTALLED_SHARED_FILES) : PRIMARY_ARCH_DIR := $(dir $(DEFAULT_DEX_PREOPT_INSTALLED_IMAGE))
147$(LIBART_TARGET_BOOT_ART_VDEX_INSTALLED_SHARED_FILES) : SECOND_ARCH_DIR := $(dir $($(my_2nd_arch_prefix)DEFAULT_DEX_PREOPT_INSTALLED_IMAGE))
148$(LIBART_TARGET_BOOT_ART_VDEX_INSTALLED_SHARED_FILES) : $(DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME)
149 @echo "Install: $@"
150 @mkdir -p $(dir $@)
151 @rm -f $@
152 $(hide) cp "$(dir $<)$(notdir $@)" "$@"
153 # Make symlink for both the archs. In the case its single arch the symlink will just get overridden.
154 @mkdir -p $(PRIMARY_ARCH_DIR)
155 $(hide) ln -sf /$(DEXPREOPT_BOOT_JAR_DIR)/$(notdir $@) $(PRIMARY_ARCH_DIR)$(notdir $@)
156 @mkdir -p $(SECOND_ARCH_DIR)
157 $(hide) ln -sf /$(DEXPREOPT_BOOT_JAR_DIR)/$(notdir $@) $(SECOND_ARCH_DIR)$(notdir $@)
158
159my_2nd_arch_prefix :=
Brian Carlstromced4bff2013-11-14 23:44:56 -0800160
161########################################################################
162# For a single jar or APK
163
Ying Wangb9aa5d42014-05-13 13:57:28 -0700164# $(1): the input .jar or .apk file
165# $(2): the output .odex file
Mathieu Chartierd022b652018-03-23 21:57:02 -0700166# In the case where LOCAL_ENFORCE_USES_LIBRARIES is true, PRIVATE_DEX2OAT_CLASS_LOADER_CONTEXT
167# contains the normalized path list of the libraries. This makes it easier to conditionally prepend
168# org.apache.http.legacy.boot based on the SDK level if required.
Brian Carlstromced4bff2013-11-14 23:44:56 -0800169define dex2oat-one-file
Ying Wangb9aa5d42014-05-13 13:57:28 -0700170$(hide) rm -f $(2)
171$(hide) mkdir -p $(dir $(2))
Mathieu Chartierd022b652018-03-23 21:57:02 -0700172stored_class_loader_context_libs=$(PRIVATE_DEX2OAT_STORED_CLASS_LOADER_CONTEXT_LIBS) && \
173class_loader_context_arg=--class-loader-context=$(PRIVATE_DEX2OAT_CLASS_LOADER_CONTEXT) && \
174class_loader_context=$(PRIVATE_DEX2OAT_CLASS_LOADER_CONTEXT) && \
175stored_class_loader_context_arg="" && \
176uses_library_names="$(PRIVATE_USES_LIBRARY_NAMES)" && \
177optional_uses_library_names="$(PRIVATE_OPTIONAL_USES_LIBRARY_NAMES)" && \
Mathieu Chartier116790d2018-05-14 10:13:37 -0700178aapt_binary="$(AAPT)" && \
Mathieu Chartiercda2ef12018-05-11 09:33:41 -0700179$(if $(filter true,$(PRIVATE_ENFORCE_USES_LIBRARIES)), \
Mathieu Chartierd022b652018-03-23 21:57:02 -0700180source build/make/core/verify_uses_libraries.sh "$(1)" && \
181source build/make/core/construct_context.sh "$(PRIVATE_CONDITIONAL_USES_LIBRARIES_HOST)" "$(PRIVATE_CONDITIONAL_USES_LIBRARIES_TARGET)" && \
182,) \
183ANDROID_LOG_TAGS="*:e" $(DEX2OAT) \
Colin Crossdd2ff552014-07-09 22:09:50 -0700184 --runtime-arg -Xms$(DEX2OAT_XMS) --runtime-arg -Xmx$(DEX2OAT_XMX) \
Mathieu Chartierd022b652018-03-23 21:57:02 -0700185 $${class_loader_context_arg} \
186 $${stored_class_loader_context_arg} \
Ying Wangb9aa5d42014-05-13 13:57:28 -0700187 --boot-image=$(PRIVATE_DEX_PREOPT_IMAGE_LOCATION) \
188 --dex-file=$(1) \
189 --dex-location=$(PRIVATE_DEX_LOCATION) \
190 --oat-file=$(2) \
Brian Carlstromced4bff2013-11-14 23:44:56 -0800191 --android-root=$(PRODUCT_OUT)/system \
Ying Wangb9aa5d42014-05-13 13:57:28 -0700192 --instruction-set=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_ARCH) \
Ian Rogersa18a2832014-10-17 01:05:50 -0700193 --instruction-set-variant=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_CPU_VARIANT) \
Alex Lightce090d32014-07-24 16:26:13 -0700194 --instruction-set-features=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES) \
Richard Uhler41408b02017-02-28 17:05:12 +0000195 --runtime-arg -Xnorelocate --compile-pic \
Alexey Alexandrove4690632016-09-19 10:54:21 -0700196 --no-generate-debug-info --generate-build-id \
Andreas Gampe06d86e92015-03-05 19:18:18 -0800197 --abort-on-hard-verifier-error \
Nicolas Geoffraya5bb1802017-04-28 15:00:28 +0100198 --force-determinism \
Jeff Haod1d3fd92015-12-16 17:20:11 -0800199 --no-inline-from=core-oj.jar \
Ying Wang3a61eeb2016-03-11 10:32:01 -0800200 $(PRIVATE_DEX_PREOPT_FLAGS) \
Mathieu Chartier192b91c2017-02-08 18:30:31 -0800201 $(PRIVATE_ART_FILE_PREOPT_FLAGS) \
Mathieu Chartiera4b993b2017-02-28 11:17:32 -0800202 $(PRIVATE_PROFILE_PREOPT_FLAGS) \
Ying Wang3a61eeb2016-03-11 10:32:01 -0800203 $(GLOBAL_DEXPREOPT_FLAGS)
Brian Carlstromced4bff2013-11-14 23:44:56 -0800204endef