title: What optimizations can I expect from Dalvik and the Android toolchain?
body: <p>I'm working on a high-performance Android application (a game), and though I try to code for readability first, I like to keep in the back of my mind a picture of what is happening under the hood. With C++, I've developed a fairly good intuition about what the compiler will and won't do for me. I'm trying to do the same for Java/Android.</p>
  
  <p>Hence this question. I could find very little about this topic on the web. Will the Java compiler, Dalvik converter (dx) and/or JITter (on Android 2.2+) perform optimizations like the following?</p>
  
  <ul>
  <li><p>Method inlining. Under what conditions? <code>private</code> methods can always safely be inlined; will this be done? How about <code>public final</code> methods? Methods on objects of other classes? <code>static</code> methods? What if the runtime type of the object can easily be deduced by the compiler? Should I declare methods as <code>final</code> or <code>static</code> wherever possible?</p></li>
  <li><p>Common subexpression elimination. For example, if I access <code>someObject.someField</code> twice, will the lookup be done only once? What if it's a call to a getter? What if I use some arithmetic expression twice; will it be evaluated only once? What if I use the result of some expression, whose value I know not to change, as the upper bound of a <code>for</code> loop?</p></li>
  <li><p>Bounds checking on array lookups. Will the toolchain eliminate this in certain conditions, like the archetypical <code>for</code> loop?</p></li>
  <li><p>Value inlining. Will accesses to some <code>public static final int</code> always be inlined? Even if they're in another class? Even if they're in another package?</p></li>
  <li><p>Branch prediction. How big an issue is this even? Is branching a large performance hit on a typical Android device?</p></li>
  <li><p>Simple arithmetic. Will <code>someInt * 2</code> be replaced by <code>someInt &lt;&lt; 1</code>?</p></li>
  </ul>
  
  <p>Etcetera...</p>