fix: avoid SIGSEGV in CompileUnboundScript under Rosetta 2#13
Merged
Conversation
V8's ScriptCompiler::CompileUnboundScript crashes with a null-pointer dereference inside the JIT when an amd64 binary runs under Rosetta on arm64 macOS. Detect Rosetta via sysctl.proc_translated and fall back to ScriptCompiler::Compile + GetUnboundScript, which produces the same UnboundScript through V8's context-bound compile path. The fallback preserves full API semantics: cross-context reuse, code cache round-trip via CreateCodeCache, and eager compilation mode all work identically. Zero performance impact — same parse/compile pipeline, one extra Local<Script> handle (~nanoseconds). Only activates under Rosetta; native builds are completely unaffected.
8d63417 to
1cfb06b
Compare
The 2.5x speedup threshold is tight on noisy CI runners (observed 2.33x on ubuntu-latest with 3.39x on immediate retry in the same job). Add a single retry when the first measurement misses the bar, consistent with how perf-regression tests should handle scheduling jitter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sysctl.proc_translated(macOS) and caches the resultIsolateCompileUnboundScriptusesScriptCompiler::Compile+GetUnboundScript()instead of the directScriptCompiler::CompileUnboundScriptcall that crashes with a null-deref SIGSEGVSetForceRosettaFallbackto exercise the fallback path on native hardwarePerformance
Zero impact. Both paths use the same V8 parser/compiler pipeline. The fallback adds one extra
Local<Script>handle and aGetUnboundScript()extraction (~nanoseconds). Only activates under Rosetta — production deploys on native arch see no code path change.Test plan
TestIsolateCompileUnboundScript_RosettaFallback— forces fallback, compiles with eager mode, runs across two contexts, round-trips code cache to a second isolateCompileUnboundScripttests continue to pass