[lworld] RFR: 8316742: [lworld] Intrinsify Unsafe::isFlattenedArray()
Roberto Castañeda Lozano
rcastanedalo at openjdk.org
Tue Oct 17 10:40:00 UTC 2023
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.
-------------
Commit messages:
- Refine comment, again
- Refine comment
- List new intrinsic consistently with definition order
- Simplify microbenchmarks
- Remove redundant check
- Move implementation of isFlattenedArray into its own function again
- Remove unnecessary array check, relax assertion
- Update microbenchmarks
- Add microbenchmarks
- Add basic test cases
- ... and 7 more: https://git.openjdk.org/valhalla/compare/3a5d7d9f...30b88700
Changes: https://git.openjdk.org/valhalla/pull/938/files
Webrev: https://webrevs.openjdk.org/?repo=valhalla&pr=938&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8316742
Stats: 170 lines in 11 files changed: 162 ins; 4 del; 4 mod
Patch: https://git.openjdk.org/valhalla/pull/938.diff
Fetch: git fetch https://git.openjdk.org/valhalla.git pull/938/head:pull/938
PR: https://git.openjdk.org/valhalla/pull/938
More information about the valhalla-dev
mailing list