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