.apk 在 ART 中的安装过程.与 Dalvik VM 安装过程的区别 [英] Installation process of .apk within ART. Difference from Dalvik VM installation process

查看:24
本文介绍了.apk 在 ART 中的安装过程.与 Dalvik VM 安装过程的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我回答了这个问题,这里描述了 .apk 文件到安卓手机的整个安装过程.一件事是关于使用 Dalvik VM.现在我想知道使用 ART 的安装过程是否完全相同?有什么区别?我的意思是 PackageManagerpath转换为 dex 格式 等的工作.谷歌搜索没有提供太多信息,只是关于性能、管理内存和类似的东西.如果有知识的人可以分享这些信息,我将非常感激.

Recently I answered this question, where was described whole installation process of .apk file to android phone. The one thing it was about using Dalvik VM. And now I'm wondered is installation process is exactly same using ART? What are the differences? I mean the work of PackageManager, path, convertion to dex format etc. Googling didn't give much info, only about performance power, managing memory and something similar. I would be very thankful if someone with knowledge could share this information.

推荐答案

Android 应用程序采用 .apk 文件格式,Java 类转换为 DEX 字节码.DEX 字节码格式独立于设备架构,需要转换为本地机器码才能在设备上运行.这对于 ARTDalvik 运行时都是一样的.

Android apps come in the .apk file format, with Java classes converted into DEX bytecode. The DEX bytecode format is independent of device architecture and needs to be translated to native machine code to run on the device. This is the same for both the ART and the Dalvik runtimes.

DalvikART 的最显着变化是 Dalvik 基于 Just-in-Time (JIT) 编译,而 ART 基于 Ahead-of-Time(AOT) 编译.

The most significant change from Dalvik to ART is that Dalvik is based on Just-in-Time (JIT) compilation, while ART is based on Ahead-of-Time (AOT) compilation.

使用 Dalvik JIT 编译器,每次运行应用程序时,它都会动态地将一部分 Dalvik 字节码转换为机器码.随着执行的进行,更多的字节码被编译和缓存.另一方面,ART 配备了 Ahead-of-Time 编译器.在应用程序的安装阶段,它会将 DEX 字节码静态转换为机器码并存储在设备的存储中.这是在设备上安装应用时发生的一次性事件.

With the Dalvik JIT compiler, each time when the app is run, it dynamically translates a part of the Dalvik bytecode into machine code. As the execution progresses, more bytecode is compiled and cached. On the other hand, ART is equipped with an Ahead-of-Time compiler. During the app’s installation phase, it statically translates the DEX bytecode into machine code and stores in the device’s storage. This is a one-time event which happens when the app is installed on the device.

性能

ART 运行时相对于 Dalvik 运行时的最重要优势是应用程序在 ART 上运行得更快.由于DEX字节码在安装过程中已经被翻译成机器码,因此在运行时不需要额外的时间来编译它.出于同样的原因,当使用 ART 启动时,该应用的启动速度也会更快.

The most important benefit of ART runtime over Dalvik runtime is that the app runs faster on ART. Because DEX bytecode has been translated into machine code during installation, no extra time is needed to compile it during the runtime. The app starts faster as well when launched with ART for the same reason.

因为 Dalvik 需要额外的内存用于 JIT 代码缓存,所以应用在 ART 上运行时占用的内存占用更小.

Because Dalvik requires extra memory for JIT code cache, an app occupies a smaller memory footprint when it runs on ART.

电池寿命

使用 Dalvik 运行时,JIT 编译是 CPU 绑定的.由于AOT编译,ART在应用程序执行过程中将CPU从DEX字节码转换为机器码中解放出来,从而降低能耗.使用 ART 可延长电池寿命,即需要为电池充电的时间间隔.

With Dalvik runtime, the JIT compilation is CPU bound. Because of AOT compilation, ART frees the CPU from translating DEX bytecode to machine code during the app’s execution, thus reducing energy consumption. Using ART leads to a longer battery life, which is the time interval when a battery recharging is needed.

安装时间

因为 AOT 编译器会在应用安装过程中将 DEX 字节码翻译成机器码,所以应用需要更长的时间才能安装在带有 ART 的设备上运行.考虑到我们在上一节中讨论的更快执行和更短启动时间的好处,这个在应用安装期间只发生一次的额外时间是值得的.

Because the AOT compiler translates DEX bytecode into machine code during the app installation, an app takes longer to install on a device with ART runtime. Considering the benefits of faster execution and shorter launch time we discussed in the previous section, this extra time which happens only once during the app’s installation is well worth it.

存储空间

使用 ART 运行时,AOT 编译器将应用程序的 DEX 字节码转换为机器代码并将其存储在设备的存储中.预编译的二进制文件比 DEX 字节码占用更多的空间.因此,与 Dalvik 运行时相比,存储空间更大.

With ART runtime, the AOT compiler translates the app’s DEX bytecode into machine code and stores it in the device’s storage. The pre-compiled binary occupies more space than the DEX bytecode. Thus results in a larger storage footprint comparing with Dalvik runtime.

总结

到目前为止,我们已经为 Android 引入了新的 ART 运行时.我们还讨论了它的好处和妥协,集中在它的 Ahead-of-Time 编译和性能改进上.目前已发布预览版,仍在积极开发和优化中,目前我们无法就切换到 ART Runtime 获得多少性能提供定量结论.可以肯定的是,ART 将取代 Dalvik 作为基于 x86 的设备上的 Android 运行时.

To this point we have introduced the new ART runtime for Android. We also discussed its benefits and compromises, centralizing in its Ahead-of-Time compilation and performance improvement. Currently released for preview and still under active development and optimization, at this point of time we cannot provide a quantitative conclusion on how much performance gained by switching to ART Runtime. One thing for sure is ART will replace Dalvik as the Android runtime on the x86 based devices.

来源.

这篇关于.apk 在 ART 中的安装过程.与 Dalvik VM 安装过程的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆