skip to main content
research-article

Zero-overhead metaprogramming: reflection and metaobject protocols fast and without compromises

Published:03 June 2015Publication History
Skip Abstract Section

Abstract

Runtime metaprogramming enables many useful applications and is often a convenient solution to solve problems in a generic way, which makes it widely used in frameworks, middleware, and domain-specific languages. However, powerful metaobject protocols are rarely supported and even common concepts such as reflective method invocation or dynamic proxies are not optimized. Solutions proposed in literature either restrict the metaprogramming capabilities or require application or library developers to apply performance improving techniques. For overhead-free runtime metaprogramming, we demonstrate that dispatch chains, a generalized form of polymorphic inline caches common to self-optimizing interpreters, are a simple optimization at the language-implementation level. Our evaluation with self-optimizing interpreters shows that unrestricted metaobject protocols can be realized for the first time without runtime overhead, and that this optimization is applicable for just-in-time compilation of interpreters based on meta-tracing as well as partial evaluation. In this context, we also demonstrate that optimizing common reflective operations can lead to significant performance improvements for existing applications.

References

  1. K. Asai. Compiling a Reflective Language Using MetaOCaml. In Proceedings of the 2014 International Conference on Generative Programming: Concepts and Experiences, GPCE 2014, pages 113–122. ACM, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. V. Bala, E. Duesterwald, and S. Banerjia. Dynamo: A Transparent Dynamic Optimization System. In Proceedings of the ACM SIGPLAN 2000 Conference on Programming Language Design and Implementation, PLDI ’00, pages 1–12. ACM, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. C. F. Bolz and L. Tratt. The Impact of Meta-Tracing on VM Design and Implementation. Science of Computer Programming, 2013.Google ScholarGoogle Scholar
  4. C. F. Bolz, A. Cuni, M. Fijalkowski, and A. Rigo. Tracing the Meta-level: PyPy’s Tracing JIT Compiler. In Proceedings of the 4th Workshop on the Implementation, Compilation, Optimization of Object-Oriented Languages and Programming Systems, ICOOOLPS ’09, pages 18–25. ACM, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. G. T. Brown. Ruby Best Practices. O’Reilly, Sebastopol, CA, June 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. S. Brunthaler. Efficient Interpretation Using Quickening. In Proceedings of the 6th Symposium on Dynamic Languages, number 12 in DLS, pages 1–14. ACM, Oct. 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. K. Casey, M. A. Ertl, and D. Gregg. Optimizing Indirect Branch Prediction Accuracy in Virtual Machine Interpreters. ACM Trans. Program. Lang. Syst., 29(6):37, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. S. Chiba. A Study of Compile-time Metaobject Protocol. Phd thesis, University of Tokyo, November 1996.Google ScholarGoogle Scholar
  9. L. P. Deutsch and A. M. Schiffman. Efficient implementation of the smalltalk-80 system. In POPL ’84: Proceedings of the 11th ACM SIGACT-SIGPLAN symposium on Principles of programming languages, pages 297–302. ACM, 1984. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Z. DeVito, D. Ritchie, M. Fisher, A. Aiken, and P. Hanrahan. Firstclass Runtime Generation of High-performance Types Using Exotypes. In Proceedings of the 35th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI ’14, pages 77–88. ACM, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. M. Fowler. Domain-Specific Languages. Addison-Wesley, October 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. A. Gal, C. W. Probst, and M. Franz. HotpathVM: An Effective JIT Compiler for Resource-constrained Devices. In Proc. of VEE, pages 144–153. ACM, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. M. Golm and J. Kleinöder. Jumping to the Meta Level. In P. Cointe, editor, Meta-Level Architectures and Reflection, volume 1616 of LNCS, pages 22–39. Springer, 1999.Google ScholarGoogle ScholarCross RefCross Ref
  14. M. Grimmer, M. Rigger, R. Schatz, L. Stadler, and H. Mössenböck. TruffleC: Dynamic Execution of C on a Java Virtual Machine. In Proc of the Conference on Principles and Practices of Programming on the Java Platform: Virtual Machines, Languages, and Tools, PPPJ ’14, pages 17–26. ACM, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. M. Haupt, R. Hirschfeld, T. Pape, G. Gabrysiak, S. Marr, A. Bergmann, A. Heise, M. Kleine, and R. Krahn. The SOM Family: Virtual Machines for Teaching and Research. In Proceedings of the 15th Annual Conference on Innovation and Technology in Computer Science Education (ITiCSE), pages 18–22. ACM Press, June 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. C. Humer, C. Wimmer, C. Wirth, A. Wöß, and T. Würthinger. A Domain-Specific Language for Building Self-Optimizing AST Interpreters. In Proceedings of the 13th International Conference on Generative Programming: Concepts and Experiences, GPCE ’14. ACM, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. U. Hölzle, C. Chambers, and D. Ungar. Optimizing Dynamically-Typed Object-Oriented Languages With Polymorphic Inline Caches. In ECOOP ’91: European Conference on Object-Oriented Programming, volume 512 of LNCS, pages 21–38. Springer, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. H. Inoue, H. Hayashizaki, P. Wu, and T. Nakatani. Adaptive multilevel compilation in a trace-based java jit compiler. In Proceedings of the ACM International Conference on Object Oriented Programming Systems Languages and Applications, OOPSLA ’12, pages 179–194, New York, NY, USA, 2012. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. T. Kalibera, P. Maj, F. Morandat, and J. Vitek. A Fast Abstract Syntax Tree Interpreter for R. In Proceedings of the 10th ACM SIGPLAN/SIGOPS International Conference on Virtual Execution Environments, VEE’14, pages 89–102. ACM, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. G. Kiczales, J. des Rivières, and D. G. Bobrow. The Art of the Metaobject Protocol. The MIT Press, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. S. Marr and T. D’Hondt. Identifying A Unifying Mechanism for the Implementation of Concurrency Abstractions on Multi-Language Virtual Machines. In Objects, Models, Components, Patterns, 50th International Conference, TOOLS 2012, volume 7304 of LNCS, pages 171–186. Springer, May 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. S. Marr, T. Pape, and W. De Meuter. Are We There Yet? Simple Language Implementation Techniques for the 21st Century. IEEE Software, 31(5):60–67, September 2014. ISSN 0740-7459.Google ScholarGoogle ScholarCross RefCross Ref
  23. H. Masuhara, S. Matsuoka, K. Asai, and A. Yonezawa. Compiling Away the Meta-level in Object-oriented Concurrent Reflective Languages Using Partial Evaluation. In Proceedings of the Tenth Annual Conference on Object-oriented Programming Systems, Languages, and Applications, OOPSLA ’95, pages 300–315. ACM, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. R. Olsen. Eloquent Ruby. Professional Ruby. Addison-Wesley, Upper Saddle River, NJ, February 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. J. R. Rose. Bytecodes meet Combinators: invokedynamic on the JVM. In Proceedings of the Third Workshop on Virtual Machines and Intermediate Languages, pages 1–11. ACM, Oct. 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. C. Seaton, M. L. Van De Vanter, and M. Haupt. Debugging at Full Speed. In Proceedings of the Workshop on Dynamic Languages and Applications, Dyla’14, pages 2:1–2:13. ACM, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. A. Shali and W. R. Cook. Hybrid Partial Evaluation. In Proceedings of the 2011 ACM International Conference on Object Oriented Programming Systems Languages and Applications, OOPSLA ’11, pages 375–390. ACM, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. G. Sullivan. Dynamic Partial Evaluation. In Programs as Data Objects, volume 2053 of LNCS, pages 238–256. Springer, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. W. Taha and T. Sheard. Multi-stage Programming with Explicit Annotations. In Proceedings of the 1997 ACM SIGPLAN Symposium on Partial Evaluation and Semantics-based Program Manipulation, PEPM ’97, pages 203–217. ACM, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. E. Tanter, J. Noyé, D. Caromel, and P. Cointe. Partial Behavioral Reflection: Spatial and Temporal Selection of Reification. In Proceedings of the 18th Annual ACM SIGPLAN Conference on Objectoriented Programing, Systems, Languages, and Applications, pages 27–46. ACM, October 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. S. Tobin-Hochstadt, V. St-Amour, R. Culpepper, M. Flatt, and M. Felleisen. Languages as libraries. In Proceedings of the 32nd ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI ’11, pages 132–141. ACM, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. L. Tratt. Compile-time Meta-programming in a Dynamically Typed OO Language. In Proceedings of the 2005 Symposium on Dynamic Languages, DLS ’05, pages 49–63. ACM, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. T. Würthinger, A. Wöß, L. Stadler, G. Duboscq, D. Simon, and C. Wimmer. Self-Optimizing AST Interpreters. In Proceedings of the 8th Dynamic Languages Symposium, DLS’12, pages 73–82, October 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. 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 2013 ACM International Symposium on New Ideas, New Paradigms, and Reflections on Programming & Software, Onward!’’13, pages 187–204. ACM, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. A. Wöß, C. Wirth, D. Bonetta, C. Seaton, C. Humer, and H. Mössenböck. An Object Storage Model for the Truffle Language Implementation Framework. In Proceedings of the 2014 International Conference on Principles and Practices of Programming on the Java Platform: Virtual Machines, Languages, and Tools, PPPJ ’14. ACM, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. W. Zhang, P. Larsen, S. Brunthaler, and M. Franz. Accelerating Iterators in Optimizing AST Interpreters. In Proceedings of the 2014 ACM International Conference on Object Oriented Programming Systems Languages & Applications, OOPSLA ’’14, pages 727–743. ACM, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Zero-overhead metaprogramming: reflection and metaobject protocols fast and without compromises

      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

      Full Access

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!