I have been benchmarked my multihreaded program using -agentlib:hprof=cpu=samples
and was surprised to find the following line in the results:
rank self accum count trace method
1 52.88% 52.88% 8486 300050 java.lang.Object.hashCode
I never explicitly call hashCode() in my program.
What can be the reason for this? How can I understand the source for this time “waste” and whether it is normal or not?
Thanks,
David
Most likely you’re using very intensively a Map such as a HashMap.
HashMap used the
hashCodeto distribute the objects. If you’re using many objects with this data structure, is very important your.equalsand your.hashCodemethod are properly implemented.See: Effective Java Item 8: Always override hashCode when you override equals