Java XX 的默认值:MaxDirectMemorySize
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3773775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Default for XX:MaxDirectMemorySize
提问by Timur Fanshteyn
What is the default value for XX:MaxDirectMemorySize?
XX:MaxDirectMemorySize 的默认值是多少?
采纳答案by John Gardner
From http://www.docjar.com/html/api/sun/misc/VM.java.html
来自http://www.docjar.com/html/api/sun/misc/VM.java.html
i see:
我懂了:
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;
so it appears to default to 64 megs.
所以它似乎默认为 64 兆。
回答by leventov
From sun.misc.VM
, it's Runtime.getRuntime.maxMemory()
, that's what is configured with -Xmx
. E. g. if you don'tconfigure -XX:MaxDirectMemorySize
and doconfigure -Xmx5g
, the "default" MaxDirectMemorySize
will also be 5 Gb, and the total heap+direct memory usage of the app may grow up to 5 + 5 = 10 Gb.
从sun.misc.VM
,它是Runtime.getRuntime.maxMemory()
,这就是配置-Xmx
. 例如 如果您不配置-XX:MaxDirectMemorySize
和做配置-Xmx5g
,“默认”MaxDirectMemorySize
也将是5 GB,总堆+直接存储器应用的使用可能会增长到5 + 5 = 10 GB。
回答by Robert Wunsch
For JDK8:
对于 JDK8:
The 64MB are set arbitrarily initially, ...
64MB是初始任意设置的,...
(From: https://github.com/frohoff/jdk8u-dev-jdk/blob/master/src/share/classes/sun/misc/VM.java#L186)
(来自:https: //github.com/frohoff/jdk8u-dev-jdk/blob/master/src/share/classes/sun/misc/VM.java#L186)
// A user-settable upper limit on the maximum amount of allocatable direct
// buffer memory. This value may be changed during VM initialization if
// "java" is launched with "-XX:MaxDirectMemorySize=<size>".
//
// The initial value of this field is arbitrary; during JRE initialization
// it will be reset to the value specified on the command line, if any,
// otherwise to Runtime.getRuntime().maxMemory().
//
private static long directMemory = 64 * 1024 * 1024;
... but then the directMemory is set to maxMemory() ~= Heapsize here (if the maxDirectMemorySize-Parameter is not set):
...但是这里的 directMemory 设置为 maxMemory() ~= Heapsize(如果未设置 maxDirectMemorySize-Parameter):
(from: https://github.com/frohoff/jdk8u-dev-jdk/blob/master/src/share/classes/sun/misc/VM.java#L286)
(来自:https: //github.com/frohoff/jdk8u-dev-jdk/blob/master/src/share/classes/sun/misc/VM.java#L286)
// Set the maximum amount of direct memory. This value is controlled
// by the vm option -XX:MaxDirectMemorySize=<size>.
// The maximum amount of allocatable direct buffer memory (in bytes)
// from the system property sun.nio.MaxDirectMemorySize set by the VM.
// The system property will be removed.
String s = (String)props.remove("sun.nio.MaxDirectMemorySize");
if (s != null) {
if (s.equals("-1")) {
// -XX:MaxDirectMemorySize not given, take default
directMemory = Runtime.getRuntime().maxMemory();
} else {
long l = Long.parseLong(s);
if (l > -1)
directMemory = l;
}
}
The test seems to support this claim, "test.java.nio.Buffer.LimitDirectMemory.java":
测试似乎支持这个说法,“test.java.nio.Buffer.LimitDirectMemory.java”:
if (size.equals("DEFAULT"))
return (int)Runtime.getRuntime().maxMemory();