skip to main content
research-article

JEqualityGen: generating equality and hashing methods

Authors Info & Claims
Published:10 October 2010Publication History
Skip Abstract Section

Abstract

Manually implementing equals (for object comparisons) and hashCode (for object hashing) methods in large software projects is tedious and error-prone. This is due to many special cases, such as field shadowing, comparison between different types, or cyclic object graphs. Here, we present JEqualityGen, a source code generator that automatically derives implementations of these methods.

JEqualityGen proceeds in two states: it first uses source code reflection in MetaAspectJ to generate aspects that contain the method implementations, before it uses weaving on the bytecode level to insert these into the target application. JEqualityGen generates not only correct, but efficient source code that on a typical large-scale Java application exhibits a performance improvement of more than two orders of magnitude in the equality operations generated, compared to an existing system based on runtime reflection. JEqualityGen achieves this by generating runtime profiling code that collects data. This enables it to generate optimised method implementations in a second round.

References

  1. }}Sun Microsystems Inc. Java Platform Standard Ed. 6.Google ScholarGoogle Scholar
  2. }}M. Vaziri, F. Tip, S. Fink, and J. Dolby. Declarative Object Identity Using Relation Types. In ECOOP, LNCS 4609, pp. 54--78. Springer, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. }}D. Rayside, Z. Benjamin, R. Singh, J. P. Near, A. Milicevic, and D. Jackson. Equality and hashing for (almost) free: Generating implementations from abstraction functions. In ICSE, pp. 342--352. IEEE,2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. }}JFreeChart. http://www.jfree.org/jfreechart/.Google ScholarGoogle Scholar
  5. }}S. Khoshafian and G. P. Copeland. Object Identity. In OOPSLA, SIGPLAN Notices 21(11), pp. 406--416, 1986. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. }}P. Grogono and M. Sakkinen. Copying and Comparing: Problems and Solutions. In ECOOP, LNCS 1850, pp. 226--250. Springer, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. }}S. Abiteboul and J. Van Den Bussche. Deep equality revisited. Deductive and Object-Oriented Databases, LNCS 1013, pp. 213--228. Springer, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. }}D. Hovemeyer and W. Pugh. Finding Bugs is Easy. ACM SIGPLAN Notices, 39(12):92--106, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. }}M. Odersky, L. Spoon, and B. Venners. Programming in Scala: A Comprehensive Step-by-step Guide. Artima, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. }}J. Bloch. Effective Java (2nd Edition). Prentice Hall, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. }}B. Meyer. Eiffel: The Language. Prentice Hall, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. }}J. Jones and R. Smith. Automated auditing of design principle adherence. In Proc. ACM Southeast Regional Conference, pp. 158--159. ACM, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. }}D. Zook, S. S. Huang, and Y. Smaragdakis. Generating AspectJ Programs with Meta-AspectJ. In GPCE, LNCS 3286, pp. 1--18. Springer, 2004.Google ScholarGoogle Scholar
  14. }}G. Kiczales, E. Hilsdale, J. Hugunin, M. Kersten, J. Palm, and W. G. Griswold. An Overview of AspectJ. In ECOOP, LNCS 2072, pp. 327--353. Springer, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. }}E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design Patterns - Elements of Reusable Object-Oriented Software. Addison-Wesley, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. }}B. W. Kernighan and D. M. Ritchie. The C Programming Language (2nd edition). Prentice Hall, 1988. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. }}S. M. Blackburn et al. The DaCapo benchmarks: Java benchmarking development and analysis. In OOPSLA, pp. 169--190. ACM, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. }}Eclipse IDE. http://www.eclipse.org/.Google ScholarGoogle Scholar
  19. }}B. Aktemur, J. Jones, S. N. Kamin, and L. Clausen. Optimizing Marshalling by Run-Time Program Generation. In GPCE, LNCS 3676, pp. 221--236. Springer, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. JEqualityGen: generating equality and hashing methods

    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

    • Published in

      cover image ACM SIGPLAN Notices
      ACM SIGPLAN Notices  Volume 46, Issue 2
      GPCE '10
      Febuary 2011
      185 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/1942788
      Issue’s Table of Contents
      • cover image ACM Conferences
        GPCE '10: Proceedings of the ninth international conference on Generative programming and component engineering
        October 2010
        198 pages
        ISBN:9781450301541
        DOI:10.1145/1868294
        • General Chair:
        • Eelco Visser,
        • Program Chair:
        • Jaakko Järvi

      Copyright © 2010 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 10 October 2010

      Check for updates

      Qualifiers

      • research-article

    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!