user1873379
user1873379

Reputation: 75

Java heap memory flow

Lets say, My RAM is 30 GB and I have given jmx as 10 GB and jms as 5 GB and started the java process. How actually heap is sized/resized with those values? Is it like 5GB is taken as initial heap space and 10 GB is kept aside for jvm (and the remaining 15 GB is available for other processes on RAM) or only 5 GB is allocated and increases to max of 10 GB (meanwhile other process are authorized to use 25 GB)? How does this happen?

Upvotes: 2

Views: 984

Answers (2)

Ankur Lathi
Ankur Lathi

Reputation: 7836

The JVM has a heap that is the runtime data area from which memory for all class instances and arrays are allocated. It is created at the JVM start-up.

Java heap allocation starts with min size -Xms and increases upto Xmx.

  • -Xms - Set the minimum available memory for the JVM

  • -Xmx - Set the maximum available memory for the JVM. The Java application cannot use more heap memory then defined via this parameter.

By default, the maximum heap size is 64 Mb.

Heap memory for objects is reclaimed by an automatic memory management system which is known as a garbage collector. The heap may be of a fixed size or may be expanded and shrunk, depending on the garbage collector's strategy.

So, I think latter one is correct statement.

only 5 GB (XMS) is allocated and increases to max of 10 GB (XMX) (meanwhile other process are authorized to use 25 GB)

Upvotes: 2

Chetan Gole
Chetan Gole

Reputation: 743

  • -Xms This sets initial Java heap size
  • -Xmx This sets maximum Java heap size

At initialization of the virtual machine, the entire space for the heap is reserved. The size of the space reserved can be specified with the -Xmx option. If the value of the -Xms parameter is smaller than the value of the -Xmx parameter, not all of the space that is reserved is immediately committed to the virtual machine. The uncommitted space is labeled "virtual" in this figure. The different parts of the heap ( permanent generation, tenured generation, and young generation) can grow to the limit of the virtual space as needed..... source - OTN -Tuning Garbage Collection

Upvotes: 2

Related Questions