(There will be a comment, but it's too long for that.)
This is a fairly common procedure for 4-byte fields to be used for short local vars, since the JVM is conceptually a 4-byte register machine and with all the other garbage in the frame stack, it does not make much difference.
For example, fields that are likely to depend on tradeoffs with storage preservation, and also to spend cycles expanding and leveling out - frequent cost increases take a small cycle, and even on architectures that are supposedly “agnostic” with regard to border alignment there it’s usually a penalty for access to borders, so “packing” fields without first rebuilding them to preserve word / double word boundaries can cost performance.
So, if the JVM selects a "package", you usually need to reorder the fields. Naive JVMs avoid reordering as it simplifies some aspects of the JVM, but (as one example) in AS / 400 we found that aggressive reordering and instance packing fields received a 30% performance increase for patented memory applications.
I never looked at Dalwick's insides. The standard Sun-based JVMs historically (in spite of everything recently) depended on the layout / order of things in the .class file and, therefore, did not "naturally" succumb to reordering. But Dalvik re-creates the .class file, and therefore it is better suited for reordering instance fields.
Note that to test the hypothesis that Dalvik packs short fields, you would need to create a class with several dozen instance fields, and then determine what the resulting size of the object was. Also (assuming the packaging is visible in the first case), create a class with the short and int (or possibly long ) fields to see if Dalvik will change them to achieve the packaging.
Hot licks
source share