En savoir plus
With the growing popularity of Java, dynamic compilation has received increased attention. It improves the performance of virtual machines by translating the bytecodes of an application into optimized machine code while the application is running. Since compilation time adds to run time, a dynamic compiler must achieve a trade-off between time spent on optimizations and execution speed of the resulting machine code. A new escape analysis algorithm in the dynamic compiler of Sun Microsystems' Java HotSpot VM identifies objects that are accessible only by a single method or thread. Its results are used to replace fields of objects with scalar variables, to allocate objects on the stack instead of the heap, and to remove synchronization. The produced machine code is smaller and executes faster because fewer objects are allocated on the heap and the garbage collector runs lessfrequently. An interprocedural analysis supports the compiler in inlining decisions and detects parameters that can be allocated in the stack frame of the caller. When the machine code needs to be deoptimized because dynamic class loading invalidates assumptions of the compiler, the optimized objects are reallocated on the heap and relocked as necessary. This book presents the new escape analysis algorithm and illustrates its work with several examples. It describes the implemented optimizations and evaluates them on a set of typical benchmarks and applications. Special attention is paid to the modifications of the garbage collector and the deoptimization framework that allows a safe execution of optimized methods.