Cost-Effective Compilation Techniques for Java Just-In-Time Compilers 3

Cost-Effective Compilation Techniques for Java Just-In-Time Compilers 3

IEICE TRANS. ??, VOL.Exx–??, NO.xx XXXX 200x 1 PAPER Cost-Effective Compilation Techniques for Java Just-in-Time Compilers Kazuyuki SHUDO†, Satoshi SEKIGUCHI†, Nonmembers, and Yoichi MURAOKA ††, Fel low SUMMARY Java Just-in-Time compilers have to satisfy a policies. number of requirements in conflict with each other. Effective execution of a generated code is not the only requirement, but 1. Ease of use as a base of researches. compilation time, memory consumption and compliance with the 2. Cost-effective development. Less labor and rela- Java Virtual Machine specification are also important. We have tively much effect. developed a Java Just-in-Time compiler keeping implementation 3. Adequate quality and performance for practical labor little. Another important objective is developing an ad- equate base of following researches which utilize this compiler. use. The proposed compilation techniques take low compilation cost and low development cost. This paper also describes optimization Compiler development involves much work on a methods implemented in the compiler, for instance, instruction parser, intermediate representations and a number of folding, exception handling with signals and code patching. optimizations. Because of it, we have to consider those key words: Runtime compilation, Java Virtual Machine, Stack human and engineering factor seriously in addition to caching, Instruction folding, Code patching technical requirements like performance. Our plan on the development of the JIT compiler was to have a prac- 1. Introduction tical compiler with work several man-month. Our an- other goal was specifically having a research base on Just-in-Time (JIT) compilers for Java bytecode have which we do following researches with less labor while to satisfy a number of requirements, which are differ- developing it with less work. ent from those for ordinary compilers. Effective execu- It is known that development efforts need vast tion of a generated code is not the only requirement, work when extreme high performance is set as one of but the time and memory consumed by compilation the goals. We do not head such a goal and set our line should worth performance gain because the compila- to baseline compiler, which saves compilation time and tion takes place while the target program is running. memory. Java bytecode JIT compilers also suffer relatively strict In this paper, we present cost-effective code gener- specifications of Java language and Java Virtual Ma- ation and optimization methods we have implemented chine (JVM). The rules in the specifications yield high- in the JIT compiler and their effects. The code genera- reproducibility of execution results of Java programs on tion technique is template connecting. The code gener- different platforms. But part of the rules limit a class ator basically connects given templates of native code of optimizations and performance improvement by the corresponding to internal instructions. In addition to compilers. the technique, stack caching [1] was implemented in the Because of conflicting requirements for Java run- compiler and the technique makes use of multiple reg- time, a number of different runtimes have naturally isters over templates. There have been a JIT compiler appeared and even an individual runtime takes dif- which caches only the top of stack on a register and a ferent options on its behavior according to character- bytecode interpreter of Sun Microsystems’ Classic VM istics of user programs. For instance, Sun Microsys- which does dynamic stack caching. But there has been tems’ HotSpot Server VM has a JIT compiler special- no JIT compiler stack caching is applied to and the JIT ized to computation-intensive application. The com- compiler we have developed is the first case. This tech- piler spends much time on compilation of code segments nique, template connecting with stack caching achieved which have been recognized as “hot spot”, a code seg- utilization of multiple registers with less compilation ment expected to run many times. Oppositely, a run- cost. Furthermore the compiler became easy in use as time for embedded application tends to save power con- a base of researches because the template connecting sumption rather than performance improvement. technique allows us to modify native code generated by We developed a JIT compiler along the following the compiler directly as mentioned in 2. In the next section, we describe an overview of the †National Institute of Advanced Industrial Science and Technology, Tsukuba Central 2, 1-1-1 Umezono, Tsukuba- JIT compiler shuJIT and present the structure of the shi, 305-8568 Japan compiler and the code generation method. And we dis- ††Waseda University, 3-4-1 Okubo, Shinjuku-ku, Tokyo, cuss how they affect easiness in use as a research base 169-8555 Japan and the compilation cost. In 3, pros and cons of the IEICE TRANS. ??, VOL.Exx–??, NO.xx XXXX 200x 2 Java bytecode shuJIT Java internal code bytecode shuJIT x86 fill_cache internal code native code Translation into shuJIT internal code array_check laload shuJIT internal code ..... ..... flush_cache fill_cache movl (%edx), %eax Optimization daload dld array_check fldl (%eax,%ecx,8) dmul dmul daload_dld shuJIT internal code dadd dst dmul addl $8, %esp dastore flush_cache fmull (%esp) Replacement with native code ..... flush_cache dadd ..... dld dst_dastore dadd Replacement dst x86 native code with native code fill_cache Optimization lastore Translation into Fig. 1 Structure of shuJIT. shuJIT internal code (Part of Linpack#daxpy method) Fig. 2 An example of compilation. stack caching technique in this compiler are discussed. After effects of optimizations implemented in the com- piler are shown in 4, two important factors which af- the internal code is just one-to-one or one-to-many re- fect usability, peak performance and invocation time placement. are evaluated in 5. We conclude with 6. Native code generation in the last stage of compila- tion is achieved by replacement of the internal instruc- 2. Overview of the JIT Compiler tions with templates, which are pre-compiled pieces of native code. The compiler has the templates be- We have been developing and distributing shuJIT, a cause compiler developers provided them. The pre- Java bytecode Just-in-Time (JIT) compiler. The com- pared templates were written as simulating JVM stack piler supports Intel’s IA-32 processors, known as x86, with hardware-supported stack of the processor. Java and Linux, FreeBSD and NetBSD OSes. Except tem- bytecode instructions push a value on a JVM stack are plates of generated native code, which are written in as- basically translated to processor’s push instructions. sembly code for x86, the compiler is in C language. The The aims to adopt such a template connecting compiler works with a Java Virtual Machine (JVM) technique are as follows. Classic VM, which are distributed with Sun Microsys- • Saving of development cost. tems’ Java 2 Platform, Standard Edition (Java 2 SE) • Easy modification of generated code. and Java Development Kit. ShuJIT is expected to work • Control of compilation cost. on PC or more rich environments as declared with sup- porting architecture and OSes. The technique eliminates the need of assembler in the Practicality, stability and reliability for daily use compiler and we could save the labor on its develop- were also our goals while ease of use as a research base ment. Assembler is not necessary because the prepared is one of the goals. Compliance with the JVM specifi- templates which have native code can be assembled cation [2] is, of course, one of the important goals. If while the compiler itself is compiled by a C compiler. a compiler does not achieve one of these goals, derived Development cost of an assembler for x86 is relatively researches from the compiler ought to lack reality. We high compared with one for RISC processors because could have a certain number of users of shuJIT as the bit patterns of x86 machine instructions are not very compiler achieved those goals. There were over 7500 regular. downloads of the source code and about 8500 down- 48 days after the start of its development, the com- loads of the binary for 2 and a half years since its first piler started working and could compiled simple Java release in September of 2001. programs. It is difficult to compare the development Fig. 1 shows an overview of the compiler. First, the cost with other software, but the cost seems to be very compiler translate Java bytecode instructions in a given low as cost of JIT compiler development. method to shuJIT internal instructions. The compiler Generated native code can be directly modified by then applies optimization techniques to the internal in- making changes on the templates because the templates structions. The techniques described in 4 are instruc- appear in the generated code directly. It is a natu- tion folding (4.2), inlining (4.5 and 4.6) and direct ral conclusion that the compiler is easy to be applied invocation (4.1). Finally the compiler translates the to researches which need modification of generated na- internal code to x86 native code and resolve function tive code. The compiler has been utilized as a base of calls. Fig. 2 is an example of compilation by shuJIT. such researches [3]–[5] because of the property. Because The intermediate representation, shuJIT internal usual compilers use a more fine-grain internal represen- code is extended Java bytecode and has peculiar in- tation like GCC’s RTL just before code generation, it structions. Translation process from Java bytecode to is not possible to modify generated code directly and SHUDO et al.: COST-EFFECTIVE COMPILATION TECHNIQUES FOR JAVA JUST-IN-TIME COMPILERS 3 shuJIT shuJIT internal code (part of Linpack#daxpy method) : memory EDX ECX ECX EDX ... memory memory EDX memory ECX (1) iload (2) iload memory memory memory memory memory (3) iconst_1 (1) iload state 0 ....

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    13 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us