RFR: 8377895: Create sizeof_auto, to reduce narrowing conversions [v5]

Leo Korinth lkorinth at openjdk.org
Wed Feb 18 16:25:36 UTC 2026


> `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` .

Leo Korinth has updated the pull request incrementally with one additional commit since the last revision:

  change second example to use int type

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/29716/files
  - new: https://git.openjdk.org/jdk/pull/29716/files/839d70c8..243316cb

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=29716&range=04
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=29716&range=03-04

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/29716.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/29716/head:pull/29716

PR: https://git.openjdk.org/jdk/pull/29716


More information about the hotspot-dev mailing list