[foreign] RFR 8209497: Polish Resource API
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Thu Aug 16 09:50:07 UTC 2018
On 16/08/18 01:54, John Rose wrote:
> On Aug 15, 2018, at 3:18 AM, Maurizio Cimadamore <maurizio.cimadamore at oracle.com> wrote:
>> And then, the following Java code:
>>
>> Foo foo = () -> {};
>>
>> The above 'foo' is, at least in my opinion, just a plain Java object. In a way, I have not even used the Panama API, at least not directly.
> Hmm…. What would happen if Callback gets a default method which reports Scope::HEAP as a constant scope? Then all lambdas spun by Java will have the correct classification as resources: Nothing to free that isn’t covered by the GC. Binder created Callbacks would get both the resource and an override to the default scope reporter.
I thought about that; scope has boundary information attached to it -
more specifically a base + offset pair wrapped in a memory region. So,
this would mean that we need to create a new scope (with a new memory
region) every time the Resource::scope() method is called. Doable, of
course, but not sure that makes things that much clearer.
One deeper discomfort I have on this view is that I still view the
relationship between callbacks and resources as an *has-a*, not a
*is-a*. That is, a callback is always a heap allocated object -
sometimes it just happens to have some piece of native storage attached
to it to complete the job. E.g. it could be a Java object calling a Java
method, or a Java object calling a native method. But it's always a Java
object - so I'm not sure that saying that callbacks are resources does
the API a service?
Maurizio
More information about the panama-dev
mailing list