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

Cited By

View all
  • (2023)Transpilers: A Systematic Mapping Review of Their Usage in Research and IndustryApplied Sciences10.3390/app1306366713:6(3667)Online publication date: 13-Mar-2023
  • (2021)CompGen: generation of fast JIT compilers in a multi-language VMProceedings of the 17th ACM SIGPLAN International Symposium on Dynamic Languages10.1145/3486602.3486930(35-47)Online publication date: 19-Oct-2021
  • (2019)Supporting on-stack replacement in unstructured languages by loop reconstruction and extractionProceedings of the 16th ACM SIGPLAN International Conference on Managed Programming Languages and Runtimes10.1145/3357390.3361030(1-13)Online publication date: 21-Oct-2019
  • Show More Cited By

Index Terms

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

    Recommendations

    Comments

    Information & Contributors

    Information

    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
    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]

    Sponsors

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 21 October 2015

    Permissions

    Request permissions for this article.

    Check for updates

    Author Tags

    1. Graal
    2. Java
    3. JavaScript
    4. ahead-of-time compilation
    5. optimization

    Qualifiers

    • Research-article

    Conference

    SPLASH '15
    Sponsor:

    Acceptance Rates

    Overall Acceptance Rate 32 of 77 submissions, 42%

    Upcoming Conference

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • Downloads (Last 12 months)18
    • Downloads (Last 6 weeks)1
    Reflects downloads up to 12 Sep 2024

    Other Metrics

    Citations

    Cited By

    View all
    • (2023)Transpilers: A Systematic Mapping Review of Their Usage in Research and IndustryApplied Sciences10.3390/app1306366713:6(3667)Online publication date: 13-Mar-2023
    • (2021)CompGen: generation of fast JIT compilers in a multi-language VMProceedings of the 17th ACM SIGPLAN International Symposium on Dynamic Languages10.1145/3486602.3486930(35-47)Online publication date: 19-Oct-2021
    • (2019)Supporting on-stack replacement in unstructured languages by loop reconstruction and extractionProceedings of the 16th ACM SIGPLAN International Conference on Managed Programming Languages and Runtimes10.1145/3357390.3361030(1-13)Online publication date: 21-Oct-2019
    • (2018)Dominance-based duplication simulation (DBDS): code duplication to enable compiler optimizationsProceedings of the 2018 International Symposium on Code Generation and Optimization - CGO 201810.1145/3179541.3168811(126-137)Online publication date: 2018
    • (2018)Dominance-based duplication simulation (DBDS): code duplication to enable compiler optimizationsProceedings of the 2018 International Symposium on Code Generation and Optimization10.1145/3168811(126-137)Online publication date: 24-Feb-2018
    • (2024)GraalSP: Polyglot, efficient, and robust machine learning-based static profilerJournal of Systems and Software10.1016/j.jss.2024.112058213(112058)Online publication date: Jul-2024
    • (2023)Beehive SPIR-V Toolkit: A Composable and Functional API for Runtime SPIR-V Code GenerationProceedings of the 15th ACM SIGPLAN International Workshop on Virtual Machines and Intermediate Languages10.1145/3623507.3623555(61-72)Online publication date: 18-Oct-2023
    • (2021)CompGen: generation of fast JIT compilers in a multi-language VMProceedings of the 17th ACM SIGPLAN International Symposium on Dynamic Languages10.1145/3486602.3486930(35-47)Online publication date: 19-Oct-2021

    View Options

    Get Access

    Login options

    View options

    PDF

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    Media

    Figures

    Other

    Tables

    Share

    Share

    Share this Publication link

    Share on social media