On Fri, 3 Jul 2026 12:38:04 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).

Thanks Tobias for your review! I've added some more tests to exercise the cases 
when we don't know that we are dealing with a value object during parsing:
- `testCloneAbstract`: We never know that it is a value object.
- `testCloneAbstractRef/Val`: We only know after parsing that we have a ref or 
value object.

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

PR Comment: https://git.openjdk.org/valhalla/pull/2625#issuecomment-4877066603

Reply via email to