Java · Programming

JVM Tuning

It is important that before we do any type of JVM tuning, we should throughly profile our system.
Memory leaks caused by our application code cannot be fixed by jvm tuning.

Java memory is divided into two main parts:

1. Heap size = (Young Gen, Tenured Gen,Permanent Gen)
2. Stack Size allocated to each thread.

Total Memory Used = heap + (stack size)*number of threads

JVM memory settings.

These settings can be tweaked to avoid the java.lang.OutOfMemoryError.

-Xms Set minimum available memory.
-Xmx Set maximum available memory.
-Xmn Set size of young generation.
-Xss Set the size of stack.

Where is the memory size in k,m etc.


java -Xmx1024m -Xms512m -Xmn256m -Xss1024k HelloWorld

This example sets the maximum available memory to 1024 MB, Start Memory to 512 MB, New Generation 256 MB and Stack Size to 1024 KB.

For more options run the following command at the command line.

java -X

$ java -X

-Xmixed mixed mode execution (default)
-Xint interpreted mode execution only
-Xbootclasspath: set search path for bootstrap classes and resources
-Xbootclasspath/a: append to end of bootstrap class path
-Xbootclasspath/p: prepend in front of bootstrap class path
-Xnoclassgc disable class garbage collection. Use with care.
-Xincgc enable incremental garbage collection
-Xloggc: log GC status to a file with time stamps
-Xbatch disable background compilation
-Xms set initial Java heap size
-Xmx set maximum Java heap size
-Xss set java thread stack size
-Xprof output cpu profiling data
-Xfuture enable strictest checks, anticipating future default
-Xrs reduce use of OS signals by Java/VM (see documentation)
-Xcheck:jni perform additional checks for JNI functions
-Xshare:off do not attempt to use shared class data
-Xshare:auto use shared class data if possible (default)
-Xshare:on require using shared class data, otherwise fail.

For the full list of JVM options refer


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s