Skip to content

Clean up some locking around hierarchy modification#8849

Merged
headius merged 1 commit intojruby:jruby-9.4from
headius:rubymodule_consistent_locking
May 29, 2025
Merged

Clean up some locking around hierarchy modification#8849
headius merged 1 commit intojruby:jruby-9.4from
headius:rubymodule_consistent_locking

Conversation

@headius
Copy link
Member

@headius headius commented May 28, 2025

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

@headius headius added this to the JRuby 9.4.13.0 milestone May 28, 2025
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
@headius headius force-pushed the rubymodule_consistent_locking branch from 1dc3341 to 2534dda Compare May 29, 2025 02:49
@headius headius merged commit 5f2e846 into jruby:jruby-9.4 May 29, 2025
96 of 97 checks passed
@headius headius deleted the rubymodule_consistent_locking branch May 29, 2025 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant