[Java] 5 "enable JIT compilation" for Java virtual machines
Today, we started to practice the 5 "enable JIT compilation" of Java virtual machines"
5 Series in total
- One of the actual Java virtual machines is "Heap Overflow processing"
- Practice: Java Virtual Machine 2 "virtual machine working mode"
- Java Virtual Machine 3: New Generation GC of G1"
- 4. Disable System. gc () for Java virtual machines ()"
- 5. "enable JIT compilation"
Java Virtual Machine supports three execution modes: Explain execution, mixed mode, and compilation execution. By default, the execution mode is mixed. Use the command line java-version to view the virtual machine execution mode:
C:\Users\Administrator>java -versionjava version "1.7.0_13"Java(TM) SE Runtime Environment (build1.7.0_13-b20)Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01,mixed mode)
The "mixed mode" output above indicates the mixed mode. In mixed mode, some functions are interpreted and executed, and some may be compiled and executed. The Virtual Machine determines whether a function needs to be compiled and executed based on whether the function is a hotspot code. If the function is frequently called and used repeatedly, it will be considered as a hotspot and the hotspot code will be compiled and executed.
The explain execution mode indicates that all codes are interpreted and executed without any JIT compilation. You can use the-Xint parameter to enable the explain Execution Mode:
C:\Users\Administrator>java -Xint -versionjava version "1.7.0_13"Java(TM) SE Runtime Environment (build1.7.0_13-b20)Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01,interpreted mode)
The compile execution mode is opposite to the explain execution mode. All functions, whether hotspot code or not, are compiled and executed. You can set the parameter-Xcomp to the compile mode:
C:\Users\Administrator>java -Xcomp -versionjava version "1.7.0_13"Java(TM) SE Runtime Environment (build1.7.0_13-b20)Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01,compiled mode)
In general, the execution efficiency of the compilation mode is much higher than that of the interpretation mode. For more examples, refer to "Practical Java Virtual Machine.
[Example 11-36] the following code does not stop calculating the circumference rate, and shows the running time:
public static double calcPi(){ doublere=0; for(inti=1;i<10000;i++){ re+=((i&1)==0?-1:1)*1.0/(2*i-1); } returnre*4;}public static void main(String[] args) { longb=System.currentTimeMillis(); for(inti=0;i<10000;i++) calcPi(); longe=System.currentTimeMillis(); System.out.println("spend:"+(e-b)+"ms");}
Run the above code using the virtual machine parameter-Xint and output:
Spend: 2794 ms
Run the above code using the virtual machine parameter-Xcomp and output:
Spend: 1082 ms
Obviously, in this example, compile and run is about three times faster than explain.
Q: 397196583