Skip to content

Optimize NMethod type check#1701

Merged
apangin merged 3 commits into
masterfrom
nmethod-type
Mar 18, 2026
Merged

Optimize NMethod type check#1701
apangin merged 3 commits into
masterfrom
nmethod-type

Conversation

@apangin

@apangin apangin commented Mar 18, 2026

Copy link
Copy Markdown
Member

Description

Currently, NMethod::isInterpreter, isNMethod, isStub and isVTableStub are implemented by comparing the name using strcmp/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:

Benchmark Before After %
spring-petclinic 13042 11656 -10.6%
renaissance dotty 18490 16322 -11.7%

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 isType methods 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 replaced isInterpreter with a single pointer comparison, since HotSpot has exactly one Code Blob with the name Interpreter.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Comment thread src/stackWalker.cpp
anchor = NULL;
}

if (nm->isNMethod()) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No actual changes; just swapped nm->isInterpreter() and nm->isNMethod() branches.

@apangin apangin merged commit cc0eab1 into master Mar 18, 2026
78 of 79 checks passed
@apangin apangin deleted the nmethod-type branch March 18, 2026 18:06
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.

2 participants