Theoretical limit for maximum heap size on 32 bit JVM is 2^32 (4GB) and for 64 bit JVM is 2^64 (16EB).
As no system currently have 2^64 bit of physical memory or RAM, so the maximum heap allocation depends on how much your operating system allows.
A 32 bit JVM running on x32 Windows operating system with 4GB has limitation to use less than 2GB as heap memory and this is due to the JVM that tries to allocate the heap as a contiguous memory chunk and windows seems to reserves around 2GB for its own & user processes. However in Linux or Solaris, one can set maximum heap space, more than 2GB and less than max memory and memory allocated to operating system.
To validate the maximum heap that can be allocated:
To validate the maximum heap that can be allocated:
1) Create a file named “MemoryUtil.java” with the below code
public class MemoryUtil{
private static final int MegaBytes = 10241024;
public static void main(String args[]) {
long totalMemory = Runtime.getRuntime().totalMemory()/MegaBytes;
long maxMemory = Runtime.getRuntime().maxMemory()/MegaBytes;
long freeMemory = Runtime.getRuntime().freeMemory()/MegaBytes;
System.out.println("JVM totalMemory also = initial heap size of JVM : " + totalMemory);
System.out.println("JVM maxMemory also = maximum heap size of JVM: " + maxMemory);
System.out.println("JVM freeMemory: " + freeMemory);
}
}
2) Change the value for “-xms” as required and execute the below command to validate the max memory that can you used on the machine
${JAVA_HOME}/bin/java -XX:PermSize=128M -XX:MaxPermSize=256M -Xms512m -Xmx3500m MemoryUtil
No comments :
Post a Comment