Was ist der Standardwert für XX: MaxDirectMemorySize?
Von http://www.docjar.com/html/api/Sun/misc/VM.Java.html
aha:
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;
es scheint also auf 64 MB voreingestellt zu sein.
Von Sun.misc.VM
ist es Runtime.getRuntime.maxMemory()
, das ist es, was mit -Xmx
konfiguriert wird. Z.B. Wenn Sie nicht konfigurieren -XX:MaxDirectMemorySize
und do configure -Xmx5g
, ist die "Standardeinstellung" MaxDirectMemorySize
ebenfalls 5 GB, und die gesamte Heap + direkte Speichernutzung der App kann ansteigen 5 + 5 = 10 Gb.
Für JDK8:
Die 64MB werden anfänglich willkürlich eingestellt, ...
(Von: 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;
... aber dann ist directMemory auf maxMemory () gesetzt ~ Heapsize hier (falls der maxDirectMemorySize-Parameter nicht gesetzt ist):
(von: 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;
}
}
Der Test scheint diese Behauptung zu unterstützen: "Test.Java.nio.Buffer.LimitDirectMemory.Java":
if (size.equals("DEFAULT"))
return (int)Runtime.getRuntime().maxMemory();