2010-09-22 22 views
17

XX的默認值是什麼:MaxDirectMemorySize?XX的默認值:MaxDirectMemorySize

+0

我記得默認值是取-Xmx的值。這應該通過一個簡單的測試來驗證。 – irreputable 2010-09-22 22:49:51

+4

直接內存用於其他與堆無關的特定事物。從我在探索中發現的情況來看,它看起來像64是默認值,使用-1作爲值將其設置爲-Xmx。 – 2010-09-23 00:25:05

回答

16

http://www.docjar.com/html/api/sun/misc/VM.java.html

我看到:

163  // A user-settable upper limit on the maximum amount of allocatable direct 
164  // buffer memory. This value may be changed during VM initialization if 
165  // "java" is launched with "-XX:MaxDirectMemorySize=<size>". 
166  // 
167  // The initial value of this field is arbitrary; during JRE initialization 
168  // it will be reset to the value specified on the command line, if any, 
169  // otherwise to Runtime.getRuntime.maxDirectMemory(). 
170  // 
171  private static long directMemory = 64 * 1024 * 1024; 

所以它似乎默認爲64兆。

+1

這 - http://docs.oracle.com/cd/E15289_01/doc.40/e15062/optionxx.htm#BABGCFFB - 直接相反,聲稱它會是「無限的」? – StaxMan 2013-05-29 19:22:02

+2

docs.oracle.com鏈接指向JRockit的文檔,而不是OpenJDK。 – technomancy 2013-05-30 20:38:33

+1

該註釋表明,如果未在命令行中指定該值,則從maxDirectMemory()中獲取該值。這裏的鏈接(http://mail.openjdk.java.net/pipermail/core-libs-dev/2012-January/008884.html)將錯誤修正爲maxMemory()(這裏沒有這樣的方法),反過來等於您在命令行上設置的-Xmx。 – 2013-08-01 05:55:37

5

sun.misc.VM,這是Runtime.getRuntime.maxMemory(),這就是配置-Xmx。例如,如果你配置-XX:MaxDirectMemorySize配置-Xmx5g,「默認」 MaxDirectMemorySize也將是5 GB,總堆+應用程序的直接內存使用量可能會增長到5 + 5 = 10 GB。