1ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstrom####################################
2ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstrom# dexpreopt support for ART
3ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstrom#
4ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstrom####################################
5ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstrom
68a3dd242acf1bbdf0f64c93336719a0017708adeFredrik Roubert# Default to debug version to help find bugs.
78a3dd242acf1bbdf0f64c93336719a0017708adeFredrik Roubert# Set USE_DEX2OAT_DEBUG to false for only building non-debug versions.
88a3dd242acf1bbdf0f64c93336719a0017708adeFredrik Roubertifeq ($(USE_DEX2OAT_DEBUG),false)
9ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian CarlstromDEX2OAT := $(HOST_OUT_EXECUTABLES)/dex2oat$(HOST_EXECUTABLE_SUFFIX)
108a3dd242acf1bbdf0f64c93336719a0017708adeFredrik Roubertelse
118a3dd242acf1bbdf0f64c93336719a0017708adeFredrik RoubertDEX2OAT := $(HOST_OUT_EXECUTABLES)/dex2oatd$(HOST_EXECUTABLE_SUFFIX)
128a3dd242acf1bbdf0f64c93336719a0017708adeFredrik Roubertendif
13ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstrom
14b00263f96a90c9f77cf7d8d90742a0884290bf60Jeff Hao# Pass special classpath to skip uses library check.
15b00263f96a90c9f77cf7d8d90742a0884290bf60Jeff Hao# Should modify build system to pass used libraries properly later.
16b00263f96a90c9f77cf7d8d90742a0884290bf60Jeff HaoDEX2OAT_CLASSPATH := "&"
17b00263f96a90c9f77cf7d8d90742a0884290bf60Jeff Hao
18ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian CarlstromDEX2OAT_DEPENDENCY += $(DEX2OAT)
19ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstrom
200c9b3bac65e1ba3d57371c71ff6a0b524558451fYing Wang# Use the first preloaded-classes file in PRODUCT_COPY_FILES.
210c9b3bac65e1ba3d57371c71ff6a0b524558451fYing WangPRELOADED_CLASSES := $(call word-colon,1,$(firstword \
220c9b3bac65e1ba3d57371c71ff6a0b524558451fYing Wang    $(filter %system/etc/preloaded-classes,$(PRODUCT_COPY_FILES))))
23ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstrom
2496a522037ff7079cbf48625c3cfb5ec49b7e6db6Andreas Gampe# Use the first compiled-classes file in PRODUCT_COPY_FILES.
2596a522037ff7079cbf48625c3cfb5ec49b7e6db6Andreas GampeCOMPILED_CLASSES := $(call word-colon,1,$(firstword \
2696a522037ff7079cbf48625c3cfb5ec49b7e6db6Andreas Gampe    $(filter %system/etc/compiled-classes,$(PRODUCT_COPY_FILES))))
2796a522037ff7079cbf48625c3cfb5ec49b7e6db6Andreas Gampe
28dd2ff5541e9bfcad8e0b9d3cd1275eb4a73d31f4Colin Crossdefine get-product-default-property
29dd2ff5541e9bfcad8e0b9d3cd1275eb4a73d31f4Colin Cross$(strip $(patsubst $(1)=%,%,$(filter $(1)=%,$(PRODUCT_DEFAULT_PROPERTY_OVERRIDES))))
30cffe289dc6a5a248ac28805e1ad129681da002feBrian Carlstromendef
31cffe289dc6a5a248ac28805e1ad129681da002feBrian Carlstrom
32dd2ff5541e9bfcad8e0b9d3cd1275eb4a73d31f4Colin CrossDEX2OAT_IMAGE_XMS := $(call get-product-default-property,dalvik.vm.image-dex2oat-Xms)
33dd2ff5541e9bfcad8e0b9d3cd1275eb4a73d31f4Colin CrossDEX2OAT_IMAGE_XMX := $(call get-product-default-property,dalvik.vm.image-dex2oat-Xmx)
34dd2ff5541e9bfcad8e0b9d3cd1275eb4a73d31f4Colin CrossDEX2OAT_XMS := $(call get-product-default-property,dalvik.vm.dex2oat-Xms)
35dd2ff5541e9bfcad8e0b9d3cd1275eb4a73d31f4Colin CrossDEX2OAT_XMX := $(call get-product-default-property,dalvik.vm.dex2oat-Xmx)
36cffe289dc6a5a248ac28805e1ad129681da002feBrian Carlstrom
37a57aaa3664b8791cebc209c96d1369dff61727edNikola Veljkovicifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64))
387d70f830bce969575b358a39e041e85013881cd4Ian Rogers# MIPS specific overrides.
397d70f830bce969575b358a39e041e85013881cd4Ian Rogers# For MIPS the ART image is loaded at a lower address. This causes issues
407d70f830bce969575b358a39e041e85013881cd4Ian Rogers# with the image overlapping with memory on the host cross-compiling and
417d70f830bce969575b358a39e041e85013881cd4Ian Rogers# building the image. We therefore limit the Xmx value. This isn't done
427d70f830bce969575b358a39e041e85013881cd4Ian Rogers# via a property as we want the larger Xmx value if we're running on a
437d70f830bce969575b358a39e041e85013881cd4Ian Rogers# MIPS device.
4487f0d006f254dc49621a8cd925b5448344eb367fIan RogersDEX2OAT_XMX := 128m
457d70f830bce969575b358a39e041e85013881cd4Ian Rogersendif
467d70f830bce969575b358a39e041e85013881cd4Ian Rogers
47ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstrom########################################################################
48ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstrom# The full system boot classpath
49ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstrom
50b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wang# Returns the path to the .odex file
51b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wang# $(1): the arch name.
52b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wang# $(2): the full path (including file name) of the corresponding .jar or .apk.
53b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wangdefine get-odex-file-path
54820fe32d467b7b8b25ef1645eec8876492619f75Richard Uhler$(dir $(2))oat/$(1)/$(basename $(notdir $(2))).odex
55b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wangendef
56b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wang
574e358ab2c3635439db5bd1a1ef424d5c1250ce00Alex Light# Returns the full path to the installed .odex file.
584e358ab2c3635439db5bd1a1ef424d5c1250ce00Alex Light# This handles BOARD_USES_SYSTEM_OTHER_ODEX to install odex files into another
594e358ab2c3635439db5bd1a1ef424d5c1250ce00Alex Light# partition.
604e358ab2c3635439db5bd1a1ef424d5c1250ce00Alex Light# $(1): the arch name.
614e358ab2c3635439db5bd1a1ef424d5c1250ce00Alex Light# $(2): the full install path (including file name) of the corresponding .apk.
624e358ab2c3635439db5bd1a1ef424d5c1250ce00Alex Lightifeq ($(BOARD_USES_SYSTEM_OTHER_ODEX),true)
634e358ab2c3635439db5bd1a1ef424d5c1250ce00Alex Lightdefine get-odex-installed-file-path
64eaa9d88cf4ab060990063c75418667c80fcba0c3Nicolas Geoffray$(if $(call install-on-system-other, $(2)),
654e358ab2c3635439db5bd1a1ef424d5c1250ce00Alex Light  $(call get-odex-file-path,$(1),$(patsubst $(TARGET_OUT)/%,$(TARGET_OUT_SYSTEM_OTHER)/%,$(2))),
664e358ab2c3635439db5bd1a1ef424d5c1250ce00Alex Light  $(call get-odex-file-path,$(1),$(2)))
674e358ab2c3635439db5bd1a1ef424d5c1250ce00Alex Lightendef
684e358ab2c3635439db5bd1a1ef424d5c1250ce00Alex Lightelse
694e358ab2c3635439db5bd1a1ef424d5c1250ce00Alex Lightget-odex-installed-file-path = $(get-odex-file-path)
704e358ab2c3635439db5bd1a1ef424d5c1250ce00Alex Lightendif
714e358ab2c3635439db5bd1a1ef424d5c1250ce00Alex Light
72b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wang# Returns the path to the image file (such as "/system/framework/<arch>/boot.art"
73b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wang# $(1): the arch name (such as "arm")
74b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wang# $(2): the image location (such as "/system/framework/boot.art")
75b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wangdefine get-image-file-path
76b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wang$(dir $(2))$(1)/$(notdir $(2))
77b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wangendef
78b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wang
79ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstrom# note we use core-libart.jar in place of core.jar for ART.
80ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian CarlstromLIBART_TARGET_BOOT_JARS := $(patsubst core, core-libart,$(DEXPREOPT_BOOT_JARS_MODULES))
81ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian CarlstromLIBART_TARGET_BOOT_DEX_LOCATIONS := $(foreach jar,$(LIBART_TARGET_BOOT_JARS),/$(DEXPREOPT_BOOT_JAR_DIR)/$(jar).jar)
82ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian CarlstromLIBART_TARGET_BOOT_DEX_FILES := $(foreach jar,$(LIBART_TARGET_BOOT_JARS),$(call intermediates-dir-for,JAVA_LIBRARIES,$(jar),,COMMON)/javalib.jar)
83ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstrom
8452dcb2f8162ff3d7f758e4938b844875995d554aColin Cross# dex preopt on the bootclasspath produces multiple files.  The first dex file
8552dcb2f8162ff3d7f758e4938b844875995d554aColin Cross# is converted into to boot.art (to match the legacy assumption that boot.art
8652dcb2f8162ff3d7f758e4938b844875995d554aColin Cross# exists), and the rest are converted to boot-<name>.art.
8752dcb2f8162ff3d7f758e4938b844875995d554aColin Cross# In addition, each .art file has an associated .oat file.
8870470166c76f7436e1530be558d10e18df5379ecDavid BrazdilLIBART_TARGET_BOOT_ART_EXTRA_FILES := $(foreach jar,$(wordlist 2,999,$(LIBART_TARGET_BOOT_JARS)),boot-$(jar).art boot-$(jar).oat boot-$(jar).vdex)
8970470166c76f7436e1530be558d10e18df5379ecDavid BrazdilLIBART_TARGET_BOOT_ART_EXTRA_FILES += boot.oat boot.vdex
9052dcb2f8162ff3d7f758e4938b844875995d554aColin Cross
91b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wangmy_2nd_arch_prefix :=
92b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wanginclude $(BUILD_SYSTEM)/dex_preopt_libart_boot.mk
93b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wang
9487538e4f8b2e0451c03dbbe86d9e868b6d1a930bYing Wangifneq ($(TARGET_TRANSLATE_2ND_ARCH),true)
95b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wangifdef TARGET_2ND_ARCH
96b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wangmy_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
97b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wanginclude $(BUILD_SYSTEM)/dex_preopt_libart_boot.mk
98b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wangmy_2nd_arch_prefix :=
99b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wangendif
10087538e4f8b2e0451c03dbbe86d9e868b6d1a930bYing Wangendif
101ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstrom
102ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstrom
103ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstrom########################################################################
104ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstrom# For a single jar or APK
105ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstrom
106b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wang# $(1): the input .jar or .apk file
107b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wang# $(2): the output .odex file
108ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstromdefine dex2oat-one-file
109b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wang$(hide) rm -f $(2)
110b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wang$(hide) mkdir -p $(dir $(2))
111401ffaeb7560fa088d540ed1c150c3f196ebf993Joe Onorato$(hide) ANDROID_LOG_TAGS="*:e" $(DEX2OAT) \
112dd2ff5541e9bfcad8e0b9d3cd1275eb4a73d31f4Colin Cross	--runtime-arg -Xms$(DEX2OAT_XMS) --runtime-arg -Xmx$(DEX2OAT_XMX) \
113b00263f96a90c9f77cf7d8d90742a0884290bf60Jeff Hao	--runtime-arg -classpath --runtime-arg $(DEX2OAT_CLASSPATH) \
114b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wang	--boot-image=$(PRIVATE_DEX_PREOPT_IMAGE_LOCATION) \
115b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wang	--dex-file=$(1) \
116b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wang	--dex-location=$(PRIVATE_DEX_LOCATION) \
117b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wang	--oat-file=$(2) \
118ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstrom	--android-root=$(PRODUCT_OUT)/system \
119b9aa5d43de114cecdf94fabb23d3f61f147b627dYing Wang	--instruction-set=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_ARCH) \
120a18a28305d5bf2176f8aff197cf18cde81539379Ian Rogers	--instruction-set-variant=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_CPU_VARIANT) \
121ce090d3f4508cb9130ab700833ae51a7fff8b373Alex Light	--instruction-set-features=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES) \
12241408b0e1a9a8e38f040980dc1c3288d5a90ec09Richard Uhler	--runtime-arg -Xnorelocate --compile-pic \
123e469063a932c84c7e0bf464ab2e519da81f89ca8Alexey Alexandrov	--no-generate-debug-info --generate-build-id \
12406d86e929d966f70bfb814efe52b33c0920a0862Andreas Gampe	--abort-on-hard-verifier-error \
125f7add1092930e6f0e4a9aea0649bea7ba6c83dd4Nicolas Geoffray	--force-determinism \
126d1d3fd933f3d79dfffc12c68a21ae1a1e1b21cc0Jeff Hao	--no-inline-from=core-oj.jar \
1273a61eeb6cb588b9a206bd80814183bcc0263cd13Ying Wang	$(PRIVATE_DEX_PREOPT_FLAGS) \
128192b91c97f6ec9631b566a56fae11825d8a99e0bMathieu Chartier	$(PRIVATE_ART_FILE_PREOPT_FLAGS) \
1299968fdcd856b33be7d9f3f8067b584823f2d62b4Mathieu Chartier	$(PRIVATE_PROFILE_PREOPT_FLAGS) \
1303a61eeb6cb588b9a206bd80814183bcc0263cd13Ying Wang	$(GLOBAL_DEXPREOPT_FLAGS)
131ced4bff58e76a16ebce3a35ed24aadc8490ca39bBrian Carlstromendef
132