GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(profiler): make _class_map access signal-safe in walkVM by jbachorik · Pull Request #512 · DataDog/java-profiler

Conversation

@jbachorik

@jbachorik jbachorik commented May 7, 2026 •
edited by atlassian Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

What does this PR do?:

Fixes a SIGSEGV in Dictionary::clear reached via Profiler::dump by closing two correctness holes around Profiler::_class_map. Also covers the crash signature from PROF-14550 (same root cause, dump-path variant).

  • walkVM at hotspotSupport.cpp:388 previously called the inserting 2-arg Dictionary::lookup from a signal handler, which calls malloc/calloc (dictionary.cpp:25,114). That is async-signal-unsafe and could tear the malloc arena. Switched to the existing read-only bounded_lookup(..., 0) guarded by OptionalSharedLockGuard (tryLockShared); on miss or contention the synthetic vtable-target frame is skipped — the JVMTI / Java-API path will populate the entry from a non-signal context.
  • Recording::writeClasses previously called _classes->collect(map) with no lock while JVMTI shared-lock writers (Profiler::lookupClass, ObjectSampler, LivenessTracker) could mutate the dictionary, and the dump path's exclusive _class_map.clear() ran shortly after. Now wrapped in SharedLockGuard guard(Profiler::instance()->classMapLock()). Multiple shared-lock holders coexist with CAS-based inserters; the exclusive clear() waits until writeClasses returns.
  • Added a public Profiler::classMapLock() accessor next to the existing classMap() accessor.
  • Documented the signal-safety hazard on the inserting Dictionary::lookup overloads.
  • Corrected the misleading comments in writeCpool and writeClasses that previously claimed concurrent access was already safe.

Motivation:

PROF-14549 reports a SIGSEGV in Dictionary::collect reached via Recording::writeClasses during Profiler::dump. PROF-14550 reports the same SIGSEGV in Dictionary::clear reached via Profiler::dump directly. Both trace to the same root cause:

  1. walkVM calling inserting lookup from a signal handler — malloc-arena tearing under signal preemption.
  2. writeClasses reading the Dictionary chain unsynchronised against the dump-path clear().

The vtable_target feature is on by default, so the buggy site is reachable on every CPU/wall/native-alloc sample whose top frame is a vtable stub.

Additional Notes:

  • The BCI_ALLOC reuse at hotspotSupport.cpp:388 is semantic overloading (frame marker, not allocation event). It was downported from upstream async-profiler and is preserved as-is here — only the signal-safety of the lookup is changed.
  • The same hazard exists in upstream src/stackWalker.cpp:399-405. Filing the equivalent fix upstream is a follow-up.
  • Trade-off: first-occurrence vtable-target annotations for cold classes are temporarily lost until the JVMTI / Java-API path inserts the class via Profiler::lookupClass. Eliminating the SIGSEGV outweighs the cosmetic loss.

How to test the change?:

  • New unit/stress tests at ddprof-lib/src/test/cpp/dictionary_concurrent_ut.cpp cover:
    1. bounded_lookup(..., 0) on a miss returns INT_MAX and does not insert.
    2. bounded_lookup(..., 0) on a hit returns the same id that the inserting lookup produced.
    3. ~500ms concurrent run with 4 shared-lock inserter threads, one shared-lock collector thread, and one exclusive-lock clear thread — regression gate for the lock discipline (PROF-14549).
    4. ~500ms concurrent run with 4 OptionalSharedLockGuard + bounded_lookup(0) "signal-handler" threads vs one exclusive-lock clear thread — regression gate for the PROF-14550 dump-path crash signature.
  • Existing CPU / wall / native-alloc / JVMTI alloc / liveness profile tests continue to pass.

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: PROF-14549, PROF-14550

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

chatgpt-codex-connector[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@jbachorik jbachorik added the AI label May 7, 2026
@jbachorik
jbachorik requested a review from Copilot May 7, 2026 10:12
@jbachorik jbachorik changed the title fix(profiler): make _class_map access signal-safe in walkVM (PROF-14549) fix(profiler): make _class_map access signal-safe in walkVM May 7, 2026
Copilot started reviewing on behalf of jbachorik May 7, 2026 10:13
View session

This comment was marked as outdated.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jbachorik @claude
fix(profiler): make _class_map access signal-safe in walkVM
7880e7c
walkVM ran the inserting Dictionary::lookup from a signal handler, calling
malloc/calloc — async-signal-unsafe. Recording::writeClasses also walked
_class_map without holding _class_map_lock, racing the exclusive clear()
that follows in Profiler::dump.

Switch the vtable-target site to bounded_lookup(..., 0) and skip the
synthetic frame on miss; hold _class_map_lock shared while writeClasses
recurses into Dictionary::collect; document the signal-safety hazard on
the inserting overloads; add a concurrent test for the lock discipline.

Fixes PROF-14549.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@jbachorik
jbachorik force-pushed the muse/sigsegv-in-recording-writeclasses branch from f3e2ccb to 7880e7c Compare May 7, 2026 10:25
@jbachorik
jbachorik requested a review from Copilot May 7, 2026 10:28
@jbachorik

jbachorik commented May 7, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Copilot started reviewing on behalf of jbachorik May 7, 2026 10:29
View session
chatgpt-codex-connector[bot]
chatgpt-codex-connector Bot reviewed May 7, 2026
View reviewed changes

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7880e7ce7f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Resolved

Uh oh!

There was an error while loading. Please reload this page.

Copilot AI reviewed May 7, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ddprof-lib/src/test/cpp/dictionary_concurrent_ut.cpp Resolved

Uh oh!

There was an error while loading. Please reload this page.

@jbachorik @claude
fix(profiler): guard signal-side _class_map reads against clear()
a293e96
Codex flagged a remaining race after the initial fix: walkVM's read-only
bounded_lookup still traverses row->next and reads row->keys[j] without
holding _class_map_lock, while Profiler::dump's exclusive _class_map.clear()
runs in the unlockAll -> lock window and free()s those same nodes/strings.

Take _class_map_lock shared via OptionalSharedLockGuard (try-lock so the
signal handler never blocks). When an exclusive clear() is in progress,
drop the synthetic vtable-target frame instead of dereferencing freed
memory.

Also add the missing <cstring> include in dictionary_concurrent_ut.cpp;
strlen() previously worked only via a transitive include through
gtest_crash_handler.h.

Addresses review comments on PR #512.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@dd-octo-sts

dd-octo-sts Bot commented May 7, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #34248828775 | Commit: c5adab3 | Duration: 0s (longest job)

✅ All 0 test jobs passed

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


Updated: 2026-09-08 16:24:11 UTC

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jbachorik
jbachorik commented May 7, 2026
View reviewed changes
Comment thread ddprof-lib/src/test/cpp/dictionary_concurrent_ut.cpp Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ddprof-lib/src/main/cpp/flightRecorder.cpp Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ddprof-lib/src/main/cpp/flightRecorder.cpp Resolved

Uh oh!

There was an error while loading. Please reload this page.

@jbachorik muse
docs: align comments with accessor names; drop JIRA reference
bc05222
flightRecorder.cpp: refer to classMap()/classMapLock() rather
than the underlying _class_map/_class_map_lock fields.
dictionary_concurrent_ut.cpp: drop PROF-14549 ticket reference.

Co-Authored-By: muse <muse@noreply>
@jbachorik
jbachorik force-pushed the muse/sigsegv-in-recording-writeclasses branch from 8f59e1a to bc05222 Compare May 7, 2026 20:22
@jbachorik
jbachorik requested a review from Copilot May 7, 2026 20:23
Copilot started reviewing on behalf of jbachorik May 7, 2026 20:24
View session
Copilot AI reviewed May 7, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ddprof-lib/src/test/cpp/dictionary_concurrent_ut.cpp Resolved

Uh oh!

There was an error while loading. Please reload this page.

@jbachorik
Address comments
9707596
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@jbachorik
jbachorik marked this pull request as ready for review May 7, 2026 20:32
@jbachorik
jbachorik requested a review from a team as a code owner May 7, 2026 20:32
@jbachorik
Merge branch 'main' into muse/sigsegv-in-recording-writeclasses
b80d1d6
@jbachorik jbachorik added the AI: Author Signed-off label May 7, 2026
@jbachorik @claude
test(dictionary): add PROF-14550 regression for walkVM bounded_lookup…
210309c
… vs dump clear

Adds SignalHandlerBoundedLookupVsDumpClear: concurrent signal-handler threads
(OptionalSharedLockGuard + bounded_lookup(0)) vs a dump thread (exclusive lock
+ dict.clear()), reproducing the PROF-14550 crash signature without the fix.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
jbachorik added a commit that referenced this pull request May 8, 2026
@jbachorik @claude
fix(profiler): guard signal-side _class_map reads against clear()
11c08e5
Codex flagged a remaining race after the initial fix: walkVM's read-only
bounded_lookup still traverses row->next and reads row->keys[j] without
holding _class_map_lock, while Profiler::dump's exclusive _class_map.clear()
runs in the unlockAll -> lock window and free()s those same nodes/strings.

Take _class_map_lock shared via OptionalSharedLockGuard (try-lock so the
signal handler never blocks). When an exclusive clear() is in progress,
drop the synthetic vtable-target frame instead of dereferencing freed
memory.

Also add the missing <cstring> include in dictionary_concurrent_ut.cpp;
strlen() previously worked only via a transitive include through
gtest_crash_handler.h.

Addresses review comments on PR #512.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
rkennke
rkennke approved these changes May 11, 2026
View reviewed changes

@rkennke rkennke left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks good. Thank you!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jbachorik
fix(profiler): eliminate SIGSEGV race on _class_map.clear() in signal…
cb6c809
… handler and dump path (#516)
@jbachorik
jbachorik merged commit c5adab3 into main May 12, 2026
83 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@jbachorik
jbachorik deleted the muse/sigsegv-in-recording-writeclasses branch May 12, 2026 11:02
@github-actions github-actions Bot added this to the 1.43.0 milestone May 12, 2026
This was referenced May 12, 2026
test(jfr): regression test for dump+restart race (SIGSEGV in _Rb_tree_increment) #523
Closed
refactor(vtable_target): defer receiver resolution to dump time via SafeAccess #527
Merged
jbachorik added a commit that referenced this pull request May 13, 2026
@jbachorik @claude
fix(profiler): pre-register vtable receiver classes via JVMTI (PROF-1…
3115f92
…4618)

Restores vtable_target frame capture in CPU-only recordings. After PR #512
made walkVM signal-safe (bounded_lookup with size_limit=0, no malloc),
_class_map was only populated by allocation/liveness paths via lookupClass.
In a CPU-only recording these paths never fire, so signal-safe lookups
always missed and vtable-target frames were silently dropped.

This change pre-populates _class_map from safe JVM-thread contexts:

- Profiler::preregisterLoadedClasses(jvmtiEnv*) calls GetLoadedClasses +
  GetClassSignature + ObjectSampler::normalizeClassSignature, inserting
  every reference class into _class_map.  Invoked at Profiler::start()
  (after clearAll()) and Profiler::dump() (after clearStandby()).
  TripleBufferedDictionary::lookup is thread-safe via RefCountGuard so no
  external locking is needed.

- VM::ClassPrepare is moved out-of-line to vmEntry.cpp (vmEntry.h is
  included by profiler.h, hence the prior inline definition could not
  reference Profiler::instance()).  The handler still calls loadMethodIDs
  first, then conditionally inserts the new class when
  _features.vtable_target is set.

The hot signal-handler path in hotspotSupport.cpp is unchanged —
pre-registration runs only on JVM threads, never under a signal.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
jbachorik added a commit that referenced this pull request May 13, 2026
@jbachorik @claude
fix(profiler): pre-register vtable receiver classes via JVMTI (PROF-1…
6e825c7
…4618)

Restores vtable_target frame capture in CPU-only recordings. After PR #512
made walkVM signal-safe (bounded_lookup with size_limit=0, no malloc),
_class_map was only populated by allocation/liveness paths via lookupClass.
In a CPU-only recording these paths never fire, so signal-safe lookups
always missed and vtable-target frames were silently dropped.

This change pre-populates _class_map from safe JVM-thread contexts:

- Profiler::preregisterLoadedClasses(jvmtiEnv*) calls GetLoadedClasses +
  GetClassSignature + ObjectSampler::normalizeClassSignature, inserting
  every reference class into _class_map.  Invoked at Profiler::start()
  (after clearAll()) and Profiler::dump() (after clearStandby()).
  TripleBufferedDictionary::lookup is thread-safe via RefCountGuard so no
  external locking is needed.

- VM::ClassPrepare is moved out-of-line to vmEntry.cpp (vmEntry.h is
  included by profiler.h, hence the prior inline definition could not
  reference Profiler::instance()).  The handler still calls loadMethodIDs
  first, then conditionally inserts the new class when
  _features.vtable_target is set.

The hot signal-handler path in hotspotSupport.cpp is unchanged —
pre-registration runs only on JVM threads, never under a signal.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
jbachorik added a commit that referenced this pull request May 15, 2026
@jbachorik @claude
fix(profiler): pre-register vtable receiver classes via JVMTI (PROF-1…
2dbee3f
…4618)

Restores vtable_target frame capture in CPU-only recordings. After PR #512
made walkVM signal-safe (bounded_lookup with size_limit=0, no malloc),
_class_map was only populated by allocation/liveness paths via lookupClass.
In a CPU-only recording these paths never fire, so signal-safe lookups
always missed and vtable-target frames were silently dropped.

This change pre-populates _class_map from safe JVM-thread contexts:

- Profiler::preregisterLoadedClasses(jvmtiEnv*) calls GetLoadedClasses +
  GetClassSignature + ObjectSampler::normalizeClassSignature, inserting
  every reference class into _class_map.  Invoked at Profiler::start()
  (after clearAll()) and Profiler::dump() (after clearStandby()).
  TripleBufferedDictionary::lookup is thread-safe via RefCountGuard so no
  external locking is needed.

- VM::ClassPrepare is moved out-of-line to vmEntry.cpp (vmEntry.h is
  included by profiler.h, hence the prior inline definition could not
  reference Profiler::instance()).  The handler still calls loadMethodIDs
  first, then conditionally inserts the new class when
  _features.vtable_target is set.

The hot signal-handler path in hotspotSupport.cpp is unchanged —
pre-registration runs only on JVM threads, never under a signal.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@jbachorik jbachorik added the identified-by:crashtracking Issue identified via crash tracking label Jul 1, 2026
@zhengyu123 zhengyu123 added the fixed_version: v_1.43.0 Version this PR's fix shipped in label Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@chatgpt-codex-connector chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] left review comments
@rkennke rkennke rkennke approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

AI: Author Signed-off AI fixed_version: v_1.43.0 Version this PR's fix shipped in identified-by:crashtracking Issue identified via crash tracking

Projects

None yet

Milestone

1.43.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@jbachorik @rkennke @zhengyu123
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.