"Java" real-time Java Virtual Machine Five "turn on JIT compilation"

Source: Internet
Author: User
Tags value of pi

Start the "JIT compilation" on the Five "Java Virtual machines" today

Total of 5 Series

    • "Heap overflow processing" in one of the actual Java virtual machines
    • Virtual machine working mode for Java Virtual machine
    • The three "G1 of the New generation GC" of Java Virtual machine
    • Live Java Virtual machine Four "Disable System.GC ()"
    • Real-time Java Virtual Machine Five "turn on JIT compilation"

Java Virtual machines have 3 modes of execution, namely interpretation execution, mixed mode, and compilation execution, which are in mixed mode by default. Use the command line java–version to view the execution mode of the virtual machine:

C:\users\administrator>java-"1.7.0_13"Java (TM) SE Runtime Environment (build1. 7.0_13-64-bit Server VM (build 23.7-b01,mixed mode)

The "mixed Mode" output above indicates the blending mode. In mixed mode, some functions are interpreted and some of them may be compiled for execution. The virtual machine determines whether the function needs to be compiled and executed based on whether the function is judged to be hot code. If a function is called very frequently and is used repeatedly, it is considered a hotspot and the hotspot code is compiled and executed.

Interpreting the execution pattern means that all the code is interpreted for execution, without any JIT compilation, and you can use the parameter-xint to turn on interpreted execution mode:

C:\users\administrator>java-xint-"1.7.0_13"Java (TM) SE Runtime Environment (build1. 7.0_13-64-bit Server VM (build 23.7-b01,interpreted mode)

In contrast to the compile execution pattern and the interpretation execution pattern, for all functions, whether or not the hotspot code is compiled, the parameter-xcomp can be set to compile mode:

C:\users\administrator>java-xcomp-"1.7.0_13"Java (TM) SE Runtime Environment (build1. 7.0_13-64-bit Server VM (build 23.7-b01,compiled mode)

In general, the execution efficiency of the compilation mode is much higher than the interpretation mode. More examples refer to the book Java Virtual Machine in action.

The code under "Example 11-36" keeps calculating the value of pi and gives the time it takes to run:

 Public Static Doublecalcpi () {Doublere=0;  for(inti=1;i<10000;i++) {Re+ = ((i&1) ==0?-1:1) *1.0/(2*i-1); } returnre*;} Public Static voidMain (string[] args) {LONGB=System.currenttimemillis ();  for(inti=0;i<10000;i++) calcpi (); Longe=System.currenttimemillis (); System.out.println ("Spend:" + (E-b) + "MS");}

Use the virtual machine parameter-xint to run the above code, output:

Spend:2794ms

Use the virtual machine parameter-xcomp to run the above code, output:

Spend:1082ms

Obviously, it is about 3 times times faster to use a compile run in this case than the interpretation.

"Real-combat Java Virtual Machine" a book Q Exchange Group: 397196583

"Java" real-time Java Virtual Machine Five "turn on JIT compilation"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.