Skip to content

Bring back compile_to_stencil_offthread - #500

Merged
Gae24 merged 13 commits into
servo:mainfrom
sagudev:offthread
Oct 29, 2026
Merged

Gae24 merged 13 commits into
servo:mainfrom
sagudev:offthread

Conversation

@sagudev

@sagudev sagudev commented Aug 30, 2024 •

Copy link
Copy Markdown
Member

As discussed in #474 (comment), this brings it back. For each offthread compilation we create a new thread that does the compilation. In servo this can be replaced by custom thread pool.

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Signed-off-by: Samson <16504129+sagudev@users.noreply.github.com>
@Gae24

Gae24 commented May 3, 2026

Copy link
Copy Markdown
Contributor

It would be great to have this working again, is the remaining work just on the servo side?

@sagudev

sagudev commented May 3, 2026

Copy link
Copy Markdown
Member Author

IIRC new test does not work in debugmozjs, meaning that something is wrong and we need to fix this first.

@Gae24

Gae24 commented May 8, 2026

Copy link
Copy Markdown
Contributor

I've tried to rebase and test it, resulting in SIGSEGV: invalid memory reference and STATUS_ACCESS_VIOLATION crashes and some assertion failures:

@sagudev

sagudev commented May 8, 2026

Copy link
Copy Markdown
Member Author

I remember MOZ_ASSERT(*stackLimitThreadId_ == GetTid());, that's the one I've been trying to debug.

@Gae24

Gae24 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

With debugmozjs it seems C++ ends up receiving corrupted data:

Rust side:

(gdb) p fc
$6 = mozjs::offthread::FrontendContext (0x7fffe8000c80)
(gdb) p &(*frontend_options.ptr)._base
$7 = (*mut mozjs_sys::generated::root::JS::ReadOnlyCompileOptions) 0x7ffff008a890
(gdb) p *frontend_options.ptr
$8 = mozjs_sys::generated::root::JS::OwningCompileOptions {_base: mozjs_sys::generated::root::JS::ReadOnlyCompileOptions {_base: mozjs_sys::generated::root::JS::TransitiveCompileOptions {filename_: mozjs_sys::generated::root::JS::ConstUTF8CharsZ {data_: 0x7ffff00f9e30}, introducerFilename_: mozjs_sys::generated::root::JS::ConstUTF8CharsZ {data_: 0x0}, sourceMapURL_: 0x0, mutedErrors_: false, forceStrictMode_: false, alwaysUseFdlibm_: false, skipFilenameValidation_: false, hideScriptFromDebugger_: false, deferDebugMetadata_: false, eagerDelazificationStrategy_: mozjs_sys::generated::root::JS::DelazificationOption::OnDemandOnly, selfHostingMode: false, discardSource: false, sourceIsLazy: false, allowHTMLComments: true, nonSyntacticScope: false, topLevelAwait: true, borrowBuffer: false, usePinnedBytecode: false, prefableOptions_: mozjs_sys::generated::root::JS::PrefableCompileOptions {_bitfield_align_1: [], _bitfield_1: mozjs_sys::generated::root::__BindgenBitfieldUnit<[u8; 1]> {storage: [
            2]}, asmJSOption_: mozjs_sys::generated::root::JS::AsmJSOption::DisabledByAsmJSPref}, introductionType: 0x0, introductionLineno: 0, introductionOffset: 0, hasIntroductionInfo: false}, lineno: 1, column: mozjs_sys::generated::root::JS::ColumnNumberOneOrigin {_base: 1}, scriptSourceOffset: 0, isRunOnce: false, noScriptRval: false}}

Inside CompileGlobalScriptToStencil:

(gdb) p fc
$9 = (JS::FrontendContext *) 0x7ffff008a890
(gdb) p options
$10 = (const JS::ReadOnlyCompileOptions &) @0x7ffff76ed6e0: {<JS::TransitiveCompileOptions> = {filename_ = {data_ = 0x7ffff00546f0 "1 + 1\177"},
    introducerFilename_ = {data_ = 0x7f0000000005 <error: Cannot access memory at address 0x7f0000000005>},
    sourceMapURL_ = 0x7ffff76ed760 u"\xdd10翿", mutedErrors_ = 194, forceStrictMode_ = 169, alwaysUseFdlibm_ = 156, skipFilenameValidation_ = 88,
    hideScriptFromDebugger_ = 85, deferDebugMetadata_ = 85, eagerDelazificationStrategy_ = JS::DelazificationOption::OnDemandOnly,
    selfHostingMode = false, discardSource = 144, sourceIsLazy = 168, allowHTMLComments = 8, nonSyntacticScope = 240, topLevelAwait = 255,
    borrowBuffer = 127, usePinnedBytecode = false, prefableOptions_ = {importAttributes_ = false, sourcePragmas_ = false,
      throwOnAsmJSValidationFailure_ = false, asmJSOption_ = 16},
    introductionType = 0x40000555558ab6a <error: Cannot access memory at address 0x40000555558ab6a>, introductionLineno = 0,
    introductionOffset = 2684354560, hasIntroductionInfo = 168}, lineno = 2147479560, column = {<JS::detail::MaybeLimitedColumnNumber<0>> = {
      static OriginValue = <optimized out>, value_ = 262144}, <No data fields>}, scriptSourceOffset = 0, isRunOnce = false, noScriptRval = false}

@Gae24

Gae24 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Huh, TIL rust-lang/rust-bindgen#778.
Looking back at the esr bump PR, we were already doing the same thing :|
https://github.com/Gae24/mozjs/actions/runs/27352146549

@Gae24

Gae24 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

My changes are at https://github.com/Gae24/mozjs/tree/offthread, do I push them here or should I open a new PR that supersede this one?

@sagudev

sagudev commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

You should be able to push them here.

@Gae24 Gae24 mentioned this pull request Oct 1, 2026
Comment thread mozjs-sys/src/jsapi.cpp Resolved
Comment thread mozjs/src/offthread.rs Resolved
Comment thread mozjs/src/offthread.rs Resolved
Comment thread mozjs/tests/offthread.rs Resolved
Comment thread mozjs/tests/offthread.rs Resolved
@Gae24
Gae24 force-pushed the offthread branch 4 times, most recently from 8202561 to 064a45b Compare October 27, 2026 22:10
Gae24 added 7 commits October 29, 2026 09:19
Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
- Don't call `PrepareForInstantiate` with a null stencil
- Provide FrontendContext to allow retrieving errors
- Provide options used for compilation, `ConvertFrontendErrorsToRuntimeErrors` needs the same ones

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
@Gae24
Gae24 marked this pull request as ready for review October 29, 2026 08:22
@Gae24
Gae24 enabled auto-merge (squash) October 29, 2026 09:29
@Gae24
Gae24 merged commit 6e69c16 into servo:main Oct 29, 2026
45 checks passed
xbwwj pushed a commit to xbwwj/servo that referenced this pull request Oct 29, 2026
Restore offthread compilation.
Currently it's limited to classic scripts, matching the exact state
prior to its removal.
Companion PR to servo/mozjs#500

Testing: Preference is already enabled, should be covered by existing
tests
Fixes: servo#32870

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
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.

3 participants