Closed Bug 395962 Opened 17 years ago Closed 17 years ago

ActionMonkey: Add SpiderMonkey request model to MMgc

Categories

(Tamarin Graveyard :: Garbage Collection (mmGC), defect)

defect
Not set
normal

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: jorendorff, Assigned: jorendorff)

References

Details

Attachments

(2 files, 6 obsolete files)

SpiderMonkey uses a request model for two things:  to prevent one thread from touching GC-managed objects while another thread is doing GC; and to prevent threads from touching the same object at the same time.  The goal of this bug is to lift the former piece into tamarin-central, enabled at compile time with an MMGC_THREADSAFE macro.

The cross-platform build will support this with an option to configure.py.

Actionmonkey will be updated to use the new MMGC_THREADSAFE features to implement JS_BeginRequest and so forth.
Blocks: 393038
Blocks: 395963
Blocks: 394297
(In reply to comment #0)
> SpiderMonkey uses a request model for two things:  to prevent one thread from
> touching GC-managed objects while another thread is doing GC; and to prevent
> threads from touching the same object at the same time.

The thread-safety for object access is more subtle than that. Two or more requests  (JS API activations including of the interpreter) running in two or more threads can in fact share access to a given object on a fine-grained basis, but at the cost of compare-and-swap optimized synchronization that falls back to OS-level mutexes when there's contention.

The win of the request model is for most objects, which are not shared among threads racing in requests.

Most objects are ST. A few shared ones are (likely) shared sequentially. For both of these cases, the request model eliminates all locking overhead of the CAS or OS mutex kind, imposing only a short and usually well-predicted branch test depending on a couple of extra loads.

/be
Depends on: 399020
Attached patch v1 (obsolete) — Splinter Review
I'm pretty happy with this patch, except maybe it makes it look a little *too* easy.  It wasn't that easy to write, honest. :)

This patch is against actionmonkey-tamarin, but the only relevant difference between that and tamarin-central at this point is a few extra callbacks.
Assignee: nobody → jorendorff
Status: NEW → ASSIGNED
Attachment #289741 - Flags: review?(brendan)
Comment on attachment 289741 [details] [diff] [review]
v1

Adding r?=treilly.

Tom, if you want you can wait for me to post the version that targets tamarin-central (next Monday). It'll be pretty much the same patch though (see previous comment).
Attachment #289741 - Flags: review?(treilly)
Blocks: 404879
Attached patch v1 against tamarin-central (obsolete) — Splinter Review
Basically the same patch, but this one works on top of tamarin-central.
Attachment #290390 - Flags: review?(treilly)
Attached patch v2 (obsolete) — Splinter Review
I merged in the latest Tamarin changes, and now I'm getting sporadic crashes when running tests against the Release build **without** MMGC_THREADSAFE.  Looking into it.  In the meantime here's an updated patch, just a snapshot.
Attachment #290390 - Attachment is obsolete: true
Attachment #290390 - Flags: review?(treilly)
Comment on attachment 291554 [details] [diff] [review]
v2

The crashes were nothing.  "xcodebuild -blahblah clean" fixed it.
Attachment #291554 - Attachment description: v2 - snapshot, seeing sporadic crashes though → v2
Attachment #291554 - Flags: review?(brendan)
Attachment #291554 - Flags: review?(treilly)
v3 coming up.  Here are the significant differences from v2.  (v3 might also incorporate some merging, or dropping an unrelated patch from my queue, trivial stuff.)
Attached patch v3 (obsolete) — Splinter Review
Two changes suggested by treilly:

* move assertion macros to GC.h so they can be used in GCAlloc.cpp
* clean up GCWeakRef allocation in MMGC_THREADSAFE mode
Attachment #289741 - Attachment is obsolete: true
Attachment #291554 - Attachment is obsolete: true
Attachment #289741 - Flags: review?(treilly)
Attachment #289741 - Flags: review?(brendan)
Attachment #291554 - Flags: review?(treilly)
Attachment #291554 - Flags: review?(brendan)
Attachment #292067 - Flags: review?(brendan)
Comment on attachment 292067 [details] [diff] [review]
v3

Tommy, if you'd rather have Ed do the review, let me know.
Attachment #292067 - Flags: review?(treilly)
Comment on attachment 292067 [details] [diff] [review]
v3

Looks good to me.
Attachment #292067 - Flags: review?(treilly) → review+
Summary: Add SpiderMonkey request model to MMgc → ActionMonkey: Add SpiderMonkey request model to MMgc
Oop, I was waiting for a new patch -- should I review the attached one? Thanks,

/be
Yes, please review this one.  I do need to unbitrot it, but nothing really significant has changed.
Actually I did tweak one line of a comment in here:

                /**
                 * Wait for the current GC operation, if any, to finish.
                 *
-                * @access Requires(m_lock)
+                * @access Requires(!request && m_lock)
                 */
                void WaitForGCDone()

but otherwise v4 is just a newer v3.
Attachment #292066 - Attachment is obsolete: true
Attachment #292067 - Attachment is obsolete: true
Attachment #292067 - Flags: review?(brendan)
Attachment #293149 - Attachment is patch: true
Attachment #293149 - Attachment mime type: application/octet-stream → text/plain
Attachment #293149 - Flags: review?(brendan)
Blocks: 393023
Comment on attachment 293149 [details] [diff] [review]
v4 - same as v3, just unbitrotted

Up to date still? I thought I'd see precollect, but it's not removed by this patch, and not visible in the context. It's still in my up-to-date actionmonkey-tamarin MMgc/GC.cpp.

/be
This patch is against tamarin-central, so precollect isn't there.

The idea is to land this in tamarin-central, then merge it over to actionmonkey-tamarin.  I've already done that merge in my own repo; for the effects on precollect(), see lines 71-88 of this patch:

http://hg.mozilla.org/users/jorendorff_mozilla.com/actionmonkey-tamarin-patches/?file/tip/mmgc-threadsafe

Just wondering why precollect *and* the nested-lock enterExclusiveGC callback?

/be
It's to retain existing SpiderMonkey behavior.

The JSGC_BEGIN gcCallback has to be called from outside the gc lock.  precollect() is for that.

A few things have to happen while the gc lock is held, after the thread has decided to do GC but before the lock is released.  For example, rt->gcThread and rt->gcContext are set.  enterExclusiveGC() is for those.

Comment on attachment 293149 [details] [diff] [review]
v4 - same as v3, just unbitrotted

>+
>+		{
>+			USING_CALLBACK_LIST(this);
>+			for (GCCallback *cb = m_callbacks; cb; cb = cb->nextCB)
>+				cb->enterExclusiveGC();

Only thought is to comment this method in the class, warning about it nesting in the GC lock (first in its own callback list lock), a deadlock hazard.

Looks good otherwise. I'll be reviewing more tonight.

/be
Attachment #293149 - Flags: review?(brendan) → review+
Attached patch v5 - (pushed)Splinter Review
pushed changeset 4d9bc2b6eebd to tamarin-central

(but see bug 410839)
Attachment #293149 - Attachment is obsolete: true
Depends on: 410839, 411364
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: