public static long getMaxJvmHeapMemory ( ) { final long maxMemory = Runtime . getRuntime ( ) . maxMemory ( ) ; if ( maxMemory != Long . MAX_VALUE ) { // we have the proper max memory return maxMemory ; } else { // max JVM heap size is not set - use the heuristic to use 1/4th of the physical memory final long physicalMemory = Hardware . getSizeOfPhysicalMemory ( ) ; if ( physicalMemory != - 1 ) { // got proper value for physical memory return physicalMemory / 4 ; } else { throw new RuntimeException ( "Could not determine the amount of free memory.\n" + "Please set the maximum memory for the JVM, e.g. -Xmx512M for 512 megabytes." ) ; } } }
The maximum JVM heap size in bytes .