JDK-7172708 : 32/64 bit type issues on Windows after Mac OS X port
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 7u4
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2012-05-30
  • Updated: 2013-06-26
  • Resolved: 2012-06-15
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 hs23.2Fixed
Description
Reported by Chris Dennis on the jdk7u mailing list

"I believe that when the Mac OS X support was merged in to the jdk7u-dev forest that a mistake was made regarding Visual Studio's lack of inttypes.h.  The symptom of this bug can be seen in the following output:

$ java -showversion -d64 -XX:MaxDirectMemorySize=4g OffHeapAllocationTest
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)

Command Line: [-XX:MaxDirectMemorySize=4g]
sun.misc.VM.maxDirectMemory() = 0
java.nio.Bits.maxMemory = 0

Experimenting with different MaxDirectMemorySize values clearly shows this to be a 32-bit wrap-around issue.  When Mac OS X support was merged in, the INTX_FORMAT which is used to write the MaxDirectMemorySize global in to the system properties was modified to use PRIdPTR from inttypes.h.  As Visual Studio lacks inttypes.h, definitions for this (and the other associated format specifiers) were added to globalDefinitions_visCPP.hpp.  However the definitions added are only correct for a 32-bit system.  I believe the following changeset corrects that error (no Windows access prevents me from verifying this fix however)."

Reproducer

public class TestMaxDirectMemory {

   public static void main(String[] args) {
	System.out.println(sun.misc.VM.maxDirectMemory());
   }
}

When run with -XX:MaxDirectMemorySize=4g on a 64bit Windows 1.7.0_04 VM it will print 0 since the high 32bits will get dropped.

Comments
EVALUATION http://hg.openjdk.java.net/lambda/lambda/hotspot/rev/40b4aaf010e4
29-06-2012

EVALUATION <moved to hs24 subCR>
14-06-2012

EVALUATION http://hg.openjdk.java.net/hsx/hsx23.2/hotspot/rev/7871a1b632cb
13-06-2012

EVALUATION See suggested fix.
08-06-2012

SUGGESTED FIX diff -r bca9e76ea254 src/share/vm/utilities/globalDefinitions_visCPP.hpp --- a/src/share/vm/utilities/globalDefinitions_visCPP.hpp Tue Mar 20 10:17:41 2012 -0700 +++ b/src/share/vm/utilities/globalDefinitions_visCPP.hpp Tue May 22 17:24:57 2012 -0400 @@ -220,9 +220,15 @@ #define PRIu64 "I64u" #define PRIx64 "I64x" +#ifdef _LP64 +#define PRIdPTR "I64d" +#define PRIuPTR "I64u" +#define PRIxPTR "I64x" +#else #define PRIdPTR "d" #define PRIuPTR "u" #define PRIxPTR "x" +#endif #define offset_of(klass,field) offsetof(klass,field)
30-05-2012