Integrated: 8271459: C2: Missing NegativeArraySizeException when creating StringBuilder with negative capacity

Christian Hagedorn chagedorn at openjdk.java.net
Tue Oct 5 07:06:15 UTC 2021


On Thu, 23 Sep 2021 13:25:51 GMT, Christian Hagedorn <chagedorn at openjdk.org> wrote:

> Stringopts does not take into account that a negative `int` argument for `StringBuilder(int)` results in a `NegativeArraySizeException` when optimizing away `StringBuilder` usages into single strings.
> 
> The suggested fix does the following:
> - Bailout of Stringopts if C2 knows that an `int` argument is always negative.
> - Apply stringopts but insert an additional runtime check with an UCT if C2 cannot tell if an `int` argument is positive or negative.
> 
> I added some IR tests to verify the fix and also ran some standard benchmarks.
> 
> I also updated `TestIRMatching` to test the new and updated default regexes.
> 
> Thanks,
> Christian

This pull request has now been integrated.

Changeset: 3953e077
Author:    Christian Hagedorn <chagedorn at openjdk.org>
URL:       https://git.openjdk.java.net/jdk/commit/3953e0774c59c5e936e752aa08b6b6778e232994
Stats:     276 lines in 4 files changed: 269 ins; 0 del; 7 mod

8271459: C2: Missing NegativeArraySizeException when creating StringBuilder with negative capacity

Reviewed-by: roland, thartmann, neliasso

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

PR: https://git.openjdk.java.net/jdk/pull/5652


More information about the hotspot-compiler-dev mailing list