#86

Root JS values built into lists one at a time

Opennaillizardwants to merge intofrom

A few natives build a JS array one item at a time and keep each item in a malloc'd buffer until the end: readdir, process.argv (n_info), os.networkInterfaces, os.cpus on macOS, and napi_create_bigint_words. The generated Tov-array-to-JS conversion does the same for arrays over 16 items. Every item is a string, so every item is an allocation that can collect. JavaScriptCore's conservative scan covers the stack and registers, not the heap, so the strings made so far get freed, and then JSObjectMakeArray puts dead cells into a live array.

It showed up as a daemon that segfaulted once or twice a day, each time somewhere unrelated: rope resolution in String.prototype.endsWith, Array.prototype.join, JSString::visitChildren → analyzeInvalidHandleAndCrash, JIT code dereferencing garbage. The trigger was readdirSync over a directory with ~14k entries.

The fix adds tv_js_set_at (js.h/js.c), and each site now puts items straight into the array, which lives on the stack. Codegen keeps the stack buffer for arrays of 16 or fewer.

Test: tests/npm/gc_roots reads a 4000-entry directory (with and without withFileTypes) and hands JS a 4000-string Tov array, 20 rounds each with garbage in between. tests/npm.rs runs it with JSC_slowPathAllocsBetweenGCs=50. On main it segfaults or reads back thousands of wrong strings; with the fix it passes. scripts/linux.sh cargo test --release --no-fail-fast passes in full.

Activity

2
vercel[bot]24d ago

@naillizard is attempting to deploy a commit to the Cap Software Inc Team on Vercel.

A member of the Team first needs to authorize it.