Skip to content

8377895: Create sizeof_auto, to reduce narrowing conversions#29716

Open
lkorinth wants to merge 1 commit intoopenjdk:masterfrom
lkorinth:_8377895
Open

8377895: Create sizeof_auto, to reduce narrowing conversions#29716
lkorinth wants to merge 1 commit intoopenjdk:masterfrom
lkorinth:_8377895

Conversation

@lkorinth
Copy link
Contributor

@lkorinth lkorinth commented Feb 13, 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 .


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8377895: Create sizeof_auto, to reduce narrowing conversions (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/29716/head:pull/29716
$ git checkout pull/29716

Update a local copy of the PR:
$ git checkout pull/29716
$ git pull https://git.openjdk.org/jdk.git pull/29716/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 29716

View PR using the GUI difftool:
$ git pr show -t 29716

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/29716.diff

Using Webrev

Link to Webrev Comment

`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.
@bridgekeeper
Copy link

bridgekeeper bot commented Feb 13, 2026

👋 Welcome back lkorinth! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Feb 13, 2026

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the hotspot hotspot-dev@openjdk.org label Feb 13, 2026
@openjdk
Copy link

openjdk bot commented Feb 13, 2026

@lkorinth The following label will be automatically applied to this pull request:

  • hotspot

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 13, 2026
@mlbridge
Copy link

mlbridge bot commented Feb 13, 2026

Webrevs

Copy link
Member

@stefank stefank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the change looks good. The gtests doesn't compile everywhere so that needs to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot hotspot-dev@openjdk.org rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

2 participants