The VM.maxDirectMemory method doesn't behave properly on negative numbers,
which can be passed in from HotSpot via the sun.nio.MaxDirectMemorySize system
property when a ridiculously large value is specified on the command line.
Rather than taking the hardwired default value of 64MB it should instead take
the value of Runtime.getRuntime().maxMemory(). This difference is more
noticeable now that we have ergonomic GC sizing.
% cat MDM.java
public class MDM {
public static void main(String[] args) {
long mm = Runtime.getRuntime().maxMemory();
long mdm = sun.misc.VM.maxDirectMemory();
if (mm != mdm)
throw new Error("maxMemory = " + mm
+ ", maxDirectMemory = " + mdm);
}
}
% /local/jdk/1.5/bin/java -version
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b50)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b50, mixed mode)
% /local/jdk/1.5/bin/java -XX:MaxDirectMemorySize=42g MDM
Exception in thread "main" java.lang.Error: maxMemory = 66650112, maxDirectMemory = 67108864
at MDM.main(MDM.java:8)
%
-- ###@###.### 2004/5/14
which can be passed in from HotSpot via the sun.nio.MaxDirectMemorySize system
property when a ridiculously large value is specified on the command line.
Rather than taking the hardwired default value of 64MB it should instead take
the value of Runtime.getRuntime().maxMemory(). This difference is more
noticeable now that we have ergonomic GC sizing.
% cat MDM.java
public class MDM {
public static void main(String[] args) {
long mm = Runtime.getRuntime().maxMemory();
long mdm = sun.misc.VM.maxDirectMemory();
if (mm != mdm)
throw new Error("maxMemory = " + mm
+ ", maxDirectMemory = " + mdm);
}
}
% /local/jdk/1.5/bin/java -version
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b50)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b50, mixed mode)
% /local/jdk/1.5/bin/java -XX:MaxDirectMemorySize=42g MDM
Exception in thread "main" java.lang.Error: maxMemory = 66650112, maxDirectMemory = 67108864
at MDM.main(MDM.java:8)
%
-- ###@###.### 2004/5/14
- relates to
-
JDK-4879883 (bf) Allocating direct buffers causes OutOfMemoryError
- Resolved
-
JDK-5037521 TEST_BUG: 1.4.2_05 regtest 4879883 fails on Win2003 on Itanium 64 bit and RedHat AMD 64 bit
- Resolved
-
JDK-5042840 Regression test java/nio/Buffer/LimitDirectMemory.sh fails on 64-bit machines
- Resolved