Java Heap Size - Place to
store objects created by your Java application, this is where Garbage
Collection takes place, the memory used by your Java application.
-Xms - Set initial Java heap size
-Xmx - Set maximum Java heap size
$ java -Xms512m -Xmx1024m JavaApp
Young Generation - Consist of Eden, S0
and S1 Space
-Xmn - Set the size of young generation.
$java -Xmn512m MyJavaProgram
$java -Xmn1g MyJavaProgram
Some more switches for Young generation
memory configuration are:
- -XX:NewSize - Set the minimum size of young generation which is allocated at initialization of JVM.
- -XX:MaxNewSize - Set the maximum size of young generation that JVM can use.
- -XX:SurvivorRatio - used to tune the size of the survivor spaces. For example -XX:SurvivorRatio=6 sets the ratio between each survivor space and eden to be 1:6.In other words, each survivor space will be one eighth of the young generation (not one seventh, because there are two survivor spaces).
- -XX:NewRatio : NewRatio controls the size of young and old generation. For example -XX:NewRatio=3 means that the ratio between the young and old/tenured generation is 1:3. In other words, the combined size of the eden and survivor spaces will be one fourth of the total heap size.
Perm Gen Size - Place to
store your loaded class definition and metadata.
XX:PermSize - Set initial PermGen Size.
-XX:MaxPermSize - Set the maximum PermGen Size.
$ java -XX:PermSize=64m -XX:MaxPermSize=128m JavaApp
Note:
PermGen space is replaced by MetaSpace in Java 8. The PermSize and MaxPermSize JVM arguments are ignored and a warning is issued if present at start-up.
PermGen space is replaced by MetaSpace in Java 8. The PermSize and MaxPermSize JVM arguments are ignored and a warning is issued if present at start-up.
Most allocations for
the class metadata are now allocated out of native memory. * The classes that
were used to describe class metadata have been removed.
Main difference
between old PermGen and new MetaSpace is, you don't have to mandatory define
upper limit of memory usage. You can keep MetaSpace space limit unbounded. Thus
when memory usage increases you will not get OutOfMemoryError error. Instead
the reserved native memory is increased to full-fill the increase memory usage.
You can define the max
limit of space for MetaSpace, and then it will throw OutOfMemoryError :
Metadata space. Thus it is important to define this limit cautiously, so that
we can avoid memory waste.
Java Stack Size -Size of a
Java thread. If a project has a lot of threads processing, try reduce this
stack size to avoid running out of memory.
-Xss = set java thread stack size
$ java -Xss512k JavaApp
No comments:
Post a Comment