[foreign] RFR 8210264: cleanup semantics of function pointer conversion

John Rose john.r.rose at oracle.com
Sat Sep 1 03:46:05 UTC 2018

On Aug 31, 2018, at 9:04 AM, Maurizio Cimadamore <maurizio.cimadamore at oracle.com> wrote:
> http://cr.openjdk.java.net/~mcimadamore/panama/8210264/ <http://cr.openjdk.java.net/~mcimadamore/panama/8210264/>
This is a good cleanup.

An object is allowed to implement two functional interfaces, and even
two interfaces which annotated as native callbacks. So it is possible
that allocateCallback will be presented with an ambiguous input.
I suggest that Util.findCallback throw an exception in that case,
instead of returning the first marked FI that that it finds.

This won't harm correct code but will let us exclude some corner

Another way to slice this is to require a runtime witness as follows:

<T> Callback<T> allocateCallback(Class<T> funcInt, T funcIntfInstance);
default <T> Callback<T> allocateCallback(T funcIntfInstance) {
  return allocateCallback(Utils.findCallback(funcIntfInstance.getClass()), funcIntfInstance);

I.e., allow explicit specification of which FI we care about but specify
a sensible default.  The explicit specification has two effects:  First,
it allows cast-free passing of a lambda, and second it allows the
approach to scale to non-native FI types (assuming the scope
has rules for dealing with type conversion).

— John

More information about the panama-dev mailing list