Instruction Optimization
The code in a Java method will be translated into instructions in JavaVM language.
Delete NOP
nop instructions do nothing at all, so the semantics of a program will be never changed after they are deleted.
Delete unused code
Isolated instructions that cannot be reached through any path may be deleted.
Delete Unnecessary Exception Tables
In an attribute of "Exceptions", information such as "jump <X> if an error occurs between <A> and <B>" is summarized as a table.
If you investigate the jumped address of an item of that attribute, sometimes the exception never occurs. In such a cases, that item may be deleted along with its unused exception table.
Delete and rewrite GOTO
There are three kinds of tasks related to the compression of gotos.
- Deletion of gotos that jumps to the next instruction.
The semantics of the goto instruction that jumps to the next instruction are the same as nop. - Replace goto to goto jumps with a single goto that will jump directly.
No instructions are deleted and so the program size is same, but execution speed may be faster. - Replace goto that jumps to RETURN/ATHROW with RETURN/ATHROW
The size of RETURN/ATHROW is smaller than that of goto, so the program size will be smaller than before. And also there are some possibilities that information(i.e. StackMap attribute) added on during preverify will decrease.
Change the order of local variables
Among instructions regarding data operation, there are "load" and "save" type instructions that operate upon local variables. These types of instructions are shorter than the others if they access local variables indexed from 0 to 3
Regarding each local variables accessed by "load" and "save" type instructions, SophiaCompress(Java) OASIS investegates how they are accessed and moves those variables frequently accessed into the entries indexed from 0 to 3.
Inline method expansion
Inline method expansion means that a method call will be replaced with instruction codes inside its method.
In general, program size may be smaller as a whole after inline method expansion if a method is very small or called from only one place .
Integrate class variables into array
Program size may be smaller after the same type of variables are put together into an array.
It is because variable information such as CP entries for names will be cut down. But the size of access instructions gets bigger when accessing arrays, so a tradeoff must be considered.
Change access flag
If access flags of class/method/field are same, high compression efficency can be achived.
Delete "System.out.print[ln]"
System.out.print has nothing to do with program execution on a mobile phone and may be safely deleted.
Delete "Runtime.gc()"
Runtime.gc() that will call the GarbageCollector may be safely deleted.
Others: Support JDK 1.4
SophiaCompress(Java) OASIS will safely compress an application compliled with Java 2 SDK 1.4.2.