Java Magazine, March/April 2016
ORACLE COM JAVAMAGAZINE MARCH APRIL 2016 17 inside java high and low level optimizations that the compiler performs when generating machine code OpenJDK includes two JIT compilers often known as the client and server compilers Originally you had to pick one or the other on the java command line using either the client or server options In recent JDK releases the default configuration is to use them both in what is called tiered compilation mode You can see tiered compilation in action in the previous trace Method fib is first compiled at Level 3 that is using the client compiler but including code to count method calls and paths taken at branches fib is then recompiled at Level 4 which uses the server compiler The client JIT compiler was designed for desktop applications that typically run only for a short time possibly only for a few seconds or perhaps a few minutes In contrast the server JIT compiler was intended for applications that run for hours days or even months Both compilers optimize but they make very different trade offs Essentially the client JIT compiler performs less optimization than the server JIT producing slower compiled code but generating it more quickly The trade off is easy to see For example in the OpenJDK source code from the OpenJDK repository the Java library source is in the subdirectory jdk src share classes We ran javadoc with only the client compiler as shown below where the input file jdkfiles lists all Java source files found below src share classes time javadoc quiet J XX TieredStopAtLevel 2 @ jdkfiles real 4m41775s user 5m31390s sys 0m1862s Command line option J is used to pass an argument to the underlying JVM The option XX TieredStopAtLevel 2 asks the JVM to execute only at Level 1 interpreted or Level 2 client compiler without profiling To run the JVM using only the server compiler you would pass the option XX TieredCompilation which switches off tiered compilation It generates these timings time javadoc quiet J XX TieredCompilation @ jdkfiles real 3m30083s user 4m50410s sys 0m1880s Going to the server compiler has dropped the elapsed time from 4 minutes and 40 seconds to 3 minutes and 30 seconds or a reduction of 25 percent It is interesting to look at the change in user time which is the amount of CPU time used across all of the cores In the first run 50 seconds more CPU time was used than real elapsed time In the second run there was 1 minute and 20 seconds of extra CPU time a 60 percent increase So 60 percent more JIT compiler time cut 25 percent off the total execution time JIT compilation is done in background threads normally on an otherwise idle CPU So compilation doesnt slow down an application by stealing the CPU The usefulness of a JIT compiler depends on two things the speed of the code it generates and how fast it delivers that code Delivery time is important because execution switches to compiled code only after The method is called enough times to be queued for compilation The compiler dequeues the method and generates the compiled code The server compiler produces faster code but that faster code has some catching up to do Because each server compiled method arrives later than the corresponding client compiled method methods that are hot when scheduled for compilation might have gone cold by the time the compiled code is
You must have JavaScript enabled to view digital editions.