RFR: 8262295: C2: Out-of-Bounds Array Load from Clone Source [v3]

Tobias Hartmann thartmann at openjdk.java.net
Tue Mar 23 09:34:41 UTC 2021


On Tue, 23 Mar 2021 09:19:22 GMT, Richard Reingruber <rrich at openjdk.org> wrote:

>>> 
>>> 
>>> 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.
>> 
>>    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.
>
> 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!

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

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


More information about the hotspot-compiler-dev mailing list