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 — Harden crash protection in StackWalker by apangin · Pull Request #1629 · async-profiler/async-profiler

Conversation

@apangin

@apangin apangin commented Dec 21, 2025

Copy link
Copy Markdown
Collaborator

Description

Rework signal-based crash protection in StackWalker::walk to make it more robust and support native threads.

I made the following changes:

  1. Instead of using ThreadShadow::_exception_file field from VMStructs, store jmp_buf pointer in a one of 16 (CONCURRENCY_LEVEL) slots. walkVM is always called under one of 16 locks that protect _calltrace_buffer, so there is always a slot that a thread can exlusively use. This also works for non-Java threads.
  2. In SIGSEGV handler, look for a slot that currently holds a pointer to jmp_buf of the current thread. This jmp_buf should be close to the current stack pointer - usually within 8 KB, but I increased the limit to 32 KB just in case. Since walkVM can be called recursively (e.g. when running cpu and wall profiling together), we need to scan through all slots and find the closest one.
  3. Refactor StackWalker::walkVM to keep only one version of the function instead of three. This also helps to decrease the number of passed arguments: there were already 8 parameters and I wanted to add another one (lock_index).
  4. Add an extra sanity check to validate SP on each unwinding step. This brakes deepStack test, but this is actually for a good reason. It's useful to have a hard limit of the stack walking depth (currently 1 MB) to ensure we don't go too far and accidentally jump beyond the current stack. Stacks deeper than 1 MB are very rare in practice.

Related issues

Resolves #1626

How has this been tested?

Injected random segfaults in stack walking code and verified that it does not crash JVM.
Tested with extreme profiling settings on x86 and ARM64.

-agentpath:libasyncProfiler.so=start,event=cpu,interval=100us,wall=1ms,alloc,file=out.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 added 2 commits December 21, 2025 02:18
@apangin
Improve walkVM crash protection
6dbc377
@apangin
Fix deepStack test
b091a78
Baraa-Hasheesh
Baraa-Hasheesh reviewed Dec 21, 2025
View reviewed changes
Comment thread src/profiler.cpp Resolved

Uh oh!

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

Comment thread src/stackWalker.cpp Resolved

Uh oh!

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

Comment thread src/stackWalker.cpp Resolved

Uh oh!

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

Comment thread test/test/stackwalker/StackwalkerTests.java Resolved

Uh oh!

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

@apangin
Update code comment
57378ea
Baraa-Hasheesh
Baraa-Hasheesh reviewed Dec 21, 2025
View reviewed changes
Comment thread src/stackWalker.cpp Resolved

Uh oh!

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

Baraa-Hasheesh
Baraa-Hasheesh approved these changes Dec 21, 2025
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.

Change looks good to me

Sorry, something went wrong.

Uh oh!

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

apangin reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@apangin

apangin commented Dec 21, 2025

Copy link
Copy Markdown
Collaborator Author

Thank you for the review.

All reactions

Sorry, something went wrong.

Uh oh!

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

@apangin
apangin merged commit 9c425ca into master Dec 21, 2025
@apangin
apangin deleted the crash-protection branch December 21, 2025 23:17
@async-profiler async-profiler deleted a comment from zhangdc007 Jan 28, 2026
@retronym retronym mentioned this pull request Oct 25, 2026
macOS: one fault during a cstack=vm stack walk blocks the profiling signal in every thread (wall/cpu samples stop) #1828
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@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.

Enhance crash protection in async-profiler VM stack walker

Uh oh!

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

2 participants

@apangin @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.