[foreign-memaccess] [Rev 02] RFR: Add unsigned adapter handles

Chris Hegarty chegar at openjdk.java.net
Mon May 18 15:51:58 UTC 2020

On Mon, 18 May 2020 10:33:28 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Chris Hegarty has updated the pull request incrementally with one additional commit since the last revision:
>>   remove additional whitespace and comment line
> I think the decisions in your document are sound. One point which is perhaps not stated clearly (but which we have
> discussed) was also the fact that `char` is a perfectly decent carrier when users want to work with 16 bits in an
> unsigned fashion, and that motivates some of the choices we made downstream (e.g. to just support `int` and `long`
> as *adapted* types).  After looking at the code some more, I agree with Jorn that the templating is perhaps
> unnecessary. We can go from byte/short/int to wider type using the unsigned helpers on the wrapper types. And we can go
> reverse by using `MethodHandle::explicitCastArguments` which does a cast conversion (which in case of primitives e.g.
> from `long` to `int` will do a narrowing, which is exactly what you want).  So I think there's a way for the code to
> set up some kind of table, and then just pick the adapter MHs from there. I think this will simplify the code quite a
> bit and remove the `j.l.i` dependency.

Thanks @JornVernee and @mcimadamore for your comments.

The templating was cute when I started, but as rows in the table were eliminated it no longer carries its own weight.

This update removes the templating. I decided to keep the implementation in its own class for now, so that we can see
if we really want to merge it into MemoryHandles. Most of the implementation is not really sharable with other parts of


PR: https://git.openjdk.java.net/panama-foreign/pull/173

More information about the panama-dev mailing list