On Fri, 3 Jul 2026 14:10:20 GMT, Christian Hagedorn <[email protected]> 
wrote:

>> The `clone()` intrinsic directly returns a value object because it has no 
>> identity - the clone is trivially a no-op:
>> https://github.com/openjdk/valhalla/blob/2af7c2350b22ed03850b6b6c146b622ca758f441/src/hotspot/share/opto/library_call.cpp#L6041-L6045
>> 
>> But this is incorrect if the value class does not implement `Cloneable`. In 
>> this case, we must throw `CloneNotSupportedException` which is currently 
>> missing.
>> 
>> The fix adds a check whether the value class implements `Cloneable`. If it 
>> does, we execute the existing code no-op path. Otherwise, we could either do 
>> a call to the runtime `clone()` implementation, as done for the existing 
>> slow path of this intrinsic, or we simply emit an uncommon trap. I've 
>> decided to use the latter approach since it's more straight forward and 
>> rather an edge-case situation. I also included a `too_many_traps()` check to 
>> avoid repeated recompilations.
>> 
>> Thanks,
>> Christian
>>  
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Christian Hagedorn has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Add more tests

Perfect, thanks for adding more tests!

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

Marked as reviewed by thartmann (Committer).

PR Review: 
https://git.openjdk.org/valhalla/pull/2625#pullrequestreview-4626548712

Reply via email to