openj9 icon indicating copy to clipboard operation
openj9 copied to clipboard

Add VirtualThread native stubs and the active VirtualThread list

Open EricYangIBM opened this issue 3 years ago • 13 comments

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]

EricYangIBM avatar Jul 11 '22 19:07 EricYangIBM

The notifyJvmtiEvents field will be set to true in VirtualThread.java: https://github.com/ibmruntimes/openj9-openjdk-jdk19/pull/18

EricYangIBM avatar Jul 21 '22 19:07 EricYangIBM

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?

EricYangIBM avatar Jul 21 '22 20:07 EricYangIBM

The two hidden fields sounds best - you can't use the macros, but you can copy the code.

gacholio avatar Jul 21 '22 21:07 gacholio

This PR is ready for review

EricYangIBM avatar Jul 25 '22 14:07 EricYangIBM

Added global ref to an empty virtual thread to the activeVirtualThreadList

EricYangIBM avatar Jul 26 '22 18:07 EricYangIBM

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?

EricYangIBM avatar Jul 27 '22 19:07 EricYangIBM

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

EricYangIBM avatar Jul 28 '22 20:07 EricYangIBM

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.

gacholio avatar Jul 28 '22 23:07 gacholio

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

gacholio avatar Jul 29 '22 15:07 gacholio

LGTM. The commits need to be squashed before the PR builds are launched.

babsingh avatar Aug 05 '22 17:08 babsingh

Squashed

EricYangIBM avatar Aug 05 '22 18:08 EricYangIBM

jenkins test sanity amac jdk19,jdk17

babsingh avatar Aug 05 '22 18:08 babsingh

jenkins compile win jdk19,jdk17

babsingh avatar Aug 05 '22 18:08 babsingh