Skip to content

Port async-profiler#1701: optimize nmethod type checks#423

Open
jbachorik wants to merge 1 commit intomainfrom
jb/ap_1701
Open

Port async-profiler#1701: optimize nmethod type checks#423
jbachorik wants to merge 1 commit intomainfrom
jb/ap_1701

Conversation

@jbachorik
Copy link
Collaborator

@jbachorik jbachorik commented Mar 19, 2026

What does this PR do?:
Ports async-profiler#1701 (commit cc0eab1) into the Datadog fork, adapting it for our VMNMethod-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:

  1. isInterpreter() pointer comparison — HotSpot has exactly one Interpreter code blob. We now record its VMNMethod* at JVM startup (via addRuntimeStub) and compare with this instead of calling strcmp. O(1) instead of O(n).
  2. Inline startsWith template — Replaces strcmp/strncmp calls in isNMethod, isStub, and isVTableStub with a compile-time-unrolled character loop, avoiding the indirect PLT call to the standard library.
  3. Branch reordering in stackWalker.cppisInterpreter() is now checked before isNMethod() since it is now a single pointer comparison.

Additional Notes:

  • _interpreter_start is stored separately so that resolveOffsets() can retry findNMethod if the code heap was not yet initialized when addRuntimeStub("Interpreter", ...) was called.
  • The improvement can be observed via the existing WALKVM_* counters (e.g. walkvm_java_frame_ok) recorded during profiling runs.
  • Closes Upstream async-profiler changes detected (2026-03-19) #421.

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:

  • If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.
  • JIRA: [JIRA-XXXX]

Unsure? Have a question? Request a review!

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>
@jbachorik jbachorik added the AI label Mar 19, 2026
@jbachorik jbachorik marked this pull request as ready for review March 19, 2026 20:37
@jbachorik jbachorik requested a review from a team as a code owner March 19, 2026 20:37
@jbachorik jbachorik requested review from rkennke and zhengyu123 March 19, 2026 20:39
@dd-octo-sts
Copy link

dd-octo-sts bot commented Mar 19, 2026

CI Test Results

Run: #23315546091 | Commit: 03046c0 | Duration: 10m 2s (longest job)

All 32 test jobs passed

Status Overview

JDK glibc-aarch64/debug glibc-amd64/debug musl-aarch64/debug musl-amd64/debug
8 - - -
8-ibm - - -
8-j9 - -
8-librca - -
8-orcl - - -
11 - - -
11-j9 - -
11-librca - -
17 - -
17-graal - -
17-j9 - -
17-librca - -
21 - -
21-graal - -
21-librca - -
25 - -
25-graal - -
25-librca - -

Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled

Summary: Total: 32 | Passed: 32 | Failed: 0


Updated: 2026-03-19 20:44:23 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upstream async-profiler changes detected (2026-03-19)

1 participant