skip to main content
10.1145/1375581.1375592acmconferencesArticle/Chapter ViewAbstractPublication PagespldiConference Proceedingsconference-collections
research-article

Expressive and safe static reflection with MorphJ

Published: 07 June 2008 Publication History

Abstract

Recently, language extensions have been proposed for Java and C# to support pattern-based reflective declaration. These extensions introduce a disciplined form of meta-programming and aspect-oriented programming to mainstream languages: They allow members of a class (i.e., fields and methods) to be declared by statically iterating over and pattern-matching on members of other classes. Such techniques, however, have been unable to safely express simple, but common, idioms such as declaring getter and setter methods for fields.
In this paper, we present a mechanism that addresses the lack of expressiveness in past work without sacrificing safety. Our technique is based on the idea of nested patterns that elaborate the outer-most pattern with blocking or enabling conditions. We implemented this mechanism in a language, MorphJ. We demonstrate the expressiveness of MorphJ with real-world applications. In particular, the MorphJ reimplementation of DSTM2, a software transactional memory library, reduces 1,107 lines of Java reflection and bytecode engineering library calls to just 374 lines of MorphJ code. At the same time, the MorphJ solution is both high level and safer, as MorphJ can separately type check generic classes and catch errors early. We present and formalize the MorphJ type system, and offer a type-checking algorithm.

References

[1]
E. Allen, J. Bannet, and R. Cartwright. A first-class approach togenericity. In Proc. of Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA), 2003.
[2]
Apache Software Foundation. Byte-code engineering library."http://jakarta.apache.org/bcel/manual.html". Accessed Mar.'08.
[3]
J. Bachrach and K. Playford. The Java syntactic extender (JSE). In Proc. of Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA), 2001.
[4]
J. Baker and W. C. Hsieh. Maya: multiple--dispatch syntaxextension in Java. In Proc. of Programming Language Design and Implementation (PLDI), 2002.
[5]
C. Calcagno, W. Taha, L. Huang, and X. Leroy. Implementing multi-stage languages using ASTs, gensym, and reflection. In Proc. of Generative Programming and Component Engineering (GPCE),2003.
[6]
D. Draheim, C. Lutteroth, and G. Weber. A type system for reflective program generators. In Proc. of Generative Programming and Component Engineering (GPCE), 2005.
[7]
M. Fähndrich, M. Carbin, and J. R. Larus. Reflective program generation with patterns. In Proc. of Generative Programming and Component Engineering (GPCE), 2006.
[8]
E. Gamma, R. Helm, and R. Johnson. Design Patterns. Elements of Reusable Object-Oriented Software. Addison-Wesley Professional Computing Series. Addison-Wesley, 1995.
[9]
M. Herlihy. SXM: C# Software Transactional Memory. "http://www.cs.brown.edu/ mph/SXM/README.doc". Accessed Mar.'08.
[10]
M. Herlihy, V. Luchangco, and M. Moir. A flexible frameworkfor implementing software transactional memory. In OOPSLA '06: Proceedings of the 21st annual ACM SIGPLAN conference on Object-oriented programming systems, languages, and applications, 2006.
[11]
S. S. Huang and Y. Smaragdakis. Easy language extension with Meta-AspectJ. In Proc. of International Conference on Software Engineering (ICSE), 2006.
[12]
S. S. Huang and Y. Smaragdakis. Morphing with nested patterns: Making generic classes highly configurable. Technical report, 2007. http://www.cc.gatech.edu/,ssh/mjnested-tr.pdf.
[13]
S. S. Huang, D. Zook, and Y. Smaragdakis. Statically safe program generation with SafeGen. In Proc. of Generative Programming and Component Engineering (GPCE), 2005.
[14]
S. S. Huang, D. Zook, and Y. Smaragdakis. Morphing: Safely shapinga class in the image of others. In Proc. of the European Conference on Object-Oriented Programming (ECOOP), 2007.
[15]
A. Igarashi, B. C. Pierce, and P. Wadler. Featherweight java: aminimal core calculus for java and gj. ACM Trans. Program. Lang. Syst., 23(3):396--450, 2001.
[16]
P. Jansson and J. Jeuring. PolyP - a polytypic programming language extension. In POPL '97: Proceedings of the 24th ACM SIGPLANSIGACT symposium on Principles of programming languages, 1997.
[17]
G. Kiczales, J. des Rivieres, and D. G. Bobrow. The Art of the Metaobject Protocol. MIT Press, 1991.
[18]
G. Kiczales, J. Lamping, A. Menhdhekar, C. Maeda, C. Lopes, J.-M. Loingtier, and J. Irwin. Aspect-oriented programming. In Proc. of European Conf. on Object-Oriented Programming (ECOOP), 1997.
[19]
R. Lämmel and S. P. Jones. Scrap your boilerplate: a practical design pattern for generic programming. In TLDI '03: Proceedings of the 2003 ACM SIGPLAN international workshop on Types in languagesdesign and implementation, 2003.
[20]
M. Mohnen. Interfaces with default implementations in Java. In Proc. of Principles and Practice of Programming, 2002.
[21]
J. Reppy and A. Turon. Metaprogramming with traits. In ECOOP'07: Proceedings of the European Conference on Object-Oriented Programming, 2007.
[22]
T. Sheard and S. P. Jones. Template meta-programming for Haskell. In Proc. of the ACM SIGPLAN workshop on Haskell, 2002.
[23]
W. Taha and T. Sheard. Multi-stage programming with explicit annotations. In Proc. of Partial Evaluation and semantics-based Program Manipulation (PEPM), 1997.
[24]
E. Visser. Program transformation with Stratego/XT: Rules, strategies, tools, and systems in Stratego/XT 0.9. In Domain-Specific Program Generation. Springer-Verlag, 2004. LNCS 3016.
[25]
S. Weirich and L. Huang. A design for type-directed Java. In Workshop on Object-Oriented Developments (WOOD), 2004.

Cited By

View all

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
PLDI '08: Proceedings of the 29th ACM SIGPLAN Conference on Programming Language Design and Implementation
June 2008
396 pages
ISBN:9781595938602
DOI:10.1145/1375581
  • General Chair:
  • Rajiv Gupta,
  • Program Chair:
  • Saman Amarasinghe
  • cover image ACM SIGPLAN Notices
    ACM SIGPLAN Notices  Volume 43, Issue 6
    PLDI '08
    June 2008
    382 pages
    ISSN:0362-1340
    EISSN:1558-1160
    DOI:10.1145/1379022
    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: 07 June 2008

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. aspect-oriented programming
  2. class morphing
  3. language extensions
  4. meta-programming
  5. object-oriented programming
  6. structural abstraction

Qualifiers

  • Research-article

Conference

PLDI '08
Sponsor:

Acceptance Rates

Overall Acceptance Rate 406 of 2,067 submissions, 20%

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)5
  • Downloads (Last 6 weeks)1
Reflects downloads up to 16 Oct 2024

Other Metrics

Citations

Cited By

View all

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