Integrated: 8377895: Create sizeof_auto to reduce narrowing conversions
Leo Korinth
lkorinth at openjdk.org
Fri Feb 27 09:54:50 UTC 2026
On Fri, 13 Feb 2026 16:02:52 GMT, Leo Korinth <lkorinth at openjdk.org> wrote:
> `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.
>
> The change in `cpCache.hpp` is an example where we would get an implicit narrowing warning (if we had those enabled) using normal `sizeof`, but where `sizeof_auto` will not make the expression a `size_t` .
This pull request has now been integrated.
Changeset: 94a34a32
Author: Leo Korinth <lkorinth at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/94a34a32aa723e4620f4ef4700b3e20d6ab9bf62
Stats: 59 lines in 3 files changed: 58 ins; 0 del; 1 mod
8377895: Create sizeof_auto to reduce narrowing conversions
Reviewed-by: kbarrett, jsjolen, dlong, aboldtch, stefank, ayang
-------------
PR: https://git.openjdk.org/jdk/pull/29716
More information about the hotspot-dev
mailing list