用途
build阶段可以将apk dex生成oat文件(odex),dex2oat 源码目录/system/bin/dex2oat
4种编译模式:
- verify:只验证 DEX 代码
- quicken:验证DEX 代码,并优化一些 DEX 指令,以获得更好的解译器性能。
- speed:验证 DEX 代码,并对所有方法进行 AOT 编译
- speed-profile:运行 DEX 代码验证,并对profile配置文件中列出的方法进行 AOT 编译
配置方法:PRODUCT_DEXPREOPT_SPEED_APPS
调试手段
手动adb shell发起dex2oat:
adb shell cmd package compile -m speed-profile -f com.tencent.mm
移除:
adb shell cmd package compile --reset com.tencent.mm
查看dex优化过的Apk
adb shell "dumpsys package dexopt"
Boot Image Profiles
Android 11开始支持生成boot image profiles,app profile文件路径:
/data/misc/profiles/cur/0/com.android.chrome/primary.prof
使用命令聚合所有独立app profile的boot classpath:
adb shell cmd package snapshot-profile android
设备配置
打开boot profile的方法:
adb root
adb shell stop
adb shell setprop dalvik.vm.profilebootclasspath true
adb shell setprop dalvik.vm.profilesystemserver true
adb shell start
persist.device_config.runtime_native_boot.profilesystemserver=true
persist.device_config.runtime_native_boot.profilebootclasspath=true
art/tools/boot-image-profile-configure-device.sh包含了上述操作
生成boot image profiles
https://source.android.google.cn/docs/core/runtime/boot-image-profiles#generating-boot-image-profiles