Fix flaky StacktraceCollectorProfilerTest across JVM versions#119
Draft
kimjune01 wants to merge 2 commits into
Draft
Fix flaky StacktraceCollectorProfilerTest across JVM versions#119kimjune01 wants to merge 2 commits into
kimjune01 wants to merge 2 commits into
Conversation
The test asserted an exact stack depth of 4, but modern JVMs (JDK 11+) add synthetic lambda helper frames that increase the stack depth to 6+. Replace the brittle exact-match assertion with a minimum depth check. The profiler behavior under test is capturing the target thread's meaningful frames (Thread.sleep at top, Thread.run at bottom), not enforcing specific JVM implementation details. Fixes uber-common#112
JDK 17+ delegates Thread.sleep to sleepNanos0, so the top stack
frame is no longer exactly "sleep". Assert startsWith("sleep")
to handle sleep, sleepNanos, and sleepNanos0 across JVM versions.
Author
|
Cannot validate on current setup, so drafting. Please close or take it over. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #112
Problem
StacktraceCollectorProfilerTest.profile()asserts an exact stack depth of 4 at line 101:This fails on modern JVMs (JDK 11+) where lambda expressions introduce synthetic helper frames, increasing the stack depth to 6+. The test creates a thread using a lambda:
JDK 11+ adds lambda implementation frames that aren't present in JDK 8, causing the brittle exact-match assertion to fail.
Solution
Replace the brittle exact stack depth assertion with a minimum depth check:
This maintains the semantic correctness checks:
Thread.sleep(the blocking operation being profiled)Thread.run(the thread entry point)TIMED_WAITINGprofile()three times)The profiler behavior under test is capturing meaningful stack frames, not enforcing JVM implementation details about synthetic lambda frames.
Testing
The fix makes the test robust across JDK 8, 11, 17, and future versions while preserving all semantic guarantees about stack capture correctness.