Smaller byte code for small constants
    Paul Govereau 
    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 
statement:
   long x = 3;
produces the code:
   ldc2_w #index
   lstore_n
However, we could save ourselves a constant pool slot with:
   bipush 3
   i2l
   istore_n
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?
Thanks,
Paul
    
    
More information about the compiler-dev
mailing list