Fix memory leak with FastThrow optimization - #12254
Conversation
HotSpot JVM has a special optimization when some special exceptions are (implicitly) thrown like NullPointerException. The JIT will replace a throw with a newly created Exception that walk the stack to produce the stacktrace by a throw with a singleton instance of the exception without stacktrace. This singleton exception is kept forever by the JVm contrary to usual way to throw exception to create the object at location of the exception. Therefore the map snapshotsByThrowable in ExceptionProbeManager which maps Exception instance to ThrowableState object keep an instance forever with the along snapshots collected. At some point the number of snapshots kept can lead to OOME. The fix is to clear the snapshot list after sending the snapshot and tagging the span. We also add a cap to the number of snapshots (256) added to the ThrowableState object.
|
Hi! 👋 Thanks for your pull request! 🎉 To help us review it, please make sure to:
If you need help, please check our contributing guidelines. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 15c924f41d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Clearing the shared list leaves a reused FastThrow instance with an empty state, so later error spans lose snapshot and replay tags. The same list also has unsafe concurrent access, and its new check permits more than 256 entries.
🤖 Datadog Autotest · Commit 15c924f · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest
|
🎯 Code Coverage (details) 🔗 Commit SHA: a882216 | Docs | View more details | Give us feedback! |
Debugger benchmarksParameters
See matching parameters
SummaryFound 5 performance improvements and 0 performance regressions! Performance is the same for 4 metrics, 6 unstable metrics.
See unchanged results
Request duration reports for reportsgantt
title reports - request duration [CI 0.99] : candidate=None, baseline=None
dateFormat X
axisFormat %s
section baseline
noprobe (357.74 µs) : 305, 411
. : milestone, 358,
basic (325.65 µs) : 320, 332
. : milestone, 326,
loop (8.095 ms) : 8032, 8158
. : milestone, 8095,
section candidate
noprobe (356.861 µs) : 300, 414
. : milestone, 357,
basic (317.02 µs) : 310, 324
. : milestone, 317,
loop (7.565 ms) : 7558, 7573
. : milestone, 7565,
|
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
dudikeleti
left a comment
There was a problem hiding this comment.
It’s worth looking at the bot comments.
What Does This Do
The fix is to clear the snapshot list after sending the snapshot and tagging the span. We also add a cap to the number of snapshots (256) added to the ThrowableState object.
Motivation
HotSpot JVM has a special optimization when some special exceptions are (implicitly) thrown like NullPointerException. The JIT will replace a throw with a newly created Exception that walk the stack to produce the stacktrace by a throw with a singleton instance of the exception without stacktrace.
This singleton exception is kept forever by the JVm contrary to usual way to throw exception to create the object at location of the exception.
Therefore the map snapshotsByThrowable in ExceptionProbeManager which maps Exception instance to ThrowableState object keep an instance forever with the along snapshots collected.
At some point the number of snapshots kept can lead to OOME.
Additional Notes
Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issueJira ticket: DEBUG-6056