JP2005284729A - Virtual machine compiling byte code into native code - Google Patents

Virtual machine compiling byte code into native code Download PDF

Info

Publication number
JP2005284729A
JP2005284729A JP2004097947A JP2004097947A JP2005284729A JP 2005284729 A JP2005284729 A JP 2005284729A JP 2004097947 A JP2004097947 A JP 2004097947A JP 2004097947 A JP2004097947 A JP 2004097947A JP 2005284729 A JP2005284729 A JP 2005284729A
Authority
JP
Japan
Prior art keywords
stack
frame
code
native code
native
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Withdrawn
Application number
JP2004097947A
Other languages
Japanese (ja)
Inventor
Kazumi Iikura
二美 飯倉
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Fujitsu Ltd
Original Assignee
Fujitsu Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Fujitsu Ltd filed Critical Fujitsu Ltd
Priority to JP2004097947A priority Critical patent/JP2005284729A/en
Publication of JP2005284729A publication Critical patent/JP2005284729A/en
Withdrawn legal-status Critical Current

Links

Images

Abstract

<P>PROBLEM TO BE SOLVED: To make method call more effective in a Java (R) virtual machine for compiling a byte code into a native code to execute it. <P>SOLUTION: A method which is not JIT compiled is executed by an interpreter 1. A method satisfying specified conditions is compiled into a native code 4 by a JIT compiler 2. The JIT compiler 2 decides whether or not the method to be JIT compiled can be executed without creating a frame. As to such a method, a native code to be executed without creating a frame is generated; otherwise, a native code to be executed by creating a frame is generated. Also, all the methods to be JIT compiled may be compiled into native codes which create frames when the necessity arises. <P>COPYRIGHT: (C)2006,JPO&NCIPI

Description

本発明は、バイトコードをネイティブコードにコンパイルする仮想マシンに関し、さらに詳細にはJava(登録商標)プログラム言語におけるバイトコードをネイティブコードにコンパイルして実行するJava(登録商標)仮想マシンに関するものである。なお、Java(登録商標)はサンマイクロシステムズ社の登録商標であり、以下ジャバともいう。   The present invention relates to a virtual machine that compiles byte code into native code, and more particularly to a Java (registered trademark) virtual machine that compiles and executes byte code in the Java (registered trademark) programming language. . Java (registered trademark) is a registered trademark of Sun Microsystems, Inc. and is also referred to as Java hereinafter.

近年、家電機器、車載機器などの組み込みシステムにおいてジャバシステムが用いられる事例が増えている。ジャバプログラムはジャバのバイトコードをジャバ仮想マシンで実行するインタプリタ型のため、そのままでは実行効率が悪い。
そこでジャバプログラムのスピードアップの方法の一つとして、バイトコードをJITedコード(本発明ではネイティブコードという)にコンパイルして実行する、Just in Time(JIT)コンパイルという方法がある
JITされたコードは(1)コードそのものの実行効率の改善、(2)メソッド呼び出しの効率化、によってバイトコードの実行より高速になっている。
しかし、上記組み込みシステム等では、メモリ量に制限があり、JITコンパイラの動作中にメモリが不足する状況が生ずる。
そこで、破棄可能な既存のJITedコードの一部あるいは全てを破棄し、それらが占めていた領域を開放することにより、新たな空きメモリを得るという方法が知られている。例えば、特許文献1には、スレッドスタック上でJITedフレームのみを検出し、アクティブなメソッドを発見し、非アクティブなメソッドのJITedコードを破棄することで、空きメモリを得る方法が提案されている。上記破棄する作業全体をJITコード・ガーベジコレクション(GC)と呼んでいる。
In recent years, Java systems are increasingly used in embedded systems such as home appliances and in-vehicle devices. Since the Java program is an interpreter type that executes Java bytecode in a Java virtual machine, the execution efficiency is poor as it is.
Therefore, as one method for speeding up the Java program, there is a method called Just in Time (JIT) compilation in which byte code is compiled into JITed code (in the present invention, called native code) and executed. It is faster than bytecode execution by 1) improving the execution efficiency of the code itself and (2) increasing the efficiency of method calls.
However, in the above-described embedded system or the like, the amount of memory is limited, and there is a situation where the memory becomes insufficient during the operation of the JIT compiler.
Therefore, a method is known in which a part or all of the existing JITed code that can be discarded is discarded, and an area occupied by them is released to obtain a new free memory. For example, Patent Document 1 proposes a method of obtaining free memory by detecting only JITed frames on a thread stack, discovering active methods, and discarding JITed codes of inactive methods. The entire operation to be discarded is called JIT code garbage collection (GC).

ここで、メソッド呼び出しの効率化について説明する。ジャバ仮想マシンはスレッドごとにインタプリタスタックを持っていて、メソッド呼び出しの時、インタプリタスタックに新しいフレームがプッシュされ、メソッドから復帰する時、フレームがポップされる。
一方、JITされたメソッドがJITされたメソッドを呼び出す時、ネイティブコードのサブルーチン呼び出しと同様、ネイティブスタックにフレームを作る。ネイティブスタックを使った呼び出しはインタプリタスタックを使った呼び出しより低コストなため、プログラムが高速化される。
しかし、JITされたメソッドがネイティブスタックを使って呼び出しを行うシステムでは、ガーベジコレクション(GC)の時のスタックスキャンと、例外が起きた時の例外ハンドリングを、インタプリタスタックだけでなくネイティブスタックでも行わなければならない。
ネイティブスタックは(1)インタプリタスタックと構造が全く異なり、構造はCPUアーキテクチャに依存する、(2)JITされたメソッドのフレームだけでなく一般のサブルーチンのフレームも混在する、などの理由でスタックスキャン等が煩雑であるという問題がある。
Here, the efficiency of the method call will be described. The Java virtual machine has an interpreter stack for each thread. When a method is called, a new frame is pushed onto the interpreter stack, and when returning from a method, a frame is popped.
On the other hand, when a JIT method calls a JIT method, a frame is created on the native stack, similar to a subroutine call of a native code. Calls using the native stack are less expensive than calls using the interpreter stack, which speeds up the program.
However, in a system in which JIT methods call using the native stack, stack scanning during garbage collection (GC) and exception handling when an exception occurs must be performed in the native stack as well as the interpreter stack. I must.
The native stack has a completely different structure from the interpreter stack, the structure depends on the CPU architecture, and (2) a stack of general subroutine frames as well as JIT method frames, etc. There is a problem that is complicated.

また、ネイティブスタックを使う呼び出しでは、ジャバプログラムで深い呼び出しや再帰呼び出しがあると、ネイティブスタックが大幅に伸長する。特にクラスの初期化ではスーパークラスの初期化ルーチンが再帰的に起動され、ネイティブスタックが伸長しやすい。組み込み系でないシステムではメモリの制約が少なく、また、一般的にメモリアクセスを制御するハードウエアが実装されていてハードウエア的にネイティブスタックのオーバーフローチェックが行えるので、ネイティブスタックの伸長はそれほど問題にならない。しかし、前記した組み込みシステムではメモリが少なくメモリアクセスを制御するハードウエアが実装されていない場合も多いので、ネイティブスタックの伸長はできるだけ回避したい。
以上のようなことから組み込みシステムでは、JITされたコードのメソッド呼び出しもインタプリタスタックを使う方法がある。この方法はメソッド呼び出しの効率化があまり期待できないという欠点があるが、(1)スタックスキャン、例外ハンドリングがJITされていないメソッドと共通化できる、(2)メソッド呼び出しに伴いインタプリタスタックは伸長するがネイティブスタックは伸長しない、という利点がある。
しかしやはり組み込みシステムでもできるだけインタプリタスタックへフレームを作ることを抑えてメソッド呼び出しを効率化したいという要求がある。
特開2000−35890号公報
In calls using the native stack, if there is a deep call or recursive call in the Java program, the native stack will be greatly expanded. Especially in class initialization, the superclass initialization routine is recursively started, and the native stack is likely to expand. In non-embedded systems, there are few memory restrictions, and since hardware that controls memory access is generally implemented and native stack overflow checking can be performed in hardware, native stack expansion is not a problem. . However, in the above-mentioned embedded system, there are many cases where there is little memory and hardware for controlling memory access is often not implemented.
As described above, in an embedded system, there is a method of using an interpreter stack for method calling of JIT code. This method has the disadvantage that method call efficiency cannot be expected very much, but (1) stack scanning and exception handling can be shared with methods that are not JIT. (2) Although the interpreter stack expands with method calls. The native stack has the advantage of not expanding.
However, there is still a need to make method calls more efficient by suppressing the creation of frames on the interpreter stack as much as possible even in embedded systems.
JP 2000-35890 A

従来技術ではJITされたメソッドの呼び出しにネイティブスタックを使うとスタックスキャン等が煩雑になり、かつ、ネイティブスタックが伸長する問題が起き、一方、メソッドの呼び出しにインタプリタスタックを使うとメソッド呼び出しの高速化が期待できない。
本発明は上記問題を解決し、バイトコードをネイティブコードにコンパイルして実行する、組み込みシステム等に適用されるジャバ仮想マシンにおいて、メソッド呼び出しを効率化することを目的とする。
さらに詳細には、メソッドがフレームを作らずに実行できるかどうか判別し、それらのメソッドがフレームを作らず実行できるネイティブコードを生成するJITコンパイラを提供することを目的とする。
また、フレームが必要かどうか実行してみなければわからないメソッドを、メソッド実行時に必要になった時にフレームを作るようなネイティブコードを生成するJITコンパイラを提供することを目的とする。
また、実行時に必ずフレームを必要とするメソッドを判別し、実行時にフレームの有無のチェックを行わないネイティブコードを生成するJITコンパイラを提供することを目的とする。
さらに、コンパイル時にオペランドスタックの内容の型を計算し、オペランドスタックの内容をキャッシュ、デキャッシュするコードを持つネイティブコードを生成するJITコンパイラを提供することを目的とする。
In the prior art, using a native stack for JIT method calls complicates stack scanning and the problem that the native stack expands. On the other hand, using an interpreter stack for method calls speeds up method calls. I can not expect.
SUMMARY OF THE INVENTION An object of the present invention is to solve the above problems and to make method calls more efficient in a Java virtual machine applied to an embedded system or the like that compiles byte code into native code and executes it.
More specifically, an object of the present invention is to provide a JIT compiler that determines whether methods can be executed without creating a frame, and generates native code that can be executed without those methods.
It is another object of the present invention to provide a JIT compiler that generates a native code that creates a frame when a method that is necessary to execute a method is required when the method is executed.
It is another object of the present invention to provide a JIT compiler that determines a method that always requires a frame at the time of execution and generates a native code that does not check for the presence of a frame at the time of execution.
It is another object of the present invention to provide a JIT compiler that calculates the type of the contents of an operand stack at the time of compilation and generates native code having code for caching and decacheing the contents of the operand stack.

(1)本発明の第1の特徴では、これからJITコンパイルされるメソッドが、フレームを作らないで実行できるかどうかを判別し、そのようなメソッドに対してはフレームを作らないで実行するネイティブコードを生成し(このようなメソッドをフレームレスメソッドという)、そうでないメソッドに対してはフレームを作って実行するネイティブコードを生成する。
フレームレスで実行できるかどうかの判別は、そのメソッドがさらにメソッドを呼び出さない、かつ、メソッド実行中にGCが起きない、かつ、メソッドが例外ハンドラを持たない、ということを判別して行う。
フレームレスメソッドではアーギュメントはインタプリタスタックにあり、アーギュメント以外のローカル変数とオペランドスタックはネイティブスタックにある。フレームレスでないメソッドではバイトコードの実行と同じく、ローカル変数もオペランドスタックもインタプリタスタックに持つ。
フレームレスかそうでないかはネイティブコードに付随するフラグで区別が明確になるようにする。ネイティブコードが呼び出される時、フラグを見て、フレームレスでないネイティブコードならばフレームを作り、そうでなければ、フレームを作らないでネイティブコードを実行開始する。従来の方法ではすべてのメソッド呼び出しの時にフレームを作っていたが、本発明の第1の特徴ではフレームがなくても実行できるメソッドはフレームを作らないで実行されるので、実行効率がよくなる。
(2)本発明の第2の特徴では、JITされるすべてのメソッドが、必要になった時にフレームを作るネイティブコードにコンパイルされる。
ネイティブコードは、ローカル変数はインタプリタスタックに持ち、オペランドスタックはネイティブスタックに持つ。
ネイティブコード実行中に、メソッドの呼び出し、オブジェクト割付、スタックスキャン、例外、が起きると、ネイティブコードがインタプリタスタックにフレームを作る。またネイティブスタックにあったオペランドスタックの内容をインタプリタスタックにデキャッシュする。メソッド呼び出し、オブジェクト割付、スタックスキャンが完了してネイティブコードの実行が再開される時、インタプリタスタックにあるオペランドスタックの内容をネイティブスタックにキャッシュする。
本発明の第2の特徴によれば、ネイティブコード実行中にメソッドの呼び出し、オブジェクト割付、スタックスキャン、例外が起きなければインタプリタスタックにフレームが作られないので、実行効率がよくなる。
(3)本発明の第3の特徴では、本発明の第2の特徴にさらに、JITコンパイルするメソッドが同期メソッドか、または、最初の分岐の前にメソッド呼び出し命令、または、オブジェクト割付命令があるかを判別し、もしそうならばネイティブコードの実行開始直後にフレームを作る。
必ずフレームを必要とするメソッドではネイティブコード実行中、フレームの有無を調べて無ければ作る処理を省略できるので、本発明の第3の特徴によれば、実行効率がよくなる。
(4)本発明の第4の特徴では、本発明の第2の特徴にさらに、コンパイル時、オペランドスタックの内容の型を計算し、インタプリタスタックからのオペランドスタック内容のキャッシュとインタプリタスタックへのオペランドスタック内容のデキャッシュを行うコードをネイティブコードに持つ。
専用のコードは汎用ルーチンより高速なので、本発明の第4の特徴によれば、実行効率がよくなる。
(1) In the first feature of the present invention, it is determined whether or not a method to be JIT-compiled can be executed without creating a frame, and the native code is executed without creating a frame for such a method. (Such a method is called a frameless method), and for other methods, generate native code that creates and executes a frame.
Whether the frameless execution can be performed is determined by determining that the method does not call the method further, GC does not occur during the method execution, and the method has no exception handler.
In the frameless method, the arguments are in the interpreter stack, and local variables and operand stacks other than the arguments are in the native stack. Non-frameless methods, like bytecode execution, have both local variables and operand stacks in the interpreter stack.
Whether it is frameless or not is made clear by a flag attached to the native code. When the native code is called, it looks at the flag and creates a frame if it is non-frameless native code, otherwise it starts executing the native code without creating a frame. In the conventional method, a frame is created at the time of every method call. However, in the first feature of the present invention, a method that can be executed without a frame is executed without creating a frame, so that the execution efficiency is improved.
(2) In the second aspect of the invention, all methods that are JITed are compiled into native code that creates a frame when needed.
The native code has local variables in the interpreter stack and operand stacks in the native stack.
When a method call, object allocation, stack scan, or exception occurs during native code execution, the native code creates a frame on the interpreter stack. The contents of the operand stack in the native stack are decached in the interpreter stack. When the method call, object allocation, and stack scan are completed and execution of native code is resumed, the contents of the operand stack in the interpreter stack are cached in the native stack.
According to the second feature of the present invention, a frame is not created in the interpreter stack unless a method call, object allocation, stack scan, or exception occurs during execution of native code, so that execution efficiency is improved.
(3) In the third feature of the present invention, in addition to the second feature of the present invention, the method for JIT compilation is a synchronous method, or there is a method call instruction or an object allocation instruction before the first branch. If so, create a frame immediately after the start of native code execution.
In a method that always requires a frame, the processing to be performed can be omitted if the presence / absence of the frame is not checked during execution of the native code. Therefore, according to the third feature of the present invention, the execution efficiency is improved.
(4) In the fourth feature of the present invention, in addition to the second feature of the present invention, the type of the contents of the operand stack is calculated at compile time, and the operand stack contents cache from the interpreter stack and the operands to the interpreter stack are calculated. Native code has code to decache stack contents.
Since the dedicated code is faster than the general purpose routine, according to the fourth aspect of the present invention, the execution efficiency is improved.

本発明によれば、以下の効果を得ることができる。
(1)インタプリタスタックを使うネイティブコードを生成するJITコンパイラにおいて、実行時にフレームを必要とする処理を行わないメソッドに対しては、フレームなしで実行するネイティブコードを生成しているので、不要なフレームの生成を抑えることができる。
(2)実行時にフレームが必要かどうかコンパイル時にわからないメソッドに対しては、ネイティブコード実行中にフレームが必要になった時だけにフレームを作ることで、不要なフレームの生成を抑えることができる。
(3)実行時に必ずフレームを必要とするメソッドに対しては、ネイティブコードの実行開始直後にフレームを作ることで、ネイティブコード実行中に、フレームが作られたかどうかのチェックを省略することができる。
(4)コンパイル時、オペランドスタックの内容の型を計算し、インタプリタスタックからのオペランドスタック内容のキャッシュと、インタプリタスタックへのオペランドスタック内容のデキャッシュを行うコードを生成することで、高速にオペランドスタックのキャッシュ、デキャッシュを行うコードを生成することができる。
According to the present invention, the following effects can be obtained.
(1) In a JIT compiler that generates native code that uses an interpreter stack, for a method that does not perform a process that requires a frame at the time of execution, a native code that is executed without a frame is generated. Generation can be suppressed.
(2) For a method that does not know whether a frame is necessary at the time of compilation, generation of an unnecessary frame can be suppressed by creating a frame only when a frame is necessary during execution of native code.
(3) For a method that always requires a frame at the time of execution, it is possible to omit checking whether a frame has been created during native code execution by creating a frame immediately after the start of execution of native code. .
(4) At compile time, the operand stack content type is calculated, and the operand stack content is cached from the interpreter stack and the code that decaches the operand stack content to the interpreter stack is generated. It is possible to generate code that performs cache and decache.

(1)第一の実施の形態
図1に本発明のシステム全体の構成を示す。
コンピュータ11はハードウエア12とOS13を有し、0S13上にジャバ仮想マシン10を備える。
ジャバ仮想マシン10はインタプリタ1とJITコンパイラ2を持つ。メソッドのバイトコード3はファイルやネットワークからロードされる。まだJITされていないメソッドはインタプリタ1で実行される。インタプリタ1でメソッドが実行される時、インタプリタスタック5にフレームが積まれる。決まった条件を満たしたメソッドはJITコンパイラ2によりネイティブコード4にコンパイルされる。ネイティブコード4が実行される時、条件によって、インタプリタスタック5にフレームが積まれる。
図2に本実施形態における上記JITコンパイラ2の機能構成を示す。JITコンパイラ2は、メソッドがフレームなしで実行できることを判別するための判別手段2aと、フレームなしで実行できるネイティブコードを生成するネイティブコード生成手段2bと、フレームがある状態で実行できるネイティブコードを生成するネイティブコード生成手段2cを有する。
(1) First Embodiment FIG. 1 shows the configuration of the entire system of the present invention.
The computer 11 has hardware 12 and an OS 13 and includes a Java virtual machine 10 on 0S13.
The Java virtual machine 10 has an interpreter 1 and a JIT compiler 2. The bytecode 3 of the method is loaded from a file or network. A method that has not yet been JITed is executed by the interpreter 1. When a method is executed by the interpreter 1, a frame is loaded on the interpreter stack 5. A method that satisfies a predetermined condition is compiled into native code 4 by the JIT compiler 2. When the native code 4 is executed, a frame is loaded on the interpreter stack 5 depending on conditions.
FIG. 2 shows a functional configuration of the JIT compiler 2 in the present embodiment. JIT compiler 2 generates determination unit 2a for determining that a method can be executed without a frame, native code generation unit 2b for generating native code that can be executed without a frame, and generation of native code that can be executed with a frame A native code generating means 2c.

図3にインタプリタでメソッドをJITするルーチンが呼び出される時の処理を示す。 メソッド呼び出し時に、そのメソッドがJITされていない場合、何回呼び出されたかをカウントアップし、指定回数以上呼び出されたメソッドがあれば、JITを試みる。
すなわち、図3に示すように、メソッドの呼び出しを開始すると、メソッドがJITされたかを調べる(ステップS1)。メソッドがJITされていれば、ステップS6に行き、ネイティブコードの実行を行う。また、JITされていなければ、ステップS2で、メソッドが呼び出された回数をカウントアップする。
そして、指定回数以上呼び出されたかを調べ(ステップS3)、指定回数以上呼び出されていなければ、バイトコードを実行する(ステップS5)。また、指定回数以上呼び出されていれば、メソッドをJITコンパイルし(ステップS4)、ネイティブコードを実行する(ステップS6)。
FIG. 3 shows a process when a routine for JITing a method by an interpreter is called. When a method is called, if the method has not been JITed, the number of times the method has been called is counted up. If there is a method that has been called more than the specified number of times, JIT is attempted.
That is, as shown in FIG. 3, when the method call is started, it is checked whether the method has been JITed (step S1). If the method is JIT, go to step S6 to execute the native code. If JIT is not performed, the number of times the method is called is incremented in step S2.
Then, it is checked whether it has been called more than the specified number of times (step S3). If it has not been called more than the specified number of times, the bytecode is executed (step S5). If the method has been called more than the specified number of times, the method is JIT compiled (step S4) and the native code is executed (step S6).

図4にメソッドをJITする時の本実施形態における処理を示す。
まず、ジャバメソッドのみJITを行う。すなわち、メソッドがジャバメソッドであるかを調べ(ステップS1)、ジャバメソッドでなければ処理を終了する。
ジャバメソッドの場合には、このメソッドがフレームなしで実行できるかどうか判別する。この判別は、このメソッドがさらにメソッドを呼び出さない、かつ、メソッド実行中にGCが起きない、かつ、メソッドが例外ハンドラを持たない、という条件を満たすかどうかを判別することによって行う(図4のステップS2〜S4)。
上記条件を満たすメソッドに対してはフレームを作らないで実行するネイティブコードを生成し(ステップS5)、そうでないメソッドに対してはフレームを作って実行するネイティブコードを生成する(ステップS6)。そして、フレーム有無を示すフラグをセットする(ステップS7)。
FIG. 4 shows processing in this embodiment when a method is JITed.
First, JIT is performed only for the Java method. That is, it is checked whether the method is a Java method (step S1). If it is not a Java method, the process is terminated.
In the case of a Java method, it is determined whether this method can be executed without a frame. This determination is performed by determining whether or not this method satisfies the conditions that no method is called, GC does not occur during the method execution, and the method has no exception handler (see FIG. 4). Steps S2 to S4).
For a method that satisfies the above conditions, a native code that is executed without creating a frame is generated (step S5), and for a method that is not, a native code that is generated and executed is generated (step S6). Then, a flag indicating the presence / absence of a frame is set (step S7).

ここでメソッドが他のメソッドを呼び出さないという判別は、メソッドのバイトコードの中にメソッド呼び出し系の命令を含まないということで判別する。
また、メソッド実行中にGCが起きないという判別は、メソッドのバイトコードの中にオブジェクト割付系の命令を含まない、かつ、メソッドが同期でない、かつ、同期系の命令を含まない、かつ、GCチェックポイントを入れる必要のある命令を含まないということで判別する。ここでGCチェックポイントを入れる必要のある命令とは後方分岐命令とサブルーチン呼び出し命令(jsr)である。
厳密の言えば、フレームレスメソッドがネイティブスタック等にオブジェクト参照をキャッシュしていなければ、フレームレスメソッド実行中にGCが起きても問題ない。例えば、メソッド実行開始時点でネイティブスタックにオペランドスタックの内容がキャッシュされていない状態ではGCが起きても差し支えない。また、メソッドのJITコンパイル時にオペランドスタックの内容の型チェックをして、オブジェクト参照を含まないようならば、後方分岐命令があってもフレームレスメソッドになりうる。
JITされたメソッドは、フレームレスかそうでないかのフラグを持つこととし、上記のようにフレームの有無を示すフラグをセットする。
Here, the determination that the method does not call another method is performed by not including a method call instruction in the byte code of the method.
Further, the determination that GC does not occur during the execution of the method is made by determining that the method bytecode does not include an object allocation instruction, the method is not synchronous, and does not include a synchronous instruction. This is determined by not including instructions that need to be checkpointed. Here, the instructions that need to have a GC checkpoint are a backward branch instruction and a subroutine call instruction (jsr).
Strictly speaking, if the frameless method does not cache the object reference in the native stack or the like, there is no problem even if GC occurs during execution of the frameless method. For example, GC may occur if the contents of the operand stack are not cached in the native stack at the start of method execution. Further, if the type of the contents of the operand stack is checked at the time of JIT compilation of the method so as not to include an object reference, it can be a frameless method even if there is a backward branch instruction.
The JIT method has a flag indicating whether it is frameless or not, and sets a flag indicating the presence or absence of a frame as described above.

ジャバのメソッド呼び出しでは呼び出し元メソッドがインタプリタスタックにフレームをプッシュし、続いて呼び出し先メソッドの実行が始まる。
図5に本発明の第1の実施形態による、メソッド呼び出し処理を示す。
最初に、フレームの有無を示すフラグ(前記図4のステップS7参照)を参照して、これから呼び出すネイティブコードがフレームレスかどうかを、判断する(ステップS1,S2)。もし、フレームレスメソッドならフレームを作らずにネイティブコードの実行を開始する。そうでなければフレームをプッシュした後(ステップS3)、ネイティブコードの実行を開始する。
一方、フレームのポップは呼び出し先メソッドが行う。すなわち、バイトコードの復帰命令をコンパイルする時、フレームレスでないメソッドはフレームをポップする処理を行う部分の処理をコードに入れるが、フレームレスメソッドではそれを入れない。
In Java method invocation, the calling method pushes the frame onto the interpreter stack, and then the execution of the called method begins.
FIG. 5 shows method call processing according to the first embodiment of the present invention.
First, referring to a flag indicating the presence / absence of a frame (see step S7 in FIG. 4), it is determined whether the native code to be called is frameless (steps S1 and S2). If it is a frameless method, it starts executing native code without creating a frame. Otherwise, after pushing the frame (step S3), execution of the native code is started.
On the other hand, the called method performs frame pop. That is, when compiling a bytecode return instruction, a non-frameless method puts the process of performing a process of popping a frame into the code, but the frameless method does not.

図6により、フレームレスメソッドが実行される時のインタプリタスタックおよびネイティブスタックの内容を、例を用いて説明する。図6において、図6(a)はインタプリタスタックの内容、(b)はネイティブスタックの内容を示す。
このフレームレスメソッドの例では、アーギュメント(引数)はインタプリタスタックにあり、アーギュメント以外のローカル変数とオペランドスタックはネイティブスタックにある。ただし、RISCアーキテクチャのCPUではオペランドスタックの内容をすべてレジスタに持つことも考えられる。
ここでは、aload_0,getfield,ireturnというバイトコード列で構成されるメソッドを例に取る。なお、aload_0,getfield,ireturnはバイトコード表現であるが、これをネイティブコードにコンパイルしたものが実行される。
この例では、アーギュメントが1個、アーギュメント以外のローカル変数が0個、従ってローカル変数は一個である。
The contents of the interpreter stack and native stack when the frameless method is executed will be described with reference to FIG. 6A shows the contents of the interpreter stack, and FIG. 6B shows the contents of the native stack.
In this frameless method example, arguments (arguments) are in the interpreter stack, and local variables and operand stacks other than arguments are in the native stack. However, a RISC architecture CPU may have all the contents of the operand stack in a register.
Here, a method composed of byte code strings of “alload — 0”, “getfield” and “irreturn” is taken as an example. Note that allo_0, getfield, and ireturn are byte code expressions, but those compiled into native code are executed.
In this example, there is one argument, zero non-argument local variables, and therefore one local variable.

初期状態ではインタプリタスタックにアーギュメントが積まれており、ネイティブスタックは空である(図6(i) )。
aload_0は0番目のローカル変数をネイティブスタックにプッシュするコードに変換される。このJITされたコードが実行されると、インタプリタスタックのオブジェクト参照(図6のA)がネイティブスタックにプッシュされる(図6(ii))。
getfieldはネイティブスタックのトップにあるオブジェクト参照のフィールド値を取得し、オブジェクト参照(図6のA)をポップし、フィールド値(図のB)をプッシュするコードに変換される。
このJITされたコードが実行されると、同図に示すように、インタプリタスタックにオブジェクト参照(図6のA)がポップされ、ネイティブスタックに、フィールド値(図のB)がプッシュされる(図6(iii) )。
ireturnはネイティブスタックのトップにある値を、呼び出し元フレームのオペランドスタックのトップに書き込むコードに変換される。フレームレスメソッドでは常に呼び出し元フレームのオペランドスタックのトップは呼び出し先メソッドの0番目のローカル変数と一致するので、この場合は0番目のローカル変数に書き込むコードに変換される。
このJITされたコードが実行されると、ネイティブスタックのトップにある値(図のB)が、インタプリタスタックに書き込まれる(図6(iv))。
ここで、呼び出し側のフレームのスタックのトップは、フレームレスメソッド呼び出し時はそのままで、フレームレスメソッドからの復帰の時にアーギュメントサイズ分減らされ、リターン値サイズ分増やされる。
In the initial state, arguments are stacked on the interpreter stack, and the native stack is empty (FIG. 6 (i)).
allow_0 is converted into code that pushes the zeroth local variable onto the native stack. When this JIT code is executed, the object reference (A in FIG. 6) of the interpreter stack is pushed onto the native stack (FIG. 6 (ii)).
getfield gets the field value of the object reference at the top of the native stack, is converted to code that pops the object reference (A in FIG. 6) and pushes the field value (B in the figure).
When this JIT code is executed, an object reference (A in FIG. 6) is popped on the interpreter stack and a field value (B in the figure) is pushed on the native stack as shown in FIG. 6 (iii)).
irturn is converted to a code that writes the value at the top of the native stack to the top of the caller frame's operand stack. In the frameless method, the top of the operand stack of the caller frame always coincides with the 0th local variable of the callee method. In this case, the code is converted to the code written to the 0th local variable.
When this JIT code is executed, the value at the top of the native stack (B in the figure) is written into the interpreter stack (FIG. 6 (iv)).
Here, the top of the caller's frame stack remains unchanged when the frameless method is called, and is decreased by the argument size and increased by the return value size when returning from the frameless method.

次に、本発明の第2〜第4の実施形態について説明する。
以下に説明する第2〜第4の実施形態は、JITされるすべてのメソッドが、必要になった時にフレームを作るネイティブコードにコンパイルされるようにしたものである。
また、第3の実施形態は、上記において、ネイティブコード実行中に必ずフレームが作られるメソッドであるかを調べ、その場合には、ネイティブコードの最初にフレームを作るコードを挿入するようにしたものである。
さらに、第4の実施形態は、上記において、コンパイル時に一命令ごとにオペランドスタックの内容の型を計算し、オペランドスタックのキャッシュ、デキャッシュをおこなうコードを、オペランドスタックの内容にもとづいて生成するようにしたものである。
図7に本発明の第2〜第4の実施形態におけるJITコンパイラ2の機能構成を示す。 第2〜第4の実施形態のJITコンパイラ2は、必要になったときにフレームを作る機能を備えたネイティブコードを生成するネイティブコード生成手段2dと、メソッドが実行時にフレームを必ず必要とするかを判別する判別手段2eと、フレームを必要とするメソッドの場合にフレームを作るネイティブコードを生成する手段2fと、スタックマップを計算する計算手段2gと、オペランドスタックのキャッシュ、デキャッシュを行うネイティブコードを生成する手段2hを有する。
Next, second to fourth embodiments of the present invention will be described.
In the second to fourth embodiments described below, all methods to be JIT are compiled into native code that creates a frame when needed.
Further, in the third embodiment, in the above, it is checked whether the method is a method in which a frame is always created during execution of native code, and in that case, the code for creating a frame is inserted at the beginning of the native code. It is.
Furthermore, in the fourth embodiment, in the above, the type of contents of the operand stack is calculated for each instruction at the time of compilation, and the code for performing cache and decache of the operand stack is generated based on the contents of the operand stack. It is a thing.
FIG. 7 shows a functional configuration of the JIT compiler 2 in the second to fourth embodiments of the present invention. The JIT compiler 2 of the second to fourth embodiments includes a native code generation unit 2d that generates a native code having a function of creating a frame when necessary, and whether a method always requires a frame at the time of execution. Discriminating means 2e, means 2f for generating a native code for creating a frame in the case of a method requiring a frame, calculation means 2g for calculating a stack map, and native code for caching and decacheing an operand stack Means for generating 2h.

(2)第2の実施形態
図8に本発明の第2の実施の形態によって、メソッドをJITする時の処理を示す。
本実施形態では、第1の実施の形態のような「フレームを作るメソッド」、「フレームを作らないメソッド」の場合分けがなく、JITされるすべてのメソッドが、上記図7に示したネイティブコードコード生成手段2dにより、必要になった時にフレームを作るネイティブコードにコンパイルされる。
すなわち、図8に示すように、メソッドがジャバメソッドであるかを調べ(ステップS1)、ジャバメソッドでなければ処理を終了し、ジャバメソッドであれば、必要になったときにフレームを作るネイティブコードを生成する(ステップS2)。この生成されたネイティブコードは、ネイティブコード実行中に、メソッドの呼び出し、オブジェクト割付、スタックスキャン、例外が起きると、実行時にフレームが作られたかどうかを判別し、まだ作られていなければインタプリタスタックにフレームを作る。
第2の実施の形態によるネイティブコードも、オペランドスタックはネイティブスタックに持つが、ローカル変数はアーギュメントであるものもそうでないものもインタプリタスタックに持つ。ただし、RISCアーキテクチャのCPUではオペランドスタックの内容をすべてレジスタに持つことも考えられる。
(2) Second Embodiment FIG. 8 shows processing when JITing a method according to the second embodiment of the present invention.
In this embodiment, there is no distinction between “method for creating a frame” and “method for not creating a frame” as in the first embodiment, and all the methods to be JIT are the native code shown in FIG. The code generation means 2d compiles it into native code that creates a frame when needed.
That is, as shown in FIG. 8, it is checked whether the method is a Java method (step S1). If it is not a Java method, the process is terminated. If it is a Java method, native code that creates a frame when necessary. Is generated (step S2). This generated native code determines whether a frame is created at runtime when a method call, object allocation, stack scan, or exception occurs during native code execution, and if it has not been created, it is added to the interpreter stack. Make a frame.
The native code according to the second embodiment also has an operand stack in the native stack, but has local variables in the interpreter stack, whether they are arguments or not. However, a RISC architecture CPU may have all the contents of the operand stack in a register.

図9にネイティブコード実行中のインタプリタスタックの様子を示す。図9(a)は実行前のインタプリタスタックの内容を示し、(b)はフレームが作られた状態を示す。
ネイティブコード実行開始時には同図(a)に示すように、呼び出し元メソッドのフレームだけがスタックにある。呼び出されたメソッドについてはローカル変数だけがスタックに置かれる。
ネイティブコード実行中に、メソッドの呼び出し、オブジェクト割付、スタックスキャン、例外が起きると、ネイティブコードが、同図(b)に示すように、インタプリタスタックにフレームを作る。またネイティブスタックまたはレジスタにあったオペランドスタックの内容を、インタプリタスタックにデキャッシュ(コピー)する。
さらに、メソッド呼び出し、オブジェクト割付、スタックスキャンが完了してネイティブコードの実行が再開される時、インタプリタスタックにあるオペランドスタックの内容をネイティブスタックまたはレジスタにキャッシュ(コピー)する。
FIG. 9 shows the state of the interpreter stack during native code execution. FIG. 9A shows the contents of the interpreter stack before execution, and FIG. 9B shows a state in which a frame is created.
At the start of native code execution, only the frame of the caller method is on the stack, as shown in FIG. For invoked methods, only local variables are placed on the stack.
When a method call, object allocation, stack scan, or exception occurs during execution of native code, the native code creates a frame on the interpreter stack as shown in FIG. Also, the contents of the operand stack in the native stack or register are decached (copied) into the interpreter stack.
Furthermore, when the method call, object allocation, and stack scan are completed and execution of native code is resumed, the contents of the operand stack in the interpreter stack are cached (copied) in the native stack or register.

図10に、バイトコードのifeqを例に用いて、必要になった時にフレームを作るネイティブコードについて説明する。
ifeqはオペランドスタックの一番上の値をポップしてそれがゼロの時分岐する命令である。この分岐が後方分岐ならば、命令実行前にGCリクエストがあった時、GCチェックポイントに入る必要がある。
ここで、GCチェックポイントについて説明する。インタプリタスタックはオブジェクト参照のルートであるためGC時にスキャンする必要がある。ただし実行効率のため、インタプリタスタックの内容が別の場所にキャッシュされていることがある(コンシステントでない)。これはインタプリタ実行時でも同様である。
スタックスキャンを行うためにはすべてのスレッドのインタプリタスタックがコンシステントでなければならない。またGCが必要になった時可能なかぎり速やかにGCを行うことが必要である。
そこでループの中にはインタプリタスタックがコンシステントでありスタックスキャン可能なGCチェックポイントを置かなければならない。ループには必ず後方分岐命令が使われるので、後方分岐命令でチェックポイントを置くようにする(jsrも同様)。
FIG. 10 illustrates native code that creates a frame when it is needed, using ifeq as a bytecode as an example.
ifeq is an instruction that pops the top value of the operand stack and branches when it is zero. If this branch is a backward branch, it is necessary to enter a GC checkpoint when there is a GC request before the instruction is executed.
Here, the GC checkpoint will be described. Since the interpreter stack is the root of the object reference, it must be scanned during GC. However, for execution efficiency, the contents of the interpreter stack may be cached elsewhere (not consistent). The same applies to interpreter execution.
In order to perform a stack scan, the interpreter stack of all threads must be consistent. Also, when GC becomes necessary, it is necessary to perform GC as quickly as possible.
Therefore, a GC checkpoint in which the interpreter stack is consistent and stack scan is possible must be placed in the loop. Since a backward branch instruction is always used for a loop, a checkpoint is placed at the backward branch instruction (the same applies to jsr).

次に、図10の処理を、行番号順に説明する。なお、図10はインテル系CPUのアセンブラ言語である。
・行1はGCリクエストがあるかどうかを取得する処理である。GCリクエストがあればEAXレジスタに非ゼロ、なければゼロが返される。
・行2〜3はGCリクエストがない場合label2へジャンプする処理である。
・行4は今実行中のメソッドのフレームへのポインタを取得する処理である。すでにフレームが作られていればEAXレジスタにフレームへのポインタが返され、まだ作られていなければヌルが返される。
・行5 〜6はすでにフレームが作られていた場合、label1へジャンプする処理である。
・行7はフレームを作るサブルーチンを呼び出す処理である。
・行9はネイティブスタックにあるオペランドスタックの内容をインタプリタスタックにデキャッシュする処理である。
・行10はGCチェックポイントに入る処理である。
・行11はインタプリタスタックにあるオペランドスタックの内容をネイティブスタックにキャッシュする処理である。
・行13〜15はifeqの処理である。すなわちオペランドスタックから1ワードポップして、ゼロであればaddress1へジャンプする。ここでaddress1はバイトコードのオフセットに対応するネイティブコードの番地である。
第2の実施の形態によるネイティブコードでは復帰する時にフレームの有無を調べ、もしフレームが作られていたらポップし、作られていなければポップしないで、復帰する。
Next, the processing of FIG. 10 will be described in the order of row numbers. FIG. 10 shows the assembler language of the Intel CPU.
Line 1 is a process for acquiring whether there is a GC request. If there is a GC request, non-zero is returned to the EAX register, otherwise zero is returned.
Lines 2 to 3 are processes for jumping to label2 when there is no GC request.
Line 4 is a process for acquiring a pointer to the frame of the currently executed method. If a frame has already been created, a pointer to the frame is returned in the EAX register, and null if it has not been created.
Lines 5 to 6 are processes for jumping to label 1 when a frame has already been created.
Line 7 is a process for calling a subroutine for creating a frame.
Line 9 is a process for decacheing the contents of the operand stack in the native stack to the interpreter stack.
Line 10 is the process that enters the GC checkpoint.
Line 11 is a process for caching the contents of the operand stack in the interpreter stack in the native stack.
Lines 13 to 15 are ifeq processing. That is, one word is popped from the operand stack, and if it is zero, jump to address1. Here, address 1 is the address of the native code corresponding to the offset of the byte code.
In the native code according to the second embodiment, the presence or absence of a frame is checked when returning, and if a frame is created, it is popped, and if it is not created, it is returned without being popped.

(3)第3の実施の形態
上記第2の実施の形態では、ネイティブコード実行中にメソッドの呼び出し、オブジェクト割付、スタックスキャン、例外が起きるとフレームが作られたかどうか調べ、作られていない場合は作る処理を行うようにしている。
しかし、メソッドが同期メソッドの時、または、最初の分岐の前にメソッド呼び出し命令、または、オブジェクト割付命令がある場合には必ずネイティブコード実行中にフレームが作られる。
したがってこのようなメソッドでは最初からフレームを作ってしまった方が、ネイティブコード実行中にフレームの有無を調べるより効率的である。
第3の実施の形態では、前記図7の判別手段2eにより、JITコンパイル時にメソッドが同期メソッドか、または、最初の分岐の前にメソッド呼び出し命令、または、オブジェクト割付命令があるかを判別し、もしそうならば、ネイティブコード生成手段2fによりフレームを作るネイティブコードを生成し、ネイティブコードの最初に挿入する。
さらに、ネイティブコード実行中にはフレームがすでにできているものとして、メソッド呼び出し命令、オブジェクト割付命令、スタックスキャン、例外のネイティブコードでは、フレームの有無を調べて無ければ作る処理を省略する。
(3) Third Embodiment In the second embodiment described above, if a method call, object allocation, stack scan, or exception occurs during native code execution, it is checked whether a frame has been created. Is trying to do the process of making.
However, when the method is a synchronous method, or if there is a method call instruction or an object allocation instruction before the first branch, a frame is created during execution of native code.
Therefore, in such a method, creating a frame from the beginning is more efficient than checking for the presence of a frame during native code execution.
In the third embodiment, the determination means 2e of FIG. 7 determines whether the method is a synchronous method at the time of JIT compilation, or whether there is a method call instruction or an object allocation instruction before the first branch. If so, the native code generating means 2f generates a native code for creating a frame and inserts it at the beginning of the native code.
Further, assuming that a frame is already formed during execution of the native code, in the method calling instruction, the object allocation instruction, the stack scan, and the exception native code, the processing to be performed if the existence of the frame is not checked is omitted.

図11に本発明の第3の実施の形態によって、メソッドをJITする時の処理を示す。 メソッドがジャバメソッドであるかを調べ(ステップS1)、ジャバメソッドでなければ処理を終了し、ジャバメソッドであれば、メソッドが同期メソッドであるかを調べ(ステップS1)、同期メソッドであれば、フレームを作って実行するネイティブコードを生成する(ステップS5)。また、同期メソッドでない場合には、最初の分岐の前にメソッドの呼び出し、オブジェクトの割付命令があるかを調べ(ステップS3)、そうであれば、上記と同様、フレームを作って実行するネイティブコードを生成する(ステップS5)。
また、そうでなければ、必要なときにフレームを作って実行するネイティブコードを生成する(ステップS4)。
FIG. 11 shows processing when JITing a method according to the third embodiment of the present invention. If the method is a Java method (step S1), if it is not a Java method, the process ends. If it is a Java method, the method is checked to determine if it is a synchronous method (step S1). A native code for generating and executing a frame is generated (step S5). If it is not a synchronous method, it is checked whether there is a method call or object allocation instruction before the first branch (step S3). If so, native code that creates and executes a frame as described above. Is generated (step S5).
Otherwise, a native code that creates and executes a frame when necessary is generated (step S4).

図12に、常にフレームを持つメソッドの本実施の形態による前記ifeqのネイティブコードを示す。
本実施の形態により生成されるネイティブコードは、前記図10に示した第2の実施の形態のネイティブコードおいて、5、6、7、8行目が省略された形であり、すでにフレームが作られていた場合、label1へジャンプする処理と、フレームを作るサブルーチンを呼び出す処理が省略されたものである。
FIG. 12 shows the native code of the ifeq according to this embodiment of the method having a frame at all times.
The native code generated by the present embodiment is a form in which the fifth, sixth, seventh, and eighth lines are omitted from the native code of the second embodiment shown in FIG. If it has been created, the process of jumping to label1 and the process of calling a subroutine for creating a frame are omitted.

(4)第4の実施の形態
前記第2の実施の形態でJITされたコードの実行中に、オペランドスタックの内容のキャッシュ、デキャッシュが行われる時、オペランドスタックの大きさ(何個値が積まれているか)は実行時にわかる。またメソッド呼び出し時のアーギュメントと戻り値に関しては、メソッドのシグニチャより型もわかる。したがって、これらの情報にもとづいてキャッシュ、デキャッシュは可能である。
しかし、この場合、値の数と型を実行の都度、取得する処理が必要である。
一方、ジャバのバイトコードではどんなパスを通っても、ある命令の実行時におけるオペランドスタックの内容の型は決まっている。すなわち、コンパイル時にキャッシュ、デキャッシュする内容の型が決まっている。したがってあるバイトコード実行中のオペランドスタックの内容に合致したキャッシュ、デキャッシュのためのコードをネイティブコードに入れることができる。
そこで、コンパイル時に、前記図7のスタックマップを計算する計算手段2gにより、オペランドスタックの内容の型を求め、オペランドスタックの内容の型に基づいて、ネイティブコードコード生成手段2hにより、キャッシュ、デキャッシュするネイティブコードを生成する。このようにすることで、実行の都度、値の数と型を取得する必要がなくなり、汎用ルーチンによるキャッシュ、デキャッシュより実行効率が良い。
以上のように、本実施の形態では、コンパイル時に一命令ごとにオペランドスタックの内容の型を計算し、オペランドスタックのキャッシュ、デキャッシュをおこなうネイティブコードを、オペランドスタックの内容にもとづいて生成する。
(4) Fourth Embodiment When the contents of the operand stack are cached or decached during the execution of the JIT code in the second embodiment, the size of the operand stack (how many values It is known at the time of execution). Also, regarding the arguments and return values when calling a method, the type is known from the method signature. Therefore, cache and decache are possible based on these information.
However, in this case, it is necessary to obtain the number and type of values every time it is executed.
On the other hand, in Java bytecode, the type of the contents of the operand stack at the time of execution of an instruction is determined regardless of the path. That is, the type of contents to be cached and decached at the time of compilation is determined. Therefore, a cache code that matches the contents of the operand stack during execution of a certain bytecode can be put in the native code.
Therefore, at the time of compiling, the type of the contents of the operand stack is obtained by the calculation means 2g for calculating the stack map of FIG. 7, and the cache and decache are generated by the native code code generation means 2h based on the type of the contents of the operand stack. Generate native code to In this way, it is not necessary to acquire the number and type of values each time execution is performed, and execution efficiency is better than cache and decache using a general-purpose routine.
As described above, in the present embodiment, the type of the contents of the operand stack is calculated for each instruction at the time of compilation, and the native code for performing the cache and decache of the operand stack is generated based on the contents of the operand stack.

図13に第4の実施の形態による、コンパイル時にオペランドスタックの内容の型を計算する処理を示す。
図13において、aload_0では、オペランドスタックにオブジェクト参照が積まれる。iload_1では整数型が積まれる。
invokevirtual java.lang.String.charAt()はStringクラスのオブジェクトと一個の整数を引数に取り、一個のchar型を返すメソッドである。
したがって、このメソッドの実行ではオブジェクト参照と整数型がポップされ、図13に示すように整数型が積まれる。(ジャバではchar型もスタックに積まれる時は32bit)
FIG. 13 shows a process for calculating the type of the contents of the operand stack at the time of compilation according to the fourth embodiment.
In FIG. 13, in load_0, an object reference is stacked on the operand stack. In iload_1, an integer type is stacked.
Invokevirtual java. lang. String. charAt () is a method that takes a String class object and a single integer as arguments and returns a single char type.
Therefore, when this method is executed, the object reference and the integer type are popped, and the integer type is stacked as shown in FIG. (In Java, the char type is 32 bits when stacked on the stack)

この場合invokevirtualの前のデキャッシュでは一個のオブジェクト参照と一個の整数型をインタプリタスタックにデキャッシュすればよい。
また、invokevirtualの後のキャッシュでは一個の整数型をネイティブスタックまたはレジスタにキャッシュすればよい。
汎用ルーチンでのキャッシュ、デキャッシュではinvokevirtualの時に、呼び出されるメソッド(ここではjava.lang.String.charAt())のシグニチャを取得し、シグニチャを参照してキャッシュ、デキャッシュを行う必要がある。すなわち、C言語などで書かれた汎用ルーチンでのデキャッシュ処理の場合、メソッドブロックからメソッドシグニチャを取得し、シグニチャのエントリ(この場合はchar型1個と参照型1個の合計2個)を一つ一つ解析しながらデキャッシュしなければならないが、本発明の第4の実施の形態ではそれが不要になる。
In this case, one object reference and one integer type may be decached in the interpreter stack in the decache before invokevirtual.
In addition, in the cache after the invokevirtual, one integer type may be cached in the native stack or register.
It is necessary to acquire a signature of a method to be called (here, java.lang.String.charAt ()) at the time of invoking in the general-purpose routine cache and decache, and perform cache and decache by referring to the signature. That is, in the case of decache processing in a general-purpose routine written in C language or the like, a method signature is obtained from a method block, and signature entries (in this case, one char type and one reference type in total) are obtained. Although it must be decached while analyzing one by one, it is not necessary in the fourth embodiment of the present invention.

本発明のシステム全体のブロック図である。It is a block diagram of the whole system of this invention. 本発明の第1の実施の形態におけるJITコンパイラの機能構成を示すブロック図である。It is a block diagram which shows the function structure of the JIT compiler in the 1st Embodiment of this invention. インタプリタ実行中にメソッドのJITコンパイルが行われる処理を示す図である。It is a figure which shows the process in which the JIT compilation of a method is performed during interpreter execution. フレームレスおよびそうでないメソッドをJITコンパイルする処理を示す図である。It is a figure which shows the process which carries out JIT compilation of the method of frameless and it is not. フレームレスおよびそうでないメソッドのネイティブコードを実行する処理を示す図である。It is a figure which shows the process which performs the native code | cord | chord of the method of frameless and that which is not so. フレームレスメソッド実行中のインタプリタスタックとネイティブスタックの様子を示す図である。It is a figure which shows the mode of the interpreter stack and native stack during frameless method execution. 本発明の第2〜第4の実施の形態におけるJITコンパイラの機能構成を示すブロック図である。It is a block diagram which shows the function structure of the JIT compiler in the 2nd-4th embodiment of this invention. 実行中にフレームが必要になった時に作るネイティブコードをJITコンパイルする処理を示す図である。It is a figure which shows the process which JIT compiles the native code made when a frame is needed during execution. ネイティブコード実行中にフレームが作られる様子を示す図である。It is a figure which shows a mode that a frame is produced during native code execution. 実行中にフレームが必要になった時に作るネイティブコードの例を示す図である。It is a figure which shows the example of the native code made when a frame is needed during execution. 必ずフレームが作られるメソッドの場合、フレームを作るコードを生成する処理を示す図である。FIG. 10 is a diagram illustrating processing for generating a code for creating a frame in the case of a method that always creates a frame. 実行中にフレームを必ず作るメソッドのネイティブコードの例を示す図である。It is a figure which shows the example of the native code of the method which always makes a frame during execution. コンパイル中にオペランドスタックの内容の型を計算する処理を示す図である。It is a figure which shows the process which calculates the type of the contents of an operand stack during compilation.

符号の説明Explanation of symbols

1 インタプリタ
2 JITコンパイラ
3 バイトコード
4 ネイティブコード
5 インタプリタスタック
6 ネイティブコードスタック
10 ジャバ仮想マシン
11 コンピュータ11
12 ハードウエア
13 OS
DESCRIPTION OF SYMBOLS 1 Interpreter 2 JIT compiler 3 Byte code 4 Native code 5 Interpreter stack 6 Native code stack 10 Java virtual machine 11 Computer 11
12 Hardware 13 OS

Claims (5)

バイトコードをネイティブコードに、プログラム実行中にコンパイルする手段を備えた仮想マシンであって、
上記コンパイルする手段は、これからコンパイルするメソッドが、フレームなしで実行できることを判別する手段と、
フレームなしで実行できる場合には、フレームを作らないで実行できるネイティブコードを生成する手段と、
フレームなしで実行できない場合には、フレームを作って実行するネイティブコードを生成する手段を備えた
ことを特徴とする仮想マシン。
A virtual machine with means to compile bytecode into native code during program execution,
The means for compiling includes means for determining that a method to be compiled can be executed without a frame;
If it can run without a frame, it can generate native code that can be run without creating a frame,
A virtual machine comprising means for generating native code for creating and executing a frame when it cannot be executed without a frame.
バイトコードをネイティブコードに、プログラム実行中にコンパイルする手段を備えた仮想マシンであって、
上記コンパイルする手段は、
コンパイルされたメソッドの実行中にフレームが必要な処理が起きたとき、そのメソッドに対応するフレームがインタプリタスタックに作られたかどうか判別するコードと、フレームが作られていない場合に、インタプリタスタックに、実行中のネイティブコードのフレームを作るコードを生成する手段と、
上記インタプリタスタックに、実行中のネイティブコードのオペランドスタックの内容をデキャッシュするコードと、上記インタプリタスタックから実行中のネイティブコードのオペランドスタックの内容をキャッシュするコードを生成する手段を備えた
ことを特徴とする仮想マシン。
A virtual machine with means to compile bytecode into native code during program execution,
The means for compiling is as follows:
When processing that requires a frame occurs during the execution of a compiled method, code that determines whether a frame corresponding to that method has been created on the interpreter stack, and if the frame has not been created, A means of generating code that creates a frame of native code that is running;
The interpreter stack includes means for generating code for decached the contents of the operand stack of the native code being executed, and code for caching the contents of the operand stack of the native code being executed from the interpreter stack. A virtual machine.
請求項2記載のコンパイルする手段は、これからコンパイルされるメソッドが必ずフレームを必要とすることを判別し、フレームを必要とする場合には、ネイティブコードに、フレームを作るコードを挿入する手段を有する
ことを特徴とする仮想マシン。
The means for compiling according to claim 2 includes means for determining that a method to be compiled from now requires a frame, and inserting a code for creating a frame into the native code when a frame is required. A virtual machine characterized by that.
請求項2または請求項3記載のコンパイルする手段は、コンパイル時にバイトコード命令ごとにオペランドスタックの内容の型を計算する手段と、
インタプリタスタックにオペランドスタックの内容をデキャッシュするコードと、
インタプリタスタックからオペランドスタックの内容をキャッシュするコードとを生成する手段を有する
ことを特徴とする仮想マシン。
The means for compiling according to claim 2 or claim 3 comprises means for calculating the type of contents of the operand stack for each bytecode instruction at compile time;
Code to decache the contents of the operand stack in the interpreter stack;
A virtual machine comprising means for generating code for caching the contents of an operand stack from an interpreter stack.
バイトコードをネイティブコードに、プログラム実行中にコンパイルする機能を備えた仮想マシンにおけるコンパイルのためのプログラムであって、
上記プログラムは、
コンパイルされたメソッドの実行中にフレームが必要な処理が起きたとき、そのメソッドに対応するフレームがインタープリタスタックに作られたかどうか判別するコードと、フレームが作られていない場合に、インタプリタスタックに、実行中のネイティブコードのフレームを作るコードを生成する処理と、
上記インタプリタスタックに、実行中のネイティブコードのオペランドスタックの内容をデキャッシュするコードと、上記インタープリタスタックから実行中のネイティブコードのオペランドスタックの内容をキャッシュするコードを生成する処理をコンピュータに実行させる
ことを特徴とするプログラム。
A program for compiling in a virtual machine with a function to compile bytecode into native code during program execution,
The above program
When processing that requires a frame occurs during the execution of a compiled method, code that determines whether a frame corresponding to that method has been created on the interpreter stack, and if the frame has not been created, Processing to generate code that creates a frame of native code that is running;
Causing the interpreter stack to execute a process for generating a code for decaching the contents of the operand stack of the native code being executed and a code for caching the contents of the operand stack of the native code being executed from the interpreter stack. A program characterized by
JP2004097947A 2004-03-30 2004-03-30 Virtual machine compiling byte code into native code Withdrawn JP2005284729A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2004097947A JP2005284729A (en) 2004-03-30 2004-03-30 Virtual machine compiling byte code into native code

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2004097947A JP2005284729A (en) 2004-03-30 2004-03-30 Virtual machine compiling byte code into native code

Publications (1)

Publication Number Publication Date
JP2005284729A true JP2005284729A (en) 2005-10-13

Family

ID=35183039

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2004097947A Withdrawn JP2005284729A (en) 2004-03-30 2004-03-30 Virtual machine compiling byte code into native code

Country Status (1)

Country Link
JP (1) JP2005284729A (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2007055883A1 (en) * 2005-11-14 2007-05-18 Microsoft Corporation Asynchronous just-in-time compilation
JP2007141153A (en) * 2005-11-22 2007-06-07 Hitachi Software Eng Co Ltd Interpreter
KR100828364B1 (en) 2006-06-28 2008-05-08 삼성전자주식회사 A method of java JIT compiling using pseudo profile and system thereof
WO2012045238A1 (en) * 2010-10-09 2012-04-12 中兴通讯股份有限公司 Startup method and device for application program on mobile device
US8341606B2 (en) 2006-02-24 2012-12-25 Samsung Electronics Co., Ltd. Method of invoking inlined method and java virtual machine using the method
US8782620B2 (en) 2012-06-12 2014-07-15 International Business Machines Corporation Processing reified generics in object-based programming environments
US9417872B2 (en) 2012-06-29 2016-08-16 Fujitsu Limited Recording medium storing address management program, address management method, and apparatus

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2007055883A1 (en) * 2005-11-14 2007-05-18 Microsoft Corporation Asynchronous just-in-time compilation
JP2007141153A (en) * 2005-11-22 2007-06-07 Hitachi Software Eng Co Ltd Interpreter
US8341606B2 (en) 2006-02-24 2012-12-25 Samsung Electronics Co., Ltd. Method of invoking inlined method and java virtual machine using the method
KR100828364B1 (en) 2006-06-28 2008-05-08 삼성전자주식회사 A method of java JIT compiling using pseudo profile and system thereof
WO2012045238A1 (en) * 2010-10-09 2012-04-12 中兴通讯股份有限公司 Startup method and device for application program on mobile device
US8726249B2 (en) 2010-10-09 2014-05-13 ZTE Corportaion Bootup method and device for application program in mobile equipment
US8782620B2 (en) 2012-06-12 2014-07-15 International Business Machines Corporation Processing reified generics in object-based programming environments
US8863098B2 (en) 2012-06-12 2014-10-14 International Business Machines Corporation Processing reified generics in object-based programming environments
US9417872B2 (en) 2012-06-29 2016-08-16 Fujitsu Limited Recording medium storing address management program, address management method, and apparatus

Similar Documents

Publication Publication Date Title
EP3314422B1 (en) Extending a virtual machine instruction set architecture
US5983021A (en) Dynamically switching statically bound function calls to dynamically bound function calls without recompilation
US6546550B1 (en) Method to determine dynamic compilation time and to select bytecode execution mode
CN107041158B (en) Restrictive access control for modular reflection
US6973644B2 (en) Program interpreter
US8296745B2 (en) Method and apparatus for portable stub generation
US9417931B2 (en) Unified metadata for external components
US20080222616A1 (en) Software translation
US20040255279A1 (en) Block translation optimizations for program code conversation
JP2000112772A (en) Data processing system for executing process in response to instruction in instruction set and its instruction processing method
JP5583514B2 (en) Compiling method for optimizing binary code, compiler system thereof, and computer program
JP2008546086A (en) Method and apparatus for translating program code with access coordination for shared resources
US20120030659A1 (en) Constructing runtime state for inlined code
US20050050528A1 (en) Method and apparatus to guarantee type and initialization safety in multithreaded programs
JP2001075827A (en) Complete request drive type link accompanying verify processing for every module
US20060070049A1 (en) Java bytecode translation method and Java interpreter performing the same
US8230407B2 (en) Apparatus and method for accelerating Java translation
US6385764B1 (en) Method and apparatus for improving invocation speed of Java methods
US20040040029A1 (en) Method call acceleration in virtual machines
US20050257202A1 (en) Data-flow based post pass optimization in dynamic compilers
US8341613B2 (en) Reducing stack space consumption via head-call optimization
US20040015912A1 (en) Method of byte code quickening: quick instructions for method invocation
JP3813019B2 (en) Program processing method, method for detecting frame related to specified method, and storage medium
JP2005284729A (en) Virtual machine compiling byte code into native code
US20050246677A1 (en) Native method invocation (NMI) custom marshalling stub service

Legal Events

Date Code Title Description
A300 Withdrawal of application because of no request for examination

Free format text: JAPANESE INTERMEDIATE CODE: A300

Effective date: 20070605