JDK-7179383 : MaxDirectMemorySize argument parsing is broken for values >2G
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: hs24
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2012-06-25
  • Updated: 2014-02-04
  • Resolved: 2012-07-14
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.
JDK 7 JDK 8 Other
7u40Fixed 8Fixed hs24Fixed
Description
See email from Chris Dennis <###@###.###>:

http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/2012-June/003826.html

A signed intx type is used for the MaxDirectMemorySize which limits its value to under 2G. But even on a 32-bit system a value >2GB is not out of the question.

Simply changing to an unsigned unitx type fixes the problem but requires a change in the way we specify "use the default". On the VM size a value of zero now means "use the default" but that causes -1 to be passed on the system property as expected by the JDK side of things.

Comments
EVALUATION http://hg.openjdk.java.net/hsx/hotspot-emb/hotspot/rev/3f1ab0c19c30
14-07-2012

EVALUATION http://hg.openjdk.java.net/hsx/hotspot-rt/hotspot/rev/3f1ab0c19c30
03-07-2012

EVALUATION See description and suggested fix.
25-06-2012

SUGGESTED FIX MaxDirectMemorySize.patch diff -r 0f62a53fae43 src/share/vm/prims/jvm.cpp --- a/src/share/vm/prims/jvm.cpp Mon Jun 04 09:17:47 2012 -0400 +++ b/src/share/vm/prims/jvm.cpp Tue Jun 05 22:29:28 2012 -0400 @@ -345,9 +345,13 @@ // Do this after setting user properties to prevent people // from setting the value with a -D option, as requested. { - char as_chars[256]; - jio_snprintf(as_chars, sizeof(as_chars), INTX_FORMAT, MaxDirectMemorySize); - PUTPROP(props, "sun.nio.MaxDirectMemorySize", as_chars); + if (FLAG_IS_DEFAULT(MaxDirectMemorySize)) { + PUTPROP(props, "sun.nio.MaxDirectMemorySize", "-1"); + } else { + char as_chars[256]; + jio_snprintf(as_chars, sizeof(as_chars), UINTX_FORMAT, MaxDirectMemorySize); + PUTPROP(props, "sun.nio.MaxDirectMemorySize", as_chars); + } } // JVM monitoring and management support diff -r 0f62a53fae43 src/share/vm/runtime/arguments.cpp --- a/src/share/vm/runtime/arguments.cpp Mon Jun 04 09:17:47 2012 -0400 +++ b/src/share/vm/runtime/arguments.cpp Tue Jun 05 22:29:28 2012 -0400 @@ -2708,6 +2708,17 @@ return JNI_EINVAL; } FLAG_SET_CMDLINE(uintx, ConcGCThreads, conc_threads); + } else if (match_option(option, "-XX:MaxDirectMemorySize=", &tail)) { + julong max_direct_memory_size = 0; + ArgsRange errcode = parse_memory_size(tail, &max_direct_memory_size, 0); + if (errcode != arg_in_range) { + jio_fprintf(defaultStream::error_stream(), + "Invalid maximum direct memory size: %s\n", + option->optionString); + describe_range_error(errcode); + return JNI_EINVAL; + } + FLAG_SET_CMDLINE(uintx, MaxDirectMemorySize, max_direct_memory_size); } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx // Skip -XX:Flags= since that case has already been handled if (strncmp(tail, "Flags=", strlen("Flags=")) != 0) { diff -r 0f62a53fae43 src/share/vm/runtime/globals.hpp --- a/src/share/vm/runtime/globals.hpp Mon Jun 04 09:17:47 2012 -0400 +++ b/src/share/vm/runtime/globals.hpp Tue Jun 05 22:29:28 2012 -0400 @@ -3703,7 +3703,7 @@ \ /* Properties for Java libraries */ \ \ - product(intx, MaxDirectMemorySize, -1, \ + product(uintx, MaxDirectMemorySize, 0, \ "Maximum total size of NIO direct-buffer allocations") \ \ /* temporary developer defined flags */ \
25-06-2012