From b9c8e43da20763c52a95824a8c9d7552a55485b5 Mon Sep 17 00:00:00 2001 From: Coleen Phillimore Date: Fri, 3 Jan 2025 17:30:52 +0000 Subject: [PATCH 1/4] 8329549: Remove FORMAT64_MODIFIER --- src/hotspot/share/runtime/os.cpp | 6 +++--- .../share/utilities/globalDefinitions_gcc.hpp | 13 +------------ .../share/utilities/globalDefinitions_visCPP.hpp | 5 +---- .../gtest/utilities/test_globalDefinitions.cpp | 5 ++++- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/hotspot/share/runtime/os.cpp b/src/hotspot/share/runtime/os.cpp index f9f3c4e145848..5bceb28822d0c 100644 --- a/src/hotspot/share/runtime/os.cpp +++ b/src/hotspot/share/runtime/os.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -971,7 +971,7 @@ static void print_hex_location(outputStream* st, const_address p, int unitsize, const uint64_t value = LITTLE_ENDIAN_ONLY((((uint64_t)i2) << 32) | i1) BIG_ENDIAN_ONLY((((uint64_t)i1) << 32) | i2); - st->print("%016" FORMAT64_MODIFIER "x", value); + st->print("%016zx", value); print_ascii_form(ascii_form, value, unitsize); } else { st->print_raw("????????????????"); @@ -995,7 +995,7 @@ static void print_hex_location(outputStream* st, const_address p, int unitsize, case 1: st->print("%02x", (u1)value); break; case 2: st->print("%04x", (u2)value); break; case 4: st->print("%08x", (u4)value); break; - case 8: st->print("%016" FORMAT64_MODIFIER "x", (u8)value); break; + case 8: st->print("%016zx", (u8)value); break; } print_ascii_form(ascii_form, value, unitsize); } else { diff --git a/src/hotspot/share/utilities/globalDefinitions_gcc.hpp b/src/hotspot/share/utilities/globalDefinitions_gcc.hpp index 863e588d18032..a2fbc3be3636b 100644 --- a/src/hotspot/share/utilities/globalDefinitions_gcc.hpp +++ b/src/hotspot/share/utilities/globalDefinitions_gcc.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -90,17 +90,6 @@ inline int g_isfinite(jfloat f) { return isfinite(f); } inline int g_isfinite(jdouble f) { return isfinite(f); } -// Formatting. -#ifdef _LP64 -# ifdef __APPLE__ -# define FORMAT64_MODIFIER "ll" -# else -# define FORMAT64_MODIFIER "l" -# endif -#else // !_LP64 -#define FORMAT64_MODIFIER "ll" -#endif // _LP64 - // gcc warns about applying offsetof() to non-POD object or calculating // offset directly when base address is null. The -Wno-invalid-offsetof // option could be used to suppress this warning, but we instead just diff --git a/src/hotspot/share/utilities/globalDefinitions_visCPP.hpp b/src/hotspot/share/utilities/globalDefinitions_visCPP.hpp index 3f22948118df9..83d075572877a 100644 --- a/src/hotspot/share/utilities/globalDefinitions_visCPP.hpp +++ b/src/hotspot/share/utilities/globalDefinitions_visCPP.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -103,9 +103,6 @@ inline int g_isnan(jdouble f) { return _isnan(f); } inline int g_isfinite(jfloat f) { return _finite(f); } inline int g_isfinite(jdouble f) { return _finite(f); } -// Formatting. -#define FORMAT64_MODIFIER "ll" - #define offset_of(klass,field) offsetof(klass,field) #define THREAD_LOCAL __declspec(thread) diff --git a/test/hotspot/gtest/utilities/test_globalDefinitions.cpp b/test/hotspot/gtest/utilities/test_globalDefinitions.cpp index 5dc43fb543f95..d96e14ea215c5 100644 --- a/test/hotspot/gtest/utilities/test_globalDefinitions.cpp +++ b/test/hotspot/gtest/utilities/test_globalDefinitions.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -289,4 +289,7 @@ TEST(globalDefinitions, format_specifiers) { check_format(INTPTR_FORMAT, (intptr_t)0x123, "0x" LP64_ONLY("00000000") "00000123"); check_format(PTR_FORMAT, (uintptr_t)0x123, "0x" LP64_ONLY("00000000") "00000123"); + + // Check all platforms print this compatibly without leading 0x. + check_format("%016zx", (u8)0x123, "0000000000000123"); } From c93c939b923ac67a4e7eb5932bb72f90a86a7a7e Mon Sep 17 00:00:00 2001 From: Coleen Phillimore Date: Fri, 3 Jan 2025 20:24:02 +0000 Subject: [PATCH 2/4] Maybe this is better. --- src/hotspot/share/runtime/os.cpp | 4 ++-- src/hotspot/share/utilities/globalDefinitions.hpp | 5 ++++- test/hotspot/gtest/utilities/test_globalDefinitions.cpp | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/hotspot/share/runtime/os.cpp b/src/hotspot/share/runtime/os.cpp index 5bceb28822d0c..b504e5fc48dd3 100644 --- a/src/hotspot/share/runtime/os.cpp +++ b/src/hotspot/share/runtime/os.cpp @@ -971,7 +971,7 @@ static void print_hex_location(outputStream* st, const_address p, int unitsize, const uint64_t value = LITTLE_ENDIAN_ONLY((((uint64_t)i2) << 32) | i1) BIG_ENDIAN_ONLY((((uint64_t)i1) << 32) | i2); - st->print("%016zx", value); + st->print(INT64_FORMAT_X_0_, value); print_ascii_form(ascii_form, value, unitsize); } else { st->print_raw("????????????????"); @@ -995,7 +995,7 @@ static void print_hex_location(outputStream* st, const_address p, int unitsize, case 1: st->print("%02x", (u1)value); break; case 2: st->print("%04x", (u2)value); break; case 4: st->print("%08x", (u4)value); break; - case 8: st->print("%016zx", (u8)value); break; + case 8: st->print(INT64_FORMAT_X_0_, (u8)value); break; } print_ascii_form(ascii_form, value, unitsize); } else { diff --git a/src/hotspot/share/utilities/globalDefinitions.hpp b/src/hotspot/share/utilities/globalDefinitions.hpp index ce864119d75fd..4d825e75bb053 100644 --- a/src/hotspot/share/utilities/globalDefinitions.hpp +++ b/src/hotspot/share/utilities/globalDefinitions.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -132,6 +132,9 @@ class oopDesc; #define UINT64_FORMAT_X_0 "0x%016" PRIx64 #define UINT64_FORMAT_W(width) "%" #width PRIu64 +// Format without leading 0x +#define INT64_FORMAT_X_0_ "%016" PRIx64 + // Format integers which change size between 32- and 64-bit. #define SSIZE_FORMAT "%" PRIdPTR #define SSIZE_PLUS_FORMAT "%+" PRIdPTR diff --git a/test/hotspot/gtest/utilities/test_globalDefinitions.cpp b/test/hotspot/gtest/utilities/test_globalDefinitions.cpp index d96e14ea215c5..efee2e99a3086 100644 --- a/test/hotspot/gtest/utilities/test_globalDefinitions.cpp +++ b/test/hotspot/gtest/utilities/test_globalDefinitions.cpp @@ -291,5 +291,5 @@ TEST(globalDefinitions, format_specifiers) { check_format(PTR_FORMAT, (uintptr_t)0x123, "0x" LP64_ONLY("00000000") "00000123"); // Check all platforms print this compatibly without leading 0x. - check_format("%016zx", (u8)0x123, "0000000000000123"); + check_format(INT64_FORMAT_X_0_, (u8)0x123, "0000000000000123"); } From f2223d2c1b580ea228bc8f64ca075853e850b954 Mon Sep 17 00:00:00 2001 From: Coleen Phillimore Date: Tue, 7 Jan 2025 12:36:43 +0000 Subject: [PATCH 3/4] Use INT64_FORMAT_0 --- src/hotspot/share/runtime/os.cpp | 4 ++-- src/hotspot/share/utilities/globalDefinitions.hpp | 4 ++-- test/hotspot/gtest/utilities/test_globalDefinitions.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hotspot/share/runtime/os.cpp b/src/hotspot/share/runtime/os.cpp index b504e5fc48dd3..c3f286c0b208d 100644 --- a/src/hotspot/share/runtime/os.cpp +++ b/src/hotspot/share/runtime/os.cpp @@ -971,7 +971,7 @@ static void print_hex_location(outputStream* st, const_address p, int unitsize, const uint64_t value = LITTLE_ENDIAN_ONLY((((uint64_t)i2) << 32) | i1) BIG_ENDIAN_ONLY((((uint64_t)i1) << 32) | i2); - st->print(INT64_FORMAT_X_0_, value); + st->print(INT64_FORMAT_0, value); print_ascii_form(ascii_form, value, unitsize); } else { st->print_raw("????????????????"); @@ -995,7 +995,7 @@ static void print_hex_location(outputStream* st, const_address p, int unitsize, case 1: st->print("%02x", (u1)value); break; case 2: st->print("%04x", (u2)value); break; case 4: st->print("%08x", (u4)value); break; - case 8: st->print(INT64_FORMAT_X_0_, (u8)value); break; + case 8: st->print(INT64_FORMAT_0, (u8)value); break; } print_ascii_form(ascii_form, value, unitsize); } else { diff --git a/src/hotspot/share/utilities/globalDefinitions.hpp b/src/hotspot/share/utilities/globalDefinitions.hpp index 4d825e75bb053..e1512d42d75e6 100644 --- a/src/hotspot/share/utilities/globalDefinitions.hpp +++ b/src/hotspot/share/utilities/globalDefinitions.hpp @@ -132,8 +132,8 @@ class oopDesc; #define UINT64_FORMAT_X_0 "0x%016" PRIx64 #define UINT64_FORMAT_W(width) "%" #width PRIu64 -// Format without leading 0x -#define INT64_FORMAT_X_0_ "%016" PRIx64 +// Format with padding without leading 0x +#define INT64_FORMAT_0 "%016" PRIx64 // Format integers which change size between 32- and 64-bit. #define SSIZE_FORMAT "%" PRIdPTR diff --git a/test/hotspot/gtest/utilities/test_globalDefinitions.cpp b/test/hotspot/gtest/utilities/test_globalDefinitions.cpp index efee2e99a3086..bfbd725c92f32 100644 --- a/test/hotspot/gtest/utilities/test_globalDefinitions.cpp +++ b/test/hotspot/gtest/utilities/test_globalDefinitions.cpp @@ -291,5 +291,5 @@ TEST(globalDefinitions, format_specifiers) { check_format(PTR_FORMAT, (uintptr_t)0x123, "0x" LP64_ONLY("00000000") "00000123"); // Check all platforms print this compatibly without leading 0x. - check_format(INT64_FORMAT_X_0_, (u8)0x123, "0000000000000123"); + check_format(INT64_FORMAT_0, (u8)0x123, "0000000000000123"); } From 6ac66379b6058cf1160f784605385d4765899cf0 Mon Sep 17 00:00:00 2001 From: Coleen Phillimore Date: Tue, 7 Jan 2025 14:04:13 +0000 Subject: [PATCH 4/4] You're right, it's UINT64_FORMAT and moved the comment. --- src/hotspot/share/runtime/os.cpp | 4 ++-- src/hotspot/share/utilities/globalDefinitions.hpp | 5 ++--- test/hotspot/gtest/utilities/test_globalDefinitions.cpp | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/hotspot/share/runtime/os.cpp b/src/hotspot/share/runtime/os.cpp index c3f286c0b208d..9c73e255db2e1 100644 --- a/src/hotspot/share/runtime/os.cpp +++ b/src/hotspot/share/runtime/os.cpp @@ -971,7 +971,7 @@ static void print_hex_location(outputStream* st, const_address p, int unitsize, const uint64_t value = LITTLE_ENDIAN_ONLY((((uint64_t)i2) << 32) | i1) BIG_ENDIAN_ONLY((((uint64_t)i1) << 32) | i2); - st->print(INT64_FORMAT_0, value); + st->print(UINT64_FORMAT_0, value); print_ascii_form(ascii_form, value, unitsize); } else { st->print_raw("????????????????"); @@ -995,7 +995,7 @@ static void print_hex_location(outputStream* st, const_address p, int unitsize, case 1: st->print("%02x", (u1)value); break; case 2: st->print("%04x", (u2)value); break; case 4: st->print("%08x", (u4)value); break; - case 8: st->print(INT64_FORMAT_0, (u8)value); break; + case 8: st->print(UINT64_FORMAT_0, (u8)value); break; } print_ascii_form(ascii_form, value, unitsize); } else { diff --git a/src/hotspot/share/utilities/globalDefinitions.hpp b/src/hotspot/share/utilities/globalDefinitions.hpp index e1512d42d75e6..86bee7a071f7e 100644 --- a/src/hotspot/share/utilities/globalDefinitions.hpp +++ b/src/hotspot/share/utilities/globalDefinitions.hpp @@ -99,6 +99,7 @@ class oopDesc; // _X_0 - print as hexadecimal, with leading 0s: 0x00012345 // _W(w) - prints w sized string with the given value right // adjusted. Use -w to print left adjusted. +// _0 - print as hexadecimal, with leading 0s, without 0x prefix: 0012345 // // Note that the PTR format specifiers print using 0x with leading zeros, // just like the _X_0 version for integers. @@ -131,9 +132,7 @@ class oopDesc; #define UINT64_FORMAT_X "0x%" PRIx64 #define UINT64_FORMAT_X_0 "0x%016" PRIx64 #define UINT64_FORMAT_W(width) "%" #width PRIu64 - -// Format with padding without leading 0x -#define INT64_FORMAT_0 "%016" PRIx64 +#define UINT64_FORMAT_0 "%016" PRIx64 // Format integers which change size between 32- and 64-bit. #define SSIZE_FORMAT "%" PRIdPTR diff --git a/test/hotspot/gtest/utilities/test_globalDefinitions.cpp b/test/hotspot/gtest/utilities/test_globalDefinitions.cpp index bfbd725c92f32..9cadc91aeb94d 100644 --- a/test/hotspot/gtest/utilities/test_globalDefinitions.cpp +++ b/test/hotspot/gtest/utilities/test_globalDefinitions.cpp @@ -291,5 +291,5 @@ TEST(globalDefinitions, format_specifiers) { check_format(PTR_FORMAT, (uintptr_t)0x123, "0x" LP64_ONLY("00000000") "00000123"); // Check all platforms print this compatibly without leading 0x. - check_format(INT64_FORMAT_0, (u8)0x123, "0000000000000123"); + check_format(UINT64_FORMAT_0, (u8)0x123, "0000000000000123"); }