• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1####################################
2# dexpreopt support for ART
3#
4####################################
5
6# 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)
10PATCHOAT := $(HOST_OUT_EXECUTABLES)/patchoat$(HOST_EXECUTABLE_SUFFIX)
11else
12DEX2OAT := $(HOST_OUT_EXECUTABLES)/dex2oatd$(HOST_EXECUTABLE_SUFFIX)
13PATCHOAT := $(HOST_OUT_EXECUTABLES)/patchoatd$(HOST_EXECUTABLE_SUFFIX)
14endif
15
16DEX2OAT_DEPENDENCY += $(DEX2OAT)
17PATCHOAT_DEPENDENCY += $(PATCHOAT)
18
19# 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))))
22
23# Use the first compiled-classes file in PRODUCT_COPY_FILES.
24COMPILED_CLASSES := $(call word-colon,1,$(firstword \
25    $(filter %system/etc/compiled-classes,$(PRODUCT_COPY_FILES))))
26
27# Use the first dirty-image-objects file in PRODUCT_COPY_FILES.
28DIRTY_IMAGE_OBJECTS := $(call word-colon,1,$(firstword \
29    $(filter %system/etc/dirty-image-objects,$(PRODUCT_COPY_FILES))))
30
31define get-product-default-property
32$(strip \
33  $(eval _prop := $(patsubst $(1)=%,%,$(filter $(1)=%,$(PRODUCT_DEFAULT_PROPERTY_OVERRIDES))))\
34  $(if $(_prop),$(_prop),$(patsubst $(1)=%,%,$(filter $(1)=%,$(PRODUCT_SYSTEM_DEFAULT_PROPERTIES)))))
35endef
36
37DEX2OAT_IMAGE_XMS := $(call get-product-default-property,dalvik.vm.image-dex2oat-Xms)
38DEX2OAT_IMAGE_XMX := $(call get-product-default-property,dalvik.vm.image-dex2oat-Xmx)
39DEX2OAT_XMS := $(call get-product-default-property,dalvik.vm.dex2oat-Xms)
40DEX2OAT_XMX := $(call get-product-default-property,dalvik.vm.dex2oat-Xmx)
41
42ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64))
43# MIPS specific overrides.
44# For MIPS the ART image is loaded at a lower address. This causes issues
45# with the image overlapping with memory on the host cross-compiling and
46# building the image. We therefore limit the Xmx value. This isn't done
47# via a property as we want the larger Xmx value if we're running on a
48# MIPS device.
49DEX2OAT_XMX := 128m
50endif
51
52########################################################################
53# The full system boot classpath
54
55# Returns the path to the .odex file
56# $(1): the arch name.
57# $(2): the full path (including file name) of the corresponding .jar or .apk.
58define get-odex-file-path
59$(dir $(2))oat/$(1)/$(basename $(notdir $(2))).odex
60endef
61
62# Returns the full path to the installed .odex file.
63# This handles BOARD_USES_SYSTEM_OTHER_ODEX to install odex files into another
64# partition.
65# $(1): the arch name.
66# $(2): the full install path (including file name) of the corresponding .apk.
67ifeq ($(BOARD_USES_SYSTEM_OTHER_ODEX),true)
68define get-odex-installed-file-path
69$(if $(call install-on-system-other, $(2)),
70  $(call get-odex-file-path,$(1),$(patsubst $(TARGET_OUT)/%,$(TARGET_OUT_SYSTEM_OTHER)/%,$(2))),
71  $(call get-odex-file-path,$(1),$(2)))
72endef
73else
74get-odex-installed-file-path = $(get-odex-file-path)
75endif
76
77# Returns the path to the image file (such as "/system/framework/<arch>/boot.art"
78# $(1): the arch name (such as "arm")
79# $(2): the image location (such as "/system/framework/boot.art")
80define get-image-file-path
81$(dir $(2))$(1)/$(notdir $(2))
82endef
83
84# note we use core-libart.jar in place of core.jar for ART.
85LIBART_TARGET_BOOT_JARS := $(patsubst core, core-libart,$(DEXPREOPT_BOOT_JARS_MODULES))
86LIBART_TARGET_BOOT_DEX_LOCATIONS := $(foreach jar,$(LIBART_TARGET_BOOT_JARS),/$(DEXPREOPT_BOOT_JAR_DIR)/$(jar).jar)
87LIBART_TARGET_BOOT_DEX_FILES := $(foreach jar,$(LIBART_TARGET_BOOT_JARS),$(call intermediates-dir-for,JAVA_LIBRARIES,$(jar),,COMMON)/javalib.jar)
88
89# dex preopt on the bootclasspath produces multiple files.  The first dex file
90# is converted into to boot.art (to match the legacy assumption that boot.art
91# exists), and the rest are converted to boot-<name>.art.
92# In addition, each .art file has an associated .oat file.
93LIBART_TARGET_BOOT_ART_EXTRA_FILES := $(foreach jar,$(wordlist 2,999,$(LIBART_TARGET_BOOT_JARS)),boot-$(jar).art boot-$(jar).art.rel boot-$(jar).oat)
94LIBART_TARGET_BOOT_ART_EXTRA_FILES += boot.art.rel boot.oat
95LIBART_TARGET_BOOT_ART_VDEX_FILES := $(foreach jar,$(wordlist 2,999,$(LIBART_TARGET_BOOT_JARS)),boot-$(jar).vdex)
96LIBART_TARGET_BOOT_ART_VDEX_FILES += boot.vdex
97
98# If we use a boot image profile.
99my_use_profile_for_boot_image := $(PRODUCT_USE_PROFILE_FOR_BOOT_IMAGE)
100ifeq (,$(my_use_profile_for_boot_image))
101# If not set, set the default to true if we are not a PDK build. PDK builds
102# can't build the profile since they don't have frameworks/base.
103ifneq (true,$(TARGET_BUILD_PDK))
104my_use_profile_for_boot_image := true
105endif
106endif
107
108ifeq (true,$(my_use_profile_for_boot_image))
109
110# Location of text based profile for the boot image.
111my_boot_image_profile_location := $(PRODUCT_DEX_PREOPT_BOOT_IMAGE_PROFILE_LOCATION)
112ifeq (,$(my_boot_image_profile_location))
113# If not set, use the default.
114my_boot_image_profile_location := frameworks/base/config/boot-image-profile.txt
115endif
116
117# Code to create the boot image profile, not in dex_preopt_libart_boot.mk since the profile is the same for all archs.
118my_out_boot_image_profile_location := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/boot.prof
119$(my_out_boot_image_profile_location): PRIVATE_PROFILE_INPUT_LOCATION := $(my_boot_image_profile_location)
120$(my_out_boot_image_profile_location): $(PROFMAN) $(LIBART_TARGET_BOOT_DEX_FILES) $(my_boot_image_profile_location)
121	@echo "target profman: $@"
122	@mkdir -p $(dir $@)
123	ANDROID_LOG_TAGS="*:e" $(PROFMAN) \
124		--create-profile-from=$(PRIVATE_PROFILE_INPUT_LOCATION) \
125		$(addprefix --apk=,$(LIBART_TARGET_BOOT_DEX_FILES)) \
126		$(addprefix --dex-location=,$(LIBART_TARGET_BOOT_DEX_LOCATIONS)) \
127		--reference-profile-file=$@
128
129# We want to install the profile even if we are not using preopt since it is required to generate
130# the image on the device.
131my_installed_profile := $(TARGET_OUT)/etc/boot-image.prof
132$(eval $(call copy-one-file,$(my_out_boot_image_profile_location),$(my_installed_profile)))
133ALL_DEFAULT_INSTALLED_MODULES += $(my_installed_profile)
134
135endif
136
137LIBART_TARGET_BOOT_ART_VDEX_INSTALLED_SHARED_FILES := $(addprefix $(PRODUCT_OUT)/$(DEXPREOPT_BOOT_JAR_DIR)/,$(LIBART_TARGET_BOOT_ART_VDEX_FILES))
138
139my_2nd_arch_prefix :=
140include $(BUILD_SYSTEM)/dex_preopt_libart_boot.mk
141
142ifneq ($(TARGET_TRANSLATE_2ND_ARCH),true)
143ifdef TARGET_2ND_ARCH
144my_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
145include $(BUILD_SYSTEM)/dex_preopt_libart_boot.mk
146endif
147endif
148
149# Copy shared vdex to the directory and create corresponding symlinks in primary and secondary arch.
150$(LIBART_TARGET_BOOT_ART_VDEX_INSTALLED_SHARED_FILES) : PRIMARY_ARCH_DIR := $(dir $(DEFAULT_DEX_PREOPT_INSTALLED_IMAGE))
151$(LIBART_TARGET_BOOT_ART_VDEX_INSTALLED_SHARED_FILES) : SECOND_ARCH_DIR := $(dir $($(my_2nd_arch_prefix)DEFAULT_DEX_PREOPT_INSTALLED_IMAGE))
152$(LIBART_TARGET_BOOT_ART_VDEX_INSTALLED_SHARED_FILES) : $(DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME)
153	@echo "Install: $@"
154	@mkdir -p $(dir $@)
155	@rm -f $@
156	$(hide) cp "$(dir $<)$(notdir $@)" "$@"
157	# Make symlink for both the archs. In the case its single arch the symlink will just get overridden.
158	@mkdir -p $(PRIMARY_ARCH_DIR)
159	$(hide) ln -sf /$(DEXPREOPT_BOOT_JAR_DIR)/$(notdir $@) $(PRIMARY_ARCH_DIR)$(notdir $@)
160	@mkdir -p $(SECOND_ARCH_DIR)
161	$(hide) ln -sf /$(DEXPREOPT_BOOT_JAR_DIR)/$(notdir $@) $(SECOND_ARCH_DIR)$(notdir $@)
162
163my_2nd_arch_prefix :=
164
165########################################################################
166# For a single jar or APK
167
168# $(1): the input .jar or .apk file
169# $(2): the output .odex file
170# In the case where LOCAL_ENFORCE_USES_LIBRARIES is true, PRIVATE_DEX2OAT_CLASS_LOADER_CONTEXT
171# contains the normalized path list of the libraries. This makes it easier to conditionally prepend
172# org.apache.http.legacy.boot based on the SDK level if required.
173define dex2oat-one-file
174$(hide) rm -f $(2)
175$(hide) mkdir -p $(dir $(2))
176stored_class_loader_context_libs=$(PRIVATE_DEX2OAT_STORED_CLASS_LOADER_CONTEXT_LIBS) && \
177class_loader_context_arg=--class-loader-context=$(PRIVATE_DEX2OAT_CLASS_LOADER_CONTEXT) && \
178class_loader_context=$(PRIVATE_DEX2OAT_CLASS_LOADER_CONTEXT) && \
179stored_class_loader_context_arg="" && \
180uses_library_names="$(PRIVATE_USES_LIBRARY_NAMES)" && \
181optional_uses_library_names="$(PRIVATE_OPTIONAL_USES_LIBRARY_NAMES)" && \
182$(if $(PRIVATE_ENFORCE_USES_LIBRARIES), \
183source build/make/core/verify_uses_libraries.sh "$(1)" && \
184source build/make/core/construct_context.sh "$(PRIVATE_CONDITIONAL_USES_LIBRARIES_HOST)" "$(PRIVATE_CONDITIONAL_USES_LIBRARIES_TARGET)" && \
185,) \
186ANDROID_LOG_TAGS="*:e" $(DEX2OAT) \
187	--runtime-arg -Xms$(DEX2OAT_XMS) --runtime-arg -Xmx$(DEX2OAT_XMX) \
188	$${class_loader_context_arg} \
189	$${stored_class_loader_context_arg} \
190	--boot-image=$(PRIVATE_DEX_PREOPT_IMAGE_LOCATION) \
191	--dex-file=$(1) \
192	--dex-location=$(PRIVATE_DEX_LOCATION) \
193	--oat-file=$(2) \
194	--android-root=$(PRODUCT_OUT)/system \
195	--instruction-set=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_ARCH) \
196	--instruction-set-variant=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_CPU_VARIANT) \
197	--instruction-set-features=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES) \
198	--runtime-arg -Xnorelocate --compile-pic \
199	--no-generate-debug-info --generate-build-id \
200	--abort-on-hard-verifier-error \
201	--force-determinism \
202	--no-inline-from=core-oj.jar \
203	$(PRIVATE_DEX_PREOPT_FLAGS) \
204	$(PRIVATE_ART_FILE_PREOPT_FLAGS) \
205	$(PRIVATE_PROFILE_PREOPT_FLAGS) \
206	$(GLOBAL_DEXPREOPT_FLAGS)
207endef
208