Commit cf42bb1
fix(codecache): make memoryUsage() accurate and live
CodeCache::memoryUsage() drove the CODECACHE_NATIVE_SIZE_BYTES counter
but both under-counted and went stale:
- The blob array was counted as _capacity * sizeof(CodeBlob*) — a
pointer's worth — while the array holds CodeBlob (three pointers),
a ~3x undercount.
- Symbol name strings were approximated as _count * sizeof(NativeFunc),
a fixed 4 bytes each, ignoring the name length that dominates the
actual allocation.
- The DWARF unwind table and build-id string were not counted at all.
- CodeCacheArray cached the sum at add() time, so it never reflected a
library's later symbol growth.
Recompute both accurately on demand instead. CodeCache::memoryUsage() now
sums the full blob array, each symbol's real name-string allocation (via
new NativeFunc::allocSize()), its own name, the DWARF table, and the
build-id. CodeCacheArray::memoryUsage() sums the live per-library values
(the array is append-only, so iterating the published prefix is safe
alongside concurrent adds); the stale _used_memory cache is removed.
memoryUsage() is only called at dump time, so the O(symbols) recompute is
not on any hot path.
Tests: new codeCache_ut asserts usage tracks per-symbol name length, that
a longer name costs more than a shorter one, and that the blob array is
counted at full CodeBlob size rather than a pointer's.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 77c2122 commit cf42bb1
3 files changed
Lines changed: 99 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
147 | 169 | | |
148 | 170 | | |
149 | 171 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
77 | 86 | | |
78 | 87 | | |
79 | 88 | | |
| |||
251 | 260 | | |
252 | 261 | | |
253 | 262 | | |
254 | | - | |
255 | | - | |
256 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
257 | 268 | | |
258 | 269 | | |
259 | 270 | | |
| |||
266 | 277 | | |
267 | 278 | | |
268 | 279 | | |
269 | | - | |
270 | 280 | | |
271 | 281 | | |
272 | 282 | | |
273 | | - | |
| 283 | + | |
274 | 284 | | |
275 | 285 | | |
276 | 286 | | |
| |||
296 | 306 | | |
297 | 307 | | |
298 | 308 | | |
299 | | - | |
300 | 309 | | |
301 | 310 | | |
302 | 311 | | |
| |||
316 | 325 | | |
317 | 326 | | |
318 | 327 | | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
319 | 332 | | |
320 | | - | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
321 | 342 | | |
322 | 343 | | |
323 | 344 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
0 commit comments