[WebKit] parse javascriptcore-advanced (iii) register allocation & trampoline

Source: Internet
Author: User
Register Allocation

For a JIT, the consumption of register allocation to the system is usually a bottle diameter. Previously, there were graph coloring allocators, chaitin style, and other allocation methods. Now we want to introduce the linear scan algorithm used by dfg JIT. The basic operation mode is to sort the variables that occupy registers according to their lifecycles, and check which registers can be recycled for reuse during use.

Let's first look at some definitions:

Live interval: a sequence of commands that a variable can survive. It can also be called continuity. This also relies on the depth-first or breadth-first algorithm. For example, B1 ~ B4 represents fourBasic blocks, W/R represents read and write.

Spilling: it is called overflow when a variable is stored in the stack.

Interference: When two active areas exist in one program, it is said that there will be interference between them.

The Algorithm Execution process is described as follows:

1. Calculate the live interval of the variable.

2. traversal:

2.1 If live interval has expired, discard it.

2.2 allocate new live interval and registers.

2.3 if it cannot be allocated (the required interval is too long), spill it out and select a lower-cost variable.

Complexity: O (V logr) (V is the number of variables, r registers)

Below is:

Trampoline

Next, we will introduce the trampoline, trampoline, or spring Technology Used in JIT to achieve the effect of delayed compilation (which may not be used in other fields ). A spring bed is a function stub that triggers JIT execution when called. Once JIT compiles this function into a machine code, the pointer of the spring bed will be replaced with the pointer of the real function.

In JSC, view the implementation in jitstubs. cpp, such as ctitrampoline. The following is a call Stack:

Then jump to the specific operation (it may be called back to the slow path corresponding to llint for processing ):

Reprinted please indicate the source: http://blog.csdn.net/horkychen

Refer:

Massimilliano Poletto, linear scan register allocation

CS 380c Lecture 14, register allocation

Mono: runtime: Documentation: Trampoline

Ctitrampoline

Trampoline on Wikipedia


Series indexes:

Basics (1) JSC and WebCore

Basics (ii) interpreter basics and JSC Core Components

Basic (3) code implementation from script code to JIT compilation

Basic (4) page parsing and JavaScript element execution

Advanced Article (1) SSA (Static Single Assignment)

Advanced (ii) type inference)

Advanced (iii) register allocation & trampoline

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.