Printf changes
Greg Lewis
glewis at eyesbeyond.com
Mon Jan 24 00:18:38 PST 2011
G'day all,
I'd like to commit the included changes to how things are printed within
HotSpot. The current version seems to cause problems on MacOS X (or at
least I ran into problems compiling a 64 bit version of OpenJDK7).
I've changed the format specifications to use the C99 printf format
definitions, which should make things more portable. I've tested things
on FreeBSD/i386 and MacOS X/x86_64. I'd appreciate some wider testing
(particularly MacOS X/i386).
diff -r aca9fccf1724 src/os/bsd/vm/os_bsd.cpp
--- a/src/os/bsd/vm/os_bsd.cpp Sun Jan 23 22:23:01 2011 -0800
+++ b/src/os/bsd/vm/os_bsd.cpp Mon Jan 24 00:13:27 2011 -0800
@@ -22,8 +22,6 @@
*
*/
-# define __STDC_FORMAT_MACROS
-
// no precompiled headers
#include "classfile/classLoader.hpp"
#include "classfile/systemDictionary.hpp"
diff -r aca9fccf1724 src/os/linux/vm/os_linux.cpp
--- a/src/os/linux/vm/os_linux.cpp Sun Jan 23 22:23:01 2011 -0800
+++ b/src/os/linux/vm/os_linux.cpp Mon Jan 24 00:13:27 2011 -0800
@@ -22,8 +22,6 @@
*
*/
-# define __STDC_FORMAT_MACROS
-
// no precompiled headers
#include "classfile/classLoader.hpp"
#include "classfile/systemDictionary.hpp"
diff -r aca9fccf1724 src/share/vm/oops/constantPoolOop.cpp
--- a/src/share/vm/oops/constantPoolOop.cpp Sun Jan 23 22:23:01 2011 -0800
+++ b/src/share/vm/oops/constantPoolOop.cpp Mon Jan 24 00:13:27 2011 -0800
@@ -1312,7 +1312,7 @@
}
case JVM_CONSTANT_Long: {
u8 val = Bytes::get_Java_u8(bytes);
- printf("long "INT64_FORMAT, *(jlong *) &val);
+ printf("long "INT64_FORMAT, (int64_t) *(jlong *) &val);
ent_size = 8;
idx++; // Long takes two cpool slots
break;
diff -r aca9fccf1724 src/share/vm/utilities/globalDefinitions.hpp
--- a/src/share/vm/utilities/globalDefinitions.hpp Sun Jan 23 22:23:01 2011 -0800
+++ b/src/share/vm/utilities/globalDefinitions.hpp Mon Jan 24 00:13:27 2011 -0800
@@ -37,6 +37,9 @@
#include "utilities/macros.hpp"
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
+
// This file holds all globally used constants & types, class (forward)
// declarations and a few frequently used utility functions.
@@ -1180,20 +1183,20 @@
// (in ILP32).
// Format 32-bit quantities.
-#define INT32_FORMAT "%d"
-#define UINT32_FORMAT "%u"
+#define INT32_FORMAT "%" PRId32
+#define UINT32_FORMAT "%" PRIu32
#define INT32_FORMAT_W(width) "%" #width "d"
#define UINT32_FORMAT_W(width) "%" #width "u"
-#define PTR32_FORMAT "0x%08x"
+#define PTR32_FORMAT "0x%08" PRIx32
// Format 64-bit quantities.
-#define INT64_FORMAT "%" FORMAT64_MODIFIER "d"
-#define UINT64_FORMAT "%" FORMAT64_MODIFIER "u"
-#define PTR64_FORMAT "0x%016" FORMAT64_MODIFIER "x"
+#define INT64_FORMAT "%" PRId64
+#define UINT64_FORMAT "%" PRIu64
+#define PTR64_FORMAT "0x%016" PRIx64
-#define INT64_FORMAT_W(width) "%" #width FORMAT64_MODIFIER "d"
-#define UINT64_FORMAT_W(width) "%" #width FORMAT64_MODIFIER "u"
+#define INT64_FORMAT_W(width) "%" #width PRId64
+#define UINT64_FORMAT_W(width) "%" #width PRIu64
// Format macros that allow the field width to be specified. The width must be
// a string literal (e.g., "8") or a macro that evaluates to one.
@@ -1218,19 +1221,17 @@
// using "%x".
#ifdef _LP64
#define PTR_FORMAT PTR64_FORMAT
-#define UINTX_FORMAT UINT64_FORMAT
-#define INTX_FORMAT INT64_FORMAT
#define SIZE_FORMAT UINT64_FORMAT
#define SSIZE_FORMAT INT64_FORMAT
#else // !_LP64
#define PTR_FORMAT PTR32_FORMAT
-#define UINTX_FORMAT UINT32_FORMAT
-#define INTX_FORMAT INT32_FORMAT
#define SIZE_FORMAT UINT32_FORMAT
#define SSIZE_FORMAT INT32_FORMAT
#endif // _LP64
+#define UINTX_FORMAT "%" PRIuPTR
+#define INTX_FORMAT "%" PRIdPTR
-#define INTPTR_FORMAT PTR_FORMAT
+#define INTPTR_FORMAT "%" PRIdPTR
// Enable zap-a-lot if in debug version.
--
Greg Lewis Email : glewis at eyesbeyond.com
Eyes Beyond Web : http://www.eyesbeyond.com
Information Technology FreeBSD : glewis at FreeBSD.org
More information about the bsd-port-dev
mailing list