Skip to content

node:v8: heap statistics shape, cachedDataVersionTag, ERR_NOT_BUILDING_SNAPSHOT (+4 tests) - #34841

Closed
cirospaciari wants to merge 1 commit into
mainfrom
claude/node-v8-small-gaps
Closed

node:v8: heap statistics shape, cachedDataVersionTag, ERR_NOT_BUILDING_SNAPSHOT (+4 tests)#34841
cirospaciari wants to merge 1 commit into
mainfrom
claude/node-v8-small-gaps

Conversation

@cirospaciari

Copy link
Copy Markdown
Member

Four small node:v8 API gaps, each verified against the node v26.3.0 binary before implementation.

API before now
getHeapStatistics() 14 keys node's exact 15 (total_allocated_bytes = JSC heapCapacity, a real number)
getHeapSpaceStatistics() / getHeapCodeStatistics() threw node's shape with JSC's real totals — see the judgment call below
getCppHeapStatistics() missing validated arg (node's exact ERR_INVALID_ARG_VALUE message), empty statistics — node itself reports empty when cppgc holds nothing
cachedDataVersionTag() missing stable uint32 from runtime version + recorded flags; changes across setFlagsFromString, which the test asserts
setFlagsFromString() validate-then-throw validate-and-record no-op (feeds the version tag)
startupSnapshot callbacks NotImplemented node's exact ERR_NOT_BUILDING_SNAPSHOT

The one judgment call: getHeapSpaceStatistics must return exactly V8's 13 space names (the test and shape-dependent consumers require them), but JSC has one undivided heap. JSC's real used/capacity numbers are reported under old_space; the other twelve names carry zeros. The names are shape, the numbers are real — nothing is fabricated.

Deliberately skipped: writeHeapSnapshot Buffer/URL paths (PR #34084 already fixes exactly this — duplicating would conflict), queryObjects (needs real heap iteration by prototype chain, which JSC doesn't expose — an honest implementation is a new native heap-walk binding), test-v8-flags (%IsSmi natives syntax) and test-v8-serdes (native V8 Serializer classes).

No overlap with #34550 (GCProfiler untouched) or #34523 (its test-v8-flag-type-check.js passes against this implementation; one trivial import-line adjacency whenever the second lands).

Verification

All 4 tests byte-identical to upstream, pass on node (ceiling), fail on unpatched bun (control), pass 3× each on this build with the CI invocation. 12 tamper mutations (3 per file), every one fails. Regressions: test/js/node/v8/ 48/48, stubs.test.js 378/378, v8-heap-snapshot.test.ts 7/7, all pre-existing vendored v8/worker heap tests green. tsc clean in touched files.

…G_SNAPSHOT

getHeapStatistics gains total_allocated_bytes so the key set matches node's
exactly. getHeapSpaceStatistics and getHeapCodeStatistics report JSC's real
totals in node's shape instead of throwing: JSC has one undivided heap, so its
used and capacity numbers appear under old_space and the other twelve V8 space
names carry zeros; the names are required by shape-dependent consumers, the
numbers are real. getCppHeapStatistics validates its argument with node's
message and returns the empty statistics node itself reports when cppgc holds
nothing.

setFlagsFromString validates and records the flags instead of throwing, and
cachedDataVersionTag derives a stable uint32 from the runtime version plus the
recorded flags, so the tag changes across a setFlagsFromString call as node's
does. startupSnapshot callbacks throw node's ERR_NOT_BUILDING_SNAPSHOT.

writeHeapSnapshot path handling is deliberately untouched: PR #34084 already
fixes it. queryObjects is not implemented; it needs real heap iteration by
prototype chain, which JSC does not expose.

Adds test-v8-stats, test-v8-version-tag, test-v8-startup-snapshot-api and
test-cppheap-stats from Node v26.3.0, verbatim.
@robobun

robobun commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator
Updated 1:18 PM PT - Jul 20th, 2026

@cirospaciari, your commit 5442bd9 has 3 failures in Build #76347 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 34841

That installs a local version of the PR into your bun-34841 executable, so you can run:

bun-34841 --bun

@github-actions

Copy link
Copy Markdown
Contributor

Found 2 issues this PR may fix:

  1. node:v8 getHeapSpaceStatistics is not yet implemented in Bun #7684 - PR implements getHeapSpaceStatistics() which was throwing NotImplementedError
  2. Implement node:v8 setFlagsFromString #11264 - PR changes setFlagsFromString() from throwing NotImplementedError to a functional no-op

If this is helpful, copy the block below into the PR description to auto-close these issues on merge.

Fixes #7684
Fixes #11264

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown
Contributor

This PR may be a duplicate of:

  1. feat(v8): add competitive node:v8 getHeapSpaceStatistics #25446 - Also implements getHeapSpaceStatistics() with V8's space names mapped over JSC's single heap

🤖 Generated with Claude Code

@cirospaciari

Copy link
Copy Markdown
Member Author

Folded into #34660 (branch merged) as part of PR consolidation — same commits and tests, fewer PRs.

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