RFR: 8340620: Fix -Wzero-as-null-pointer-constant warnings for CompressedOops
Aleksey Shipilev
shade at openjdk.org
Wed Sep 25 08:40:36 UTC 2024
On Wed, 25 Sep 2024 07:47:21 GMT, Stefan Karlsson <stefank at openjdk.org> wrote:
>> Please review this change that fixes -Wzero-as-null-pointer-constant warnings
>> in CompressedOops code. These all relate to CompressedOops::base().
>>
>> I also added a couple of asserts to verify our assumptions about null pointer
>> constants being representationally zero. That isn't a Standard-conforming
>> assumption, but holds for all platforms we currently support. I considered,
>> and even explored, a couple of different options.
>>
>> (1) Continue to have CompressedOops::base() be a pointer, but avoid that
>> assumption, being more careful about how zero-valued pointers are treated. But
>> that adds significant complexity that we can't test, since we don't support
>> any platforms needing that extra work.
>>
>> (2) Change CompressedOops::base() to an integral adjustment. This is probably
>> the correct approach, but is much more intrusive and wide ranging in the
>> changes required. Maybe something for the future.
>>
>> Testing: mach5 tier1-5
>> GHA testing, verifying builds on some platforms not supported by Oracle.
>>
>> There are some simple changes to s390 and ppc code that I haven't tested,
>> beyond verifying compilation.
>
> src/hotspot/share/oops/compressedOops.inline.hpp line 53:
>
>> 51: // Assume a null base casts to zero. Otherwise we need more complexity that
>> 52: // we can't test, since this is true for all currently supported platforms.
>> 53: assert(0 == reinterpret_cast<uintptr_t>(nullptr), "null pointer value not zero?");
>
> Could this be a static_assert?
+1. Although I would expect any sane compiler to fold it, maybe it is still not optimized with something like `-O0`. Or maybe just move these asserts to `CompressedOops::initialize`, so whatever happens, happens once.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/21172#discussion_r1774809759
More information about the hotspot-dev
mailing list