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.
- Adobe. Small Web Format, 2015. URL http://www.adobe. com/devnet/swf.html.Google Scholar
- Adobe. ActionScript, 2015. URL http://www.adobe.com/ devnet/actionscript/documentation.html.Google Scholar
- D. F. Bacon, S. L. Graham, and O. J. Sharp. Compiler transformations for high-performance computing. ACM Computing Surveys (CSUR), 26(4):345–420, 1994. Google ScholarDigital Library
- Box2d. Box2D Physics Engine, 2015. URL http://box2d.org/.Google Scholar
- C. Cifuentes. Reverse compilation techniques. PhD thesis, Queensland University of Technology, 1994.Google Scholar
- CLBG. Computer Language Benchmark Game, 2015. URL http://benchmarksgame.alioth.debian.org/.Google Scholar
- C. Click. Global code motion/global value numbering. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation, pages 246–257. ACM Press, 1995. DOI: 10.1145/207110.207154. Google ScholarDigital Library
- R. Cytron, J. Ferrante, B. K. Rosen, M. N. Wegman, and F. K. Zadeck. Efficiently computing static single assignment form and the control dependence graph. ACM Transactions on Programming Languages and Systems, 13(4):451–490, 1991. Google ScholarDigital Library
- DOI: 10.1145/115372.115320.Google ScholarDigital Library
- DB. DeltaBlue Benchmark, 2015. URL https://github.com/ xxgreg/deltablue.Google Scholar
- G. Duboscq, L. Stadler, T. Würthinger, D. Simon, C. Wimmer, and H. Mössenböck. Graal IR: An extensible declarative intermediate representation. In Proceedings of the Asia-Pacific Programming Languages and Compilers Workshop. ACM Press, 2013.Google Scholar
- G. Duboscq, T. Würthinger, L. Stadler, C. Wimmer, D. Simon, and H. Mössenböck. An intermediate representation for speculative optimizations in a dynamic compiler. In Proceedings of the ACM Workshop on Virtual Machines and Intermediate Languages, pages 1–10. ACM Press, 2013. DOI: 10.1145/2542142.2542143. Google ScholarDigital Library
- A. Erosa and L. J. Hendren. Taming control flow: A structured approach to eliminating goto statements. In In Proceedings of the International Conference on Computer Languages, pages 229–240. IEEE Computer Society Press, 1994. DOI: 10.1109/ICCL.1994.288377.Google Scholar
- Google. Crankshaft: V8’s optimizing compiler, 2012. URL http://blog.chromium.org/2010/12/new-crankshaft-for-v8. html.Google Scholar
- Google. V8 JavaScript Engine, 2012. URL http://code.google. com/p/v8/.Google Scholar
- Google. Closure Compiler, 2015. URL https://developers. google.com/closure/compiler/.Google Scholar
- Google. Web Toolkit {GWT}, 2015. URL http://www. gwtproject.org/.Google Scholar
- Jaroslav Tulach. DukeScript: Bck2Brwsr VM, 2015. URL http://wiki.apidesign.org/wiki/Bck2Brwsr.Google Scholar
- jashkenas. List of Languages that compile to JavaScript, 2015. URL https://github.com/jashkenas/coffeescript/wiki/ List-of-languages-that-compile-to-JS.Google Scholar
- JBox2D. Piston Bechnmark, 2015. URL http://www.jbox2d. org/.Google Scholar
- T. Lászl´o and Á. Kiss. Obfuscating c++ programs via control flow flattening. Annales Universitatis Scientarum Budapestinensis de Rolando Eötvös Nominatae, Sectio Computatorica, 30:3–19, 2009.Google Scholar
- T. Lindholm, F. Yellin, G. Bracha, and A. Buckley. The Java Virtual Machine Specification, Java SE 8 Edition, 2015. URL https://docs.oracle.com/javase/specs/jvms/se8/jvms8.pdf. Google ScholarDigital Library
- Linpack. Linpack Benchmark, 2015. URL http://www.netlib. org/benchmark/linpackjava/.Google Scholar
- Lisperator. UglifyJs2, 2015. URL http://lisperator.net/ uglifyjs/.Google Scholar
- LLVM. Clang, 2015. URL http://clang.llvm.org/.Google Scholar
- LLVM. Low-Level Virtual Machine, 2015. URL http://llvm. org/.Google Scholar
- J. Miecznikowski and L. Hendren. Decompiling java using staged encapsulation. In Reverse Engineering, 2001. Proceedings. Eighth Working Conference on, pages 368–374. IEEE, 2001. DOI: 10.1109/WCRE.2001.957845. Google Scholar
- J. Miecznikowski and L. Hendren. Decompiling java bytecode: Problems, traps and pitfalls. In Compiler Construction, volume 2304, pages 111–127. Springer Berlin Heidelberg, 2002. DOI: 10.1007/3-540-45937-5˙10. Google Scholar
- J. Miecznikowski and L. Hendren. Decompiling java bytecode: Problems, traps and pitfalls. In Compiler construction, pages 111–127. Springer, 2002. Google ScholarDigital Library
- Mozilla. ASM.js, 2015. URL http://asmjs.org/.Google Scholar
- Mozilla. Developer Network (MDN): JavaScript, 2015. URL https://developer.mozilla.org/de/docs/Web/JavaScript.Google Scholar
- Mozilla. Shumway, 2015. URL http://mozilla.github.io/ shumway/.Google Scholar
- OCaml. The OCaml Language, 2015. URL https://ocaml.org/.Google Scholar
- OpenJDK. Graal, 2015. URL http://openjdk.java.net/projects/ graal/.Google Scholar
- M. Paleczny, C. Vick, and C. Click. The Java HotSpot TM Server compiler. In Proceedings of the Symposium on Java Virtual Machine Research and Technology, pages 1–12, 2001. Google ScholarDigital Library
- A. Puder, V. Woeltjen, and A. Zakai. Cross-compiling Java to JavaScript via tool-chaining. In Proceedings of the International Conference on the Principles and Practice of Programming in Java, pages 25–34. ACM Press, 2013. DOI: 10.1145/2500828.2500831. Google ScholarDigital Library
- Racket. The Racket Language, 2015. URL http://racket-lang. org/.Google Scholar
- SCI2. SciMark 2 Benchmark, 2015. URL http://math.nist. gov/scimark2/.Google Scholar
- Spec. SPECjbb2005 Java Server Benchmark, 2015. URL https://www.spec.org/jbb2005/.Google Scholar
- L. Stadler, G. Duboscq, H. Mössenböck, T. Würthinger, and D. Simon. An experimental study of the influence of dynamic compiler optimizations on scala performance. In Proceedings of the 4th Workshop on Scala, page 9. ACM, 2013. DOI: 10.1145/2489837.2489846. Google ScholarDigital Library
- L. Stadler, T. Würthinger, and H. Mössenböck. Partial escape analysis and scalar replacement for Java. In Proceedings of the International Symposium on Code Generation and Optimization, page 165. ACM, 2014. DOI: 10.1145/2544137.2544157. Google ScholarDigital Library
- TEA. TEA VM, 2015. URL http://teavm.org/.Google Scholar
- R. Vallée-Rai, P. Co, E. Gagnon, L. Hendren, P. Lam, and V. Sundaresan. Soot-a java bytecode optimization framework. In Proceedings of the 1999 conference of the Centre for Advanced Studies on Collaborative research, page 13. IBM Press, 1999. Google ScholarDigital Library
- J. Vilk and E. D. Berger. Doppio: breaking the browser language barrier. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation, pages 508–518. ACM, 2014. Google ScholarDigital Library
- DOI: 10.1145/2594291.2594293.Google ScholarDigital Library
- J. Vouillon and V. Balat. From bytecode to javascript: the js of ocaml compiler. Software: Practice and Experience, 44 (8):951–972, 2014.Google ScholarDigital Library
- C. Wang, J. Hill, J. Knight, and J. Davidson. Software tamper resistance: Obstructing static analysis of programs. Technical report, 2000. Google ScholarDigital Library
- H. S. Warren. Hacker’s delight. Addison-Wesley, Upper Saddle River, NJ, 2nd ed. edition, 2013. ISBN 0321842685.Google Scholar
- T. Würthinger, C. Wimmer, and H. Mössenböck. Array bounds check elimination in the context of deoptimization. Science of Computer Programming, 74(5-6), 2009. Google ScholarDigital Library
- DOI: 10.1016/j.scico.2009.01.002.Google ScholarDigital Library
- T. Würthinger, A. Wöß, L. Stadler, G. Duboscq, D. Simon, and C. Wimmer. Self-optimizing AST interpreters. In Proceedings of the Dynamic Languages Symposium, page 73. ACM Press, 2012. DOI: 10.1145/2384577.2384587. Google ScholarDigital Library
- T. Würthinger, C. Wimmer, A. Wöß, L. Stadler, G. Duboscq, C. Humer, G. Richards, D. Simon, and M. Wolczko. One VM to rule them all. In Proceedings of the ACM international symposium on New ideas, new paradigms, and reflections on programming and software, pages 187–204, 2013. DOI: 10.1145/2509578.2509581. Google ScholarDigital Library
- D. Yoo and S. Krishnamurthi. Whalesong: Running racket in the browser. In Proceedings of the Dynamic Languages Symposium, pages 97–108. ACM, 2013. Google ScholarDigital Library
- A. Zakai. Emscripten: An LLVM-to-JavaScript compiler. In Companion to the ACM SIGPLAN Conference on Object Oriented Programming Systems, Languages, and Applications, pages 301–312. ACM Press, 2011. Google ScholarDigital Library
- DOI: 10.1145/2048147.2048224.Google ScholarDigital Library
Index Terms
- Java-to-JavaScript translation via structured control flow reconstruction of compiler IR
Recommendations
Truffle: a self-optimizing runtime system
SPLASH '12: Proceedings of the 3rd annual conference on Systems, programming, and applications: software for humanityWe present Truffle, a novel framework for implementing managed languages in Java™. The language implementer writes an AST interpreter, which is integrated in our framework that allows tree rewriting during AST interpretation. Tree rewrites incorporate ...
Java-to-JavaScript translation via structured control flow reconstruction of compiler IR
DLS '15We 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-...
An efficient native function interface for Java
PPPJ '13: Proceedings of the 2013 International Conference on Principles and Practices of Programming on the Java Platform: Virtual Machines, Languages, and ToolsWe present an efficient and dynamic approach for calling native functions from within Java. Traditionally, programmers use the Java Native Interface (JNI) to call such functions. This paper introduces a new mechanism which we tailored specifically ...
Comments