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

Maurizio Cimadamore mcimadamore at openjdk.java.net
Tue Apr 20 09:47:19 UTC 2021


On Tue, 20 Apr 2021 01:15:15 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

> Regarding `GLOBAL_SCOPE.acquire`, it seems harmless. Writing uniform scope logic might get harder if the global scope behaves differently, but i don't have a strong sense of how libraries might operate on scope.s It might well be the case if something accepts and wraps a segment e.g. a matrix whose element buffer is allocated independently/externally and it needs to be kept alive for the life time of the matrix.

Not just about GLOBAL_SCOPE - but also about newImplicitScope. Yes, there is a tension between uniform usage and how meaningful these operations are. My intuition was to exploit a trick of try with resources which is tolerant to `null`s.

So, if you do


try (var handle = scope.acquire()) {
   ...
}

And, sometimes, the handle is null, the TWR is still valid (javac inserts a null check in the finalizer), but at least you don't have an odd handle on your hands which doesn't really do what it says on the tin (e.g. calling `Handle::close` does nothing).

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

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


More information about the panama-dev mailing list