Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8306434

add support of virtual threads to JVMTI StopThread

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P4
    • 21
    • hotspot
    • None
    • behavioral
    • minimal
    • Hide
      The compatibility risk is minimal.
      The JVMTI function StopThread is a debugging feature. An update in the JDWP spec of ThreadReference.Stop command will be needed to adopt to new error codes for virtual threads. The JDI level may need to be adjusted as well. This is a behavior change that could impact users, but would only impacts users of the virtual threads preview releases. Related update in JDWP and JDI specs is a subject of a separate enhancement and CSR.
      Show
      The compatibility risk is minimal. The JVMTI function StopThread is a debugging feature. An update in the JDWP spec of ThreadReference.Stop command will be needed to adopt to new error codes for virtual threads. The JDI level may need to be adjusted as well. This is a behavior change that could impact users, but would only impacts users of the virtual threads preview releases. Related update in JDWP and JDI specs is a subject of a separate enhancement and CSR.
    • Other
    • SE

    Description

      Summary

      The JVMTI StopThread function is updated to support virtual threads.

      Problem

      Currently the JVMTI StopThread function may be used to send an asynchronous exception to a platform thread. It needs to be extended to support virtual threads as well.

      Solution

      The JVMTI spec for StopThread is updated so that it can be used to send an asynchronous exception to a virtual thread in some situations.

      The error code JVMTI_ERROR_UNSUPPORTED_OPERATION is removed. Two new error codes are added instead: JVMTI_ERROR_THREAD_NOT_SUSPENDED and JVMTI_ERROR_OPAQUE_FRAME.

      Specification

      The JVMTI spec includes the following changes below:

      The StopThread function description is updated to remove the word "platform" from the statement:

      Send the specified asynchronous exception to the specified platform thread.

      The description of the StopThread 'thread' parameter is updated to replace the statement:

      The thread may not be a virtual thread. Otherwise, the error
      code JVMTI_ERROR_UNSUPPORTED_OPERATION will be returned.

      with:

      The StopThread function may be used to send an asynchronous
      exception to a virtual thread when it is suspended at an event.
      An implementation may support sending an asynchronous exception
      to a suspended virtual thread in other cases.

      The following StopThread error code description is removed:

      JVMTI_ERROR_UNSUPPORTED_OPERATION: is a virtual thread.

      The following two StopThread error code descriptions are added:

      JVMTI_ERROR_THREAD_NOT_SUSPENDED:
      The thread is a virtual thread and was not suspended and
      was not the current thread.
      
      JVMTI_ERROR_OPAQUE_FRAME:
      The thread is a suspended virtual thread and the implementation 
      was unable to throw an asynchronous exception from the current frame.

      A general description of the JVMTI_ERROR_OPAQUE_FRAME error was:

      Information about the frame is not available (e.g. for native frames).

      It is extended to be:

      Information about the frame is not available (e.g. for native frames),
      or the function cannot be performed on the thread's current frame.

      The full jvmti.xml diff is:

      diff --git a/src/hotspot/share/prims/jvmti.xml b/src/hotspot/share/prims/jvmti.xml
      index 456876fbcb9..cbb0cb6c84b 100644
      --- a/src/hotspot/share/prims/jvmti.xml
      +++ b/src/hotspot/share/prims/jvmti.xml
      @@ -1892,7 +1892,7 @@ jvmtiEnv *jvmti;
           <function id="StopThread" num="7">
             <synopsis>Stop Thread</synopsis>
             <description>
      -        Send the specified asynchronous exception to the specified platform thread.
      +        Send the specified asynchronous exception to the specified thread.
             </description>
             <origin>jvmdi</origin>
             <capabilities>
      @@ -1903,8 +1903,10 @@ jvmtiEnv *jvmti;
                 <jthread impl="noconvert"/>
                   <description>
                     The thread to stop.
      -              The <code>thread</code> may not be a virtual thread. Otherwise, the error code
      -              <errorlink id="JVMTI_ERROR_UNSUPPORTED_OPERATION"></errorlink> will be returned.
      +              The <functionlink id="StopThread"></functionlink> function may be used to send
      +              an asynchronous exception to a virtual thread when it is suspended at an event.
      +              An implementation may support sending an asynchronous exception to a suspended
      +              virtual thread in other cases.
                    </description>
               </param>
               <param id="exception">
      @@ -1915,8 +1917,12 @@ jvmtiEnv *jvmti;
               </param>
             </parameters>
             <errors>
      -        <error id="JVMTI_ERROR_UNSUPPORTED_OPERATION">
      -          <paramlink id="thread"/> is a virtual thread.
      +        <error id="JVMTI_ERROR_THREAD_NOT_SUSPENDED">
      +          Thread is a virtual thread and was not suspended and was not the current thread.
      +        </error>
      +        <error id="JVMTI_ERROR_OPAQUE_FRAME">
      +          The thread is a suspended virtual thread and the implementation was unable
      +          to throw an asynchronous exception from the current frame.
               </error>
             </errors>
           </function>
      @@ -11974,7 +11980,8 @@ myInit() {
             There are no Java programming language or JNI stack frames at the specified depth.
           </errorid>
           <errorid id="JVMTI_ERROR_OPAQUE_FRAME" num="32">
      -      Information about the frame is not available (e.g. for native frames).
      +      Information about the frame is not available (e.g. for native frames),
      +      or the function cannot be performed on the thread's current frame.
           </errorid>
           <errorid id="JVMTI_ERROR_DUPLICATE" num="40">
             Item already set.

      Attachments

        Issue Links

          Activity

            People

              sspitsyn Serguei Spitsyn
              sspitsyn Serguei Spitsyn
              Alan Bateman, David Holmes
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: