[lworld] RFR: 8316742: [lworld] Intrinsify Unsafe::isFlattenedArray()

Tobias Hartmann thartmann at openjdk.org
Wed Oct 18 08:25:53 UTC 2023


On Tue, 17 Oct 2023 10:15:39 GMT, Roberto Castañeda Lozano <rcastanedalo at openjdk.org> wrote:

> This changeset introduces a compiler intrinsic for `jdk.internal.misc.Unsafe::isFlattenedArray(Class<?> arrayClass)`. The intrinsic reuses C2's `FlatArrayCheckNode`, and exploits the assumptions made by the native implementation (`arrayClass` is non-null and non-primitive) to avoid unnecessary null checks. Reusing `FlatArrayCheckNode` in this different context requires small generalizations of its macro expansion logic.
> 
> Additionally, the changeset removes a no-longer-needed check in `java.lang.invoke.VarHandles::makeArrayElementHandle(Class<?> arrayClass)` and re-enables the `compiler.gcbarriers::TestZGCBarrierElision` tests (whose failures were caused by the introduction of calls to `isFlattenedArray` inhibiting barrier optimizations).
> 
> Local experiments with the included micro-benchmarks show that the changeset:
> - speeds up direct calls to `isFlattenedArray` by between 24x and 48x depending on whether the tested class is known to C2,
> - speeds up `java.lang.invoke.VarHandle.set(Object... args)` by an order of magnitude, and
> - preserves the performance of `java.lang.invoke.MethodHandles.arrayElementVarHandle(Class<?> arrayClass)` despite the simplification of the underlying `java.lang.invoke.VarHandles::makeArrayElementHandle(Class<?> arrayClass)` method.
> 
> Complete results are attached [here](https://github.com/openjdk/valhalla/files/12927498/results.ods).
> 
> 
> #### Testing
> - tier1-5 (windows-x64, linux-x64, linux-aarch64, macosx-x64, macosx-aarch64; release and debug mode)
> 
> **Acknowledgments:** thanks to Tobias Hartmann for discussions on earlier versions of this changeset.

Looks great, thanks for working on this Roberto!

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

Marked as reviewed by thartmann (Committer).

PR Review: https://git.openjdk.org/valhalla/pull/938#pullrequestreview-1684406517



More information about the valhalla-dev mailing list