RFR: 8337683: Fix -Wconversion problem with arrayOop.hpp [v5]
Dean Long
dlong at openjdk.org
Thu Aug 8 19:33:39 UTC 2024
On Thu, 8 Aug 2024 11:07:41 GMT, Coleen Phillimore <coleenp at openjdk.org> wrote:
>> src/hotspot/share/oops/arrayOop.hpp line 74:
>>
>>> 72: #ifdef ASSERT
>>> 73: // make sure it isn't called before UseCompressedOops is initialized.
>>> 74: static int arrayoopdesc_hs = 0;
>>
>> Why not just do a `checked_cast<int>` on the return statement? (or even a range assert and a static cast?)
>
> Because restricting the types is better than checked_cast. The return type of length_offset_in_bytes() is int.
Also I think the current checked_cast still has problems with signed <--> unsigned.
Another technique to use an even more restricted type. For example, if these offset_in_bytes() functions returned uint16_t, then the value can be widened to either `int` or `size_t` without a cast.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20431#discussion_r1710159357
More information about the hotspot-dev
mailing list