Smaller byte code for small constants
paul.govereau at oracle.com
Fri Sep 12 18:39:46 UTC 2014
Currently, for long, float and double, javac will emit an ldc
instruction for small constants (aside from 0, 1, 2). For instance, this
long x = 3;
produces the code:
However, we could save ourselves a constant pool slot with:
The same trick can be used for float and double constants that happen to
be round integers (modulo the semantics of i2f?).
Are there bad consequences for the interpreter or runtime compiler if we
made this change in javac?
More information about the compiler-dev