Repository navigation
fix(profiler): mark skipped frozen virtual-thread callers as truncated #877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kaahos
wants to merge
10
commits into
main
Choose a base branch
from
paul.fournillon/fix-frozen-virtual-thread-truncation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e3bf2d3
fix(profiler): mark skipped frozen virtual-thread callers as truncated
kaahos 40b9ed1
Merge branch 'main' into paul.fournillon/fix-frozen-virtual-thread-tr…
kaahos 235f1e4
test: fix CI failures
kaahos 2f40d67
Merge branch 'main' into paul.fournillon/fix-frozen-virtual-thread-tr…
kaahos 57049e9
Merge branch 'main' into paul.fournillon/fix-frozen-virtual-thread-tr…
kaahos ccddb17
Merge branch 'main' into paul.fournillon/fix-frozen-virtual-thread-tr…
kaahos aa66961
sphinx: address review feedback on PR #877
jbachorik 9d06c30
fix(profiler): preserve explicit truncation in JFR stacks
kaahos c275b8c
Merge branch 'main' into paul.fournillon/fix-frozen-virtual-thread-tr…
kaahos 4dc9a2a
Merge branch 'main' into paul.fournillon/fix-frozen-virtual-thread-tr…
kaahos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * Copyright 2026, Datadog, Inc. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #ifndef _HOTSPOT_CONTBOUNDARY_H | ||
| #define _HOTSPOT_CONTBOUNDARY_H | ||
|
|
||
| // Classification of a virtual-thread continuation boundary crossed by walkVM. | ||
| // Two independent facts are derived from it: | ||
| // - completeness: whether the crossing proves no older Java callers remain | ||
| // frozen in a heap StackChunk (only Thawed does; everything else marks | ||
| // the sample truncated); | ||
| // - layout (JDK 21-26, no ContinuationEntry in vmStructs): whether the | ||
| // enterSpecial frame FP is the current fp (Thawed, Unverified) or the | ||
| // saved caller FP at *fp (Frozen). | ||
| enum class ContBoundary : unsigned char { | ||
| Thawed, // verified: bottom VT frame returns to cont_entry_return_pc / enterSpecial | ||
| Frozen, // verified: bottom VT frame returns to cont_returnBarrier | ||
| Unverified, // speculative: unknown CodeHeap PC on a carrier; state unknown | ||
| }; | ||
|
|
||
| // Only a verified fully-thawed boundary proves completeness. Any other value, | ||
| // including future enumerators, defaults to "not proven". | ||
| constexpr bool contBoundaryProvesComplete(ContBoundary kind) { | ||
| return kind == ContBoundary::Thawed; | ||
| } | ||
|
|
||
| // JDK 21-26 entry_fp derivation: fp itself, unless verified frozen (then *fp). | ||
| constexpr bool contBoundaryEntryFpIsCurrentFp(ContBoundary kind) { | ||
| return kind != ContBoundary::Frozen; | ||
| } | ||
|
|
||
| // Per-call-site classification used by walkVM. Call sites must pass one of | ||
| // these, never a bare enumerator. | ||
| inline constexpr ContBoundary CONT_BOUNDARY_AT_RETURN_BARRIER = ContBoundary::Frozen; | ||
| inline constexpr ContBoundary CONT_BOUNDARY_AT_ENTRY_RETURN_PC = ContBoundary::Thawed; | ||
| inline constexpr ContBoundary CONT_BOUNDARY_AT_ENTER_SPECIAL_NM = ContBoundary::Thawed; | ||
| inline constexpr ContBoundary CONT_BOUNDARY_AT_SPECULATIVE_UNKNOWN_NM = ContBoundary::Unverified; | ||
|
|
||
| #endif // _HOTSPOT_CONTBOUNDARY_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * Copyright 2026, Datadog, Inc. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| // Included first: the TU fails to compile if the header is not self-contained. | ||
| #include "hotspot/contBoundary.h" | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| // Compile-time checks: the predicates and per-site constants are constexpr. | ||
| static_assert(!contBoundaryProvesComplete(ContBoundary::Frozen), "Frozen must not prove completeness"); | ||
| static_assert(!contBoundaryEntryFpIsCurrentFp(ContBoundary::Frozen), "Frozen uses *fp layout"); | ||
| static_assert(contBoundaryProvesComplete(ContBoundary::Thawed), "Thawed proves completeness"); | ||
| static_assert(contBoundaryEntryFpIsCurrentFp(ContBoundary::Thawed), "Thawed uses fp layout"); | ||
| static_assert(!contBoundaryProvesComplete(ContBoundary::Unverified), "Unverified must not prove completeness"); | ||
| static_assert(contBoundaryEntryFpIsCurrentFp(ContBoundary::Unverified), "Unverified keeps the thawed fp layout guess"); | ||
| static_assert(!contBoundaryProvesComplete(CONT_BOUNDARY_AT_SPECULATIVE_UNKNOWN_NM), | ||
| "speculative crossing must mark the sample truncated"); | ||
| static_assert(contBoundaryEntryFpIsCurrentFp(CONT_BOUNDARY_AT_SPECULATIVE_UNKNOWN_NM), | ||
| "speculative crossing keeps the thawed fp layout guess"); | ||
| static_assert(!contBoundaryProvesComplete(CONT_BOUNDARY_AT_RETURN_BARRIER), | ||
| "return barrier crossing must mark the sample truncated"); | ||
| static_assert(!contBoundaryEntryFpIsCurrentFp(CONT_BOUNDARY_AT_RETURN_BARRIER), | ||
| "return barrier crossing uses *fp layout"); | ||
|
|
||
| // R4: return barrier (frozen frames remain) marks truncated and uses *fp. | ||
| TEST(ContBoundary, FrozenMarksTruncatedAndUsesSavedFp) { | ||
| EXPECT_FALSE(contBoundaryProvesComplete(ContBoundary::Frozen)); | ||
| EXPECT_FALSE(contBoundaryEntryFpIsCurrentFp(ContBoundary::Frozen)); | ||
| } | ||
|
|
||
| // R5/R6: verified fully-thawed boundary is complete and uses fp. | ||
| TEST(ContBoundary, ThawedIsCompleteAndUsesCurrentFp) { | ||
| EXPECT_TRUE(contBoundaryProvesComplete(ContBoundary::Thawed)); | ||
| EXPECT_TRUE(contBoundaryEntryFpIsCurrentFp(ContBoundary::Thawed)); | ||
| } | ||
|
|
||
| // R7/R10: speculative (unverified) crossing marks truncated but keeps the | ||
| // thawed layout guess. Pre-fix semantics treated it as "thawed => complete". | ||
| TEST(ContBoundary, UnverifiedMarksTruncatedButKeepsThawedLayout) { | ||
| EXPECT_FALSE(contBoundaryProvesComplete(ContBoundary::Unverified)); | ||
| EXPECT_TRUE(contBoundaryEntryFpIsCurrentFp(ContBoundary::Unverified)); | ||
| } | ||
|
|
||
| // R4-R7: per-call-site constants classify each walkVM boundary. | ||
| TEST(ContBoundary, CallSiteConstantsClassifyEachBoundary) { | ||
| EXPECT_EQ(CONT_BOUNDARY_AT_RETURN_BARRIER, ContBoundary::Frozen); | ||
| EXPECT_EQ(CONT_BOUNDARY_AT_ENTRY_RETURN_PC, ContBoundary::Thawed); | ||
| EXPECT_EQ(CONT_BOUNDARY_AT_ENTER_SPECIAL_NM, ContBoundary::Thawed); | ||
| EXPECT_EQ(CONT_BOUNDARY_AT_SPECULATIVE_UNKNOWN_NM, ContBoundary::Unverified); | ||
|
|
||
| EXPECT_FALSE(contBoundaryProvesComplete(CONT_BOUNDARY_AT_SPECULATIVE_UNKNOWN_NM)); | ||
| EXPECT_TRUE(contBoundaryEntryFpIsCurrentFp(CONT_BOUNDARY_AT_SPECULATIVE_UNKNOWN_NM)); | ||
| EXPECT_FALSE(contBoundaryProvesComplete(CONT_BOUNDARY_AT_RETURN_BARRIER)); | ||
| EXPECT_FALSE(contBoundaryEntryFpIsCurrentFp(CONT_BOUNDARY_AT_RETURN_BARRIER)); | ||
| EXPECT_TRUE(contBoundaryProvesComplete(CONT_BOUNDARY_AT_ENTRY_RETURN_PC)); | ||
| EXPECT_TRUE(contBoundaryEntryFpIsCurrentFp(CONT_BOUNDARY_AT_ENTRY_RETURN_PC)); | ||
| EXPECT_TRUE(contBoundaryProvesComplete(CONT_BOUNDARY_AT_ENTER_SPECIAL_NM)); | ||
| EXPECT_TRUE(contBoundaryEntryFpIsCurrentFp(CONT_BOUNDARY_AT_ENTER_SPECIAL_NM)); | ||
| } | ||
|
|
||
| // R9: completeness is an allow-list — only Thawed proves it; any other value, | ||
| // including an out-of-range one, defaults to "not proven" (truncated). | ||
| TEST(ContBoundary, OnlyThawedProvesCompleteness) { | ||
| const ContBoundary all[] = {ContBoundary::Thawed, ContBoundary::Frozen, ContBoundary::Unverified}; | ||
| for (ContBoundary k : all) { | ||
| EXPECT_EQ(contBoundaryProvesComplete(k), k == ContBoundary::Thawed); | ||
| } | ||
| ContBoundary unknown = static_cast<ContBoundary>(0xFE); | ||
| EXPECT_FALSE(contBoundaryProvesComplete(unknown)); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
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.
[Sphinx Review — LOW] asyncJavaTraceWithPostProcessing appends a synthetic "JVM Continuation" frame when the carrier thread is a VT carrier, but does not set *truncated even though AGCT (like the VM walker before this fix) does not reconstruct the frozen virtual-thread callers. The truncated flag is available in that function's signature (it is passed through to getJavaTraceAsync) and the new test asserts completeness via cstack=vm/vmx only, so the cstack modes that dispatch to the AGCT arm (cstack < CSTACK_VM, e.g. default/dwarf) can still emit stacks that omit a JVM-confirmed logical caller while claiming completeness. This is the same class of incompleteness the change fixes for walkVM.
Suggestion: In the isCarryingVirtualThread() branch of asyncJavaTraceWithPostProcessing, set *truncated = true (guarded on truncated != nullptr) before appending the synthetic frame, mirroring the walkThroughContinuation change; extend the new test's cstack matrix to cover at least one AGCT-dispatched mode.