RFR: 8295044: Implementation of Foreign Function and Memory API (Second Preview) [v27]

Alan Bateman alanb at openjdk.org
Wed Nov 16 16:40:31 UTC 2022


On Wed, 16 Nov 2022 16:13:16 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/foreign/Arena.java line 132:
>> 
>>> 130:      * and all the memory segments associated with it can no longer be accessed. Furthermore, any off-heap region of memory backing the
>>> 131:      * segments associated with that scope are also released.
>>> 132:      * @throws IllegalStateException if the arena has already been {@linkplain #close() closed}.
>> 
>> It's not wrong to specify that close throw if already closed but it goes against the advice in AutoCloseable to try to have close methods be idempotent. There may be a good reason for this but I can't help wondering if there are error cases when wrapping that might lead to close being called more than once.
>
> In our experience with using the API, having exceptions when something is funny about close is very valuable info (as also stated in the javadoc). Almost always there's a subtle temporal bug going on which the ISE catches. I'm not sure if here you refer to the fact that the javadoc is being overly broad in saying "already been closed" instead of "already been closed _successfully_" ? What kind of problems are you thinking of?

Most of the AutoCloseable in the platform are Closeables where close is specified to have no effect when already closed. With a confined Arena it would be benign for the owner to invoke close again. If it's been useful at finding bugs then okay. The scenario that made me wonder about this is something like the follow where MyWrapper::close invokes Arena::close.

        try (var arena = Arena.openConfined();
             var wrapper = new MyWrapper(arena)) {
            :
        }

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

PR: https://git.openjdk.org/jdk/pull/10872


More information about the hotspot-dev mailing list