Java optimization: only bytecode vs JIT

When developing games for Android devices, I need to target devices that don’t have JIT, and rely only on bytecode optimization. I wonder if the set of these optimizations is empty or not ...

Actually, the java compiler (hard, javac, not JIT) does any optimization, for example, converting / 4 to → 2? Or every job optimization for JIT?

+6
java android bytecode jit
source share
2 answers

The standard Java compiler does some optimizations, but it leaves most of them in JIT.

JIT knows which processor the program is running on, and also has access to run-time information, and therefore it can do more optimizations than the Java compiler could do. In addition, advance advanced optimizations could "partially confuse" byte code, making JIT optimization difficult.

I don’t know what the Google compiler does when it translates your Java bytecode into Dalvik code - it can do wider optimizations.

Perhaps this tool will be useful to you: Dalvik Optimization and verification with dexopt

By the way, the example you cited is not always valid; converting a / 4 to a >> 2 does not guarantee that your program will run faster on any processor. I read an article somewhere once (sorry, I can’t find it right now ...), which explained that on modern x86 processors, a >> 2 can be even slower than a / 4 .

In any case, do not make premature optimizations, such as converting a / 4 to a >> 2 manually into source code, unless you have real evidence (from performance measurements) that it is advisable to do this.

+7
source share

If your execution platform does indeed execute bytecodes, your intuitions about things like a / 4 faster than a >> 2 are likely to be wrong. You need to do serious application profiling to figure out:

  • is it worth optimizing at all
  • where to focus your efforts and
  • which (micro) optimizations really work.

FWIW, the javac compiler is unlikely to try to perform micro-inversion of arithmetic. The optimal native code depends on the hardware of the real execution platform, and if javac tried to optimize the bytecodes, this could make the JIT compiler difficult.

+2
source share

All Articles