RFR: 8339526: C2: store incorrectly removed for clone() transformed to series of loads/stores [v2]
    Roland Westrelin 
    roland at openjdk.org
       
    Mon Oct 13 15:20:43 UTC 2025
    
    
  
On Mon, 13 Oct 2025 09:05:13 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
> Hi Roland, thanks for looking into this!
> 
> Can you explain why the `clone` in `inlined2` creates an `ArrayCopy` node? I think I'm missing some context here. Because we are cloning an `A` and not an array, right?
Naming of the node is unfortunate as it's also used for instance clones. Historically, optimizations for arraycopy have been used for instance clones as well and that's where the misleading name comes from. For arraycopy and array/instance clones: large arrays/instances are bulk copied with a call to subroutine added during macro expansion, small arrays/instances are copied with a series or loads/stores added during igvn and there's also code so that the a copy to a non escaping array/instance doesn't get in the way of EA and can be eliminated.
> test/hotspot/jtreg/compiler/arraycopy/TestCloneUnknownClassAtParseTime.java line 63:
> 
>> 61:     private static A inlined2() throws CloneNotSupportedException {
>> 62:         A a = field;
>> 63:         return (A)a.clone();
> 
> Out of curiosity: why do we even add a `ArrayCopy` here?
Does my reply to your comment above answer that question?
-------------
PR Comment: https://git.openjdk.org/jdk/pull/27604#issuecomment-3397942139
PR Review Comment: https://git.openjdk.org/jdk/pull/27604#discussion_r2426643140
    
    
More information about the hotspot-compiler-dev
mailing list