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.
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- Kathleen Fisher. A typed calculus of traits. In Workshop on Foundations of Object-oriented Programming, 2004.Google Scholar
- Matthew Flatt, Shriram Krishnamurthi, and Matthias Felleisen. Classes and mixins. In Proc. of the Symposium on Principles of Programming Languages. ACM, 1998. Google ScholarDigital Library
- Ira R. Forman and Nate Forman. Java Reflection in Action (In Action series). Manning Publications Co., Greenwich, CT, USA, 2004. Google ScholarDigital Library
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- Shan Shan Huang, David Zook, and Yannis Smaragdakis. Statically safe program generation with safegen. Sci. Comput. Program., 2011. Google ScholarDigital Library
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- 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 ScholarCross Ref
- 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 ScholarDigital Library
- Luigi Liquori and Arnaud Spiwack. Feathertrait: A modest extension of featherweight java. ACM Trans. Program. Lang. Syst., 2008. Google ScholarDigital Library
- 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 ScholarDigital Library
- Oscar Nierstrasz, Stéphane Ducasse, and Nathanael Schärli. Flattening traits. Journal of Object Technology, 2006.Google ScholarCross Ref
- John Reppy and Aaron Turon. Metaprogramming with traits. In Proc. of the European Conf. on Object-Oriented Programming. Springer, 2007. Google ScholarDigital Library
- 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 ScholarCross Ref
- Tim Sheard and Simon Peyton Jones. Template metaprogramming for Haskell. In Haskell Workshop '02. ACM, 2002. Google ScholarDigital Library
- Charles Smith and Sophia Drossopoulou. Chai: Traits for Java-Like Languages. In Proc. of the European Conf. on Object-Oriented Programming. Springer, 2005. Google ScholarDigital Library
- 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 ScholarDigital Library
Index Terms
- Compile-time reflection and metaprogramming for Java
Recommendations
Zero-overhead metaprogramming: reflection and metaobject protocols fast and without compromises
PLDI '15: Proceedings of the 36th ACM SIGPLAN Conference on Programming Language Design and ImplementationRuntime 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 ...
Pattern-based traits
SAC '12: Proceedings of the 27th Annual ACM Symposium on Applied ComputingThere have been exciting developments with respect to compile-time reflection for C# and Java. Fähndrich et al. [2006] introduced what we call pattern-based reflection as a high-level notation for inspecting members of old classes and generating members ...
Backstage Java: making a difference in metaprogramming
OOPSLA '11: Proceedings of the 2011 ACM international conference on Object oriented programming systems languages and applicationsWe propose Backstage Java (BSJ), a Java language extension which allows algorithmic, contextually-aware generation and transformation of code. BSJ explicitly and concisely represents design patterns and other encodings by employing compile-time ...
Comments