Skip to content

Add per-thread closeScope queue for ScopedMemoryAccess close handling#23455

Open
babsingh wants to merge 1 commit intoeclipse-openj9:masterfrom
babsingh:main9
Open

Add per-thread closeScope queue for ScopedMemoryAccess close handling#23455
babsingh wants to merge 1 commit intoeclipse-openj9:masterfrom
babsingh:main9

Conversation

@babsingh
Copy link
Contributor

@babsingh babsingh commented Mar 5, 2026

Replace the previous global closeScope notification mechanism with a
per-thread close request list. Each thread maintains a queue of
J9CloseScopeListNode entries representing pending MemorySessionImpl
close requests.

ScopedMemoryAccess.closeScope0 now walks all threads, identifies
threads accessing the session via @Scoped methods, and enqueues a
close request on the target thread. Global refs to the session and
error are shared across all nodes and tracked via a hidden
MemorySessionImpl.closeScopeCount field.

javaCheckAsyncMessages processes the queued requests, delivers the
ScopedAccessError when appropriate, decrements the session counter,
and releases the global refs once the last thread processes the
request.

This removes the VM-global closeScopeMutex / notifyCount mechanism
and avoids races when multiple sessions are closed concurrently.

Related: #22934

Signed-off-by: Babneet Singh sbabneet@ca.ibm.com

Replace the previous global closeScope notification mechanism with a
per-thread close request list. Each thread maintains a queue of
J9CloseScopeListNode entries representing pending MemorySessionImpl
close requests.

ScopedMemoryAccess.closeScope0 now walks all threads, identifies
threads accessing the session via @Scoped methods, and enqueues a
close request on the target thread. Global refs to the session and
error are shared across all nodes and tracked via a hidden
MemorySessionImpl.closeScopeCount field.

javaCheckAsyncMessages processes the queued requests, delivers the
ScopedAccessError when appropriate, decrements the session counter,
and releases the global refs once the last thread processes the
request.

This removes the VM-global closeScopeMutex / notifyCount mechanism
and avoids races when multiple sessions are closed concurrently.

Related: eclipse-openj9#22934

Signed-off-by: Babneet Singh <sbabneet@ca.ibm.com>
@babsingh babsingh requested a review from gacholio March 5, 2026 18:04
@babsingh
Copy link
Contributor Author

babsingh commented Mar 5, 2026

@gacholio Requesting your review.

This PR alone should resolve #22934, since the wait logic at the end of closeScope0 has been removed.

The earlier proposed test and OpenJ9 fixes are no longer required:

The JIT issue was previously tracked here: #13211 (comment).

With this PR, the JIT issue is no longer observed. The failure frequency has dropped to the point that we see 0 failures in 100 runs, so it is no longer a blocker for the Java 26 release.

FYI, @tajila @hzongaro

}
omrthread_monitor_exit(vm->closeScopeMutex);

closeScopeCount = J9OBJECT_I64_LOAD(currentThread, closeScopeObj, vm->closeScopeCountOffset);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be derived from the loop above?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of the mutex seems inconsistent (value here is read outside the mutex).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants