Closed Bug 1334885 Opened 7 years ago Closed 7 years ago

Allow wasm signal handlers to work with multiple threads in a runtime

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla54
Tracking Status
firefox54 --- fixed

People

(Reporter: bhackett1024, Assigned: bhackett1024)

References

Details

Attachments

(2 files)

Attached patch patchSplinter Review
Currently the wasm signal handlers treat JS runtimes as if they were single threaded.  Most of these places can be fixed by just operating on a JSContext instead of a JSRuntime.  The main impact of this patch is that on OS X separate mach exception handler threads are created for each JSContext that runs wasm code, plus the thread that created the runtime in the first place (so that process wide signal handlers are in place for interrupting Ion code).
Attachment #8831518 - Flags: review?(luke)
Assignee: nobody → bhackett1024
Comment on attachment 8831518 [details] [diff] [review]
patch

Review of attachment 8831518 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks!

::: js/src/wasm/WasmInstance.cpp
@@ +539,5 @@
>          return false;
>  
> +    // Make sure any signal handling infrastructure required for this thread
> +    // has been installed.
> +    if (!EnsureSignalHandlers(cx))

This can be a hot path and we're going to try to add an inline JIT path for this sometime soon so could you instead move this check to the top of Module::instantiate() and update the comment in Runtime.cpp accordingly?

Also, it looks like EnsureSignalHandlers(cx) doesn't report an error, so you need to here.  It'd be better of course if EnsureSignalHandlers(cx) reported its own error, but I'm guessing that it can't because it's called during JSRuntime::init.

::: js/src/wasm/WasmSignalHandlers.cpp
@@ +1232,4 @@
>  #ifdef JS_SIMULATOR
>          (void)ContextToPC(context);  // silence static 'unused' errors
>  
> +        void* pc = cx->runtime()->simulator()->get_pc_as<void*>();

(I'm assuming the simulator is getting moved into the cx in a later patch.)
Attachment #8831518 - Flags: review?(luke) → review+
(In reply to Luke Wagner [:luke] from comment #1)
> ::: js/src/wasm/WasmSignalHandlers.cpp
> @@ +1232,4 @@
> >  #ifdef JS_SIMULATOR
> >          (void)ContextToPC(context);  // silence static 'unused' errors
> >  
> > +        void* pc = cx->runtime()->simulator()->get_pc_as<void*>();
> 
> (I'm assuming the simulator is getting moved into the cx in a later patch.)

Ermm, it is in JSContext after bug 1325050, I just forgot to test this patch in a simulator build.  It doesn't look like the simulator will have an impact on this patch, though.
(In reply to Luke Wagner [:luke] from comment #1)
> ::: js/src/wasm/WasmInstance.cpp
> @@ +539,5 @@
> >          return false;
> >  
> > +    // Make sure any signal handling infrastructure required for this thread
> > +    // has been installed.
> > +    if (!EnsureSignalHandlers(cx))
> 
> This can be a hot path and we're going to try to add an inline JIT path for
> this sometime soon so could you instead move this check to the top of
> Module::instantiate() and update the comment in Runtime.cpp accordingly?

Hmm, looking at Module::instantiate() it seems like it creates a WasmInstanceObject which is placed in some zone and can be used by any thread operating in that zone.  If this interpretation is right then with this change it would be possible for a thread to call into wasm without having its signal handlers installed.

Another option that might be best is to just install the signal handlers when creating any thread which can run JS (the runtime's main thread, and soon any additional cooperative threads created for it).  I don't see any downsides to this, its only effect is to add more threads on OS X and per a google search OS X will let you create thousands of threads in a process.
Attached patch followupSplinter Review
Diff vs. the previous patch.  Also, s/zone/compartment/ in the first sentence in comment 3.
Attachment #8834959 - Flags: review?(luke)
Comment on attachment 8834959 [details] [diff] [review]
followup

Review of attachment 8834959 [details] [diff] [review]:
-----------------------------------------------------------------

Makes sense, thanks!
Attachment #8834959 - Flags: review?(luke) → review+
Pushed by bhackett@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/2600c68923ce
Allow wasm signal handlers to work with multiple threads in a runtime, r=luke.
https://hg.mozilla.org/mozilla-central/rev/2600c68923ce
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla54
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: