The default maximum heap size is Hotspot.

According to the following document http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#par_gc.ergonomics.default_size , the default maximum heap size for Parallel GC is selected using the MIN formula ( memory / 4, 1GB), This is obvious from the formula, but the document still notes that "the default maximum heap size will not exceed 1 GB, regardless of how much memory is installed on the machine." To make sure I wrote the following program

     public class Allocate {

         public static void main (String [] args) throws Exception {
             long megabytes = Long.valueOf (args [0]);
             long bytes = megabytes * 1024 * 1024;
             int longs = (int) (bytes / 8);
             long [] arr = new long [longs];
             Thread.sleep (Long.MAX_VALUE);
             System.out.println (arr.length);
         }
     }

I ran this program on a box with 16 GB of RAM.

     smeldris@us4nrsdn01 allocation] $ /usr/java/jdk1.6.0_26/bin/java Allocate 2048 & [1] 9291 [ smeldris@us4nrsdn01 allocation] $ /usr/java/jdk1.6.0_26/bin/jmap -heap 9291 Attaching to process ID 9291, please wait ... Debugger attached successfully.  Server compiler detected.  JVM version is 20.1-b02 using thread-local object allocation.  Parallel GC with 8 thread (s) Heap Configuration: MinHeapFreeRatio = 40 MaxHeapFreeRatio = 70 MaxHeapSize = 4208984064 (4014.0MB) NewSize = 1310720 (1.25MB) MaxNewSize = 17592186044415 MB OldSize = 5439488) 21757952 (20.75MB) MaxPermSize = 85983232 (82.0MB) Heap Usage: PS Young Generation Eden Space: capacity = 65798144 (62.75MB) used = 1315976 (1.2550125122070312MB) free = 64482168 (61.49498748779297MB21610110000100001 10944512 (10.4375MB) used = 0 (0.0MB) free = 10944512 (10.4375MB) 0.0% used To Space: capacity = 10944512 (10.4375MB) used = 0 (0.0MB) free = 10944512 (10.4375MB) 0.0% used PS Old Generation capacity = 2322923520 (2215.3125MB) used = 2147483664 (2048.000015258789MB) free = 175439856 (167.31248474121094MB) 92.44745449045176% used PS Perm Generation capacity = 21757952 (20.75MB2) 20485652 562 (2) 11.980686417545181% used [ smeldris@us4nrsdn01  smeldris@us4nrsdn01 allocation] $ 

An array of 2 GB was allocated in the old generation. MaxHeapSize - 4 GB, which is 1/4 of the system memory. Why did the JVM reserve 4 GB for the heap?

+4
source share
1 answer

I posted this question to open the jdk mailing list here http://mail.openjdk.java.net/pipermail/hotspot-gc-use/2011-August/000912.html .

Ergonomics GC has been changed in (1.6.0_18), but the documentation has not yet been updated.

Corresponding error Id http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6887571 . Release Notes http://www.oracle.com/technetwork/java/javase/6u18-142093.html

+3
source

Source: https://habr.com/ru/post/1368998/


All Articles