1. 程式人生 > >JIT 編譯器文件翻譯 _ jit-compiler-design.txt

JIT 編譯器文件翻譯 _ jit-compiler-design.txt



JIT Compiler Design       即時(just in time)編譯器設計
                              



  Copyright (C) 2006 Pekka Enberg


  This file is released under the GPLv2.




Introduction 簡介
============


The compiler is divided into the following passes: control-flow graph 這個編譯器可分為以下步驟:控制流圖構造,
construction, bytecode parsing, instruction selection, and code 位元組碼解析,指令選擇 和程式碼釋出。
emission.  The compiler analyzes the given bytecode sequence to find 編譯器解析位元組碼序列,尋找基本的塊來構造控制流圖
basic blocks for constructing the control-flow graph.  This pass is 
done first to simplify parsing of bytecode branches.  Bytecode 這一步會先執行,以便簡化位元組碼分支的解析
sequence is then parsed and converted to an expression tree. The tree 然後位元組碼序列被解析和轉化為表示式樹
is given to the instruction selector to lower the IR to three-address 這個樹傳給指令選擇器以降低三地址程式碼的(IR?)
code.  Code emission phase converts that sequence to machine code  程式碼釋出階段把序列轉化為可執行的機器程式碼
which can be executed.


Programs are compiled one method at a time.  Invocation of a method is 程式(java程式)被一次編譯為一個方法。
replaced with an invocation of a special per-method JIT trampoline     方法的呼叫被替換為一個特殊的per-method JIT彈簧床
that is responsible for compiling the actual target method upon first   彈簧床負責編譯那個真正的目標方法的首次呼叫
invocation.




Intermediate Representations 中間表示
============================


The compiler has two intermediate representations: expression tree and 這個編譯器有兩個中間表示:表示式樹 和 三地址程式碼。
three-address code.  The expression tree is constructed from bytecode 表示式樹由方法的位元組碼序列構建,而三地址程式碼是指令選擇的結果。
sequence of a method whereas three-address code is the result of
instruction selection.  Three-address code is translated to executable  三地址程式碼被轉換為可執行的機器程式碼。
machine code.


The JIT compiler operates on one method at a time called a compilation  JIT編譯器一次操作一個被稱為編譯單元的方法。
unit.  A compilation unit is made up of one or more basic blocks which 編譯單元由一個或多個代表直線程式碼的基本塊組成。
represent straight-line code.  Each basic block has a list of one or 每個基本塊包含一個或多個語句,語句可以是獨立的或者操作一個或多個表示式樹。
more statements that can either be standalone or operate on one or two
expression trees.


The instruction selector emits three-address code for a compilation 指令選擇器給表示式樹的編譯單元發出三地址程式碼。
unit from the expression tree.  This intermediate representation is 這個中間表示基本上就是模仿本地指令集的指令序列。
essentially a sequence of instructions that mimic the native
instruction set.  One notable exception is branch targets which are 一個值得注意的例外是分支目標,它用指標和指令來表示。
represented as pointers to instructions.  The pointers are converted 指標會被轉換為真正的目標機器程式碼,在程式碼釋出時做回填。
to real machine code targets with back-patching during code emission.