Christian Wimmer

Java-to-JavaScript Translation via Structured Control Flow Reconstruction of Compiler IR

David Leopoldseder, Lukas Stadler, Christian Wimmer, Hanspeter Mössenböck: Java-to-JavaScript Translation via Structured Control Flow Reconstruction of Compiler IR. In Proceedings of the Symposium on Dynamic Languages, pages 91–103. ACM Press, 2015. doi:10.1145/2816707.2816715

Download as PDF
© ACM, 2015.

Abstract

We present an approach to cross-compile Java bytecodes to Java-Script, building on existing Java optimizing compiler technology. Static analysis determines which Java classes and methods are reachable. These are then translated to JavaScript using a re-configured Java just-in-time compiler with a new back end that generates JavaScript instead of machine code. Standard compiler optimizations such as method inlining and global value numbering, as well as advanced optimizations such as escape analysis, lead to compact and optimized JavaScript code. Compiler IR is unstructured, so structured control flow needs to be reconstructed before code generation is possible. We present details of our control flow reconstruction algorithm. Our system is based on Graal, an open-source optimizing compiler for the Java HotSpot VM and other VMs. The modular and VM-independent architecture of Graal allows us to reuse the intermediate representation, the bytecode parser, and the high-level optimizations. Our custom back end first performs control flow reconstruction and then JavaScript code generation. The generated JavaScript undergoes a set of optimizations to increase readability and performance. Static analysis is performed on the Graal intermediate representation as well. Benchmark results for medium-sized Java benchmarks such as SPECjbb2005 run with acceptable performance on the V8 JavaScript VM.