Closed Bug 1360372 Opened 7 years ago Closed 7 years ago

Acquire a cooperative thread lock when entering the system zone

Categories

(Core :: JavaScript Engine, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla55
Tracking Status
firefox55 --- fixed

People

(Reporter: billm, Assigned: billm)

References

Details

Attachments

(2 files, 1 obsolete file)

Attached patch patchSplinter Review
This patch adds a callback where we can ask Gecko to yield to other cooperative threads. We call the yield callback when entering the system zone group when another context already owns the system zone group.
Attachment #8862643 - Flags: review?(bhackett1024)
Comment on attachment 8862643 [details] [diff] [review]
patch

Brian gave an r+ by email since his internet connectivity is limited.
Attachment #8862643 - Flags: review?(bhackett1024) → review+
Pushed by wmccloskey@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/fd049b7bf3d2
Acquire cooperative lock when entering system zone group (r=bhackett)
Attached patch fix rooting hazard (obsolete) — Splinter Review
This patch avoids a rooting hazard involving the atoms compartment. There is
code in jsatom.cpp that enters the atoms compartment while unrooted pointers
are on the stack. Now that enterZoneGroup can potentially yield, this leads to
a rooting hazard. This patch avoids the hazard by using a totally separate path
that avoids enterZoneGroup when entering the atoms compartment.
Flags: needinfo?(wmccloskey)
Attachment #8863301 - Flags: review?(sphink)
Comment on attachment 8863301 [details] [diff] [review]
fix rooting hazard

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

::: js/src/jscntxt.h
@@ +206,5 @@
> +    // Special enterCompartment for atoms compartment. It requires
> +    // locking. Also, we avoid calling enterZoneGroup since that can induce GC
> +    // hazards.
> +    inline void enterAtomsCompartment(JSCompartment* c,
> +                               const js::AutoLockForExclusiveAccess* maybeLock);

Can't this be AutoLockForExclusiveAccess& ?

::: js/src/jscntxtinlines.h
@@ +455,4 @@
>  {
>      enterCompartmentDepth_++;
>  
>      if (!c->zone()->isAtomsZone())

Can this MOZ_ASSERT(!c->zone()->isAtomsZone()), or is there another way of getting here with an atoms compartment? It seems like you don't want to allow that, since the caller might not have the lock in that case.

@@ +464,5 @@
> +
> +inline void
> +JSContext::enterAtomsCompartment(
> +    JSCompartment* c,
> +    const js::AutoLockForExclusiveAccess* maybeLock)

You're in JS-land, I think that'll all fit in 99 chars.

::: js/src/jscompartment.h
@@ +1059,2 @@
>      inline AutoCompartment(JSContext* cx, JSCompartment* target,
> +                           AutoLockForExclusiveAccess* maybeLock);

If this is only used for the atoms compartment now, can you make this AutoLockForExclusiveAccess& lock?

::: js/src/jscompartmentinlines.h
@@ +43,5 @@
>  {
>      cx_->enterCompartmentOf(target);
>  }
>  
>  // Protected constructor that bypasses assertions in enterCompartmentOf.

Also mention here that it's only for the atoms compartment. (If there were no comment here at all, it'd be fine to just not say anything since the header has it, but given that there is, it seems weird to omit that detail.)
Attachment #8863301 - Flags: review?(sphink)
Looks like that was the only way we entered the atoms compartment (to the extent that I can start a browser with the assertion in place).
Attachment #8863301 - Attachment is obsolete: true
Attachment #8863457 - Flags: review?(sphink)
Attachment #8863457 - Flags: review?(sphink) → review+
Pushed by wmccloskey@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/11a43a7edbae
Acquire cooperative lock when entering system zone group (r=bhackett)
https://hg.mozilla.org/integration/mozilla-inbound/rev/7292d50807c9
Avoid rooting hazard when entering atoms compartment (r=sfink)
https://hg.mozilla.org/mozilla-central/rev/11a43a7edbae
https://hg.mozilla.org/mozilla-central/rev/7292d50807c9
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: