The Simplest Heuristics May Be the Best in Java JIT Compilers

The Simplest Heuristics May Be the Best in Java JIT Compilers

The Simplest Heuristics May Be the Best in Java JIT Compilers Jonathan L. Schilling Caldera International, Inc. 430 Mountain Avenue Murray Hill, NJ 07974 [email protected] Abstract volved, the compilation of a given piece of bytecode may or may not prove to be a net benefit over the course of The simplest strategy in Java just-in-time (JIT) com- any given application's run. pilers is to compile each Java method the first time it is called. However, better performance can often be ob- Decisions about whether to compile bytecodes are usu- tained by selectively compiling methods based on heuris- ally made on a per-method basis. The simplest JIT tics of how often they are likely to be called during compilation strategy is to compile every method the :first the rest of the program's execution. Various heuristics time it is called. More ambitious JIT strategies involve are examined when used as part of the Caldera UNIX selective compilation: some methods get compiled the Java JIT compiler. The simplest heuristics involving the first time they are called, some methods get compiled number of times the method has executed so far and the later, and some methods never get compiled at all. size of the method prove to be the most effective, with more complicated heuristics not providing much or any Given the dynamic nature of the Java language and its additional benefit. applications, it is usually not feasible to know ahead of time how long methods will take to compile, exe- cute interpretively, or execute as generated code. Thus Keywords selective compilation decisions rely on heuristics about whether compiling a method will likely result in a time savings for that method. Java, just-in-time compiler, JIT, selective compilation, heuristics, performance. The goal of the work described here is to see how the addition of selective compilation heuristics can improve the performance of a particular existing virtual machine and JIT compiler. 1 Introduction A Java just-in-time (JIT) compiler is an optimization 2 Architecture of the JVM and JIT component within Java virtual machines. Instead of Java bytecodes being interpreted each time they are ex- ecuted, the bytecodes are compiled to the underlying This paper describes work done to the Java virtual ma- machine code and from that point on the generated ma- chine in various versions of the Java Development Kit chine code is executed. and Java 2 Platform, Standard Edition for SCO and It follows from this scheme that there is a fundamental Caldera UNIX Operating Systems. 1 tradeoff in JIT compilers. Compiling the bytecodes will 1Caldera acquired the UNIX business of SCO, Inc. in May cost some appreciable amount of time, while executing 2001. Much of the work this paper describes was done whi:[e the author was employed by SCO; for the purposes of this paper the generated code instead of interpreting bytecode will pre- two companies may be considered as the same. On the Caldera sumably save some amount of time each subsequent time OpenLinux® operating system, a different Java implementation the code executes. Depending upon the actual times in- is used that is not discussed in this paper. SIGPLAN Notices 36 Vol. 38(2) This Java implementation is based on the original, "clas- The code generator in sunwjit has two passes. The first sic VM" from Sun Microsystems, Inc., of which SCO is architecture-independent and scans the bytecode for and Caldera have been source licensees. Except for the basic block and stack state information. The second is JIT compiler, most of the rest of the Java virtual ma- architecture-specific and generates the actual machine chine is a straight port of the classic VM, from the Sun code. There is no global optimization attempted, al- Solaris operating system for the Intel IA-32 architec- though "lazy code generation" modeling of the bytecode ture, to the Open UNIX® 8, UnixWare® 7, and SCO stack at compile time is performed in the manner of [5], OpenServer TM 5 operating systems for IA-32. and various other local optimizations are done as well. In general, sunwjit tries to do a decent but not great The JIT compiler described here is based upon sunwjit, code generation job, quickly. There is no ability to have a JIT compiler for Solaris/IA-32 developed by a sepa- different levels of optimization performed. rate product group within Sun and licensed by SCO and Caldera. 2 Caldera has made a number of changes to sunwjit. Some have been due to porting differences between Solaris The sunwjit compiler is loaded and invoked per the JIT and the SCO/Caldera UNIX operating systems: signal Interface Specification [19]. When each Java class is handling for trapping null reference checks, disassembly first loaded, initialization processing is done to get ready logic for tracing through pre-JNI native method stubs, for JIT usage. This includes setting up bits of "shim" probe techniques for detecting stack overflow, and so code to handle flow of control transitions among inter- on. Others have been due to bug fixes, especially for preted code, compiled code, and machine code. An in- race conditions in the dynamic code patching logic. ternal JVM structure known as the "method block" has its "invoker" field [5] set to point to the JIT compiler. In addition, the infrastructure of the JIT has been mod- When a method in the class is to be compiled, the JIT ified to permit selective compilation, as described in the compiler gets control, translates the method's bytecode remainder of this paper. This includes having the JIT be down to native IA-32 machine code, and then changes able to read in and compile all of the "quick"-form byte- the method block invoker field to point to the gener- codes [9] that are generated after methods have been ated machine code. The call is then re-invoked, and on interpreted for the first time. This also includes hav- this and subsequent invocations the generated machine ing the JIT's exception handling and stack frame walk- code executes instead of the bytecode interpreter. In a back logic handle the case where a recursively called multithreaded program, compilation may proceed con- method has both interpreted and compiled instances on currently with execution (interpreted or compiled code) the JVM's internal stack frame structures at the same in other parts of the program; only certain operations time. These and other modifications become necessary pertaining to the class of the method being compiled are once any method may be interpreted an arbitrary num- locked out. This avoids some of the compilation ineffi- ber of times before it is compiled. ciencies described in [13]. Finally, the JIT compiler sometimes detects unusual Compiling of methods the first time they are called is bytecode situations that it cannot handle correctly, such done unconditionally in the original Sun version of sun- as empty loops and overflows of the IA-32 floating point wjit. The only times methods are interpreted are if the stack. In these cases, JIT compilation is abandoned, JIT is suppressed by a JVM command-line option, or if and the JVM will continue to interpret the method each the JIT has an internal error while compiling, or if the time it is called. This approach avoids adding excessive method belongs to one of the primordial classes that complexity to the JIT to handle rarely-encountered sit- execute before the Java j ava.lang. Comp±ler class is uations. It is also in accordance with the principle of loaded. In the latter case, primordial methods will get fall-safe optimization during compilation [15]. compiled the first time they are subsequently executed after the JIT compiler is loaded. Class initializers, which There are only two possible execution states within the are known to execute at most once, are never compiled. JVM for any particular execution of a method: it is ei- Methods that are never called are never compiled. ther fully interpreted or fully compiled (and for debug- ging purposes either state can be forced on for a partic- ular method by JVM invocation options). There are no 2The sunwjit JIT compiler also has a code generator for So- cases where compilation is started while the method is laris/SPARC and was used by Sun with the classic VM on that being interpreted or where code has been compiled for platform as well. Sun does not do further development work on use but is then backed out and interpretation is resumed. any version of sunwjit, concentrating instead on their successor HotSpot JVM technology. This "one or the other" nature simplifies the JVM and 37 times that are most likely to execute a lot during the whole no JIT always JIT ! heuristic application are those that have already been executing a actual javac 7.19 8.38 i 6.77 lot up until "now" in the application. This is a simplified view of the heuristic described in [1]. Table 1: Early results with JIT As shown in Table 1, by running javac with the en- vironment variable set to 40, the same translation ran makes for easier reproducibility and debugging of prob- 6.77 seconds, a speedup of 6% over no JIT and 19% over lems; more aggressive JVM compilation strategies often always running the JIT. run into difficulties in this area [4, 14]. This improvement scheme was limited, however, by not being on by default. It required users to have to know about the feature to make use of it and to have to ex- 3 The Simple Heuristics periment by trial-and-error to get a somewhat optimal value for the environment variable.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    11 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