jvm-program compilation and code late (run-time) optimization

Source: Internet
Author: User

Advanced (run-time) optimization

1. In order to improve the efficiency of hot spot code execution, at runtime, the virtual machine will compile the code into the machine code associated with the local platform, and perform various levels of optimization, the compiler that completes this task is called the Instant compiler (Just in Time,jit compiler).

Instant compilers within a 2.Hotspot virtual machine

(1) Interpreter and compiler

Mainstream commercial virtual machines, such as HOTSPOT,J9, all include both interpreters and compilers.

Both the interpreter and the compiler have advantages: When a program needs to be started and executed quickly, the interpreter can function first, eliminating the compile time and executing it immediately. After the program runs, as time goes by, the compiler component plays a role in compiling more and more code to compile the cost code, which can get higher execution efficiency.

There are two compilers built into the hotspot virtual machine, called the client Compiler and the server Compiler, referred to as the C1 compiler and the C2 compiler, also known as the Opto compiler.

In the current mainstream hotspot virtual machine, the default uses the interpreter to work directly with one of the compilers. The user can only use the "-client" or "-server" parameter to force the specified virtual machine to run in client mode or server mode.

You can use the parameter "-xint" to force the virtual machine to run in interpreted mode.

You can use the parameter "-xcomp" to force the virtual machine to run in compile mode.

Layered compilation:

A) layer No. 0: program interpretation execution, interpreter does not start performance monitoring function, can trigger 1th layer compile

b) Layer 1th: Also known as C1 compilation, compile bytecode into native code, perform simple, reliable optimizations, and add performance monitoring logic if necessary

c) 2nd layer (or above 2 layers): Also known as C2 compilation, is also the bytecode compilation cost code, but will enable some compile time-consuming optimizations, and even the performance monitoring information to carry out some unreliable radical optimization

(2) Compile object and trigger condition

Hot spot detection and determination method: Hot spot detection based on sampled hot spot detection and counting.

The hotspot virtual machine uses a counter-based hotspot detection method, which prepares two types of counters for each method: The method call counter and the recycle counter.

        

             

(3) Compilation process

The Client compiler is a simple and fast three-segment compiler, and the main focus is on local optimization, while abandoning many time-consuming local optimization methods.

In the first phase, a platform-independent front end creates a high-level intermediate code representation (HIR) of the byte structure

In the second phase, a platform-dependent backend generates low-level intermediate code representations (LIR) from the hir

In the final stage, the platform-dependent backend uses a linear scan algorithm to allocate registers on the Lir, and to do the peephole optimization on the Lir, and then generate the machine code

Server compiler is a specially tuned compiler for service-side-specific performance configurations and a fully optimized advanced compiler that performs all the classic optimizations that it does.

Compilation optimization Technology

1. Optimization technology

  • Compiler policy: Deferred compilation, layered compilation, stack substitution, delay optimization, program dependency graph representation, static single assignment representation.
  • Optimization techniques based on performance monitoring: Optimistic null assertion, optimistic type assertion, optimistic type enhancement, optimistic array enhancement, cropping of branches not selected, optimistic polymorphic inline. Branch frequency prediction, call frequency prediction
  • Evidence-Based optimization techniques: accuracy inference, memory value inference, memory value tracking, constant folding, reassembly, operator degradation, null check elimination. Type detection degradation, type detection elimination, algebraic simplification, common sub-expression elimination
  • Data flow sensitive overrides: Conditional constant propagation, based on six-hosted type reduction conversions, unwanted code elimination
  • Language-related optimization techniques: Type inheritance relationship analysis, de-virtualization, symbolic constant propagation, automatic boxing, elimination of escape analysis, lock cancellation, lock expansion, elimination of reflections
  • Memory and code location switching: expression elevation, expression sinking, redundant storage elimination, adjacent storage merging, junction separation
  • Cyclic transformation: Cyclic expansion, cyclic stripping, safe point elimination, iterative separation, range check elimination
  • Local code adjustment: inline, Global code promotion, heat-based code separation, switch adjustment
  • Control Flow Graph Transformation: Native code orchestration, native code packet, delay slot fill, shader register allocation, linear Scan register allocation, replication aggregation, constant splitting, replication removal, address pattern matching. Command peephole optimization, based on deterministic finite state machine code generation

2. Common sub-expressions

Optimization is limited to the basic fast inside of the program, which is called internal common subexpression elimination.

If the scope of the optimization covers more than one base block, it is called global common subexpression elimination.

  

jvm-program compilation and code late (run-time) optimization

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.