[vm] Fix data race in Function::unoptimized_code (#61800) #61823
+2
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a ThreadSanitizer-detected data race when accessing
Function::unoptimized_codebetween the main compilation thread and background optimizer thread.Issue
Fixes #61800
ThreadSanitizer detected a data race where:
unoptimized_codeviaFunction::set_unoptimized_code()during compilationunoptimized_codeduring the inlining optimization pass inCallSiteInliner::GetParsedFunction()This unsynchronized access could lead to:
Changes
Applied proper acquire-release synchronization to
Function::unoptimized_codeaccessors:runtime/vm/object.h:
unoptimized_code()getter to usestd::memory_order_acquirewhen readingruntime/vm/object.cc:
set_unoptimized_code()setter to usestd::memory_order_releasewhen writingThe existing
COMPRESSED_POINTER_FIELDmacro already supports templated memory ordering, so this change leverages that existing infrastructure.Memory Ordering Semantics
Related Work
This follows the same pattern used for other concurrent code access in the Dart VM and is consistent with the existing memory ordering support in the
COMPRESSED_POINTER_FIELDmacro infrastructure.TEST=language/vm/regression_39193_test
Contribution guidelines:
dart format.Note that this repository uses Gerrit for code reviews. Your pull request will be automatically converted into a Gerrit CL and a link to the CL written into this PR. The review will happen on Gerrit but you can also push additional commits to this PR to update the code review.