JDK-8350412 : [21u] AArch64: Ambiguous frame layout leads to incorrect traces in JFR
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 8,11,17,21
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • CPU: aarch64
  • Submitted: 2025-02-20
  • Updated: 2025-04-30
  • Resolved: 2025-03-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 17 JDK 21
17.0.16Fixed 21.0.8 b01Fixed
Related Reports
Relates :  
Relates :  
Description
It was previously pointed https://bugs.openjdk.org/browse/JDK-8323755?focusedId=14640270&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14640270 that "When doing a runtime call from compiled code, JVM puts two words onto the stack: ... This breaks the invariant the stack walker relies on: the size of the compiled frame is constant".

As a result JFR recordings from a simple program from JDK-8323755 do contain wrong samples, e.g. see duplicated timeLoop() entry

jdk.ExecutionSample {
  startTime = 21:33:04.331 (2025-02-19)
  sampledThread = "timeLoop" (javaThreadId = 39)
  state = "STATE_RUNNABLE"
  stackTrace = [
    Test.time() line: 29
    Test.wrapper() line: 25
    Test.timeLoop() line: 15
    Test.timeLoop() line: 20
  ]
}

Other diagnostic tools are affected too.

Current code in 21u that is responsible for that is https://github.com/openjdk/jdk21u-dev/blob/990859cc32776e2d794de539190c9ccced1dfcd9/src/hotspot/cpu/aarch64/aarch64.ad#L3779
It's the same for other update releases.

In mainline jdk the issue has been fixed in JDK 24 as a part of JEP 491: Synchronize Virtual Threads without Pinning (JDK-8338383).

The fix is in the aarch64.ad changes:
https://github.com/openjdk/jdk/commit/78b80150e009745b8f28d36c3836f18ad0ca921f#diff-018aa61d1a7aafcf70a535fcd40a318a4bd6511fd40ac39ce4be90cc52216749R1651
Comments
Changeset: 47aafc24 Branch: master Author: Dmitry Chuyko <dchuyko@openjdk.org> Committer: Paul Hohensee <phh@openjdk.org> Date: 2025-03-19 22:06:30 +0000 URL: https://git.openjdk.org/jdk21u/commit/47aafc24dfd6c62e80ff0bb51ce7f08f90e1bbe5
30-04-2025

[jdk17u-fix-request] Approval Request from Dmitry Chuyko This is a tiny fixes of incorrect stack traces sometimes reported by JFR. It is a backport from jdk21u where the change was cherry-picked from 25. In principal the patch for 17u is similar to 21u. Testing: tier1,2 on linux-aarch64.
20-03-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk17u-dev/pull/3389 Date: 2025-03-20 09:09:32 +0000
20-03-2025

Changeset: 47aafc24 Branch: master Author: Dmitry Chuyko <dchuyko@openjdk.org> Committer: Paul Hohensee <phh@openjdk.org> Date: 2025-03-19 22:06:30 +0000 URL: https://git.openjdk.org/jdk21u-dev/commit/47aafc24dfd6c62e80ff0bb51ce7f08f90e1bbe5
19-03-2025

[~dchuyko], please backport to 24 first. -- Ah, ok, I get it, it is released in the JEP in 24.
25-02-2025

[jdk21u-fix-request] Approval Request from Dmitry Chuyko This change fixes the stack layout that leads to non-deterministic stack walking, which at least turns into incorrect traces reported by JFR, other profiling tools also loose samples or require special workarounds. It is technically a clean backport of a tiny aarch64.ad change cherry picked from JEP 491. With a constant frame size JFR stops reporting incorrect traces on aarch64. In a case of approval I'll defer the integration to 21u till JDK 24 is out (or a defer label can be used).
24-02-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk21u-dev/pull/1418 Date: 2025-02-20 12:09:51 +0000
20-02-2025