Profile Image
vishnupriya

What is Initial and Maximum Nursery/Young GenerationSize?

What is Initial and Maximum Nursery/Young GenerationSize? Have you used this JVM argument before? What are the pros & cons of using this Java argument? Can you share your perspective/experience in using this JVM argument?

  • jvm-argument

  • xmn

  • mn

  • Initial and Maximum Nursery Young GenerationSize

Please Sign In or to post your comment or answer

Profile Image

Pavel Khodakovsky

Usage:


-XmnNNN where NNN is a number indicating the amount of memory, including an
optional character indicating the unit. For example -Xmn4g indicates a nursery
size of 4 gigabytes.


The units can be specified as:
• k, K – kilobytes
• m, M – megabytes
• g, G – gigibytes
• t, T – terabytes

 

WARNING: If a unit is not specified then the number indicates an exact
number of bytes, e.g. -Xmx64 means just 64 bytes.


Examples:


Set the inital and maximum young generation to 512 megabytes:
java -Xmn512m
Set the initial and maximum young generation to 2 gigabytes:

java -Xmn2g

 

Description:


The -Xmn argument controls both the initial and maximum size of the heap for
the young generation or nursery.


The heap is the memory used to allocate Java objects for the application code
other than local variables that are created on the stack. Periodically the JVM
runs a Garbage Collection (GC) process to find unreachable objects and free the
memory associated with them. The heap is divided into the young generation
(also called the nursery), and the old generation. New objects are first created
in the young generation, and are moved into the old generation if they survive
long enough.


Garbage Collection runs more frequently in the young generation than in the
old; this comes from the empirical observation that most new objects only live
for a short time. A minor GC runs only against the young generation and is
triggered when that generation becomes full. Therefore if the size of the young
generation is too small then minor GCs will run too frequently. Conversely if
the young generation is too large then minor garbage collections are rarely done,
so the GC relies entirely on major or full collections than span the entire heap,
and take much longer.

Note that the -Xmn option sets both the initial and the maximum size for the
young generation. To set these options independently use -XX:NewSize and
-XX:MaxNewSize respectively.
Oracle recommends keeping the size of the young generation at around 25% to
50% of the total heap size.

 

Default Value:


The -Xmn parameter does not have a fixed default value. If not specified then
the value is chosen at runtime appropriately by the JVM depending on the size
of the initial and maximum total heap sizes.


To determine the default settings of a JVM instance the Print Flags Final option
can be used. It will show the settings of all flags including the thread stack size:


java -XX:+PrintFlagsFinal -version


Note that this option produces a lot of output, it will be necessary to search
for the NewSize and MaxNewSize values. For example on a device with 16Gb of
RAM this command shows (excerpted):


size_t MaxNewSize = 2575302656 {product} {ergonomic}
size_t NewSize = 1363144 {product} {default}


These sizes are in bytes (indicated by size_t), i.e. approx 2.4Gb for the maximum
and approx 1.3Mb for the initial size.


Errors:
The value of -Xmn should not be higher than the maximum heap size indicated
by -Xmx. No error is thrown in this case however it does not increase the total
heap size beyond the value indicated by -Xmx.


Arguments Related to -Xmn:
TODO: link to -Xms TODO: link to -Xmx TODO: link to -XX:NewSize TODO:
link to -XX:MaxNewSize


Related Posts:


• To learn about different memory regions in the Java Virtual Machine, see
this video clip.
• IBM documentation regarding -Xmn.
• Azul documentation: Recommended Heap Size.
• Benefits of setting initial and maximum heap size to the same value

 

NOTE:
If you have additional comments, interesting experiences or even point of disagreement with this JVM argument description, please leave a comment. Your
insights will help the entire 10+ million java developer community to develop
one standard source of documentation for all the JVM arguments.

 

Got something else on mind? Post Your Question

Not the answer you're looking for? Browse other questions tagged
  • jvm-argument

  • xmn

  • mn

  • Initial and Maximum Nursery Young GenerationSize