Question about the Method Exit Test

Chris Plummer chris.plummer at oracle.com
Tue Aug 8 22:21:13 UTC 2023


When the first breakpoint is hit, METHOD_EXIT is enabled, but it is only 
enabled on the carrier thread. Since we are only executing on the 
virtual thread when the breakpoint is hit, no METHOD_EXIT event should 
be generated.

     // Enable METHOD_EXIT events on the cthread. We should not get one.
     LOG("Hit #1: Breakpoint: %s: enabling MethodExit events on carrier 
thread: %p\n",
            mname, (void*)cthread);
     set_event_notification_mode(jvmti, jni, JVMTI_ENABLE, 
JVMTI_EVENT_METHOD_EXIT, cthread);

When the 2nd breakpoint is hit, that is when we enable METHOD_EXIT on 
the virtual thread:

   // Enable METHOD_EXIT events on the vthread. We should get one.
   LOG("Hit #2: Breakpoint: %s: enabling MethodExit events on %s thread: 
%p\n",
           mname, is_virtual ? "virtual" : "carrier", (void*)thread);
   set_event_notification_mode(jvmti, jni, JVMTI_ENABLE, 
JVMTI_EVENT_METHOD_EXIT, thread);

So now we will see METHOD_EXIT events. I don't think this has anything 
to do with lines 59-60, which have to do with deferring the enabling of 
the initial breakpoint until after a warmup period:

if (i == MSG_COUNT - 10) {
                     // Once we have warmed up, enable the first 
breakpoint which eventually will
                     // lead to enabling single stepping.
                     enableEvents(Thread.currentThread(), 
MethodExitTest.class);
                 }

My guess is this because we have 3 threads in play, and want to make 
sure they are all executing in the virtual thread before enabling 
METHOD_EXIT events.

And I think it's safe to say you can ignore the "single stepping" 
comment. This test was cloned from one of our very early jvmti virtual 
threads tests, and that comment appears to be a relic. There is also a 
reference in the C file that can go away:

   if (strcmp(event_name, "SingleStep") != 0) {
     print_stack_trace(jvmti, jni, thread);
   }

Chris

On 8/8/23 12:35 PM, Gengchen Tuo wrote:
>
> Hi all. In the Method Exit test 
> https://github.com/openjdk/jdk/blob/master/test/hotspot/jtreg/serviceability/jvmti/vthread/MethodExitTest/MethodExitTest.java, 
> no MethodExit event is expected between the first and the second 
> breakpoint hit. Why are we making this assumption? Maybe that’s 
> related to line 59 and 60 that I don’t really understand? To my 
> knowledge, the producer thread may yield between the two breakpoint 
> hits and MethodExit events will be reported.
>
>
>
> I tried to enable the MethodEntry event in the agent code and the test 
> started to fail but this shouldn’t affect the test result I believe?
>
>
>
> Thanks in advance
>
> Gengchen
>
>


More information about the loom-dev mailing list