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 — AsyncGetCallTrace replacement · Issue #795 · async-profiler/async-profiler

AsyncGetCallTrace replacement #795

New issue
Copy link
New issue
Copy link
Closed
Closed
AsyncGetCallTrace replacement#795
Copy link
Labels
enhancement

Description

@apangin
apangin
opened on Aug 11, 2023
Issue body actions

Background

AsyncGetCallTrace (AGCT) is a non-standard extension of HotSpot JVM to obtain Java stack traces outside safepoints. async-profiler has been relying on AGCT heavily, it even got its name after this function.

In the meantime, being non-API, AsyncGetCallTrace was never supported in OpenJDK well enough: it did not receive enough testing, it was broken several times even in minor JDK updates, e.g. JDK-8307549.

AsyncGetCallTrace is notorious for inability to walk Java stack in different corner cases. There is a long-standing bug JDK-8178287 with several examples. But the worst thing is that AsyncGetCallTrace can crash JVM, and there is no reliable way to get around this outside the JVM.

Furthermore, AsyncGetCallTrace has limited capabilities. It does not provide information about Java frame type (interpreted/compiled/inlined). It skips all non-Java frames, so it's impossible to see JNI or JVM internal frames in the middle of the call stack.

It was previously proposed in #66 to re-implement stack walking in async-profiler without the problematic API. However, as async-profiler got workarounds for different shortcomings of AsyncGetCallTrace, the re-implementation was postponed. But after years, we still see issues with AGCT from time to time, including random crashes and missing stack traces.

Proposal

Get rid of the dependency on AsyncGetCallTrace entirely, at least, for HotSpot JVM. Leverage VMStructs for getting offsets of the HotSpot structures essential for stack walking. Implement stack walking externally like Serviceability Agent does.

Requirements

  1. Reliability. External stack walker must be protected against JVM crashes.
  2. Quality. Collected stack traces should be at least as accurate as with AGCT; the amount of "unknown" states should be minimal.
  3. Completeness. New implementation should display all frames: Java, native and JVM stubs throughout the whole stack.
  4. Details. Stack walker should provide additional information on each frame, like JIT compilation type.
  5. Performance. While the performance of the external implementation may be inferior to the JVM built-in one, it should be fast enough for production profiling.

Target platforms

The implementation targets HotSpot JVM on Linux and macOS, both x64 and ARM64.
It is not required to provide new stack walker for other platforms and other JVM implementations.

Example

This is how mixed stack traces may look on a flame graph:

fullstack
Reacted by Yonatan Goldschmidt, Brice Dutheil, Yoni Katzuv, Evgeny Vanslov, 杨杰, yangjie, Jaromir Hamala, Okada Haruki, Tomer Shafir, Koji Lin, Long Yang and 41 more

Activity

  1. apangin
    added
    enhancement
    on Aug 11, 2023
  2. apangin
    added a commit that references this issue on Aug 16, 2023

    #795: Experimental option to obtain stack traces without AsyncGetCall…

    6e01425
  3. apangin commented on Aug 17, 2023

    @apangin
    apangin
    on Aug 17, 2023
    CollaboratorAuthor
    More actions

    Added new stack walker that does not depend on AGCT as an optional feature.
    It can be enabled with --cstack vm argument.

    With this option, async-profiler collects mixed stack traces that have Java and native frames interleaved. The total stack depth is controlled with -j jstackdepth option.

    Reacted by Francesco Nigro, Yonatan Goldschmidt, Yoni Katzuv, Nitsan Wakart, Gavin Ray, Thanh Le, Sergey Bylokhov, Sergey Tselovalnikov, Long Yang, Petr Bouda and 7 more
    Reacted by Francesco Nigro, Jules Ivanic, Gavin Ray, Thanh Le, Sergey Tselovalnikov, Long Yang, Behrooz Nobakht and Vadim Tsesko
  4. apangin commented on Aug 17, 2023

    @apangin
    apangin
    on Aug 17, 2023
    CollaboratorAuthor
    More actions

    As a part of this work, DWARF unwinding has been implemented for ARM64 (it was previously available only on x86_64).

    Reacted by Yonatan Goldschmidt, fengfu, Long Yang, Petr Bouda and Artyom Drozdov
  5. apangin commented on Aug 17, 2023

    @apangin
    apangin
    on Aug 17, 2023
    CollaboratorAuthor
    More actions

    It's worth mentioning that new stack walker is fully enclosed by the crash protection based on setjmp/longjmp. Since the stack walker does not modify any VM structures and is in the full control of async-profiler, it is safe to interrupt it anywhere in the middle of execution.

    Reacted by Yonatan Goldschmidt and Artyom Drozdov
  6. apangin commented on Aug 22, 2023

    @apangin
    apangin
    on Aug 22, 2023
    CollaboratorAuthor
    More actions

    Closing the issue as solved. Further improvements will be done in the context of separate issues.

    Reacted by Alexey Genus, Vadim Tsesko, Artyom Drozdov, kevin and Etki
  7. apangin
    closed this as completedon Aug 22, 2023
  8. krzysztofslusarski commented on Aug 22, 2023

    @krzysztofslusarski
    krzysztofslusarski
    on Aug 22, 2023
    Contributor
    More actions

    Thank you @apangin.

  9. 243300852 commented on Sep 19, 2024

    @243300852
    243300852
    on Sep 19, 2024
    More actions

    @apangin Hi apangin, I have added cstack=vm, and the console prints "cstack=vm is an experimental option, use with care". Is this option secure and reliable, and is its function consistent with the previous function? In addition, I see that some environments do not support this option. What are the environmental limitations of this option?

  10. apangin commented on Sep 20, 2024

    @apangin
    apangin
    on Sep 20, 2024
    CollaboratorAuthor
    More actions

    @243300852 cstack=vm was an experimental option in async-profiler 3.0.
    But it is no longer marked experimental in the current version in master; will be a regular option in the next release.

    cstack=vm is supported on linux-x64 and linux-aarch64 with HotSpot JVM only.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.