Debugging at Full Speed
Total Page:16
File Type:pdf, Size:1020Kb
Debugging at Full Speed Chris Seaton Michael L. Van De Vanter Michael Haupt Oracle Labs Oracle Labs Oracle Labs University of Manchester michael.van.de.vanter [email protected] [email protected] @oracle.com ABSTRACT Ruby; D.3.4 [Programming Languages]: Processors| Debugging support for highly optimized execution environ- run-time environments, interpreters ments is notoriously difficult to implement. The Truffle/- Graal platform for implementing dynamic languages offers General Terms an opportunity to resolve the apparent trade-off between Design, Performance, Languages debugging and high performance. Truffle/Graal-implemented languages are expressed as ab- Keywords stract syntax tree (AST) interpreters. They enjoy competi- tive performance through platform support for type special- Truffle, deoptimization, virtual machines ization, partial evaluation, and dynamic optimization/deop- timization. A prototype debugger for Ruby, implemented 1. INTRODUCTION on this platform, demonstrates that basic debugging services Although debugging and code optimization are both es- can be implemented with modest effort and without signifi- sential to software development, their underlying technolo- cant impact on program performance. Prototyped function- gies typically conflict. Deploying them together usually de- ality includes breakpoints, both simple and conditional, at mands compromise in one or more of the following areas: lines and at local variable assignments. The debugger interacts with running programs by insert- • Performance: Static compilers usually support debug- ing additional nodes at strategic AST locations; these are ging only at low optimization levels, and dynamic com- semantically transparent by default, but when activated can pilation may also be limited. observe and interrupt execution. By becoming in effect part • Functionality: Years of research on the topic have most of the executing program, these \wrapper" nodes are subject often given priority to optimization, resulting in de- to full runtime optimization, and they incur zero runtime bugging services that are incomplete and/or unreli- overhead when debugging actions are not activated. Condi- able. tions carry no overhead beyond evaluation of the expression, which is optimized in the same way as user code, greatly im- • Complexity: Debuggers usually require compiler sup- proving the prospects for capturing rarely manifested bugs. port, in particular the generation of additional infor- When a breakpoint interrupts program execution, the plat- mation the debugger might need when deciphering ex- form automatically restores the full execution state of the ecution state. This strategy can strongly couple their program (expressed as Java data structures), as if running respective implementations. in the unoptimized AST interpreter. This then allows full introspection of the execution data structures such as the • Inconvenience: Putting a system under observation by AST and method activation frames when in the interactive a debugger requires some form of \debug mode", for debugger console. example using the -Xdebug option when starting the 1 Our initial evaluation indicates that such support could Java Virtual Machine. be permanently enabled in production environments. As a consequence, debugging is seldom enabled in produc- tion environments. Defects that arise must be investigated Categories and Subject Descriptors in a separate development environment that differs enough D.2.5 [Software Engineering]: Debugging and Testing| from production that reproducing the issue may be hard. The VM Research Group at Oracle Labs proposes to elim- Permission to make digital or hard copies of all or part of this work for inate this conflict in optimized dynamic runtimes by making personal or classroom use is granted without fee provided that copies are not production-quality code debug-aware without adding over- made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components head. The basis for this proposal is Truffle [29], a newly of this work owned by others than ACM must be honored. Abstracting with developed platform for constructing high performance im- credit is permitted. To copy otherwise, or republish, to post on servers or to plementations of dynamic languages. A Truffle-based lan- redistribute to lists, requires prior specific permission and/or a fee. Request guage implementation is expressed as an abstract syntax tree permissions from [email protected]. 1 Dyla’14 June 09 - 11 2014, Edinburgh, United Kingdom Oracle and Java are registered trademarks of Oracle and/or its Copyright 2014 ACM 978-1-4503-2916-3/14/06 ...$15.00 affiliates. Other names may be trademarks of their respective http://dx.doi.org/10.1145/2617548.2617550. owners. (AST) interpreter, to which the framework applies aggres- semantics. Based on type information obtained at run-time, sive dynamic optimizations including type specialization, in- AST nodes speculatively replace themselves in the AST with lining, and many other techniques. type-specialized variants [30]. Should the speculation be The group's recently developed implementation of Ruby [5] wrong, they replace themselves again with other specializa- has already shown promising results [28] and is now being tions, or with generic nodes that subsume the functionality integrated with the existing implementation of Ruby on the required for all possible types. JVM, JRuby [18]. As part of a larger inquiry into techniques Truffle interpreters perform best when running atop the for adding developer tool support to Truffle, the Ruby AST Graal VM [26]: a modified HotSpot Java VM that hosts was experimentally extended to include support for a sim- the Graal dynamic compiler. The Graal VM supports par- ple yet useful debugger, as well as for Ruby's built-in trac- tial evaluation of Truffle ASTs and generates efficient ma- ing facility. Both extensions exhibit essentially zero runtime chine code from them. Tree rewriting|e. g., in case of fail- overhead until enabled, at which time the debugging/tracing ing speculations|is possible for trees compiled into machine logic accrues overhead proportional to the specific function- code by means of dynamic deoptimization [9], which tran- ality needed. sitions control from a compiled machine code method back This strategy was first explored for the Self debugger [9], into the original AST interpreter and restores the source- where debugging support is tightly integrated with execu- level execution state. tion machinery. A significant consequence of this strategy is that the representation of logic implementing debugging 2.2 Ruby Truffle functionality becomes indiscernible from the representation Ruby [5] is a dynamically typed object-oriented language of ordinary application code and thus subject to all the op- with features inspired by Smalltalk and Perl. It is best timization capabilities the VM offers for application code. known in combination with the Rails web framework for The paper is structured as follows. The next section quick development of database-backed web applications, but describes the background for this experiment in more de- it is also applied in fields as diverse as bioinformatics [7] tail: the underlying Truffle platform, the Truffle-based im- and graphics processing [16]. Although generally considered plementation of Ruby (Ruby Truffle), the combination of a relatively slow language with little support from tradi- Ruby Truffle and JRuby (JRuby+Truffle), and the proto- tional large enterprise, it has powered significant parts of type Ruby debugger. In section3, we introduce our use extremely large scale applications, for example Twitter [14] of AST \wrapper" nodes in the debugger. Section4 gives and GitHub [11]. details about the implementation in the Truffle framework, The Truffle implementation of Ruby began as a new code and about the mechanisms of the underlying VM|including base, reusing only the JRuby parser. Truffle allows for rapid the Graal compiler|that it uses. In section5, we discuss implementation: after five months of development Ruby our implementation in comparison to alternatives, in terms Truffle ran the RubySpec test suite [25], passing about 50 % of impact on peak performance. Sections6 and7 discuss of the language tests, and ran unmodified micro benchmarks related work and conclude the paper. and small kernels from real applications. Ruby Truffle's im- plementation comprised about 19,000 lines of Java in 155 2. BACKGROUND classes. The prototype debugger was also implemented dur- The context for the experiment presented here is a project ing this period, allowing it to be used to support Ruby Truf- at the VM Research Group at Oracle Labs to develop a fle's development. Truffle-based implementation of the Ruby programming lan- guage. An initial implementation produced in less than six 2.3 JRuby+Truffle months demonstrated extremely high peak performance [28]. The Truffle-based implementation of Ruby has been li- During this period the group was also evaluating tech- censed for open source and merged into JRuby: an existing niques for extending the Truffle platform with support for Java-based implementation [18]. The original JRuby began developer tools. A goal for these extensions was to exhibit as a straightforward port of the standard Ruby interpreter zero peak temporal performance overhead when when de- from C to Java. It has since become arguably the most so- bugging is enabled but not in use, and minimal overhead phisticated implementation