Profiling Field Initialisation in Java

Java encourages programmers to use constructor methods to initialise objects, supports final modifiers for documenting fields which are never modified and employs static checking to ensure such fields are only ever initialised inside constructors. Unkel and Lam observed that relatively few fields are actually declared final and showed using static analysis that many more fields have final behaviour, and even more fields are stationary (i.e. all writes occur before all reads). We present results from a runtime analysis of 14 real-world Java programs which not only replicates Unkel and Lam’s results, but suggests their analysis may have under-approximated the true figure. Our results indicate a remarkable 72-82% of fields are stationary, that final is poorly utilised by Java programmers, and that initialisation of immutable fields frequently occurs after constructor return. This suggests that the final modifier for fields does a poor job of supporting common programming practices.

[1]  Vivek Sarkar,et al.  Immutability specification and its applications , 2002, JGI '02.

[2]  Allen Goldberg,et al.  Instrumentation of Java Bytecode for Runtime Analysis , 2003 .

[3]  Xin Qi,et al.  Masked types for sound object initialization , 2009, POPL '09.

[4]  Paul H. J. Kelly,et al.  Profiling with AspectJ , 2007 .

[5]  Sophia Drossopoulou ECOOP 2009 - Object-Oriented Programming, 23rd European Conference, Genoa, Italy, July 6-10, 2009. Proceedings , 2009, ECOOP.

[6]  V. Stavridou,et al.  Abstraction and specification in program development , 1988 .

[7]  Antonio Vallecillo,et al.  Objects, Models, Components, Patterns , 2011, Lecture Notes in Computer Science.

[8]  Joseph Gil,et al.  Are We Ready for a Safer Construction Environment? , 2009, ECOOP.

[9]  Atanas Rountev,et al.  Precise memory leak detection for java software using container profiling , 2013, 2008 ACM/IEEE 30th International Conference on Software Engineering.

[10]  Peter Müller,et al.  Freedom before commitment: a lightweight type system for object initialisation , 2011, OOPSLA '11.

[11]  Dave Thomas,et al.  ECOOP 2006 - Object-Oriented Programming , 2006 .

[12]  Amer Diwan,et al.  The DaCapo benchmarks: java benchmarking development and analysis , 2006, OOPSLA '06.

[13]  Songtao Xia,et al.  Establishing object invariants with delayed types , 2007, OOPSLA.

[14]  Bilha Mendelson,et al.  Automatic detection of immutable fields in Java , 2000, CASCON.

[15]  K. Rustan M. Leino,et al.  Flexible Immutability with Frozen Objects , 2008, VSTTE.

[16]  James Noble,et al.  Understanding the Impact of Collection Contracts on Design , 2010, TOOLS.

[17]  Monica S. Lam,et al.  Automatic inference of stationary fields: a generalization of java's final fields , 2008, POPL '08.

[18]  Erik Poll,et al.  Type-based Object Immutability with Flexible Initialization - extended version , 2009 .

[19]  Nick Mitchell,et al.  The Runtime Structure of Object Ownership , 2006, ECOOP.

[20]  Alex Garthwaite,et al.  Efficient object sampling via weak references , 2000, ISMM '00.