[Integrated] [foreign-memaccess] RFR: 8245459: Add support for complex filter value var handle adaptation
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Thu May 21 21:23:18 UTC 2020
On Wed, 20 May 2020 12:57:55 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> It is sometimes necessary to apply a carrier transform on a VarHandle that is expressed in more than just a pair of
> unary function (e.g. from `A->B` and `B->A`). Sometimes the transform needs to act on some bit of external state.
> It would be nice if `MemoryHandles::filterValue` would be enhanced to accept all functions of the kind:
>
> `(C... A) ->B`
> `(C... B) -> A`
>
> So that the resulting VarHandle will apply carrier transform from A to B and will also add extra coordinate types
> (C...) which can be used by the transform filters.
> To enhance `MemoryHandles::filterValue` this way regular MH adapters are not enough; while we can implement setters, by
> combining the filters with `MethodHandles::collectArguments` there is no way to implement the getters - since that
> would require a method handle transform which adapts a return value *and* adds some extra parameters to the adapter
> handle (which are then forwarded to the filter). This patch adds the missing method handle primitive to do that; for
> now it's a package private method, namely `MethodHandles::collectReturnValue`. If people think that this could be
> useful, we can evaluate whether to open this up for method handle combinator API as well. This required to add a new
> kind of lambda form using the `LambdaFormEditor`, which was a bit tricky to get right (we currently have no transforms
> which operates on both arguments *and* return values, which makes it tricky). The implementation of
> `MemoryHandles::filterValue` is also a bit more complex, since if there are additional coordinates added by collecting
> arguments/return values, such additional coordinates might be added multiple times, so we need some steps to 'join' the
> extra coordinates (with a call to `MethodHandle::permuteArguments`) so that extra coordinate show up only once in the
> final adapter. If the filter functions used for adapting are just unary functions, then the implementation falls back
> to the simpler behavior we had before, and the permutation step is skipped (in such cases, `collectArguments` ==
> `filterArguments` and `collectReturnValue` == `filterReturnValue`).
This pull request has now been integrated.
Changeset: f72b5747
Author: Maurizio Cimadamore <mcimadamore at openjdk.org>
URL: https://git.openjdk.java.net/panama-foreign/commit/f72b5747
Stats: 199 lines in 6 files changed: 0 ins; 176 del; 23 mod
8245459: Add support for complex filter value var handle adaptation
Reviewed-by: psandoz
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/179
More information about the panama-dev
mailing list