Find Java heap memory size.

To Find out java memory,execute
java -XX:+PrintFlagsFinal -version | grep -aiE “HeapSize|permsize|threadstacksize”

[root@vpm ~]# java -XX:+PrintFlagsFinal -version | grep -aiE “HeapSize|permsize|threadstacksize”
uintx AdaptivePermSizeWeight = 20 {product}
intx CompilerThreadStackSize = 0 {pd product}
uintx ErgoHeapSizeLimit = 0 {product}
uintx HeapSizePerGCThread = 87241520 {product}
uintx InitialHeapSize := 62805312 {product}
uintx LargePageHeapSizeThreshold = 134217728 {product}
uintx MaxHeapSize := 1006632960 {product}
uintx MaxPermSize = 85983232 {pd product}
uintx PermSize = 21757952 {pd product}
intx ThreadStackSize = 1024 {pd product}
intx VMThreadStackSize = 1024 {pd product}
java version “1.7.0_71”
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

Java Memory Types

1. Java Heap Size
It is the place where objects are created by java application are stored, this is where Garbage Collection takes place,for a heavy java application,insufficient Heap size will cause java.lang.OutOfMemoryError:Java heap space Error

-Xms – sets initial java heap size
-Xmx – sets maximum java heap size

Initial heap size is 1/64 of physical memory(RAM).
Maximum heap size can be 1/4 of physical memory(RAM).

Running a java program with specified Initial heap memory size,maximum heap memory size.

javac HelloWorld.java (to compile)

java -Xmx1G -Xms16M HelloWorld (to run)

-Xmx1G (Maximum heap size of 1 GB)
-Xms16M (Initial heap size of 16MB)size can in terms of ‘m’ or ‘M’ for megabytes, ‘k’ or ‘K’ for kilobytes, and ‘g’ or ‘G’ for gigabytes.

2.Perm Gen Size
It is the place where loaded class definition and metadata is stored.
If a large code-base project is loaded, the insufficient Perm Gen size will cause the java.lang.OutOfMemoryError: PermGen Error.

-XX:PermSize – sets initial PermGen size.
-XX:MaxPermSize – sets the maximum PermGen size.
size can in terms of ‘m’ or ‘M’ for megabytes, ‘k’ or ‘K’ for kilobytes, and ‘g’ or ‘G’ for gigabytes.

Running a java program with specified PermSize,MaxPermSize memory.

javac HelloWorld.java (to compile)

java -XX:PermSize=64M -XX:MaxPermSize=128M HelloWorld

Advertisements
This entry was posted in Java, Linux. Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s