RFR: 8358821: patch_verified_entry causes problems, use nmethod entry barriers instead [v9]
Martin Doerr
mdoerr at openjdk.org
Wed Jun 25 09:52:37 UTC 2025
On Mon, 23 Jun 2025 19:26:11 GMT, Dean Long <dlong at openjdk.org> wrote:
>> This PR removes patching of the verified entry point and related code, and replaces it by refactoring the existing nmethod entry barrier.
>>
>> We used to patch the verified entry point to make sure it was not_entrant. The patched entry point then redirected to SharedRuntime::handle_wrong_method(), either directly with a jump to a stub, or indirectly with an illegal instruction and the help of the signal handler. The not_entrant state is a final state, so once an nmethod becomes not_entrant, it stays not_entrant. We can do the same thing with a permanently armed nmethod entry barrier.
>>
>> The solution I went with reserves one bit of the entry barrier guard value. This bit must remain set, so I call it a "sticky" bit. Setting the guard value now is effectively like setting a bitfield, so I needed to add a lock around it. The alternative would be to change the platform-specific code to do compare-and-swap.
>>
>> For the lock, I introduced a new NMethodEntryBarrier_lock, whose only purpose is to make the update to the guard value atomic. For ZGC, I decided to use the existing per-nmethod lock ZNMethod::lock_for_nmethod(). I suspect we could do the same for Shenandoah, if needed for performance.
>>
>> This change also makes it a bit clearer that the nmethod entry barrier effectively has two levels. Level 0 is the outer level or layer controlled by BarrierSetNMethod::nmethod_stub_entry_barrier(), and the inner layer controlled by BarrierSetNMethod::nmethod_entry_barrier(). This could be generalized if we decide we need more flavors of entry barriers. The inner barrier is mostly ignorant of the fact that the outer guard is multiplexing for both levels.
>
> Dean Long has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 16 commits:
>
> - Merge branch 'master' into 8358821-patch-verified-entry
> - 2nd try at arm fix
> - rename arm_with to guard_with
> - arm32 fix
> - s390 fix courtesy of Amit Kumar
> - remove is_sigill_not_entrant
> - more cleanup
> - more TheRealMDoerr suggestions
> - TheRealMDoerr suggestions
> - remove trailing space
> - ... and 6 more: https://git.openjdk.org/jdk/compare/6df0f5e3...a39c458c
src/hotspot/share/gc/shared/barrierSetNMethod.hpp line 52:
> 50:
> 51: public:
> 52: BarrierSetNMethod() : _current_phase(initial) {}
@fisk: The initial value doesn't match our initialization in the nmethod entry barrier code were we use 0. That causes all new nmethods to run through the barrier code when they are called for the first time. I think that is unnecessary and it slows down the startup a bit. All oops should already be correct after the nmethod got installed. And for ZGC, we call `nmethod_patch_barriers` in `ZNMethod::register_nmethod`. So, I don't see any need to execute the barrier code. We could change the initialization to use `_current_phase`. Do you agree? Should I file a new JBS issue?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25764#discussion_r2166306862
More information about the hotspot-dev
mailing list