diff --git a/src/hotspot/share/runtime/os.cpp b/src/hotspot/share/runtime/os.cpp index f9f3c4e1458..9c73e255db2 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(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("%016" FORMAT64_MODIFIER "x", (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 ce864119d75..86bee7a071f 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 @@ -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,6 +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 +#define UINT64_FORMAT_0 "%016" PRIx64 // Format integers which change size between 32- and 64-bit. #define SSIZE_FORMAT "%" PRIdPTR diff --git a/src/hotspot/share/utilities/globalDefinitions_gcc.hpp b/src/hotspot/share/utilities/globalDefinitions_gcc.hpp index 863e588d180..a2fbc3be363 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 3f22948118d..83d07557287 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 5dc43fb543f..9cadc91aeb9 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(UINT64_FORMAT_0, (u8)0x123, "0000000000000123"); }