> 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 ------------- Changes: - all: https://git.openjdk.org/valhalla/pull/2625/files - new: https://git.openjdk.org/valhalla/pull/2625/files/df281560..ec6900ce Webrevs: - full: https://webrevs.openjdk.org/?repo=valhalla&pr=2625&range=01 - incr: https://webrevs.openjdk.org/?repo=valhalla&pr=2625&range=00-01 Stats: 93 lines in 1 file changed: 93 ins; 0 del; 0 mod Patch: https://git.openjdk.org/valhalla/pull/2625.diff Fetch: git fetch https://git.openjdk.org/valhalla.git pull/2625/head:pull/2625 PR: https://git.openjdk.org/valhalla/pull/2625
