@@ -176,10 +176,11 @@ NULL`). Native stack unwinding via frame pointers or DWARF requires a signal con
176176as the starting point, so neither ` CSTACK_DEFAULT ` nor ` CSTACK_FP ` can produce
177177useful traces for malloc events.
178178
179- ` CSTACK_VM ` uses HotSpot's ` JavaFrameAnchor ` (lastJavaPC / lastJavaSP / lastJavaFP)
180- to walk Java frames, and falls back to ` __builtin_return_address ` for the native
181- portion. This works correctly from inside a malloc hook because the anchor is set
182- whenever the JVM has transitioned from Java to native.
179+ ` CSTACK_VM ` starts from ` __builtin_return_address ` for the initial frame and walks
180+ native frames via DWARF. It then uses HotSpot's ` JavaFrameAnchor ` (lastJavaPC /
181+ lastJavaSP / lastJavaFP) to transition from native to Java frames. This works
182+ correctly from inside a malloc hook because the anchor is set whenever the JVM has
183+ transitioned from Java to native.
183184
184185### Default stack mode
185186
@@ -282,9 +283,10 @@ which passes `call_trace_id = 0` (JFR null-reference convention).
282283> not used. Reentrant allocation calls would result in double-accounting.
283284
284285When `recordMalloc` calls into the profiler (stack walking, JFR buffer writes), any
285- allocations made by the profiler itself will re-enter the hooks. Because those
286- internal allocations call `_orig_malloc` directly (not the hook), there is no
287- infinite recursion, but they may be double-counted as application allocations.
286+ allocations made by the profiler itself will re-enter the hooks. Infinite recursion
287+ is prevented because the hook functions call `_orig_malloc` (a saved direct function
288+ pointer) instead of going through the GOT, but profiler-internal allocations may be
289+ double-counted as application allocations.
288290Leak detection is unaffected: the same address being recorded multiple times is
289291handled correctly by the tracking logic.
290292
0 commit comments