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.
- }}Sun Microsystems Inc. Java Platform Standard Ed. 6.Google Scholar
- }}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 Scholar
Digital Library
- }}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 Scholar
Digital Library
- }}JFreeChart. http://www.jfree.org/jfreechart/.Google Scholar
- }}S. Khoshafian and G. P. Copeland. Object Identity. In OOPSLA, SIGPLAN Notices 21(11), pp. 406--416, 1986. Google Scholar
Digital Library
- }}P. Grogono and M. Sakkinen. Copying and Comparing: Problems and Solutions. In ECOOP, LNCS 1850, pp. 226--250. Springer, 2000. Google Scholar
Digital Library
- }}S. Abiteboul and J. Van Den Bussche. Deep equality revisited. Deductive and Object-Oriented Databases, LNCS 1013, pp. 213--228. Springer, 1995. Google Scholar
Digital Library
- }}D. Hovemeyer and W. Pugh. Finding Bugs is Easy. ACM SIGPLAN Notices, 39(12):92--106, 2004. Google Scholar
Digital Library
- }}M. Odersky, L. Spoon, and B. Venners. Programming in Scala: A Comprehensive Step-by-step Guide. Artima, 2008. Google Scholar
Digital Library
- }}J. Bloch. Effective Java (2nd Edition). Prentice Hall, 2008. Google Scholar
Digital Library
- }}B. Meyer. Eiffel: The Language. Prentice Hall, 1992. Google Scholar
Digital Library
- }}J. Jones and R. Smith. Automated auditing of design principle adherence. In Proc. ACM Southeast Regional Conference, pp. 158--159. ACM, 2004. Google Scholar
Digital Library
- }}D. Zook, S. S. Huang, and Y. Smaragdakis. Generating AspectJ Programs with Meta-AspectJ. In GPCE, LNCS 3286, pp. 1--18. Springer, 2004.Google Scholar
- }}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 Scholar
Digital Library
- }}E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design Patterns - Elements of Reusable Object-Oriented Software. Addison-Wesley, 1995. Google Scholar
Digital Library
- }}B. W. Kernighan and D. M. Ritchie. The C Programming Language (2nd edition). Prentice Hall, 1988. Google Scholar
Digital Library
- }}S. M. Blackburn et al. The DaCapo benchmarks: Java benchmarking development and analysis. In OOPSLA, pp. 169--190. ACM, 2006. Google Scholar
Digital Library
- }}Eclipse IDE. http://www.eclipse.org/.Google Scholar
- }}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 Scholar
Digital Library
Index Terms
JEqualityGen: generating equality and hashing methods
Recommendations
JEqualityGen: generating equality and hashing methods
GPCE '10: Proceedings of the ninth international conference on Generative programming and component engineeringManually 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 ...
Monitoring aspects for the customization of automatically generated code for big-step models
GPCE '11: Proceedings of the 10th ACM international conference on Generative programming and component engineeringThe output of a code generator is assumed to be correct and not usually intended to be read or modified; yet programmers are often interested in this, e.g., to monitor a system property. Here, we consider code customization for a family of code ...
Monitoring aspects for the customization of automatically generated code for big-step models
GCPE '11The output of a code generator is assumed to be correct and not usually intended to be read or modified; yet programmers are often interested in this, e.g., to monitor a system property. Here, we consider code customization for a family of code ...







Comments