What is the breakdown of the statistics in a Java heap dump
-
21-06-2021 - |
Domanda
Given this heap dump
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 is from my app, ph.com.my.class.Person
. The class definition is follows:
public class Person {
private String f_name;
private String l_name;
}
In the heap dump, does the Person size (11789056)
include the memory that the 2 string variables occupying? Or will the f_name
and l_name
be counted in the String
class instead, in this case size 57412368?
UPDATED - added followup question:
So let's say each instance of:
- f_name size is 30
- l_name size is 20
- Person size is 75
If there where 10 instances of Person, there will be
- 10 * (30+20) = 500
- 10 * 75 = 750
Will the 500 be counted in String or char[]? And subsequently, will 750 be counted in Person?
Soluzione
The size of an object in the heap dump is the number of bytes allocated as a block on the heap to hold that instance. It never includes the bytes of the whole graph reachable through the object. In general that could easily mean that the size of the object is the entire heap. So in your case it takes into account the two references, but not the String instances themselves. Note also that even the String
size doesn't reflect the size of the represented string -- that's stored in a char[]
. The char[]
instances are shared between strings so the story isn't that simple.
Altri suggerimenti
Each count and size is the size of that object. If you used -histo
instead of -histo:live
this will be all the objects, even the ones which are not referenced.
Note: each String
has a char[]
and the JVM uses quite a few of these. The String
size is the size of the object itself and not its char[]