Just-In-Time Compiler for Konohascript Using LLVM
reprinted from: IPSJ Transactions on Programming 6 (1) : 9–16 (2013) IPSJ Online Transactions Vol.6 9–16 (Jan. 2013) [DOI: 10.2197/ipsjtrans.6.9] Regular Paper
Just-in-time Compiler for KonohaScript Using LLVM
Masahiro Ide1,a) Kimio Kuramitsu1,†1,b)
Received: April 20, 2012, Accepted: September 17, 2012, Released: January 29, 2013
Abstract: In recent years, as a method to improve the language performance of scripting languages has attracted the attention of the Just-In-Time (JIT) compilation techniques for scripting language. The difficulty of JIT compilation for scripting language is its dynamically typed code and in its own language runtime. The purpose of this paper is to evaluate the performance overhead of JIT compilation of runtime library’s overhead by using a statically typed script- ing language. In this study, we use a statically typed scripting language KonohaScript to analyze language runtime performance impact of the code generated by the JIT compiler.
Keywords: just-in-time compiler, scripting language
(LLVM [5]) as the compiler backend. In addition, we identify 1. Introduction three main performance-inhibiting issues in the naive translation In the past decade, significant advances have been seen in of the code in order for it to work together with the scripting lan- scripting language just-in-time (JIT) compilers for JavaScript [1], guage runtime. Finally, we evaluate the execution performance [2], as well as for other languages such as Python [3]. JIT com- by using a benchmark application with our JIT compiler. pilers can dramatically improve performance by converting ap- This paper is organized as follows: In Section 2 we give an plication code into machine code in the execution time. Unlike overview of scripting languages. Section 3 provides an overview a simple interpreter for scripting language, JIT compiled code is of our JIT compiler, followed by a description of our optimiza- executed directly on the CPU. tion techniques in Section 4. Then, Section 5 evaluates the ef- The initial implementation of a scripting language JIT com- fectiveness of our JIT compiler and related work is discussed in piler is to typically generate native code by translating a higher- Section 6. Section 7 concludes this paper. level bytecode into native code naively, where applications run 2. Scripting Language Runtime slower than equivalent implementations in C and Java. This trans- lation is straightforward, but it leads to the following two over- In this section, we define the word Scripting Language. We heads being introduced into a scripting language. First, the script- describe the features provided by the runtime system of scripting ing language JIT compiler needs to take into account the dynamic languages such as Ruby, Python, and Lua. In addition, this sec- typed code. Second, this JIT compiler needs to perform code gen- tion describes the design of KonohaScript and the relevant parts eration with a consideration of collaboration and with runtime for to our JIT compile. its own language. Relevance for dynamic typing and performance of code that the 2.1 Definition of Scripting Language JIT compiler generates is well documented by Chang et al. [4]. Scripting language is not clearly defined scientifically, but one They evaluate JIT compilers by measuring their performance of the common features of scripting languages is its dynamic changes for each full-typed, partially-typed, and un-typed piece type. The classification of the language to perform as a dynami- of code. As a result, they report that speed improvements of about cally typed language is included with Lisp and Scheme, but these 60 percent, on average, are gained by adding type information in are not called scripting languages. In recent years, several at- the benchmark codes. tempts have been made to integrate static typing features into ex- In this paper, we evaluate an overhead on JIT compiled code isting dynamic languages such as ActionScript and Thorn. An- except where this is caused by dynamically typing on that in- other feature for scripting language is an interpreter. Scripting terpreted source code. To achieve this goal, we constructed a languages require source code (or scripts) at runtime, which need JIT compiler for a statically typed scripting language, Kono- to load and execute scripts. haScript. Furthermore, we describe the design of a JIT com- In recent years, in an effort to improve their performance, piler for KonohaScript based on a Low Level Virtual Machine scripting languages were often accompanied by a JIT or bytecode compiler. Therefore, a scripting language is not able to be classi- 1 Graduate School of Yokohama National University, Yokohama, Kana- ff gawa 240–8501, Japan fied simply by the presence of the compiler. The main di erence †1 Presently with Japan Science and Technology Agency/CREST between compiled languages (e.g., C and Java) and scripting lan- a) [email protected] guages is that scripting languages can load a script and execute b) [email protected]