openj9
openj9 copied to clipboard
Add VirtualThread native stubs and the active VirtualThread list
notifyJvmtiMountBegin() will be used to add a virtual thread to the list and allocate thread local storage, while notifyJvmtiUnmountEnd() will be used to remove a virtual thread from the list and deallocate thread local storage. The list's root is a global jni ref to an empty virtual thread to prevent references to it from becoming stale.
Issue: #15183 Signed-off-by: Eric Yang [email protected]
The notifyJvmtiEvents field will be set to true in VirtualThread.java: https://github.com/ibmruntimes/openj9-openjdk-jdk19/pull/18
Proposed way of storing the list of VirtualThreads: doubly linked list like the one in J9VMThread using hidden fields in VirtualThread.class for linkNext and linkPrevious. Alternatively add these fields directly to the source code (notifyJvmtiEvents is set to true in https://github.com/ibmruntimes/openj9-openjdk-jdk19/pull/18)
@gacholio thoughts on these approaches?
The two hidden fields sounds best - you can't use the macros, but you can copy the code.
This PR is ready for review
Added global ref to an empty virtual thread to the activeVirtualThreadList
Latest commit adds/removes virtual threads from the active list. Where/how would I remove a virtual thread from the list if it gets GCd before running to completion?
GCd before running to completion
I can add this cleanup code in a future PR once the continuation cleanup is implemented. This should be everything for this PR
Correct me if I'm wrong, but doesn't maintaining this list prevent the GC case? The global ref that roots the list is a strong GC root.
I'm OK with this for now as it prevents the GC case that we're not yet handling. In future, the GC may have to manage the list as a weak root (perhaps similar to how Reference objects are tracked?). @LinHu2016
LGTM. The commits need to be squashed before the PR builds are launched.
Squashed
jenkins test sanity amac jdk19,jdk17
jenkins compile win jdk19,jdk17