Clean up some locking around hierarchy modification#8849
Merged
headius merged 1 commit intojruby:jruby-9.4from May 29, 2025
Merged
Clean up some locking around hierarchy modification#8849headius merged 1 commit intojruby:jruby-9.4from
headius merged 1 commit intojruby:jruby-9.4from
Conversation
There are too many locks in this logic, leading to deadlock potential as reported in jruby#8846. This commit tries to centralize most hierarchy-modifying or hierarchy-walking locks to using the global runtime.getHierarchyLock, and localizes parts of the same code that are only modifying the current class. In the future we should consider the thread-safety of the various structures that make up RubyModule/RubyClass, since currently most of those structures are themselves thread-safe or lock-guarded, so much of the extra locking here may be unnecessary. We also have opportunities to improve some "compute if absent" scenarios and refine the way we lock for hierarchy walking to be more localized. Fixes jruby#8846
1dc3341 to
2534dda
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
There are too many locks in this logic, leading to deadlock potential as reported in #8846. This commit tries to centralize most hierarchy-modifying or hierarchy-walking locks to using the global runtime.getHierarchyLock, and localizes parts of the same code that are only modifying the current class.
In the future we should consider the thread-safety of the various structures that make up RubyModule/RubyClass, since currently most of those structures are themselves thread-safe or lock-guarded, so much of the extra locking here may be unnecessary. We also have opportunities to improve some "compute if absent" scenarios and refine the way we lock for hierarchy walking to be more localized.
Fixes #8846