
Tracing for Web 3.0 Trace Compilation for the Next Generation Web Applications Mason Changy∗, Edwin Smith∗, Rick Reitmaier∗, Michael Bebenitay, Andreas Galyx, Christian Wimmery, Brendan Eichx, Michael Franzy ∗Adobe Corporation yUniversity of California, Irvine xMozilla Corporation fedwsmith,[email protected], fchangm,mbebenit,gal,cwimmer,[email protected], [email protected] Abstract applications become more sophisticated, they rely more and more Today’s web applications are pushing the limits of modern web on JavaScript to do the heavy lifting rather than just using it for triv- browsers. The emergence of the browser as the platform of choice ial scripting tasks. As a result, JavaScript performance has become for rich client-side applications has shifted the use of in-browser a real bottleneck to the web experience. JavaScript from small scripting programs to large computationally The flexibility and rapid prototyping abilities of dynamically intensive application logic. For many web applications, JavaScript typed languages such as JavaScript are the main factors contribut- performance has become one of the bottlenecks preventing the ing to their popularity on the web. Today’s web applications are development of even more interactive client side applications. built using an array of largely independent technologies such as While traditional just-in-time compilation is successful for stati- HTML, CSS, XML, and SQL. Making these technologies work cally typed virtual machine based languages like Java, compiling together requires a flexible and dynamically typed language. Un- JavaScript turns out to be a challenging task. Many JavaScript fortunately, flexibility comes at a cost. The performance of dynam- programs and scripts are short-lived, and users expect a responsive ically typed languages has long been many orders of magnitude browser during page loading. This leaves little time for compilation lower than their statically typed counterparts. Poor JavaScript per- of JavaScript to generate machine code. formance is a severe limitation for web applications. We present a trace-based just-in-time compiler for JavaScript Due to their highly dynamic structure, dynamically typed lan- that uses run-time profiling to identify frequently executed code guages are poor candidates for just-in-time compilation. For this paths, which are compiled to executable machine code. Our ap- reason, most dynamically typed language runtimes instead rely on proach increases execution performance by up to 116% by decom- interpretation as their primary means of execution. We introduce posing complex JavaScript instructions into a simple Forth-based Tamarin-Tracing, a new JavaScript virtual machine that aims to representation, and then recording the actually executed code path break the poor performance barrier. Our approach is to make just- through this low-level IR. Giving developers more computational in-time (JIT) compilation effective in a dynamically typed language horsepower enables a new generation of innovative web applica- runtime environment. We accomplish this by using a novel trace- tions. based compilation technique [13], which is effective in eliminating many of the problems that arise when building traditional JIT com- Categories and Subject Descriptors D.3.4 [Programming Lan- pilers for dynamically typed languages. Our trace-based compiler guages]: Processors - Compilers selects and compiles only frequently executed “hot” code paths, while interpreting rarely executed code. Moreover, the code se- General Terms Design, Languages, Performance lected for compilation can be type specialized according to the type Keywords JavaScript, Trace Trees, Tracing, Forth, Type Special- profile of the running application, allowing our compiler to make ization, Tamarin, Dynamic Compilation, Dynamically Typed Lan- aggressive type driven optimizations. This makes it possible for us guages to remove much of the principal overhead of the dynamically typed JavaScript language, compiling untyped code as typed code. 1. Introduction We compare Tamarin-Central, a conventional compiler used in the current virtual machine shipping with Adobe Flash 9, with The web has become an ubiquitous platform for content-rich appli- Tamarin-Tracing, a trace-based just-in-time compiler. We found cations. In the early days of “Web 1.0”, most web sites were fairly that Tamarin-Tracing outperforms Tamarin-Central by up to 116%. static and provided little user interaction. The “Web 2.0” revolu- Our experience with Tamarin-Tracing allows us to make the fol- tion redefined the browser as a vehicle for delivering richer media lowing contributions: content and interactivity through a fusion of existing technologies, most notably Asynchronous JavaScript and XML (AJAX). As web 1. We present a trace-based just-in-time compiler for JavaScript. 2. We compare our compiler against other production JavaScript c ACM, 2009. This is the author’s version of the work. It is posted here by permission runtimes. of ACM for your personal use. Not for redistribution. The definitive version was published in the Proceedings of the International Conference on Virtual Execution 3. We investigate type specialization on traces. Environments, pp. 71–80. VEE’09, March 11–13, 2009, Washington, DC, USA. 4. We show the performance implications of using complex vs. http://doi.acm.org/10.1145/1508293.1508304 simple opcodes. 71 2. Tamarin minimum. A fast interpreter is also essential in the case of a snippet Tamarin is the code name used for Adobe’s virtual machines that of JavaScript code that runs for only a few milliseconds. The implement ActionScript 3 (AS3) [1], a flavor of ECMAScript [11]. argument that a slow interpreter is acceptable is no longer valid JavaScript is also a flavor of ECMAScript, however AS3 supports on the web. multiple constructs that JavaScript does not, such as optional static The poor performance of interpreters is largely due to the high typing, packages, classes, and early binding. AS3 has a syntax that cost of opcode dispatch. Each opcode dispatch is at a minimum one is similar to JavaScript, and most JavaScript can be executed on indirect branch, which often introduces processor pipeline stalls. Tamarin without any modification. Tamarin does not directly op- The complexity of individual instructions is largely dwarfed by the erate on AS3 source code, but instead executes a bytecode inter- high dispatch overhead. A “simple” opcode has a fine granularity mediate format known as ActionScript bytecode (ABC) [2]. Con- yet higher dispatch overhead. A “complex” opcode has a coarse ceptually, this is the equivalent of the Java Virtual Machine Lan- granularity with the advantage of low dispatch cost. For this rea- guage (JVML) bytecode [19]. ActionScript bytecode, like JVML son, a common interpreter optimization is to group single simple bytecode, is a stack based intermediate representation. ActionScript opcodes into larger complex opcodes. This reduces the number of source files are converted to ActionScript bytecode using the Adobe dispatches at the expense of opcode complexity, which can lead Flex compiler [3]. to better interpreter performance. Forth is able to mend itself well There are currently two development branches of Tamarin: to varying levels of opcode granularity. During interpretation, the Tamarin-Central (TC) and Tamarin-Tracing (TT). Tamarin-Central coarse granularity of Super Words can reduce opcode dispatch cost, is the current virtual machine shipping with Adobe Flash 9, while while during trace recording the compiler is able to reduce the Su- Tamarin-Tracing is a research virtual machine slated for future ver- per Words to finer grained primitive words. sions of Adobe Flash. Tamarin-Central uses a conventional inter- preter and JIT compiler, while Tamarin-Tracing leverages a trace- 4. Forth based compiler to achieve performance improvements. Tamarin- Forth operates on two stacks: the data stack and the return stack. Tracing is partially a self-hosting compiler, with many portions of The data stack is used for arithmetic operations, while the return the system itself written in ActionScript 3. Tamarin-Tracing uses stack is used for control flow operations. Consider the sample Forth the Forth language as an intermediate representation. Before Ac- code: tionScript source can be executed, it is first compiled to ABC and 10 20 + . then translated to Forth. Tamarin-Tracing is essentially a Forth vir- This Forth code sequence pushes the numbers 10 and 20 onto tual machine. the data stack. These numbers are then popped off the data stack, Forth is a stack-based programming language that uses reverse added, and their sum is then pushed back onto the stack. The “.” Polish notation and operates on subroutines known as Words. Con- Forth word prints the result onto the screen. ceptually, programming in Forth is similar to programming in Forth was chosen as an intermediate language due to the lan- JVML, each Forth word behaving like a JVML bytecode. Tamarin guage’s ease in refactoring and resulting code size. Forth contains contains roughly 200 Primitive Words, which implement the basic a small number of primitive words, such as add. New words are operations such as performing arithmetic or stack manipulation. In constructed by concatenating previous words. Word definitions do Forth, words known as Super Words can be constructed by combin- not take parameters, and instead operate on either the data or re- ing other Primitive Words. For example, consider the JVML iinc turn stack without any explicit
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages10 Page
-
File Size-