7

The JVM options:

-Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8

As expected, the JVM will allocate almost 20MB memory for the JVM heap.

But please see the following GC detail:

PSYoungGen total 9216K, used 4612K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
eden space 8192K, 56% used [0x00000000ff600000,0x00000000ffa812d8,0x00000000ffe00000)
from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)
PSOldGen total 10240K, used 8192K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
object space 10240K, 80% used [0x00000000fec00000,0x00000000ff400020,0x00000000ff600000) PSPermGen total 21248K, used 3033K [0x00000000f9a00000, 0x00000000faec0000, 0x00000000fec00000)
object space 21248K, 14% used [0x00000000f9a00000,0x00000000f9cf6708,0x00000000faec0000)

The size of the young generation is as expected for the option -Xmn. The ratio of size for eden space and survivor spaces in the young generation is as expected for the option -XX:SurvivorRatio=8. But it seems in total the JVM allocated almost 40MB memory, so it is strange. Why is the JVM total allocated memory greater than -Xmx?

Env:

OS: win7 64 bit

JDK: build 1.6.0_43-b01 64bit

DontDivideByZero
  • 1,171
  • 15
  • 28
Liping Huang
  • 4,378
  • 4
  • 29
  • 46

1 Answers1

11

-Xmx sets the maximum size of the HotSpot Object-Heap, that is the sum of YoungGen (Eden + Survivor-spaces) and OldGen and that is about 20 MB. The permanent generation resides outside this heap in a separate memory-area that is controlled via the -XX:MaxPermSize option.

piet.t
  • 11,718
  • 21
  • 43
  • 52
  • so means the heap is devided into two generations: YoungGen and OldGen, not contains the PermGen? – Liping Huang Dec 23 '13 at 09:30
  • @LipingHuang Yes, that is correct. The heap is divided into the *young generation*, `PSYoungGen`, and the *old generation*, `PSOldGen`. The heap does not contain the *permanent generation*, `PSPermGen`. By the way, `PS` stands for *parallel scavenge collector* (enabled using `-XX:UseParallelGC`). – DontDivideByZero Feb 09 '15 at 09:35
  • @LipingHuang The *young generation* is further divided into the *eden space* and two *survivor spaces* known as the *from space* and *to space*. However, **only one of the *survivor spaces* contributes to the stated size of the *young generation***, as discussed [here](http://stackoverflow.com/q/28347161/3460717). – DontDivideByZero Feb 09 '15 at 09:39
  • @LipingHuang In case you are wondering why the total heap size (`PSYoungGen total 9216K` + `PSOldGen total 10240K` = `19456K` = 19MB) is less than the minimum heap size specified with `-Xms20M` then see the discussion [here](http://stackoverflow.com/q/28362435/3460717). – DontDivideByZero Feb 09 '15 at 09:45
  • @DontDivideByZero The link post is removed. Any other references? – Lebecca Oct 12 '21 at 15:02