Port async-profiler#1701: optimize nmethod type checks#423
Open
Port async-profiler#1701: optimize nmethod type checks#423
Conversation
Replace strcmp/strncmp calls in isNMethod/isInterpreter/isStub/isVTableStub with an inline startsWith template and a pointer comparison for isInterpreter, matching upstream async-profiler cc0eab1. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
CI Test ResultsRun: #23315546091 | Commit:
Status Overview
Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled Summary: Total: 32 | Passed: 32 | Failed: 0 Updated: 2026-03-19 20:44:23 UTC |
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.
What does this PR do?:
Ports async-profiler#1701 (commit
cc0eab1) into the Datadog fork, adapting it for ourVMNMethod-based class structure.Motivation:
Upstream measured up to ~11% improvement in average stack-walking speed on real benchmarks (spring-petclinic, renaissance dotty). The two main micro-optimizations are:
isInterpreter()pointer comparison — HotSpot has exactly oneInterpretercode blob. We now record itsVMNMethod*at JVM startup (viaaddRuntimeStub) and compare withthisinstead of callingstrcmp. O(1) instead of O(n).startsWithtemplate — Replacesstrcmp/strncmpcalls inisNMethod,isStub, andisVTableStubwith a compile-time-unrolled character loop, avoiding the indirect PLT call to the standard library.stackWalker.cpp—isInterpreter()is now checked beforeisNMethod()since it is now a single pointer comparison.Additional Notes:
_interpreter_startis stored separately so thatresolveOffsets()can retryfindNMethodif the code heap was not yet initialized whenaddRuntimeStub("Interpreter", ...)was called.WALKVM_*counters (e.g.walkvm_java_frame_ok) recorded during profiling runs.How to test the change?:
Existing CI covers the stack-walking paths. The performance gain can be measured by comparing stack-walk throughput on a CPU-heavy workload before and after.
For Datadog employees:
@DataDog/security-design-and-guidance.Unsure? Have a question? Request a review!