RFR: 8356865: C2: Unreasonable values for debug flag FastAllocateSizeLimit can lead to left-shift-overflow, which is UB

Manuel Hässig mhaessig at openjdk.org
Tue Jun 17 08:40:38 UTC 2025


On Mon, 16 Jun 2025 14:50:46 GMT, Benoît Maillard <bmaillard at openjdk.org> wrote:

> This PR adds a range constraint for the `-XX:FastAllocateSizeLimit` debug flag. This prevents undefined behavior caused by left-shift overflow of the flag value in `GraphKit::new_array`.
> 
> ### Testing
> - [x] [GitHub Actions](https://github.com/benoitmaillard/jdk/actions?query=branch%3AJDK-8356865)
> - [x] tier1-3, plus some internal testing
> - [x] Manual testing with values known to previously cause undefined behavior
> 
> Thanks!

Thank you for working on this, @benoitmaillard. This looks good to me.

src/hotspot/share/runtime/globals.hpp line 1100:

> 1098:           /* Note:  This value is zero mod 1<<13 for a cheap sparc set. */  \
> 1099:           "Inline allocations larger than this in doublewords must go slow")\
> 1100:           range(0, (1 << (BitsPerInt - LogBytesPerLong - 1)) - 1)           \

It would be good to add a comment as to why this specific upper limit is necessary.

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

Marked as reviewed by mhaessig (Author).

PR Review: https://git.openjdk.org/jdk/pull/25834#pullrequestreview-2934700344
PR Review Comment: https://git.openjdk.org/jdk/pull/25834#discussion_r2151674726


More information about the hotspot-dev mailing list