gecko/ipc/glue
Kyle Huey 0a62d4d460 Bug 1179909: Refactor stable state handling. r=smaug
This is motivated by three separate but related problems:

1. Our concept of recursion depth is broken for things that run from AfterProcessNextEvent observers (e.g. Promises). We decrement the recursionDepth counter before firing observers, so a Promise callback running at the lowest event loop depth has a recursion depth of 0 (whereas a regular nsIRunnable would be 1). This is a problem because it's impossible to distinguish a Promise running after a sync XHR's onreadystatechange handler from a top-level event (since the former runs with depth 2 - 1 = 1, and the latter runs with just 1).

2. The nsIThreadObserver mechanism that is used by a lot of code to run "after" the current event is a poor fit for anything that runs script. First, the order the observers fire in is the order they were added, not anything fixed by spec. Additionally, running script can cause the event loop to spin, which is a big source of pain here (bholley has some nasty bug caused by this).

3. We run Promises from different points in the code for workers and main thread. The latter runs from XPConnect's nsIThreadObserver callbacks, while the former runs from a hardcoded call to run Promises in the worker event loop. What workers do is particularly problematic because it means we can't get the right recursion depth no matter what we do to nsThread.

The solve this, this patch does the following:

1. Consolidate some handling of microtasks and all handling of stable state from appshell and WorkerPrivate into CycleCollectedJSRuntime.
2. Make the recursionDepth counter only available to CycleCollectedJSRuntime (and its consumers) and remove it from the nsIThreadInternal and nsIThreadObserver APIs.
3. Adjust the recursionDepth counter so that microtasks run with the recursionDepth of the task they are associated with.
4. Introduce the concept of metastable state to replace appshell's RunBeforeNextEvent. Metastable state is reached after every microtask or task is completed. This provides the semantics that bent and I want for IndexedDB, where transactions autocommit at the end of a microtask and do not "spill" from one microtask into a subsequent microtask. This differs from appshell's RunBeforeNextEvent in two ways:
a) It fires between microtasks, which was the motivation for starting this.
b) It no longer ensures that we're at the same event loop depth in the native event queue. bent decided we don't care about this.
5. Reorder stable state to happen after microtasks such as Promises, per HTML. Right now we call the regular thread observers, including appshell, before the main thread observer (XPConnect), so stable state tasks happen before microtasks.
2015-08-11 06:10:46 -07:00
..
BackgroundChild.h Bug 911972 - MessagePort and MessageChannel in workers, r=smaug, r=bent 2015-06-17 11:44:27 +01:00
BackgroundChildImpl.cpp Bug 1155547, Part 2: Create PNuwa protocol (managed by PBackground) for forking content processes. r=khuey 2015-07-31 15:25:27 +08:00
BackgroundChildImpl.h Bug 1155547, Part 2: Create PNuwa protocol (managed by PBackground) for forking content processes. r=khuey 2015-07-31 15:25:27 +08:00
BackgroundImpl.cpp Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
BackgroundParent.h Bug 1163387 - Rename FileImpl to BlobImpl, r=ehsan 2015-05-12 13:11:03 +01:00
BackgroundParentImpl.cpp Bug 1155547, Part 2: Create PNuwa protocol (managed by PBackground) for forking content processes. r=khuey 2015-07-31 15:25:27 +08:00
BackgroundParentImpl.h Bug 1155547, Part 2: Create PNuwa protocol (managed by PBackground) for forking content processes. r=khuey 2015-07-31 15:25:27 +08:00
BackgroundUtils.cpp Bug 1143922 - Add AsyncOpen2 to nsIChannel and perform security checks when opening a channel - loadinfo changes (r=sicking,tanvi,sworkman) 2015-07-19 19:11:57 -07:00
BackgroundUtils.h Bug 1179505 - Make LoadInfo arguments optional in ipdl (r=bent,sicking) 2015-07-13 22:43:13 -07:00
BrowserProcessSubThread.cpp Bug 1164374 - Use StaticMutex in BrowserProcessSubThread. r=froydnj. 2015-05-13 01:59:52 -07:00
BrowserProcessSubThread.h Bug 1164374 - Use StaticMutex in BrowserProcessSubThread. r=froydnj. 2015-05-13 01:59:52 -07:00
CrossProcessMutex_posix.cpp Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
CrossProcessMutex_unimplemented.cpp
CrossProcessMutex_windows.cpp
CrossProcessMutex.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
FileDescriptor.cpp
FileDescriptor.h
FileDescriptorSetChild.cpp
FileDescriptorSetChild.h
FileDescriptorSetParent.cpp
FileDescriptorSetParent.h
FileDescriptorUtils.cpp
FileDescriptorUtils.h
GeckoChildProcessHost.cpp Bug 1189352: Fix NSPR_LOG_FILE with absolute paths for sandboxed child on Windows. r=bbondy 2015-08-03 07:58:43 +01:00
GeckoChildProcessHost.h Bug 1146955 - Unify pluginID for GMP and runID for NPAPI plugins to use the same internal incrementor. r=jesup, mrbkap. 2015-04-27 15:09:45 -04:00
InputStreamParams.ipdlh
InputStreamUtils.cpp Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
InputStreamUtils.h
IOThreadChild.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
IPCMessageUtils.h Bug 968520 - Add mozilla::fallible to FallibleTArray::AppendElement calls. r=froydnj 2015-05-28 11:07:44 -07:00
MessageChannel.cpp Bug 1185639 - Allow deferred message processing to happen between consecutive IPC message dispatches. r=jimm 2015-07-21 01:21:51 -06:00
MessageChannel.h Bug 1185639 - Allow deferred message processing to happen between consecutive IPC message dispatches. r=jimm 2015-07-21 01:21:51 -06:00
MessageLink.cpp Bug 1155547, Part 2: Create PNuwa protocol (managed by PBackground) for forking content processes. r=khuey 2015-07-31 15:25:27 +08:00
MessageLink.h
MessagePump.cpp Bug 1179909: Refactor stable state handling. r=smaug 2015-08-11 06:10:46 -07:00
MessagePump.h
moz.build Bug 1185639 - Allow deferred message processing to happen between consecutive IPC message dispatches. r=jimm 2015-07-21 01:21:51 -06:00
Neutering.h Bug 1185639 - Allow deferred message processing to happen between consecutive IPC message dispatches. r=jimm 2015-07-21 01:21:51 -06:00
nsIIPCBackgroundChildCreateCallback.h
nsIIPCSerializableInputStream.h
nsIIPCSerializableURI.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
PBackground.ipdl Bug 1155547, Part 2: Create PNuwa protocol (managed by PBackground) for forking content processes. r=khuey 2015-07-31 15:25:27 +08:00
PBackgroundSharedTypes.ipdlh
PBackgroundTest.ipdl
PFileDescriptorSet.ipdl
PProcLoader.ipdl
ProcessChild.cpp
ProcessChild.h
ProcessUtils_bsd.cpp
ProcessUtils_linux.cpp Bug 1172467: Fix an IPC channel file descriptor leak from Nuwa to the child process. r=khuey 2015-07-07 12:10:05 +08:00
ProcessUtils_mac.mm
ProcessUtils_none.cpp
ProcessUtils.h Bug 1050122 - Part 2: Disable preallocate when proc loader is not initialized. r=khuey 2014-11-01 13:28:33 +08:00
ProtocolTypes.ipdlh
ProtocolUtils.cpp Bug 1128454 - Add crash report annotations for plugin bridge operation failures. r=billm 2015-07-09 19:07:49 -05:00
ProtocolUtils.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
ScopedXREEmbed.cpp Bug 1171931 - Refactor duplicated code using XRE_IsParent/ContentProcess. r=froydnj 2015-07-03 18:29:00 -07:00
ScopedXREEmbed.h
SharedMemory_posix.cpp
SharedMemory_windows.cpp
SharedMemory.cpp
SharedMemory.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
SharedMemoryBasic_android.cpp
SharedMemoryBasic_android.h
SharedMemoryBasic_chromium.h
SharedMemoryBasic_mach.cpp bug 1175898 - crash in mozilla::CrossProcessMutex::ShareToProcess(int) r=billm 2015-06-22 11:54:40 -04:00
SharedMemoryBasic_mach.h bug 1161166 - Use mach shared memory for shared memory on OSX r=billm 2015-06-17 00:38:38 -04:00
SharedMemoryBasic.h bug 1161166 - Use mach shared memory for shared memory on OSX r=billm 2015-06-17 00:38:38 -04:00
SharedMemorySysV.h
Shmem.cpp
Shmem.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
StringUtil.cpp Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
Transport_posix.cpp Bug 1128454 - Add crash report annotations for plugin bridge operation failures. r=billm 2015-07-09 19:07:49 -05:00
Transport_posix.h
Transport_win.cpp Bug 1128454 - Add crash report annotations for plugin bridge operation failures. r=billm 2015-07-09 19:07:49 -05:00
Transport_win.h
Transport.h Bug 1128454 - Add crash report annotations for plugin bridge operation failures. r=billm 2015-07-09 19:07:49 -05:00
URIParams.ipdlh
URIUtils.cpp Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
URIUtils.h
WindowsMessageLoop.cpp Bug 1185639 - Allow deferred message processing to happen between consecutive IPC message dispatches. r=jimm 2015-07-21 01:21:51 -06:00
WindowsMessageLoop.h