Java-to-JavaScript translation via structured control flow reconstruction of compiler IR

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.

[1]  Laurie Hendren,et al.  Decompiling Java Bytecode: Problems, Traps and Pitfalls , 2002, CC.

[2]  Jérôme Vouillon,et al.  From bytecode to JavaScript: the Js_of_ocaml compiler , 2014, Softw. Pract. Exp..

[3]  Hanspeter Mössenböck,et al.  Array bounds check elimination in the context of deoptimization , 2009, Sci. Comput. Program..

[4]  Laurie Hendren,et al.  Soot: a Java bytecode optimization framework , 2010, CASCON.

[5]  Alon Zakai Emscripten: an LLVM-to-JavaScript compiler , 2011, OOPSLA Companion.

[6]  Mark N. Wegman,et al.  Efficiently computing static single assignment form and the control dependence graph , 1991, TOPL.

[7]  Cliff Click,et al.  The Java HotSpot Server Compiler , 2001, Java Virtual Machine Research and Technology Symposium.

[8]  Christian Wimmer,et al.  One VM to rule them all , 2013, Onward!.

[9]  Hanspeter Mössenböck,et al.  An intermediate representation for speculative optimizations in a dynamic compiler , 2013, VMIL '13.

[10]  Christian Wimmer,et al.  Self-optimizing AST interpreters , 2012, DLS.

[11]  Frank Yellin,et al.  The Java Virtual Machine Specification , 1996 .

[12]  Laurie J. Hendren,et al.  Decompiling Java using staged encapsulation , 2001, Proceedings Eighth Working Conference on Reverse Engineering.

[13]  Henry S. Warren,et al.  Hacker's Delight , 2002 .

[14]  John Vilk,et al.  Doppio: breaking the browser language barrier , 2014, PLDI.

[15]  T. Laszlo,et al.  OBFUSCATING C++ PROGRAMS VIA CONTROL FLOW FLATTENING , 2009 .

[16]  Shriram Krishnamurthi,et al.  Whalesong: running racket in the browser , 2013, DLS '13.

[17]  Gilad Bracha,et al.  The Java Virtual Machine Specification, Java SE 8 Edition , 2013 .

[18]  Alon Zakai,et al.  Cross-compiling Java to JavaScript via tool-chaining , 2013, PPPJ.

[19]  Jack W. Davidson,et al.  Software Tamper Resistance: Obstructing Static Analysis of Programs , 2000 .

[20]  Hanspeter Mössenböck,et al.  Graal IR : An Extensible Declarative Intermediate Representation , 2013 .

[21]  Cliff Click,et al.  The java hotspot TM server compiler , 2001 .

[22]  Cliff Click,et al.  Global code motion/global value numbering , 1995, PLDI '95.

[23]  Laurie J. Hendren,et al.  Taming control flow: a structured approach to eliminating goto statements , 1994, Proceedings of 1994 IEEE International Conference on Computer Languages (ICCL'94).

[24]  Hanspeter Mössenböck,et al.  An experimental study of the influence of dynamic compiler optimizations on Scala performance , 2013, SCALA@ECOOP.

[25]  Cristina Cifuentes,et al.  Reverse compilation techniques , 1994 .

[26]  David F. Bacon,et al.  Compiler transformations for high-performance computing , 1994, CSUR.

[27]  Hanspeter Mössenböck,et al.  Partial Escape Analysis and Scalar Replacement for Java , 2014, CGO '14.