File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed
src/java.base/share/classes/jdk/internal/foreign Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -97,16 +97,19 @@ public void addOrCleanupIfFail(ResourceList.ResourceCleanup resource) {
9797 addInternal (resource );
9898 } catch (Throwable ex ) {
9999 resource .cleanup ();
100+ throw ex ;
100101 }
101102 }
102103
103104 void addInternal (ResourceList .ResourceCleanup resource ) {
104- try {
105- checkValidStateSlow ();
106- resourceList .add (resource );
107- } catch (ScopedMemoryAccess .ScopedAccessError err ) {
108- throw new IllegalStateException ("Already closed" );
109- }
105+ checkValidStateSlow ();
106+ // Note: from here on we no longer check the session state. Two cases are possible: either the resource cleanup
107+ // is added to the list when the session is still open, in which case everything works ok; or the resource
108+ // cleanup is added while the session is being closed. In this latter case, what matters is whether we have already
109+ // called `ResourceList::cleanup` to run all the cleanup actions. If not, we can still add this resource
110+ // to the list (and, in case of an add vs. close race, it might happen that the cleanup action will be
111+ // called immediately after).
112+ resourceList .add (resource );
110113 }
111114
112115 protected MemorySessionImpl (Thread owner , ResourceList resourceList , Cleaner cleaner ) {
You can’t perform that action at this time.
0 commit comments