<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi Chris,</div>
<div class="elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: Calibri, Helvetica, sans-serif;">Thanks for the explanation. Do you agree with the below analysis? If so, will it be possible to have the test fixed?</span></div>
<div class="elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: Calibri, Helvetica, sans-serif;"><br>
</span></div>
<p class="elementToProof" style="margin-top: 0px; margin-bottom: 0px; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: Calibri, Helvetica, sans-serif;"><code style="font-family: Calibri, Helvetica, sans-serif;">vthread</code> - virtual thread.</span></p>
<div class="elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: Calibri, Helvetica, sans-serif;"><br>
</span></div>
<div class="elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: Calibri, Helvetica, sans-serif;">Between <code style="font-family: Calibri, Helvetica, sans-serif;">
breakpoint_hit1</code> and <code style="font-family: Calibri, Helvetica, sans-serif;">
breakpoint_hit2</code>, the test doesn't expect the <code style="font-family: Calibri, Helvetica, sans-serif;">
PRODUCER vthread's carrier thread</code> to <b>RUN</b>. So, the test explicitly checks that no
<code style="font-family: Calibri, Helvetica, sans-serif;">JVMTI MethodExit event</code> is triggered by the
<code style="font-family: Calibri, Helvetica, sans-serif;">PRODUCER vthread's carrier thread</code>.</span></div>
<div class="elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: Calibri, Helvetica, sans-serif;"><br>
</span></div>
<div class="elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: Calibri, Helvetica, sans-serif;">I feel that this check is incorrect because the
<code style="font-family: Calibri, Helvetica, sans-serif;">PRODUCER vthread</code>
<code style="font-family: Calibri, Helvetica, sans-serif;">unmounts</code> and <code style="font-family: Calibri, Helvetica, sans-serif;">
mounts</code> between <code style="font-family: Calibri, Helvetica, sans-serif;">
breakpoint_hit1</code> and <code style="font-family: Calibri, Helvetica, sans-serif;">
breakpoint_hit2</code>. Whenever a <code style="font-family: Calibri, Helvetica, sans-serif;">
vthread</code> unmounts, the corresponding carrier thread is mounted and allowed to
<b>RUN</b>.</span></div>
<div class="elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: Calibri, Helvetica, sans-serif;"><br>
</span></div>
<div class="elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: Calibri, Helvetica, sans-serif;"><code style="font-family: Calibri, Helvetica, sans-serif;">PRODUCER vthread</code>
<code style="font-family: Calibri, Helvetica, sans-serif;">unmounts</code> while inserting an element to the
<a href="https://download.java.net/java/early_access/jdk21/docs/api/java.base/java/util/concurrent/SynchronousQueue.html" id="OWA48b73225-556c-ea29-1be8-9cffee7d96ea" class="OWAAutoLink" rel="nofollow">SynchronousQueue</a>, which is a blocking queue. Insert and remove operations are synchronized.
<code style="font-family: Calibri, Helvetica, sans-serif;">vthread</code> seems to yield and unmount if it has to wait on such an operation. Below is the PRODUCER vthread's stack trace during the
<code style="font-family: Calibri, Helvetica, sans-serif;">VirtualThreadUnmount event, which happens between breakpoint_hit1</code> and
<code style="font-family: Calibri, Helvetica, sans-serif;">breakpoint_hit2.</code></span></div>
<div class="elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<pre><div class="elementToProof"><code>Hit #1: VirtualThreadUnmount #340: enabling FramePop for method: java/lang/VirtualThread::notifyJvmtiUnmount on virtual thread: 0x27e640

VirtualThreadUnmount #340: method: java/lang/VirtualThread::notifyJvmtiUnmount, thread: VT-PRODUCER#0
JVMTI Stack Trace for thread VT-PRODUCER#0: frame count: 12
 0: java/lang/VirtualThread: yieldContinuation()Z
 1: java/lang/VirtualThread: tryYield()V
 2: java/lang/Thread: yield()V
 3: java/util/concurrent/SynchronousQueue$TransferStack: transfer(Ljava/lang/Object;ZJ)Ljava/lang/Object;
 4: java/util/concurrent/SynchronousQueue: put(Ljava/lang/Object;)V
 5: MethodExitTest: qPut(Ljava/lang/String;)V
 6: MethodExitTest: lambda$static$0()V
 7: MethodExitTest$$Lambda.0x00000000d7030b98: run()V
 8: java/lang/VirtualThread: runWith(Ljava/lang/Object;Ljava/lang/Runnable;)V
 9: java/lang/VirtualThread: run(Ljava/lang/Runnable;)V
10: java/lang/VirtualThread$VThreadContinuation$1: run()V
11: jdk/internal/vm/Continuation: enter(Ljdk/internal/vm/Continuation;)V</code></div></pre>
<div class="elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Regards,</div>
<div class="elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Babneet</div>
<div class="elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> loom-dev <loom-dev-retn@openjdk.org> on behalf of Chris Plummer <chris.plummer@oracle.com><br>
<b>Sent:</b> August 8, 2023 6:21 PM<br>
<b>To:</b> Gengchen Tuo <Gengchen.Tuo@ibm.com>; loom-dev@openjdk.org <loom-dev@openjdk.org><br>
<b>Subject:</b> [EXTERNAL] Re: Question about the Method Exit Test</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">When the first breakpoint is hit, METHOD_EXIT is enabled, but it is only
<br>
enabled on the carrier thread. Since we are only executing on the <br>
virtual thread when the breakpoint is hit, no METHOD_EXIT event should <br>
be generated.<br>
<br>
     // Enable METHOD_EXIT events on the cthread. We should not get one.<br>
     LOG("Hit #1: Breakpoint: %s: enabling MethodExit events on carrier <br>
thread: %p\n",<br>
            mname, (void*)cthread);<br>
     set_event_notification_mode(jvmti, jni, JVMTI_ENABLE, <br>
JVMTI_EVENT_METHOD_EXIT, cthread);<br>
<br>
When the 2nd breakpoint is hit, that is when we enable METHOD_EXIT on <br>
the virtual thread:<br>
<br>
   // Enable METHOD_EXIT events on the vthread. We should get one.<br>
   LOG("Hit #2: Breakpoint: %s: enabling MethodExit events on %s thread: <br>
%p\n",<br>
           mname, is_virtual ? "virtual" : "carrier", (void*)thread);<br>
   set_event_notification_mode(jvmti, jni, JVMTI_ENABLE, <br>
JVMTI_EVENT_METHOD_EXIT, thread);<br>
<br>
So now we will see METHOD_EXIT events. I don't think this has anything <br>
to do with lines 59-60, which have to do with deferring the enabling of <br>
the initial breakpoint until after a warmup period:<br>
<br>
if (i == MSG_COUNT - 10) {<br>
                     // Once we have warmed up, enable the first <br>
breakpoint which eventually will<br>
                     // lead to enabling single stepping.<br>
                     enableEvents(Thread.currentThread(), <br>
MethodExitTest.class);<br>
                 }<br>
<br>
My guess is this because we have 3 threads in play, and want to make <br>
sure they are all executing in the virtual thread before enabling <br>
METHOD_EXIT events.<br>
<br>
And I think it's safe to say you can ignore the "single stepping" <br>
comment. This test was cloned from one of our very early jvmti virtual <br>
threads tests, and that comment appears to be a relic. There is also a <br>
reference in the C file that can go away:<br>
<br>
   if (strcmp(event_name, "SingleStep") != 0) {<br>
     print_stack_trace(jvmti, jni, thread);<br>
   }<br>
<br>
Chris<br>
<br>
On 8/8/23 12:35 PM, Gengchen Tuo wrote:<br>
><br>
> Hi all. In the Method Exit test <br>
> <a href="https://github.com/openjdk/jdk/blob/master/test/hotspot/jtreg/serviceability/jvmti/vthread/MethodExitTest/MethodExitTest.java">https://github.com/openjdk/jdk/blob/master/test/hotspot/jtreg/serviceability/jvmti/vthread/MethodExitTest/MethodExitTest.java</a>
 , <br>
> no MethodExit event is expected between the first and the second <br>
> breakpoint hit. Why are we making this assumption? Maybe that’s <br>
> related to line 59 and 60 that I don’t really understand? To my <br>
> knowledge, the producer thread may yield between the two breakpoint <br>
> hits and MethodExit events will be reported.<br>
><br>
><br>
><br>
> I tried to enable the MethodEntry event in the agent code and the test <br>
> started to fail but this shouldn’t affect the test result I believe?<br>
><br>
><br>
><br>
> Thanks in advance<br>
><br>
> Gengchen<br>
><br>
><br>
</div>
</span></font></div>
</body>
</html>