RFR: 8262295: C2: Out-of-Bounds Array Load from Clone Source [v3]
Vladimir Kozlov
kvn at openjdk.java.net
Tue Mar 23 16:21:44 UTC 2021
On Tue, 23 Mar 2021 09:32:18 GMT, Tobias Hartmann <thartmann at openjdk.org> wrote:
>> Thanks for your review Tobias!
>
>> In the example below the load from clone in L6 was hoisted to SRC.
>>
>> ```java
>> 1 public static final Integer[] SRC = new Integer[4096];
>> 2 public static void testMethod_dontinline() throws Exception {
>> 3 Object[] clone = SRC.clone();
>> 4 escape1 = new Object();
>> 5 if (SRC.length > 4) {
>> 6 escape2 = clone[4]; // Load L
>> 7 }
>> 8 }
>> ```
>>
>> Actually the allocation + arraycopy in L3 could be eliminated if it wasn't for the possible deoptimization in L4 and the reference in L6. Would be cool to do the cloning lazily during deoptimization. But probably the gain isn't worth the effort/complexity.
>
> Okay, thanks for verifying!
> > Looks good to me. Just wondering, is the load still hoisted if the source array is a constant array?
>
> In the example below the load from clone in L6 was hoisted to SRC.
>
> ```java
> 1 public static final Integer[] SRC = new Integer[4096];
> 2 public static void testMethod_dontinline() throws Exception {
> 3 Object[] clone = SRC.clone();
> 4 escape1 = new Object();
> 5 if (SRC.length > 4) {
> 6 escape2 = clone[4]; // Load L
> 7 }
> 8 }
> ```
>
> Actually the allocation + arraycopy in L3 could be eliminated if it wasn't for the possible deoptimization in L4 and the reference in L6. Would be cool to do the cloning lazily during deoptimization. But probably the gain isn't worth the effort/complexity.
EA already does that - for small arrays (EliminateAllocationArraySizeLimit = 64). The issue is size because we have to put all SRC's elements on stack for reallocation during deoptimization. Changing size `new Integer[16];` allows to eliminate new array allocation:
======== Connection graph for TestOutOfBoundsArrayLoad::testMethod
JavaObject NoEscape(NoEscape) [ 87cp 314F [ 76 81 ]] 59 AllocateArray === 23 6 24 8 1 ( 57 36 31 42 1 21 ) [[ 60 61 62 74 75 76 ]] rawptr:NotNull ( int:>=0, java/lang/Object:NotNull *, bool, int ) TestOutOfBoundsArrayLoad::testMethod @ bci:3 (line 98) reexecute !jvms: TestOutOfBoundsArrayLoad::testMethod @ bci:3 (line 98)
LocalVar [ 59P [ 81 ]] 76 Proj === 59 [[ 77 81 ]] #5 !jvms: TestOutOfBoundsArrayLoad::testMethod @ bci:3 (line 98)
LocalVar [ 76 87cp 59P [ 314b ]] 81 CheckCastPP === 78 76 [[ 87 314 314 100 ]] #narrowoop: java/lang/Integer:exact *[int:16]:NotNull:exact * !jvms: TestOutOfBoundsArrayLoad::testMethod @ bci:3 (line 98)
-------------
PR: https://git.openjdk.java.net/jdk/pull/2708
More information about the hotspot-compiler-dev
mailing list