skip to main content
10.1145/2543728.2543739acmconferencesArticle/Chapter ViewAbstractPublication PagespepmConference Proceedingsconference-collections
research-article

Compile-time reflection and metaprogramming for Java

Authors Info & Claims
Published:11 January 2014Publication History

ABSTRACT

Java reflection enables us to write reusable programs that are independent of certain classes. However, when runtime performance is a big concern, we propose to use compile-time reflection for writing metaprograms that generate non-reflective class/type specific code, which has lower runtime cost.

We proposed both compile-time reflection and metaprogramming for Java, and extended our previous work on pattern-based traits. Pattern-based traits integrate pattern-based reflection with flexible composition of traits. They are capable of pattern-matching over class members and generating expressive code. We add and formalize pattern-based reflection at the statement-level, which enables a meta program to generate statements. We add reified generics for pattern-based traits, which enables a pattern to iterate over any class when traits are instantiated. We implemented an ORM tool (called PtjORM) using pattern-based traits. PtjORM uses compile-time reflection and our benchmark tests show that it has competitive runtime performance compared to the mainstream Java ORM tools.

References

  1. David Abrahams and Aleksey Gurtovoy. C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond (C++ in Depth Series). Addison-Wesley Professional, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Michael J. Carey, David J. DeWitt, and Jeffrey F. Naughton. The 007 benchmark. In Proceedings of the 1993 ACM SIGMOD international conference on Management of data, SIGMOD '93, pages 12--21, New York, NY, USA, 1993. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Dirk Draheim, Christof Lutteroth, and Gerald Weber. A type system for reflective program generators. In Proc. of the Conf. on Generative Programming and Component Engineering. Springer, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Derek Dreyer and Andreas Rossberg. Mixin' up the ml module system. In Proc. of the 13th ACM SIGPLAN International Conference on Functional Programming. ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Stéphane Ducasse, Oscar Nierstrasz, Nathanael Schärli, Roel Wuyts, and Andrew P. Black. Traits: A mechanism for fine-grained reuse. ACM Trans. Program. Lang. Syst., 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Manuel Fähndrich, Michael Carbin, and James R. Larus. Reflective program generation with patterns. In Proc. of the Conf. on Generative Programming and Component Engineering. ACM, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Kathleen Fisher. A typed calculus of traits. In Workshop on Foundations of Object-oriented Programming, 2004.Google ScholarGoogle Scholar
  8. Matthew Flatt, Shriram Krishnamurthi, and Matthias Felleisen. Classes and mixins. In Proc. of the Symposium on Principles of Programming Languages. ACM, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Ira R. Forman and Nate Forman. Java Reflection in Action (In Action series). Manning Publications Co., Greenwich, CT, USA, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Ronald Garcia and Andrew Lumsdaine. Toward foundations for type-reflective metaprogramming. In Proc. of the Conf. on Generative Programming and Component Engineering. ACM, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Shan Shan Huang and Yannis Smaragdakis. Expressive and safe static reflection with morphj. In Proc. of the Conf. on Programming Language Design and Implementation. ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Shan Shan Huang, David Zook, and Yannis Smaragdakis. Morphing: Safely shaping a class in the image of others. In Proc. of the European Conf. on Object-Oriented Programming. Springer-Verlag, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Shan Shan Huang, David Zook, and Yannis Smaragdakis. Statically safe program generation with safegen. Sci. Comput. Program., 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Ali Ibrahim and William R. Cook. Automatic prefetching by traversal profiling in object persistence architectures. In Proceedings of the 20th European conference on Object-Oriented Programming, ECOOP'06, pages 50--73, Berlin, Heidelberg, 2006. Springer-Verlag. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Atsushi Igarashi, Benjamin C. Pierce, and Philip Wadler. Featherweight Java: a minimal core calculus for Java and GJ. ACM Trans. Program. Lang. Syst., 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Gregor Kiczales, Erik Hilsdale, Jim Hugunin, Mik Kersten, Jeffrey Palm, and William G. Griswold. An overview of aspectj. In Proc. of the European Conf. on Object-Oriented Programming. Springer-Verlag, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Gregor Kiczales, John Lamping, Anurag Mendhekar, Chris Maeda, Cristina Lopes, Jean marc Loingtier, and John Irwin. Aspect-oriented programming. In Proc. of the European Conf. on Object-Oriented Programming. Springer-Verlag, 1997.Google ScholarGoogle ScholarCross RefCross Ref
  18. Giovanni Lagorio, Marco Servetto, and Elena Zucca. Featherweight jigsaw: A minimal core calculus for modular composition of classes. In Proc. of the European Conf. on Object-Oriented Programming. Springer-Verlag, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Luigi Liquori and Arnaud Spiwack. Feathertrait: A modest extension of featherweight java. ACM Trans. Program. Lang. Syst., 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Weiyu Miao and Jeremy Siek. Pattern-based traits. In Proceedings of the 27th Annual ACM Symposium on Applied Computing, SAC '12, pages 1729--1736. ACM, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Oscar Nierstrasz, Stéphane Ducasse, and Nathanael Schärli. Flattening traits. Journal of Object Technology, 2006.Google ScholarGoogle ScholarCross RefCross Ref
  22. John Reppy and Aaron Turon. Metaprogramming with traits. In Proc. of the European Conf. on Object-Oriented Programming. Springer, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Nathanael Schärli, Stephane Ducasse, Oscar Nierstrasz, and Andrew P. Black. Traits: Composable units of behaviour. In Proc. European Conf. on Object-Oriented Programming. Springer, 2003.Google ScholarGoogle ScholarCross RefCross Ref
  24. Tim Sheard and Simon Peyton Jones. Template metaprogramming for Haskell. In Haskell Workshop '02. ACM, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Charles Smith and Sophia Drossopoulou. Chai: Traits for Java-Like Languages. In Proc. of the European Conf. on Object-Oriented Programming. Springer, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Walid Taha and Tim Sheard. Multi-stage programming with explicit annotations. In Proc. of the 1997 ACM SIGPLAN Symposium on Partial Evaluation and Semantics-based Program Manipulation. ACM, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Compile-time reflection and metaprogramming for Java

        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
          PEPM '14: Proceedings of the ACM SIGPLAN 2014 Workshop on Partial Evaluation and Program Manipulation
          January 2014
          202 pages
          ISBN:9781450326193
          DOI:10.1145/2543728

          Copyright © 2014 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: 11 January 2014

          Permissions

          Request permissions about this article.

          Request Permissions

          Check for updates

          Qualifiers

          • research-article

          Acceptance Rates

          PEPM '14 Paper Acceptance Rate17of22submissions,77%Overall Acceptance Rate66of120submissions,55%

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader