Optimize NMethod type check#1701
Merged
Merged
Conversation
apangin
commented
Mar 18, 2026
| anchor = NULL; | ||
| } | ||
|
|
||
| if (nm->isNMethod()) { |
Member
Author
There was a problem hiding this comment.
No actual changes; just swapped nm->isInterpreter() and nm->isNMethod() branches.
fandreuz
approved these changes
Mar 18, 2026
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.
Description
Currently,
NMethod::isInterpreter,isNMethod,isStubandisVTableStubare implemented by comparing the name usingstrcmp/strncmp. We can make the check faster by inlining string comparison.Also, for interpreted frames, instead of checking NMethod name we could check NMethod pointer itself, because Interpreter is a singleton.
On some benchmarks, improvement in average stack walking speed can reach 10% as measured by
features=stats:Related issues
#1662
Motivation and context
This change was inspired by @fandreuz's PR: #1662
However, what I'm not happy about in that implementation is that it makes
isTypemethods stateful. I found that the actual performance issue was not in the string comparison itself, but rather in an indirect call to a standard library function. I went further and replacedisInterpreterwith a single pointer comparison, since HotSpot has exactly one Code Blob with the nameInterpreter.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.