Skip to main content

Using Hprof to estimate memory usage

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
Max8090
Offline
Joined: 2014-07-16

Hello all,

i would like to evaluate the memory usage of a Java-programm. For this i use HPROF (-agentlib:hprof=file=memdump,heap=sites). In memdump there is a secion 'sites begin', e.g:

SITES BEGIN (ordered by live bytes) Tue Jul 15 09:32:25 2014
percent live alloc'ed stack class
rank self accum bytes objs bytes objs trace name
1 10.17% 10.17% 1388920 12892 1827512 16110 300427 char[]
2 8.72% 18.89% 1190184 243 4570664 1007 302646 byte[]
3 4.68% 23.57% 639208 63 1596464 160 300352 byte[]
4 4.55% 28.12% 621792 8636 1105344 15352 305183 org.eclipse.emf.ecore.impl.ENamedElementImpl$1$1
5 4.33% 32.45% 591704 8333 1177416 16485 300398 char[]
6 3.23% 35.68% 440928 18372 1159056 48294 300106 java.util.HashMap$Entry
7 2.83% 38.51% 386160 8045 775440 16155 300388 java.util.HashMap
8 2.80% 41.31% 383024 2326 413568 2506 300437 char[]
9 1.95% 43.27% 266352 11098 518016 21584 304172 org.eclipse.emf.ecore.impl.ENamedElementImpl$1
10 1.80% 45.07% 246240 30 673056 82 306044 byte[]
11 1.49% 46.56% 203920 5098 292320 7308 302933 org.eclipse.emf.common.util.Pool$PoolEntry
12 1.41% 47.97% 192816 8027 390080 16153 300418 java.util.HashMap$Entry[]
13 1.41% 49.38% 192576 8024 192576 8024 300432 java.lang.String
14 1.31% 50.69% 178480 2287 216624 2875 302985 char[]
15 1.30% 51.99% 177264 2462 448704 6232 304174 org.eclipse.emf.ecore.impl.ENamedElementImpl$1$2
16 1.26% 53.25% 172240 2047 201424 2407 306501 char[]

To measure the memory usage, i summarize the column 'live bytes'. It seems to be good :-), because if i specify the maximum heap to this size (with -Xms -Xmx), the programm works. And if i reduce the heap size, i get the OutOfMemory-exception.

I have two questions:
What is the meaning of the column 'alloced bytes'? (in some cases i get 8gig bytes in sum; I have only 2gig physical memory in my macihne.)

If i run the programm with the same input data, in the first case with 64Meg max heap, and in the second case with 128Meg max heap, the sum of column 'live bytes' also increases.
Why is it so? (I thought 'live bytes' remains the same in both cases or reduces in the second one)

Thank you in advance for the help,
Daniel