[foreign-memaccess+abi] RFR: 8274648: Improve logic for acquiring by reference parameters in downcall handles
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Fri Oct 1 15:04:23 UTC 2021
The current logic for acquiring/releasing scopes associated with by-reference parameters in a downcall handle call is a bit naive, in the sense that it acquires/releases each parameter in isolation (possibly redundantly).
I've been working on a way to ameliorate the situation by adapting the downcall method handle so that we can pass all addressable parameters (in bulk) to a single acquire/release function. Since this function sees all arguments at once, it can decide to only acquire the unique scopes.
How to do that proved to be challenging - as simply using a for loop didn't give the performance I expected. Turns out that as soon as we take a backward branch, there is a regression compared with the base case, even when all scopes are the same. The only case where we gain is when all scopes are shared.
But I (re)discovered a trick; we can special case the acquire/release functions so that they only use a loop for a high number of addressable parameters, and use a switch (with fallthrough) instead for low counts. This makes the logic more scrutable and the performance numbers are stricty better than what we had:
BEFORE
Benchmark
CallOverheadConstant.panama_identity_struct_ref_confined avgt 30 11.544 ? 0.170 ns/op
CallOverheadConstant.panama_identity_struct_ref_confined_3 avgt 30 12.213 ? 0.228 ns/op
CallOverheadConstant.panama_identity_struct_ref_shared avgt 30 17.214 ? 0.560 ns/op
CallOverheadConstant.panama_identity_struct_ref_shared_3 avgt 30 33.132 ? 0.934 ns/op
AFTER
Benchmark Mode Cnt Score Error Units
CallOverheadConstant.panama_identity_struct_ref_confined avgt 30 11.613 ? 0.326 ns/op
CallOverheadConstant.panama_identity_struct_ref_confined_3 avgt 30 11.646 ? 0.333 ns/op
CallOverheadConstant.panama_identity_struct_ref_shared avgt 30 17.763 ? 0.639 ns/op
CallOverheadConstant.panama_identity_struct_ref_shared_3 avgt 30 17.087 ? 0.475 ns/op
As you can see, in both cases there is no cost for passing multiple addressable arguments backed by the same scope.
-------------
Commit messages:
- cleanup code and sprinkle some comments
- Bump up the number of addressable supported in the fast path
- Special case calls with up to 4 by-ref parameters.
- Merge branch 'foreign-memaccess+abi' into acquire_linker_optimized
- Simplify code.
- Reduce number of acquires if possible
Changes: https://git.openjdk.java.net/panama-foreign/pull/590/files
Webrev: https://webrevs.openjdk.java.net/?repo=panama-foreign&pr=590&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8274648
Stats: 127 lines in 2 files changed: 99 ins; 6 del; 22 mod
Patch: https://git.openjdk.java.net/panama-foreign/pull/590.diff
Fetch: git fetch https://git.openjdk.java.net/panama-foreign pull/590/head:pull/590
PR: https://git.openjdk.java.net/panama-foreign/pull/590
More information about the panama-dev
mailing list