RFR: 8377658: G1: Cleanup g1ConcurrentMark.cpp for stricter warning flags
Leo Korinth
lkorinth at openjdk.org
Fri Feb 13 11:06:47 UTC 2026
On Thu, 12 Feb 2026 20:30:31 GMT, Stefan Karlsson <stefank at openjdk.org> wrote:
>> Cleanup `g1ConcurrentMark.cpp` and included header files to remove implicit narrowing conversions.
>>
>> For gcc: `-Wconversion -Wno-float-conversion`
>> For clang: `-Wimplicit-int-conversion`
>>
>> `sizeof_auto` is created so that we can reduce the amount of casting and thus make the code more type safe. The normal `sizeof` will return a `size_t` although the size of most stuff can be represented in a `uint8_t`. `sizeof_auto` will return the size in an as small unsigned type as is possible. The result is that expressions that uses `sizeof_auto` can convert to most integral types, and no explicit narrowing cast will be needed.
>
> src/hotspot/share/oops/fieldInfo.hpp line 305:
>
>> 303: // boilerplate:
>> 304: u1 _flags;
>> 305: static constexpr u1 flag_mask(FieldStatusBitPosition pos) { return static_cast<u1>(1 << pos); }
>
> Shouldn't this use `checked_cast` or Kim's proposed `integer_cast` to make sure that a future change to `FieldStatusBitPosition` doesn't make this overflow an `u1`?
Yes, that is better.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/29701#discussion_r2803635880
More information about the hotspot-dev
mailing list