This repository was archived by the owner on Sep 2, 2022. It is now read-only.
File tree 2 files changed +16
-4
lines changed
2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -1596,8 +1596,18 @@ void nmethod::post_compiled_method_load_event(JvmtiThreadState* state) {
1596
1596
1597
1597
// Don't post this nmethod load event if it is already dying
1598
1598
// because the sweeper might already be deleting this nmethod.
1599
- if (is_not_entrant () && can_convert_to_zombie ()) {
1600
- return ;
1599
+ {
1600
+ MutexLocker ml (CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
1601
+ // When the nmethod is acquired from the CodeCache iterator, it can racingly become zombie
1602
+ // before this code is called. Filter them out here under the CompiledMethod_lock.
1603
+ if (!is_alive ()) {
1604
+ return ;
1605
+ }
1606
+ // As for is_alive() nmethods, we also don't want them to racingly become zombie once we
1607
+ // release this lock, so we check that this is not going to be the case.
1608
+ if (is_not_entrant () && can_convert_to_zombie ()) {
1609
+ return ;
1610
+ }
1601
1611
}
1602
1612
1603
1613
// This is a bad time for a safepoint. We don't want
Original file line number Diff line number Diff line change @@ -227,8 +227,10 @@ jvmtiError JvmtiCodeBlobEvents::generate_compiled_method_load_events(JvmtiEnv* e
227
227
{
228
228
NoSafepointVerifier nsv; // safepoints are not safe while collecting methods to post.
229
229
{
230
- // Walk the CodeCache notifying for live nmethods, don't release the CodeCache_lock
231
- // because the sweeper may be running concurrently.
230
+ // Walk the CodeCache notifying for live nmethods. We hold the CodeCache_lock
231
+ // to ensure the iteration is safe and nmethods are not concurrently freed.
232
+ // However, they may still change states and become !is_alive(). Filtering
233
+ // those out is done inside of nmethod::post_compiled_method_load_event().
232
234
// Save events to the queue for posting outside the CodeCache_lock.
233
235
MutexLocker mu (java_thread, CodeCache_lock, Mutex::_no_safepoint_check_flag);
234
236
// Iterate over non-profiled and profiled nmethods
You can’t perform that action at this time.
0 commit comments