JDK-6710775 : VMError::report uses %d to print what might be a long value
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: generic
  • CPU: generic
  • Submitted: 2008-06-04
  • Updated: 2010-11-17
  • Resolved: 2010-11-17
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
7Resolved
Related Reports
Relates :  
Description
###@###.### wrote (while discussing bug-ID 6695810):

 Based on values on stack C2 requested not 16 bytes
 but 8Gb + 16 bytes:

 0xfffffd7fec264440:      0x0000000200000010 0xfffffd7fff01c8e2
 0xfffffd7fec264450:      0x00000000000000d7 0xfffffd7ffe5afdc0

 0x00d7 is line number 215:

 # java.lang.OutOfMemoryError: requested 16 bytes for Chunk::new. Out of swap space?
 #
 #  Internal Error (allocation.cpp:215), pid=4425, tid=12

 There is bug in error report code which use %d to print long value:

 void VMError::report(outputStream) {
 ...
          st->print("# java.lang.OutOfMemoryError: ");
          if (_size) {
            st->print("requested ");
            sprintf(buf,"%d",_size);


vmError.hpp line 61 defines _size:

  size_t       _size;

which on 64-bit platforms will be defined as something like ulong_t

Comments
EVALUATION This bug has already been fixed by using SIZE_FORMAT macro to distinguish 32/64 bits size.
17-11-2010

SUGGESTED FIX ###@###.### points out that an even better fix is ... or use SIZE_FORMAT macro commonly used for that purpose in HotSpot code. As defined in hotspot/src/share/vm/utilities/globalDefinitions.hpp
05-06-2008

SUGGESTED FIX %d is for formatting integers. Instead use %zd as suggested by the man page for printf(3C). Here is an example program (Modified for windows-x64 format codes as well): % cat st.c #include <stdio.h> int main(int argc, char *argv[]) { size_t _size = 0x0000000200000010; (void) fprintf(stdout, "OOPS: %d\n", _size); #ifdef _WINDOWS (void) fprintf(stdout, "GOOD: %Iu\n", _size); #else (void) fprintf(stdout, "GOOD: %zu\n", _size); #endif } % cc -m64 -g -o st st.c % ./st OOPS: 16 GOOD: 8589934608
04-06-2008