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.
Jesper
source share