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

Roberto Castañeda Lozano rcastanedalo at openjdk.org
Wed Oct 18 09:23:27 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.

This pull request has now been integrated.

Changeset: 985474d2
Author:    Roberto Castañeda Lozano <rcastanedalo at openjdk.org>
Committer: Tobias Hartmann <thartmann at openjdk.org>
URL:       https://git.openjdk.org/valhalla/commit/985474d2e685b4037bd867c20f41ae03637aaeb6
Stats:     170 lines in 11 files changed: 162 ins; 4 del; 4 mod

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

Reviewed-by: thartmann

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

PR: https://git.openjdk.org/valhalla/pull/938



More information about the valhalla-dev mailing list