Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDK21 requires JVM_VirtualThreadMount/JVM_VirtualThreadUnmount implementations #16984

Closed
JasonFengJ9 opened this issue Mar 21, 2023 · 16 comments
Closed
Labels
comp:vm jdk21 project:loom Used to track Project Loom related work

Comments

@JasonFengJ9
Copy link
Member

8304303: implement VirtualThread class notifyJvmti methods as C2 intrinsics added two new JVM methods. [1]

/*
 * Virtual thread support.
 */
JNIEXPORT void JNICALL
JVM_VirtualThreadMount(JNIEnv* env, jobject vthread, jboolean hide, jboolean first_mount);

JNIEXPORT void JNICALL
JVM_VirtualThreadUnmount(JNIEnv* env, jobject vthread, jboolean hide, jboolean last_unmount);

In addition, it removed notifyJvmtiEvents which made the JCL patch Enable VirtualThread JVMTI natives by default redundant.

FYI @fengxue-IS @babsingh @tajila

[1] https://github.com/ibmruntimes/openj9-openjdk-jdk/blob/1e70d47e951486673ca369046dadc498ccba4a43/src/hotspot/share/include/jvm.h#L1143-L1150

@keithc-ca
Copy link
Contributor

jdk21 also removes the need for these functions:

JVM_VirtualThreadMountBegin
JVM_VirtualThreadMountEnd
JVM_VirtualThreadUnmountBegin
JVM_VirtualThreadUnmountEnd

@babsingh
Copy link
Contributor

From a functional perspective, the new functions are amalgamated forms of the old functions:

JVM_VirtualThreadMount:
   if (hide): JVM_VirtualThreadMountBegin
   else: JVM_VirtualThreadMountEnd

JVM_VirtualThreadUnmount:
   if (hide): JVM_VirtualThreadUnmountBegin
   else: JVM_VirtualThreadUnmountEnd

To avoid hindering the JDK19 release, this change should be applied on top of #16855.

removed notifyJvmtiEvents which made the JCL patch Enable VirtualThread JVMTI natives by default redundant.

This field has been moved to native. It is enabled from JNI GetEnv if Continuations are enabled.

@fengxue-IS
Copy link
Contributor

@thallium can you take a look at this

@JasonFengJ9
Copy link
Member Author

@JasonFengJ9
Copy link
Member Author

#16985 (comment)

		JVM_VirtualThreadMountBegin
		JVM_VirtualThreadMountEnd
		JVM_VirtualThreadUnmountBegin
		JVM_VirtualThreadUnmountEnd

These exports are not needed by JDK21+.

@keithc-ca
Copy link
Contributor

More changes coming from upstream, see

meaning the signature of two existing functions change and two new ones are introduced.

@babsingh
Copy link
Contributor

re #16984 (comment): @keithc-ca Looking for a timeline to support the new changes. Are the new changes JDK21 specific or will they flow down to JDK20?

@keithc-ca
Copy link
Contributor

I've only seen those changes in JDK21; I don't know whether those changes will get back-ported to JDK20.

@pshipton
Copy link
Member

There are some changes in the jdk20u master branch. We won't integrate anything until there is a 20.0.2 build tag. No guarantee these changes will go in to 20.0.2 or that we'll integrate anything until July 18.

openjdk/jdk20u@jdk-20.0.1+9...master

@babsingh
Copy link
Contributor

I don't see 8306028: separate ThreadStart/ThreadEnd events posting code in JVMTI VTMS transitions in openjdk/jdk20u@jdk-20.0.1+9...master. For the time being, I will assume that the new changes are JDK21-specific.

@babsingh
Copy link
Contributor

babsingh commented May 12, 2023

8306028: separate ThreadStart/ThreadEnd events posting code in JVMTI VTMS transitions

Rough draft of the OpenJ9 changes to support the above upstream changes:

JNIEXPORT void JNICALL
JVM_VirtualThreadMount(JNIEnv* env, jobject vthread, jboolean hide)
{
	if (hide) {
		JVM_VirtualThreadMountBegin(env, vthread, false);
	} else {
		JVM_VirtualThreadMountEnd(env, vthread, false);
	}
}

JNIEXPORT void JNICALL
JVM_VirtualThreadUnmount(JNIEnv* env, jobject vthread, jboolean hide)
{
	if (hide) {
		JVM_VirtualThreadUnmountBegin(env, vthread, false);
	} else {
		JVM_VirtualThreadUnmountEnd(env, vthread, false);
	}
}

JNIEXPORT void JNICALL
JVM_VirtualThreadStart(JNIEnv* env, jobject vthread)
{
	JVM_VirtualThreadMountEnd(env, vthread, false);
	// All firstMount specific code should be extracted from JVM_VirtualThreadMount[Begin|End] and consolidated here
}

JNIEXPORT void JNICALL
JVM_VirtualThreadEnd(JNIEnv* env, jobject vthread)
{
	// All lastUnmount specific code should be extracted from JVM_VirtualThreadUnmount[Begin|End] and consolidated here
	JVM_VirtualThreadUnmountBegin
}

@fengxue-IS
Copy link
Contributor

More changes coming from upstream, see

meaning the signature of two existing functions change and two new ones are introduced.

Is there any ETA on when this will be integrated into the extension-repo build branch? if we are expecting this to be done within this week, we should include the changes in #17125 rather than refactoring it shortly after merging.

thallium added a commit to thallium/openj9 that referenced this issue May 16, 2023
- Move code of APIs of JDK 20 such as JVM_VirtualThreadMountBegin
  to helpers so they can be called by APIs of both JDK 20 and 21
- Hide frames between mount/unmount begin and mount/unmount end

Fixes eclipse-openj9#16984

Signed-off-by: Gengchen Tuo <gengchen.tuo@ibm.com>
@JasonFengJ9
Copy link
Member Author

Is there any ETA on when this will be integrated into the extension-repo build branch?

The branch master/openj9-staging containing the changes in question will be promoted into openj9 branch after merging Update FFI specific code for compilation in JDK21, afterwards, the change is visible for usual JDK21 builds.

dipak-bagadiya pushed a commit to dipak-bagadiya/openj9 that referenced this issue May 24, 2023
- Move code of APIs of JDK 20 such as JVM_VirtualThreadMountBegin
  to helpers so they can be called by APIs of both JDK 20 and 21
- Hide frames between mount/unmount begin and mount/unmount end

Fixes eclipse-openj9#16984

Signed-off-by: Gengchen Tuo <gengchen.tuo@ibm.com>
babsingh pushed a commit to babsingh/openj9 that referenced this issue May 24, 2023
- Move code of APIs of JDK 20 such as JVM_VirtualThreadMountBegin
  to helpers so they can be called by APIs of both JDK 20 and 21
- Hide frames between mount/unmount begin and mount/unmount end

Fixes eclipse-openj9#16984

Signed-off-by: Gengchen Tuo <gengchen.tuo@ibm.com>
@keithc-ca
Copy link
Contributor

In

the signature of these functions changed

  • JVM_VirtualThreadMount
  • JVM_VirtualThreadUnmount

and these functions are added

  • JVM_VirtualThreadStart
  • JVM_VirtualThreadEnd

@JasonFengJ9
Copy link
Member Author

JVM_VirtualThreadStart
JVM_VirtualThreadEnd

A change to bring up latest Java 21 level including these two APIs is in progress.

@babsingh
Copy link
Contributor

babsingh commented Jun 1, 2023

#17125 has support for the new changes mentioned in #16984 (comment). The PR title and description needs to be updated but it includes all the four functions: JVM_VirtualThread Mount, Unmount, Start and End.

thallium added a commit to thallium/openj9 that referenced this issue Jun 12, 2023
- Move code of APIs of JDK 20 such as JVM_VirtualThreadMountBegin
  to helpers so they can be called by APIs of both JDK 20 and 21
- Hide frames between mount/unmount begin and mount/unmount end
- Seperate out code that is specific to first mount and last unmount.

Fixes eclipse-openj9#16984

Outlines of related functions:

virtualThread[Mount|Unmount]Begin:
    enterVThreadTransition()
    virtualThreadHideFrames(true)

virtualThread[Mount|Unmount]End:
    virtualThreadHideFrames(false)
    exitVThreadTransition()

JVM_VirtualThreadMount(bool hide):
    if (hide)
	virtualThreadMountBegin()
    else
	virtualThreadMountEnd()
	TRIGGER_J9HOOK_VM_VIRTUAL_THREAD_MOUNT()

JVM_VirtualThreadUnmount(bool hide):
    if (hide)
	TRIGGER_J9HOOK_VM_VIRTUAL_THREAD_UNMOUNT()
	virtualThreadUnmountBegin()
    else
	virtualThreadUnmountEnd()

JVM_VirtualThreadStart()
    virtualThreadMountEnd()
    TRIGGER_J9HOOK_VM_VIRTUAL_THREAD_STARTED()

JVM_VirtualThreadEnd()
    TRIGGER_J9HOOK_VM_VIRTUAL_THREAD_END()
    virtualThreadUnmountBegin()

Signed-off-by: Gengchen Tuo <gengchen.tuo@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:vm jdk21 project:loom Used to track Project Loom related work
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants