Introduction

The Hash‐Code Usage Analysis is a dynamic analysis that records whether objects had their hash‐code computed and, if so, how often. The analysis therefore keeps track of all calls to both Object.hashCode() and System.identityHashCode(Object). It moreover distinguishes between calls to Object.hashCode() and overriding implementations thereof.

Sample Profile

The format of the profile is line‐oriented; each object on the heap corresponds to a line in the produced profile.

Below is an excerpt from a real‐world profile:

java/lang/String␜substring␜(II)Ljava/lang/String;␜39	java.lang.String	0	0	2
java/lang/reflect/Array␜newInstance␜(Ljava/lang/Class;I)Ljava/lang/Object;␜-1 [Ljava.lang.String;	0	0
?	java.lang.Class	1	0

The first column identifies an object’s allocation site, which is described by a quadruple of class name, method name, method descriptor, and the index of the instruction (new, newarray, anewarray, multianewarray) that performed the allocation. The four components are separated by the “File Separator” control character ('\034'). And instruction index of −1 indicates that the object was allocated using reflection, with the other three components identifying the method performing the allocation (Constructor/Array.newInstance(…)). If an allocation site could not be determined by the Hash‐Code Usage Analysis, this is indicated by a question mark. The Class object in the above profile, e.g., was allocated very early in the VM’s startup sequence; hence, the analysis was unable to observe the object’s allocation.

The second column identifies the allocated object’s type.

The remaining columns report the number of times the object’s hash‐code has been computed. The third column reports the number of times System.identityHashCode(Object) was used, the fourth column reports the number of times Object.hashCode() itself was used, and any column thereafter reports the number of times an overriding implementation of Object.hashCode() was used—if there are such implementations for the type in question. The String object mentioned in the above profile, e.g., was hashed twice by String.hashCode(), which overrides Object.hashCode(); hence, the use is reported in the fifth column rather than the fourth. In contrast, the Class object was hashed once using System.identityHashCode(Object), which is reported in the third column.