Why the heap is changing in java

2019-09-21 15:54发布

问题:

we are starting the java process with -Xms equals to -Xmx valuem for example:

-Xms1500m -Xmx1500m -Dos.heap.max=1500m -verbose:gc -XX:MaxPermSize=256m 

and for some reason the heap is changing during runtime...:

[GC 624542K->464935K(1472000K), 0.0647450 secs] Wed Jul 3 15:58:23 2013
[GC 808811K->813332K(1472000K), 0.1407890 secs] Wed Jul 3 15:58:23 2013
[Full GC 813332K->636599K(1472000K), 0.7913590 secs] Wed Jul 3 15:58:24 2013
[GC 1016090K->956043K(1258752K), 0.1209670 secs] Wed Jul 3 15:58:24 2013
[Full GC 956043K->955974K(1258752K), 0.4132560 secs] Wed Jul 3 15:58:25 2013
[Full GC 1126726K->1122269K(1258752K), 0.4376340 secs] Wed Jul 3 15:58:25 2013
[Full GC 1126726K->1115353K(1258752K), 0.8102960 secs] Wed Jul 3 15:58:26 2013

The question is why the heap memory is changing in runtime...?

回答1:

I understand the question to be why the heap size drops from 1500m (1472000K) to something less (1258752K) even though initial size is set to 1500m.

As it turns out, this is well known behavior in long running JVMs, and is related to the PS MarkSweep / Full GC mechanism - See this article for a good writeup.

Cheers,