Skip to content

Count machine code moves in IsolateBase's code statistics - #8515

Merged
csjh merged 1 commit into
mainfrom
cormick/count-code-moves
Nov 17, 2026
Merged

csjh merged 1 commit into
mainfrom
cormick/count-code-moves

Conversation

@csjh

@csjh csjh commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Adds CodeStatistics::machineCodeMoveCount to jsg::IsolateBase::getCodeStatistics(): how many times the garbage collector moved a block of JavaScript or Wasm machine code (V8's CODE_MOVED JIT code event). Moves of bytecode aren't counted.

Why: together with jitCodeCount and wasmCodeCount, this counts the lines a perf map built from JIT code events would get (#8163), since each addition and each move adds a line. Edgeworker will export it to Prometheus to measure how fast such a map grows in production.

Testing: V8 compacts code space only when that frees a whole page, which a test's small heap never does, so the new code-move-test runs with --compact-on-every-full-gc in its own binary, since the flag applies to the whole process. The GC has to run within the same evaluation as the optimized function: Evaluator::expectEval() creates a new context for each evaluation, so otherwise the code is already dead and nothing moves. Passes 5 of 5, as does setup-test.

🤖 Generated with Claude Code

Adds CodeStatistics::machineCodeMoveCount: how many times the garbage
collector moved a block of JavaScript or Wasm machine code, which V8
reports as a CODE_MOVED JIT code event. Moves of bytecode aren't
counted.

Together with jitCodeCount and wasmCodeCount, this counts the lines a
perf map built from JIT code events would get, since both additions
and moves add a line.

V8 compacts code space only when that frees a whole page, so the test
runs with --compact-on-every-full-gc, in its own binary, since the
flag applies to the whole process.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@csjh
csjh requested review from a team as code owners November 17, 2026 04:06

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Approved with comments — The implementation and test look correct. The one note is an INFO: the CodeStatistics overview comment, which says it counts only additions, is now out of date.

Findings: 1 info (1 is an inline comment on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📝 Documentation: 💬 1 info

The CodeStatistics overview comment is stale now that the struct has a move counter.

Recommendation: 💬 Optional Nits

  • [INFO] CodeStatistics overview comment (setup.h:514-516) says the struct only counts generated-code additions; the new move counter is neither. (src/workerd/jsg/setup.h:528)
View full review
  • src/workerd/jsg/setup.h:514-516: the struct-level comment calls CodeStatistics totals of code V8 has generated and says it "Only counts additions". The new machineCodeMoveCount counts GC moves, not generated code.

✅ All other checks passed

📋 Code Quality: ✅ LGTM

The counter only goes up for code already tracked in codeMap, skips BYTE_CODE, and uses the same relaxed atomic pattern as the other statistics. The BUILD glob turns the new test into its own binary, so the process-wide GC flag does not affect other tests.


Reviewed commit: 912cdfd5

Comment thread src/workerd/jsg/setup.h Resolved
@csjh
csjh enabled auto-merge (squash) November 17, 2026 16:24
@csjh
csjh merged commit f6b41a8 into main Nov 17, 2026
23 of 24 checks passed
@csjh
csjh deleted the cormick/count-code-moves branch November 17, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants