[foreign] RFR: struct/global functions stubs should attached to some scope
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Mon Jul 9 18:06:25 UTC 2018
Hi,
there is a currently a problem with function pointers: when you assign a
functional interface object to a struct/global variable, a stub is
generated on the fly; the native stub has a weak link back to the
UpcallHandler object it originated from - but the UpcallHandler object
is not kept anywhere - which means the GC is free to collect it as soon
as possible (and this will also cause deallocation of the native stub,
via the cleaner).
We need some way to attach stub resources to scopes (either the scope of
a resource or the recently-added global library scope). That's what this
patch does. When Scope::close is called, the list of stub is null-ed, so
that the GC can deallocate things as expected.
Note that this is an incremental improvement while we await for a more
cohesive native resource management strategy/API.
The test for function callbacks has been tweaked to feature some
System.gc - w/o this patch, these alterations cause the test to fail
pretty reliably.
Webrev:
http://cr.openjdk.java.net/~mcimadamore/panama/func-scope/
Maurizio
More information about the panama-dev
mailing list