Java – Why is the java process using much more heap space than specified

javamemory usagesolaris

I'm running a Java application on Solaris using the -Xmx256M switch. When I connect via JMX, the JVM tells me the application is using about 50Mb of heap, and correctly states the maximum heap size is around 250Mb.

However, Solaris is telling me a very different story. When running pmap, for example, I get:

 ~ > pmap -S 10124 | grep heap

0002C000    3920    3920 rwx--    [ heap ]
00400000  815104  815104 rwx--    [ heap ]

Showing an incredible 800Mb of memory being used for heap space.

ps confirms the memory usage:

ps -eo vsz,rss,pid,args | sort -n

939368 925576 10124 /apps/../java -Xmx256M xxxx

I've read, but the article describes JVM using memory other than heap (i.e. stack, native libraries and threads) – but in my case, the JVM is actually using much more heap than specified.

My java version is:

java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04)
Java HotSpot(TM) Server VM (build 20.6-b01, mixed mode)

To add to the mystery, I have other Java applications running on the same box, using the same JVM with the same settings, that behave perfectly fine. What makes this application "special" is that it connects to an external third party application (RET LBN, if that helps). It does not run any JNI or native code – so why is the third party library not respecting the JVM's startup parameters?

I'm at my wits end – any help or pointers will be greatly appreciated.

Best Answer

The Java heap is a block of memory that holds java objects.

"pmap" shows the Operating System process heap. This is the memory used to run the java process. This includes all the java code, plus all the C code that makes up the java run time environment.

To show the java heap try Memory tab of jconsole, or jmap or jstat.