heapSpank icon indicating copy to clipboard operation
heapSpank copied to clipboard

research task: shallow or deep?

Open eostermueller opened this issue 9 years ago • 2 comments

Need to discover whether the jmap -histo data byte counts are shallow, deep, or somewhere between.

Need to use data from examples in issue #4.

eostermueller avatar Jan 01 '17 15:01 eostermueller

This stackoverflow question suggests a number of things remain unanswered.

eostermueller avatar Jan 01 '17 15:01 eostermueller

bytes in jmap -histo are shallow, not deep. For example, this stackoverflow question prints:

 num     #instances         #bytes  class name
----------------------------------------------
   1:       1134597     5834904800  [B
   2:        407694      144032664  [Ljava.lang.Object;
   3:       2018132      111547480  [C
...
   7:        975220       23405280  java.lang.String
...

So the bytes size of String instances are 23405280 / 975220 = 24 bytes exactly per instance (in this JVM). It is impossible that String instances are only 24 bytes including contents. So the bytes size in jmap -histo is shallow.

The bytes size depends in fact of the types and numbers of attributes declared in the class and of 32-bits/64-bits/compressed oop. The bytes size can be computed for an object according to the Java Language Specification: see for example, https://stackoverflow.com/questions/52353/in-java-what-is-the-best-way-to-determine-the-size-of-an-object

evernat avatar Oct 31 '19 13:10 evernat