Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the JVM swap the heap?

I increased the java Xmx memory limit when an exception related to insufficient heap space was thrown. However, I am currently experiencing a very long execution time that may be memory related but I have not seen the exception thrown (yet).

I am wondering what may account for the long execution time. Does the JVM swap the heap to disk?

I'm using HotSpot 1.6.0 update 34.

like image 581
H2ONaCl Avatar asked Feb 05 '13 11:02

H2ONaCl


2 Answers

The JVM does not swap to disk, no. The operating system may do so. You can detect this by checking your OS stats on the process.

As the JVM runs out of memory, garbage collection is triggered more and more frequently. Each run frees less memory, increasing the rate of GC further. Eventually a lot of time is spent in GC, which is likely the slow-down you see.

The JVM doesn't wait until 0 bytes are freed to throw OutOfMemoryError. It will actually give up when GC is simply taking too long versus the number of bytes freed.

like image 149
Sean Owen Avatar answered Nov 01 '22 11:11

Sean Owen


One possible consequence of a larger heap is an increase in GC times - the JVM has to analyse a larger space, so it takes longer - particularly if its a stop-the-world GC.

Can you flesh out your question a little?

What heap size are you using? What durations are you seeing? Whats the usage pattern of objects in your application? A few long lived objects, or lots of short lived ones, for example.

like image 34
PaulJWilliams Avatar answered Nov 01 '22 12:11

PaulJWilliams