allthingssecurity opened a new pull request, #29892: URL: https://github.com/apache/camel/pull/29892
# Description [CAMEL-26812](https://issues.apache.org/jira/browse/CAMEL-26812) Follows #29664 (CAMEL-26768, rule R2 of the sanitizer), as both change `Sanitizer.java`. Rule R1 of `camel-sanitizer` takes the stack of the thread at the first callback of every step call (`StepCall.callback()` calls `Sanitizer.trace()`), so that a second callback, if one ever comes, can be reported with both stacks. `trace()` walked the stack with `StackWalker` and turned up to `camel.sanitizer.stackDepth` frames (default `32`) into `StackTraceElement`s right away. Almost all of these traces are dropped without a report. Change: the trace keeps the `StackFrame`s of the walk, and the report turns them into `StackTraceElement`s when it shows them, with file and line as before. A trace of what was thrown keeps the `StackTraceElement`s of the `Throwable`, as before. The stacks that R2 takes (the handover and the run of a commit) get the same saving. Nothing a user configures changes, and a report looks the same. Measured with the JMH benchmark of #29528 (CAMEL-26751; kept outside the repository, as there: `SanitizerPendingTest.send_1` with `-p route=steps,split -p mode=off,t0 -p stackDepth=0,32` before and `-p mode=t0 -p stackDepth=0,8,32` after; JMH 1.37, JDK 21, 2 forks, 3 x 2 s warmup, 5 x 2 s measurement, `pendingTimeout=0`, average ns per message, on this machine): | Route | sanitizer off | stackDepth 0 | stackDepth 8, after | stackDepth 32, before | stackDepth 32, after | |---|---|---|---|---|---| | 6 steps | 913 | 1,874 (before), 1,905 (after) | 14,368 | 63,529 | 31,032 | | split of 4 parts, seda hop | 4,053 | 8,727 (before), 8,350 (after) | 31,529 | 115,709 | 61,966 | So the default costs about half of what it did. Most of what is left is the walk itself: with `stackDepth=8` a step call costs about 2 us instead of about 5 us. Kept frames: a `StackFrame` holds the method of its frame, and so its class and its class loader, for as long as the trace is kept: for R1 the stack of the first callback stays with the record of the step call as long as anything holds its callback (normally until the exchange is done); for R2 until the record of the commit goes (bounded, and cleared when the CamelContext stops). A kept frame takes about 80 bytes (`StackFrameInfo` and `MemberName`) where a `StackTraceElement` took about 48, but most traces are dropped without being converted, so less is allocated per trace. Docs: the sanitizer page says, after its table of options, what the stack costs (the numbers above for `stackDepth` 0, 8 and 32) and what a lower value trades. The default stays `32`: a lower default changes what a report shows, so it would be its own JIRA with an upgrade note, if wanted. Tests: new `SanitizerRecordTest.aReportShowsTheFramesOfBothCallbacksWithTheirFileAndLine` (the report of a second callback shows both stacks, with the file and line of the test methods; it passes before the change too, as it checks that the report did not change). The sanitizer tests of camel-core (224, with the load balancer and `shareUnitOfWork` tests that #29664 touched), camel-management (1), camel-main (10) and camel-test-main-junit6 (4) pass without and with the CI switch (`-Psanitizer`). # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it): [CAMEL-26812](https://issues.apache.org/jira/browse/CAMEL-26812). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. (I built the core modules, camel-sanitizer, camel-management, camel-main and camel-test-main-junit6 with the formatter and import-sort plugins and ran the sanitizer tests. I did not run the full root build.) # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer. _Claude Code on behalf of allthingssecurity_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
