Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.
/ jdk17 Public archive

Commit 9ec7180

Browse files
committed
8268524: nmethod::post_compiled_method_load_event racingly called on zombie
Reviewed-by: kvn, neliasso, coleenp
1 parent 01f12fb commit 9ec7180

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/hotspot/share/code/nmethod.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -1596,8 +1596,18 @@ void nmethod::post_compiled_method_load_event(JvmtiThreadState* state) {
15961596

15971597
// Don't post this nmethod load event if it is already dying
15981598
// 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+
}
16011611
}
16021612

16031613
// This is a bad time for a safepoint. We don't want

src/hotspot/share/prims/jvmtiCodeBlobEvents.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,10 @@ jvmtiError JvmtiCodeBlobEvents::generate_compiled_method_load_events(JvmtiEnv* e
227227
{
228228
NoSafepointVerifier nsv; // safepoints are not safe while collecting methods to post.
229229
{
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().
232234
// Save events to the queue for posting outside the CodeCache_lock.
233235
MutexLocker mu(java_thread, CodeCache_lock, Mutex::_no_safepoint_check_flag);
234236
// Iterate over non-profiled and profiled nmethods

0 commit comments

Comments
 (0)