RFR: 8292981: Unify and restructure integer printing format specifiers [v2]
Stefan Karlsson
stefank at openjdk.org
Tue Aug 30 12:58:38 UTC 2022
On Mon, 29 Aug 2022 12:15:17 GMT, David Holmes <dholmes at openjdk.org> wrote:
>>> (And yes we have to cast the ptrs to int using p2i but that is just because of compiler limitations/issues ... which raises the recurring old question of "have we finally reached a point where we can use %p cross-platform?")
>>
>> One motivation for using PTR_FORMAT instead of %p, is to get consistent output on all platforms. I ran the following on different OSes:
>>
>> tty->print_cr("%p " PTR_FORMAT, (void*)0x12345678, (uintptr_t)0x12345678);
>>
>> And the result is:
>>
>> Linux: 0x12345678 0x0000000012345678
>> macOS: 0x12345678 0x0000000012345678
>> Win: 0x0000000012345678 0x0000000012345678
>>
>>
>> I also tested getting zero padding on Linux, but the compiler informs me that that's not allowed: `error: '0' flag used with '%p' gnu_printf format"`.
>
>> One motivation for using PTR_FORMAT instead of %p, is to get consistent output on all platforms.
>
> Yes that has always been the problem, but I wondered whether this issue was perhaps finally resolved. Based on your results we seem closer - they all have leading 0x - but they still differ in leading zeroes. I have a recollection now that someone tried using %p fairly recently (ie last 12-24 months) and also discovered this. Kind of sad that something so conceptually simple has proven to be so difficult to get right.
@dholmes-ora Do you have any actionable items that you want me to do for this PR?
-------------
PR: https://git.openjdk.org/jdk/pull/10042
More information about the hotspot-dev
mailing list