Skip to content

Commit 37287ba

Browse files
committed
Serialize perf jitdump writes
1 parent 13db9a9 commit 37287ba

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

Python/perf_jit_trampoline.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,14 @@ static void perf_map_jit_write_entry_with_name(
577577
PyMem_RawFree(perf_map_entry);
578578
return;
579579
}
580+
581+
/*
582+
* A logical jitdump entry is written as multiple records and also consumes
583+
* a process-global code_id. Serialize the whole sequence so concurrent JIT
584+
* compilation cannot interleave records or reuse an ID.
585+
*/
586+
PyThread_acquire_lock(perf_jit_map_state.map_lock, 1);
587+
580588
/*
581589
* Write Code Unwinding Information Event
582590
*
@@ -691,6 +699,7 @@ static void perf_map_jit_write_entry_with_name(
691699
}
692700

693701
/* Clean up allocated memory */
702+
PyThread_release_lock(perf_jit_map_state.map_lock);
694703
PyMem_RawFree(perf_map_entry);
695704
}
696705

0 commit comments

Comments
 (0)