RFR: 8314258: checked_cast doesn't properly check some cases [v2]

Kim Barrett kbarrett at openjdk.org
Sat Feb 14 22:57:24 UTC 2026


On Fri, 13 Feb 2026 11:22:03 GMT, Stefan Karlsson <stefank at openjdk.org> wrote:

> Is it important to have "Range check with one comparison" or could two
> comparisons make for clearer code?

This predicate isn't only for use by integer_cast in debug builds. It can also
be used directly, even in product builds.  So performance matters more than
something just for assertions.

> Could the compiler optimize two comparisons into one?

That's an interesting question that I hadn't considered. And the answer is
yes, they can. At least, gcc and clang do so (in recent versions; I didn't
test older versions). They produce identical (or equivalent) code to the more
complicated explicit single compare source. I don't have easy access to MSVC,
but it seems likely since the others do.

Simplified accordingly.

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

PR Comment: https://git.openjdk.org/jdk/pull/29582#issuecomment-3902738452


More information about the hotspot-dev mailing list