-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure serializer reflection-dependency sentinel is accurate #66522
Conversation
Tagging subscribers to this area: @dotnet/area-system-text-json Issue DetailsFixes #66469.
|
if (s_defaultSimpleConverters is null) | ||
// s_typeInfoCreationFunc is the last field assigned. | ||
// Use it as the sentinel to ensure that all dependencies are initialized. | ||
if (s_typeInfoCreationFunc is null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought about his a little bit more, and you may want to use Volatile.Read(ref ...)
here as well. The reason is that we don't want an optimizing compiler / CPU to attempt to read s_defaultSimpleConverters or s_defaultFactoryConverters before s_typeInfoCreationFunc is confirmed not-null. Using Volatile.Read
here to complement the Volatile.Write
you have below will help guarantee this can never happen on the read side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, we might want to service 6.0 with this change since that particular change was cherry picked in #65898.
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs
Show resolved
Hide resolved
…66522) * Ensure serializer reflection-dependency sentinel is accurate * Address feedback
Fixes #66469.