[foreign] RFR 8210264: cleanup semantics of function pointer conversion
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Fri Aug 31 16:04:10 UTC 2018
Hi,
this patch changes the way in which we support callbacks - for more
details on the rationale, please see the JBS issue:
https://bugs.openjdk.java.net/browse/JDK-8210264
The idea is to model all callback with instances of the type:
Callback<T> (where T must be a functional interface)
and then have a method in Scope to do the conversion:
Callback<T> allocateCallback(T t)
This makes our 'raw' binding a lot more regular (and... well, raw).
Callbacks can be passed onto native function by simply extracting their
underlying pointer. All the magic is in the Callback::asFunction method
which maps a native callback into a Java functional interface instance
which can be used for the invocation.
Unsurprisingly, this fix has a cascade effect of simplifications in the
binder backend - see NativeInvoker and UpcallHandler. Some classes such
as UpcallHandlerFactory and UpcallStub were no longer needed and have
been removed.
Now a callback will stay alive until the scope in which it has been
created is alive (e.g. its close() method has not been called). When
that happens the callback is freed. This means no more monkey patching
with a Cleaner object and no more need for GC barriers to prevent early
deallocation.
Webrev:
http://cr.openjdk.java.net/~mcimadamore/panama/8210264/
Maurizio
More information about the panama-dev
mailing list