2

We use Eclipse memory analyzer for Java (Tomcat Web application) dump. The total heap in the resulting piechart is shown as 86 Mb. At the same time the heap limit for that JVM is set at 1.5GB and we saw the total JVM usage going up to 2.8 GB.

Why the deviation is so big?

Alex
  • 7,007
  • 18
  • 69
  • 114

3 Answers3

3

Please invoke jmap -heap TOMCAT_PID and you will see current heap usage (eden, survivor spaces, old and perm)

Also please notice that real usage of memory for Java will be XMX + MaxPerm + XSS * threads number. I'll recommend you reading great post about memory consuming in Java: http://plumbr.eu/blog/why-does-my-java-process-consume-more-memory-than-xmx

Jakub Kubrynski
  • 13,724
  • 6
  • 60
  • 85
2

Your heap memory is only a part of the memory used by the JVM. Additionally you have native memory and permgen.

You can limit the permgen memory via command line parameters. See What does PermGen actually stand for?. In my experience, the permgen limit was defaulted to something like 1G, which was way more than we ever needed. I think we overrode it to 128m.

Native memory is a lot trickier. This is memory allocated by native libraries used directly or transitively by your code.

In jrockit, you can get a print out of a memory summary via jrcmd print_memusage. Not sure how to do that in other JVMs.

Also: http://www.ibm.com/developerworks/linux/library/j-nativememory-linux/index.html

kevinmrohr
  • 821
  • 7
  • 11
  • What about reachable/unreachable objects? What is the difference between them? Are they equally important? – Alex Jan 23 '14 at 16:57
  • 1
    Reachable are those objects that have a reference to them, unreachable do not and are thus available for garbage collection. This is only relevant to your heap memory utilization, not permgen/native memory. See http://stackoverflow.com/questions/5667705/in-java-when-does-an-object-become-unreachable – kevinmrohr Jan 23 '14 at 17:13
  • I think that native memory has nothing to do with this since it is not part of the Heap. The problem is that the Heap occupation is 1.5GB but the dumped Heap is 86MB. – Aleš Jan 24 '14 at 00:36
  • He said the heap *limit* was 1.5GB, not the heap occupation. – kevinmrohr Jan 24 '14 at 14:37
2

See this reference - MAT Does Not Show the Complete Heap :

Symptom: When monitoring the memory usage interactively, the used heap size is much bigger than what MAT reports.

During the index creation, the Memory Analyzer removes unreachable objects because the various garbage collector algorithms tend to leave some garbage behind (if the object is too small, moving and re-assigning addresses is to expensive). This should, however, be no more than 3 to 4 percent. If you want to know what objects are removed, enable debug output as explained here: MemoryAnalyzer/FAQ#Enable_Debug_Output

Also, there should be some more information in this Q/A: eclipse memory analyzer sees small part (363,2MB) of entire heap dump (8GB)

Try the Keep Unreachable Objects option in Preferences -> Memory Analyzer -> Keep Unreachable Objects.

Community
  • 1
  • 1
Aleš
  • 8,896
  • 8
  • 62
  • 107