Looking for dspin bytecode
Method void dspin() 0 dconst_0 // Push double constant 0.0 1 dstore_1 // Store into local variables 1 and 2 2 goto 9 // First time through don't increment 5 dload_1 // Push local variables 1 and 2 6 dconst_1 // Push double constant 1.0 7 dadd // Add; there is no dinc instruction 8 dstore_1 // Store result in local variables 1 and 2 9 dload_1 // Push local variables 1 and 2 10 ldc2_w #4 // Push double constant 100.0 13 dcmpg // There is no if_dcmplt instruction 14 iflt 5 // Compare and loop if less than (i < 100.0) 17 return // Return void when done
The only load that follows the store is at offset 9. You can see that offset 9 can be reached in two different ways: (1) from offset 2 with goto 9 ; and (2) sequentially from offset 8
dload_1 pushes the value of local variables 1 and 2 to the operand stack (two variables due to double ): in case (1) when trying to enter the loop for the first time, and in case (2) when trying to enter the loop at later times .
Interestingly, in this example, if you delete all store and load , the behavior of the program will not change. However, the Java compiler does not usually try to be smart. It compiles Java code more or less directly. In this case, the local variable i directly corresponds to the local variables 1 and 2.
For more information, see Optimization Using the Java Compiler .
source share