On Sat, 26 Oct 2024 07:04:28 GMT, Richard Reingruber <rr...@openjdk.org> wrote:

>> src/hotspot/cpu/x86/stubGenerator_x86_64.cpp line 3796:
>> 
>>> 3794:   __ movbool(rscratch1, Address(r15_thread, 
>>> JavaThread::preemption_cancelled_offset()));
>>> 3795:   __ testbool(rscratch1);
>>> 3796:   __ jcc(Assembler::notZero, preemption_cancelled);
>> 
>> If preemption was canceled, then I wouldn't expect 
>> patch_return_pc_with_preempt_stub() to get called.  Does this mean 
>> preemption can get canceled (asynchronously be a different thread?) even 
>> afgter patch_return_pc_with_preempt_stub() is called?
>
> The comment at the `preemption_cancelled` label explains that a second 
> attempt to acquire the monitor succeeded after freezing. The vthread has to 
> continue execution. For that its frames (removed just above) need to be 
> thawed again.

If preemption was cancelled, we skip over the cleanup.  The native frames 
haven't been unwound yet.  So when we call thaw, does it cleanup the native 
frames first, or does it copy the frames back on top of the existing frames 
(overwrite)?  It seems like we could avoid redundant copying if we could 
somehow throw out the freeze data and use the native frames still on the stack, 
which would probably involve not patching in this stub until we know that the 
preemption wasn't canceled.  Some some finalize actions would be delated, like 
a two-stage commit.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/21565#discussion_r1819657858

Reply via email to