What is statistics breakdown in Java heap dump

Given this heap heap

size no. of obj class 515313696 2380602 char[] 75476832 614571 * ConstMethodKlass 57412368 2392182 java.lang.String 44255544 614571 * MethodKlass 33836872 70371 * ConstantPoolKlass 28034704 70371 * InstanceKlassKlass 26834392 349363 java.lang.Object[] 25853848 256925 java.util.HashMap$Entry[] 24224240 496587 * SymbolKlass 19627024 117963 byte[] 18963232 61583 * ConstantPoolCacheKlass 18373920 120113 int[] 15239352 634973 java.util.HashMap$Entry 11789056 92102 ph.com.my.class.Person 

And only 1 class from my application, ph.com.my.class.Person . Class definition:

 public class Person { private String f_name; private String l_name; } 

In a heap dump, does Person size (11789056) memory that 2 string variables occupy? Or instead of f_name and l_name will be considered in the String class, in this case the size is 57412368?

UPDATED - added the following question:

So let's say each instance:

  • f_name size 30
  • l_name size 20
  • Person Size - 75

If there are 10 instances of Person, there will be

  • 10 * (30 + 20) = 500
  • 10 * 75 = 750

Will 500 be counted in String or char []? And subsequently, will 750 be counted in the Person?

+4
source share
2 answers

The size of the object in the heap dump is the number of bytes allocated as a block on the heap to store this instance. It never includes the bytes of the entire graph accessible through the object. In general, this can easily mean that the size of the object is the whole bunch. Therefore, in your case, it takes into account two links , but not the String instances themselves. Also note that even the size of the String does not reflect the size of the presented string, which is stored in char[] . char[] instances are split between lines , so the story is not so simple.

+2
source

Each counter and size is the size of this object. If you used -histo instead of -histo:live , these will be all objects, even those that are not referenced.

Note: each String has char[] , and the JVM uses quite a lot. The size of String is the size of the object itself, not its char[]

+2
source

All Articles