简体   繁体   English

关闭Dalvik VM的所有优化

[英]Turn off ALL optimization by Dalvik VM

So I'm trying to write some low-level code for Android, and my main concern is that I want to avoid ALL optimization by the JIT compiler (or anything else). 因此,我正在尝试为Android编写一些底层代码,而我主要担心的是,我想避免通过JIT编译器(或其他方法)进行所有优化。 After doing some research, the best approach seems to be to: 经过研究,最好的方法似乎是:

  1. write Java bytecode by hand 手动编写Java字节码
  2. convert it to a dex file using the "dx" command 使用“ dx”命令将其转换为dex文件
  3. run it on the program using the "dalvikvm" command (via adb shell) with the "-Xverify:none -Xdexopt:none" paramaters specified 在指定了“ -Xverify:none -Xdexopt:none”参数的情况下,使用“ dalvikvm”命令(通过adb shell)在程序上运行它

My question is: will this in fact avoid ALL optimization? 我的问题是:这实际上会避免所有优化吗? The previous discussion here https://groups.google.com/forum/#!topic/android-platform/Y-pzP9z6xLw makes me unsure, and I can't 100% convince myself by reading the docs. https://groups.google.com/forum/#!topic/android-platform/Y-pzP9z6xLw上的讨论使我不确定,我无法100%通过阅读文档说服自己。

Any confirmation one way or the other is greatly appreciated. 任何一种确认或其他确认都将受到极大的赞赏。

Some of the instruction rewriting performed by dexopt cannot be disabled. 不能禁用dexopt执行的某些指令重写。 For example, accesses to volatile long fields must be handled differently from access to long fields, and the specialization is handled by replacing the field-get instruction with a different instruction. 例如,对volatile long字段的访问必须不同于对long字段的访问,并且通过使用不同的指令替换field-get指令来处理专业化。

The optimizations performed by dexopt take the form of instruction replacement, usually some sort of "quickening" that allows the VM to do a little less work. dexopt执行的优化采用指令替换的形式,通常是某种“快速”操作,可以使VM减少一些工作。 All such optimizations are performed statically, ahead of time, not dynamically at run time, so you will get consistent behavior. 所有这些优化都是提前静态执行的,而不是在运行时动态执行的,因此您将获得一致的行为。 Enabling the dexopt optimizations doesn't introduce unknowns, it just changes from one set of knowns to a different set of knowns. 启用dexopt优化并不会引入未知数,而只是从一组已知数更改为另一组已知数。

The biggest source of variation is going to be Dalvik's JIT compiler, which you can disable with -Xint:fast . 变化的最大来源将是Dalvik的JIT编译器,您可以使用-Xint:fast禁用它。 See this slightly outdated doc for notes on how to configure this system-wide. 有关如何在整个系统范围内进行配置的说明,请参阅此文档过时

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM