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 — Obtain class IDs under the sample lock by apangin · Pull Request #1809 · async-profiler/async-profiler

Conversation

@apangin

@apangin apangin commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

Description

Fixes use-after-free in Dictionary::lookup that happens when a profiling session is restarted while lock or allocation events are still being recorded.

This PR moves class name resolution under Profiler::_locks so that it cannot coincide with _class_map.clear() in Profiler::start.

Related issues

#1807

How has this been tested?

A stress test that reproduces the crash: 32 threads taking ReentrantLocks and allocating instances of 20000 classes, while the main thread restarts the profiler every 50 ms with start,event=cpu,alloc=1,lock=1,jfr.


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

Sorry, something went wrong.

Uh oh!

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

All reactions
@apangin
Obtain class IDs under the sample lock
11ca4a4
@github-actions

github-actions Bot commented Sep 20, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

linux-x64

File Base (KiB) Treatment (KiB) Delta (KiB) % Change
bin/asprof 81.72 81.72 +0.00 +0.00%
bin/jfrconv 136.54 136.54 +0.00 +0.00%
lib/libasyncProfiler.so 585.69 585.77 +0.09 +0.01%

linux-arm64

File Base (KiB) Treatment (KiB) Delta (KiB) % Change
bin/asprof 89.59 89.59 +0.00 +0.00%
bin/jfrconv 136.54 136.54 +0.00 +0.00%
lib/libasyncProfiler.so 609.22 613.12 +3.90 +0.64%

macos

File Base (KiB) Treatment (KiB) Delta (KiB) % Change
bin/asprof 116.74 116.74 +0.00 +0.00%
bin/jfrconv 136.54 136.54 +0.00 +0.00%
lib/libasyncProfiler.dylib 969.57 969.73 +0.16 +0.02%
All reactions

Sorry, something went wrong.

Uh oh!

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

Baraa-Hasheesh
Baraa-Hasheesh reviewed Sep 21, 2026
View reviewed changes
Comment thread src/lockTracer.cpp Outdated
if (updateCounter(_total_duration, duration, _interval)) {
recordContendedLock(PARK_SAMPLE, park_start_time, park_end_time, lock_name, park_blocker, time);
// Profiling session might have been stopped or restarted while the thread was parked
if (_enabled && park_start_time >= _start_time) {

@Baraa-Hasheesh Baraa-Hasheesh Sep 21, 2026

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.

Wouldn't this still potentially race?

_enabled is set to true as part of installTraps which happens way earlier than the set of _start_time

Sorry, something went wrong.

Uh oh!

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

All reactions

@Baraa-Hasheesh Baraa-Hasheesh Sep 21, 2026

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.

also as a note _start_time is a normal static value, we should probably change it to volatile or maybe use atomics?

Sorry, something went wrong.

Uh oh!

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

All reactions

@apangin apangin Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

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.

volatile or atomics are redundant: compiler can't cache values across callbacks, and there is no happens-before requirement here. Opaque read is enough.

There is no race with respect to where _enabled is set, but I noticed a different bug: since park traps are no longer uninstalled, lock samples will continue being reported during the next profiling session started without lock. I fixed that by resetting _start_time in LockTracer::stop.

Sorry, something went wrong.

Uh oh!

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

Baraa-Hasheesh reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Baraa-Hasheesh
Baraa-Hasheesh reviewed Sep 21, 2026
View reviewed changes
Comment thread src/event.h
void setClassSignature(const char* class_sig);

// Must be called under the sample lock (Profiler::_locks).
// May allocate; do not call in asynchronous signal handlers.

@Baraa-Hasheesh Baraa-Hasheesh Sep 21, 2026 •
edited
Loading

Uh oh!

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

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.

This is called for recordAllocationOutsideTLAB & recordAllocationInNewTLAB which can happen in asynchronous signal handlers (allocaTracer)

Wouldn't that cause an issue?

Sorry, something went wrong.

Uh oh!

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

All reactions

@apangin apangin Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

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.

AllocTracer's handlers are synchronous - they are only called at the specific locations when a thread is known not to be inside malloc.

Sorry, something went wrong.

Uh oh!

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

Baraa-Hasheesh reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@apangin
Reset _start_time to NOT_STARTED upon stopping lock profiling
7adf3b9
Baraa-Hasheesh
Baraa-Hasheesh approved these changes Sep 21, 2026
View reviewed changes

@Baraa-Hasheesh Baraa-Hasheesh 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.

LGTM

Sorry, something went wrong.

Uh oh!

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

All reactions
benty-amzn
benty-amzn approved these changes Sep 21, 2026
View reviewed changes
@apangin
apangin merged commit a725243 into master Sep 22, 2026
52 of 55 checks passed

Uh oh!

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

@apangin
apangin deleted the classmap-race branch September 22, 2026 00:29
@apangin apangin mentioned this pull request Sep 22, 2026
SIGSEGV crash in Dictionary::lookup when profiling with Pyroscope #1807
Closed
@github-actions github-actions Bot mentioned this pull request Sep 22, 2026
Upstream async-profiler changes detected (2026-09-22) DataDog/java-profiler#812
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

2 more reviewers
@benty-amzn benty-amzn benty-amzn approved these changes
@Baraa-Hasheesh Baraa-Hasheesh Baraa-Hasheesh approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

3 participants

@apangin @benty-amzn @Baraa-Hasheesh
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.