skip to main content
10.1145/2816707.2816715acmconferencesArticle/Chapter ViewAbstractPublication PagessplashConference Proceedingsconference-collections
research-article

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

Published:21 October 2015Publication History

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.

References

  1. Adobe. Small Web Format, 2015. URL http://www.adobe. com/devnet/swf.html.Google ScholarGoogle Scholar
  2. Adobe. ActionScript, 2015. URL http://www.adobe.com/ devnet/actionscript/documentation.html.Google ScholarGoogle Scholar
  3. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  4. Box2d. Box2D Physics Engine, 2015. URL http://box2d.org/.Google ScholarGoogle Scholar
  5. C. Cifuentes. Reverse compilation techniques. PhD thesis, Queensland University of Technology, 1994.Google ScholarGoogle Scholar
  6. CLBG. Computer Language Benchmark Game, 2015. URL http://benchmarksgame.alioth.debian.org/.Google ScholarGoogle Scholar
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. DOI: 10.1145/115372.115320.Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. DB. DeltaBlue Benchmark, 2015. URL https://github.com/ xxgreg/deltablue.Google ScholarGoogle Scholar
  11. 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 ScholarGoogle Scholar
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle Scholar
  14. Google. Crankshaft: V8’s optimizing compiler, 2012. URL http://blog.chromium.org/2010/12/new-crankshaft-for-v8. html.Google ScholarGoogle Scholar
  15. Google. V8 JavaScript Engine, 2012. URL http://code.google. com/p/v8/.Google ScholarGoogle Scholar
  16. Google. Closure Compiler, 2015. URL https://developers. google.com/closure/compiler/.Google ScholarGoogle Scholar
  17. Google. Web Toolkit {GWT}, 2015. URL http://www. gwtproject.org/.Google ScholarGoogle Scholar
  18. Jaroslav Tulach. DukeScript: Bck2Brwsr VM, 2015. URL http://wiki.apidesign.org/wiki/Bck2Brwsr.Google ScholarGoogle Scholar
  19. jashkenas. List of Languages that compile to JavaScript, 2015. URL https://github.com/jashkenas/coffeescript/wiki/ List-of-languages-that-compile-to-JS.Google ScholarGoogle Scholar
  20. JBox2D. Piston Bechnmark, 2015. URL http://www.jbox2d. org/.Google ScholarGoogle Scholar
  21. 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 ScholarGoogle Scholar
  22. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  23. Linpack. Linpack Benchmark, 2015. URL http://www.netlib. org/benchmark/linpackjava/.Google ScholarGoogle Scholar
  24. Lisperator. UglifyJs2, 2015. URL http://lisperator.net/ uglifyjs/.Google ScholarGoogle Scholar
  25. LLVM. Clang, 2015. URL http://clang.llvm.org/.Google ScholarGoogle Scholar
  26. LLVM. Low-Level Virtual Machine, 2015. URL http://llvm. org/.Google ScholarGoogle Scholar
  27. 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 ScholarGoogle Scholar
  28. 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 ScholarGoogle Scholar
  29. J. Miecznikowski and L. Hendren. Decompiling java bytecode: Problems, traps and pitfalls. In Compiler construction, pages 111–127. Springer, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Mozilla. ASM.js, 2015. URL http://asmjs.org/.Google ScholarGoogle Scholar
  31. Mozilla. Developer Network (MDN): JavaScript, 2015. URL https://developer.mozilla.org/de/docs/Web/JavaScript.Google ScholarGoogle Scholar
  32. Mozilla. Shumway, 2015. URL http://mozilla.github.io/ shumway/.Google ScholarGoogle Scholar
  33. OCaml. The OCaml Language, 2015. URL https://ocaml.org/.Google ScholarGoogle Scholar
  34. OpenJDK. Graal, 2015. URL http://openjdk.java.net/projects/ graal/.Google ScholarGoogle Scholar
  35. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  36. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  37. Racket. The Racket Language, 2015. URL http://racket-lang. org/.Google ScholarGoogle Scholar
  38. SCI2. SciMark 2 Benchmark, 2015. URL http://math.nist. gov/scimark2/.Google ScholarGoogle Scholar
  39. Spec. SPECjbb2005 Java Server Benchmark, 2015. URL https://www.spec.org/jbb2005/.Google ScholarGoogle Scholar
  40. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  41. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  42. TEA. TEA VM, 2015. URL http://teavm.org/.Google ScholarGoogle Scholar
  43. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  44. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  45. DOI: 10.1145/2594291.2594293.Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. J. Vouillon and V. Balat. From bytecode to javascript: the js of ocaml compiler. Software: Practice and Experience, 44 (8):951–972, 2014.Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. C. Wang, J. Hill, J. Knight, and J. Davidson. Software tamper resistance: Obstructing static analysis of programs. Technical report, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. H. S. Warren. Hacker’s delight. Addison-Wesley, Upper Saddle River, NJ, 2nd ed. edition, 2013. ISBN 0321842685.Google ScholarGoogle Scholar
  49. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  50. DOI: 10.1016/j.scico.2009.01.002.Google ScholarGoogle ScholarDigital LibraryDigital Library
  51. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  52. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  53. D. Yoo and S. Krishnamurthi. Whalesong: Running racket in the browser. In Proceedings of the Dynamic Languages Symposium, pages 97–108. ACM, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  54. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  55. DOI: 10.1145/2048147.2048224.Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

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

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in
    • Published in

      cover image ACM Conferences
      DLS 2015: Proceedings of the 11th Symposium on Dynamic Languages
      October 2015
      176 pages
      ISBN:9781450336901
      DOI:10.1145/2816707
      • cover image ACM SIGPLAN Notices
        ACM SIGPLAN Notices  Volume 51, Issue 2
        DLS '15
        Feburary 2016
        176 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/2936313
        • Editor:
        • Andy Gill
        Issue’s Table of Contents

      Copyright © 2015 ACM

      Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 21 October 2015

      Permissions

      Request permissions about this article.

      Request Permissions

      Check for updates

      Qualifiers

      • research-article

      Acceptance Rates

      Overall Acceptance Rate32of77submissions,42%

      Upcoming Conference

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader