RFR: 8360255: runtime/jni/checked/TestLargeUTF8Length.java fails with -XX:-CompactStrings

Aleksey Shipilev shade at openjdk.org
Wed Jun 25 08:50:32 UTC 2025


On Wed, 25 Jun 2025 07:54:16 GMT, David Holmes <dholmes at openjdk.org> wrote:

> The test creates a `String` with `Integer.MAX_VALUE/2 + 1` characters, where the character encodes as two bytes in UTF-8. That way we test when the UTF-8  length is greater than `Integer.MAX_VALUE`. However, when compact strings are disabled the maximum length of a `String`, in characters, is `Integer.MAX_VALUE/2` so the test throws a (synthetic) OOME.
> 
> The fix I chose was to change the test so that we create a slightly shorter `String` (that will always fit regardless of the compact-strings setting) but to fill it with a character that encodes to three bytes in UTF-8. Hence we still test that the UTF-8 length exceeds `Integer.MAX_LENGTH`.
> 
> Tested on Windows x64, Linux x64 and Aarch64, macOS x64 and Aarch64; on release and fastdebug builds.
> 
> Thanks

Cute trick. Looks fine.

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

Marked as reviewed by shade (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/25970#pullrequestreview-2957264613


More information about the hotspot-runtime-dev mailing list