dex2oat调用场景
boot相关image
-
若打开WITH_DEXPREOPT,则在编译system.img时,就会在host机器上执行dex预优化(默认配置)
dex2oat-cmdline = --runtime-arg -Xms64m --runtime-arg -Xmx64m --image-classes=frameworks/base/preloaded-classes --dex-file=out/target/common/obj/JAVA_LIBRARIES/core-oj_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/core-libart_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/okhttp_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/legacy-test_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/bouncycastle_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/ext_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/telephony-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/voip-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/ims-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/apache-xml_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/org.apache.http.legacy.boot_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/android.hidl.base-V1.0-java_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/android.hidl.manager-V1.0-java_intermediates/javalib.jar --dex-location=/system/framework/core-oj.jar --dex-location=/system/framework/core-libart.jar --dex-location=/system/framework/conscrypt.jar --dex-location=/system/framework/okhttp.jar --dex-location=/system/framework/legacy-test.jar --dex-location=/system/framework/bouncycastle.jar --dex-location=/system/framework/ext.jar --dex-location=/system/framework/framework.jar --dex-location=/system/framework/telephony-common.jar --dex-location=/system/framework/voip-common.jar --dex-location=/system/framework/ims-common.jar --dex-location=/system/framework/apache-xml.jar --dex-location=/system/framework/org.apache.http.legacy.boot.jar --dex-location=/system/framework/android.hidl.base-V1.0-java.jar --dex-location=/system/framework/android.hidl.manager-V1.0-java.jar --oat-symbols=out/target/product/angler/symbols/system/framework/arm64/boot.oat --oat-file=out/target/product/angler/dex_bootjars/system/framework/arm64/boot.oat --oat-location=/system/framework/arm64/boot.oat --image=out/target/product/angler/dex_bootjars/system/framework/arm64/boot.art --base=0x70000000 --instruction-set=arm64 --instruction-set-variant=cortex-a53 --instruction-set-features=default --android-root=out/target/product/angler/system --runtime-arg -Xnorelocate --compile-pic --no-generate-debug-info --generate-build-id --multi-image --no-inline-from=core-oj.jar --generate-mini-debug-info --generate-mini-debug-info --compiled-classes=frameworks/base/compiled-classes-phone
-
若未打开WITH_DEXPREOPT, 则在首次开机时由zygote负责生成boot相关image.
dex2oat-cmdline = --image=/data/dalvik-cache/arm64/system@framework@boot.art --dex-file=/system/framework/core-oj.jar --dex-file=/system/framework/core-libart.jar --dex-file=/system/framework/conscrypt.jar --dex-file=/system/framework/okhttp.jar --dex-file=/system/framework/bouncycastle.jar --dex-file=/system/framework/apache-xml.jar --dex-file=/system/framework/legacy-test.jar --dex-file=/system/framework/ext.jar --dex-file=/system/framework/framework.jar --dex-file=/system/framework/telephony-common.jar --dex-file=/system/framework/voip-common.jar --dex-file=/system/framework/ims-common.jar --dex-file=/system/framework/org.apache.http.legacy.boot.jar --dex-file=/system/framework/android.hidl.base-V1.0-java.jar --dex-file=/system/framework/android.hidl.manager-V1.0-java.jar --dex-file=/system/framework/radio_interactor_common.jar --oat-file=/data/dalvik-cache/arm64/system@framework@boot.oat --instruction-set=arm64 --instruction-set-features=a53 --base=0x70c9a000 --runtime-arg -Xms64m --runtime-arg -Xmx64m --image-classes=/system/etc/preloaded-classes --compiled-classes=/system/etc/compiled-classes --dirty-image-objects=/system/etc/dirty-image-objects --instruction-set-variant=generic --instruction-set-features=default
App的安装
dex2oat-cmdline = --zip-fd=12 --zip-location=base.apk --input-vdex-fd=-1 --output-vdex-fd=14 --oat-fd=13 --oat-location=/data/app/vmdl1712710097.tmp/oat/arm64/base.odex --instruction-set=arm64 --instruction-set-variant=cortex-a53 --instruction-set-features=default --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=quicken -j4 --swap-fd=15 --classpath-dir=/data/app/vmdl1712710097.tmp
profile-guided compilation(base.art and base.odex)
BackgroundDexOptService发起
-
profile文件
angler:/ # ls -l /data/misc/profiles/cur/0/com.aurorasoftworks.quadrant.ui.professional/ total 0 -rw------- 1 u0_a74 u0_a74 0 1970-02-21 08:36 primary.prof
-
dex2oat编译
dex2oat-cmdline = --zip-fd=12 --zip-location=base.apk --input-vdex-fd=14 --output-vdex-fd=15 --oat-fd=13 --oat-location=/data/app/com.aurorasoftworks.quadrant.ui.professional-VH_ydz-pdzC-HwMoMrkyjA==/oat/arm64/base.odex --instruction-set=arm64 --instruction-set-variant=cortex-a53 --instruction-set-features=default --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed-profile -j4 --swap-fd=16 --app-image-fd=17 --image-format=lz4 --profile-file-fd=18 --classpath-dir=/data/app/com.aurorasoftworks.quadrant.ui.professional-VH_ydz-pdzC-HwMoMrkyjA==
动态加载dex
01-12 12:22:52.992 12046 12046 W dex2oat : Using default instruction set features for ARM CPU variant (default) using conservative defaults
01-12 12:22:52.993 12046 12046 I dex2oat : /system/bin/dex2oat -j4 --dex-file=/data/data/com.netease.newsreader.activity/files/tdata_VnV324.jar --output-vdex-fd=56 --oat-fd=57 --oat-location=/data/data/com.netease.newsreader.activity/files/oat/arm/tdata_VnV324.odex --compiler-filter=quicken
01-12 12:22:53.755 12046 12046 I dex2oat : dex2oat took 763.301ms (290.864ms cpu) (threads: 4) arena alloc=11KB (12000B) java alloc=98KB (101152B) native alloc=1328KB (1360200B) free=2MB (2309816B)
01-12 12:23:24.391 12156 12156 W dex2oat : Using default instruction set features for ARM CPU variant (default) using conservative defaults
01-12 12:23:24.392 12156 12156 I dex2oat : /system/bin/dex2oat -j4 --dex-file=/data/data/com.netease.newsreader.activity/files/tdata_GBG382.jar --output-vdex-fd=50 --oat-fd=51 --oat-location=/data/data/com.netease.newsreader.activity/files/oat/arm/tdata_GBG382.odex --compiler-filter=quicken
01-12 12:23:25.688 12156 12156 I dex2oat : dex2oat took 1.298s (487.876ms cpu) (threads: 4) arena alloc=8KB (9184B) java alloc=221KB (226544B) native alloc=1265KB (1296200B) free=2MB (2373816B)
uiautomator
-
前提
若未配置WITH_DEXPREOPT,则在首次启动uiautomator时也会触发dex2oat的编译
-
启动uiautomator
$ adb shell uiautomator -h
-
dex2oat编译
01-02 05:54:26.089 30222 30222 D AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 2000 <<<<<< 01-02 05:54:26.141 30222 30222 I app_process: Using an offset of 0xff3d8000 from default art base address of 0x70000000 01-02 05:54:26.141 30222 30222 I app_process: GenerateImage: /system/bin/dex2oat --image=/data/local/tmp/dalvik-cache/arm64/system@framework@boot.art --dex-file=/system/framework/core-oj.jar --dex-file=/system/framework/core-libart.jar --dex-file=/system/framework/conscrypt.jar --dex-file=/system/framework/okhttp.jar --dex-file=/system/framework/bouncycastle.jar --dex-file=/system/framework/apache-xml.jar --dex-file=/system/framework/legacy-test.jar --dex-file=/system/framework/ext.jar --dex-file=/system/framework/framework.jar --dex-file=/system/framework/telephony-common.jar --dex-file=/system/framework/voip-common.jar --dex-file=/system/framework/ims-common.jar --dex-file=/system/framework/org.apache.http.legacy.boot.jar --dex-file=/system/framework/android.hidl.base-V1.0-java.jar --dex-file=/system/framework/android.hidl.manager-V1.0-java.jar --dex-file=/system/framework/radio_interactor_common.jar --oat-file=/data/local/tmp/dalvik-cache/arm64/system@framework@boot.oat --instruction-set=arm64 --instruction-set-features=a53 --base=0x6f3d8000 --runtim 01-02 05:54:26.257 30224 30224 I dex2oat : /system/bin/dex2oat --image=/data/local/tmp/dalvik-cache/arm64/system@framework@boot.art --dex-file=/system/framework/core-oj.jar --dex-file=/system/framework/core-libart.jar --dex-file=/system/framework/conscrypt.jar --dex-file=/system/framework/okhttp.jar --dex-file=/system/framework/bouncycastle.jar --dex-file=/system/framework/apache-xml.jar --dex-file=/system/framework/legacy-test.jar --dex-file=/system/framework/ext.jar --dex-file=/system/framework/framework.jar --dex-file=/system/framework/telephony-common.jar --dex-file=/system/framework/voip-common.jar --dex-file=/system/framework/ims-common.jar --dex-file=/system/framework/org.apache.http.legacy.boot.jar --dex-file=/system/framework/android.hidl.base-V1.0-java.jar --dex-file=/system/framework/android.hidl.manager-V1.0-java.jar --dex-file=/system/framework/radio_interactor_common.jar --oat-file=/data/local/tmp/dalvik-cache/arm64/system@framework@boot.oat --instruction-set=arm64 --instruction-set-features=a53 --base=0x6f3d8000 --runtime-arg -Xms64m -
-
编译产物
$ ls -l /data/local/tmp/dalvik-cache/arm64/ total 89816 -rw-r--r-- 1 shell shell 17024 2012-01-02 05:55 system@framework@android.test.runner.jar@classes.dex -rw-r--r-- 1 shell shell 119380 2012-01-02 05:55 system@framework@android.test.runner.jar@classes.vdex -rw-r--r-- 1 shell shell 10784768 2012-01-02 05:55 system@framework@boot.art -rw-r--r-- 1 shell shell 42107520 2012-01-02 05:55 system@framework@boot.oat -rw-r--r-- 1 shell shell 38225946 2012-01-02 05:55 system@framework@boot.vdex -rw-r--r-- 1 shell shell 25216 2012-01-02 05:55 system@framework@uiautomator.jar@classes.dex -rw-r--r-- 1 shell shell 549570 2012-01-02 05:55 system@framework@uiautomator.jar@classes.vdex
dex2oat相关配置
pm.dexopt相关
angler:/ # getprop|grep pm.dexopt
[pm.dexopt.ab-ota]: [speed-profile]
[pm.dexopt.bg-dexopt]: [speed-profile]
[pm.dexopt.boot]: [verify]
[pm.dexopt.first-boot]: [quicken]
[pm.dexopt.install]: [quicken]
这些属性定义在build/target/product/core_minimal.mk中
dex2oat编译线程个数
默认为设备cpu核数
-
dalvik.vm.boot-dex2oat-threads
- number of threads to use during boot time
- 若配置WITH_DEXPREOPT为TRUE, 则boot阶段没有要编译的东西
- 若配置WITH_DEXPREOPT为false,则会编译
- services.jar
- ethernet-service.jar
- wifi-service.jar
- com.android.location.provider.jar
- javax.obex.jar
-
dalvik.vm.dex2oat-threads
- number of threads to use after boot time
- 特指PackageManager.DexOptimizer及之后的app安装