Fix: Reduce thread blocking by double null check instead of synchronizing on Method object#521
Merged
lukaszlenart merged 2 commits intoorphan-oss:mainfrom Dec 29, 2025
Merged
Conversation
This was referenced Dec 29, 2025
Collaborator
|
Great, thanks for the patch! I'm going to merge it now and cherry pick changes into 4.8.x branch as well |
lukaszlenart
added a commit
that referenced
this pull request
Dec 29, 2025
Cherry-pick of PR #521 adapted for Java 8 compatibility. Implements double-null-check pattern for _methodAccessCache and _methodPermCache to avoid synchronizing on Method objects when cache values already exist. Fixes thread contention issues where multiple threads would block waiting to acquire locks on java.lang.reflect.Method objects even when cache values were already present. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2 tasks
Collaborator
|
PR is ready #523 |
Contributor
Author
Thank you very much for merging the patch and backporting it to the 4.8.x branch! I appreciate your attention to getting this optimization out across relevant branches, and feel confident it will help reduce the thread contention issues we observed. |
Collaborator
|
I meant 3.4.x branch - sorry for mixing things up :( |
lukaszlenart
added a commit
that referenced
this pull request
Dec 29, 2025
) Cherry-pick of PR #521 adapted for Java 8 compatibility. Implements double-null-check pattern for _methodAccessCache and _methodPermCache to avoid synchronizing on Method objects when cache values already exist. Fixes thread contention issues where multiple threads would block waiting to acquire locks on java.lang.reflect.Method objects even when cache values were already present. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
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.
PR Title
Fix: Reduce thread blocking by double null check instead of synchronizing on Method object
PR Description
Problem
We observed severe thread blocking issues in production: 980+ threads were blocked at
OgnlRuntime.invokeMethodwith the stateBLOCKED (on object monitor), waiting to lockjava.lang.reflect.Methodobjects.Root cause:
Methodobjects leads to heavy thread contention — all threads competing to execute method access checks must wait for the sameMethodmonitor, which severely degrades system concurrency and performance.Solution
To resolve the thread blocking while maintaining cache correctness, we introduced a double null check pattern to avoid unnecessary synchronization on
Methodobjects:_methodAccessCachefor existing cached values (no synchronization)Key Code Changes
synchronized (method)block inside a double null check formethodAccessCacheValueMethodobjects when the cache is already hit_methodAccessCache/_methodPermCache)syncInvokecalculation and method access checkExpected Outcome
MethodobjectsAdditional Notes