JDK-5047688 : (bf) Ridiculous direct-memory limits not handled correctly
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 5.0
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2004-05-14
  • Updated: 2019-05-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Relates :  
Relates :  
Description
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

Comments
SUGGESTED FIX --- /tmp/scdiff.G8w5mS/D9PT1T 2004-04-10 17:35:09.000000000 -0700 +++ src/share/classes/sun/misc/VM.java 2004-05-14 12:01:44.000000000 -0700 @@ -157,16 +157,15 @@ String s = (String)p.remove("sun.nio.MaxDirectMemorySize"); System.setProperties(p); - 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; - } + long dm = -1; + if (s != null && !s.equals("-1")) { + long l = Long.parseLong(s); + if (l > -1) + dm = l; } + if (dm == -1) + dm = Runtime.getRuntime().maxMemory(); + directMemory = dm; return directMemory; }
11-06-2004

EVALUATION Corner case. Need not be fixed in Tiger. -- ###@###.### 2004/5/14
05-12-0180