Skip to content

Bring back compile_to_stencil_offthread#500

Draft
sagudev wants to merge 3 commits into
servo:mainfrom
sagudev:offthread
Draft

Bring back compile_to_stencil_offthread#500
sagudev wants to merge 3 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.

WIP because of debugmozjs, error reporting and needs companion PR in servo.

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

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