[foreign-memaccess+abi] RFR: Improve ResourceScope javadoc

Maurizio Cimadamore mcimadamore at openjdk.java.net
Tue Apr 20 11:28:17 UTC 2021


On Tue, 20 Apr 2021 11:14:18 GMT, Chris Hegarty <chegar at openjdk.org> wrote:

> In my experiments, I want to restrict a scattering/gathering I/O operation to buffer views over at most one explicit scope. Doing this requires me to be able to determine scope equality either by carrying the scope explicitly or possibly retrieving it from the handle (which is not currently possible). To be kind to the GC, I think I can keep the former solution, but the latter would be convenient.

I think we want to land in a place where acquiring an implicit scope is a no-op. I'm fine with having a scope() accessor on the Handle class - but note that if we require this accessor to be always precise, even in the case of implicit scopes, that would mean that when acquiring an implicit scope we have to create a _new_ handle, just so that we can return the right scope. Worse, the handle will interact with Cleaners (as the handle will keep a strong reference to the original scope). I think mixing reachability with handles is wrong - acquiring an handle on an implicit should **not** make a scope always reachable (until the handle itself becomes unreachable), as that would make it even harder to reason about reachability.

So, the thing I can offer here is a scope() accessor which only works for explicit scopes. That is, the javadoc for ResourceScope::acquire can say that, if the acquired scope is an implicit scope a "global" handle will be returned, owned by the global scope - and that releasing a global handle is idempotent.

This way, the accessor will give you the info you want, in case where acquire does something useful - but it won't give you any info in case acquire is  a no-op, which should be ok?

-------------

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


More information about the panama-dev mailing list