gecko-dev/xpcom/base
Kyle Huey 76e3009ab8 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
..
AvailableMemoryTracker.cpp Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
AvailableMemoryTracker.h
ClearOnShutdown.cpp
ClearOnShutdown.h Bug 1145631 - Part 1: Replace MOZ_OVERRIDE and MOZ_FINAL with override and final in the tree; r=froydnj 2015-03-21 12:28:04 -04:00
CodeAddressService.h Bug 1172216 - Move nsStackwalk to mozglue. r=glandium 2015-06-10 16:32:45 -04:00
CountingAllocatorBase.h Bug 1055280 - Move CountingAllocatorBase into its own header file. r=froydnj 2014-08-25 12:34:00 -07:00
CycleCollectedJSRuntime.cpp Bug 1179909: Refactor stable state handling. r=smaug 2015-08-11 06:10:46 -07:00
CycleCollectedJSRuntime.h Bug 1179909: Refactor stable state handling. r=smaug 2015-08-11 06:10:46 -07:00
Debug.cpp
Debug.h
DebuggerOnGCRunnable.cpp Bug 1150253 - Part 2: Gecko should provide a callback for SpiderMonkey to 2015-04-22 09:43:02 -07:00
DebuggerOnGCRunnable.h Bug 1150253 - Part 2: Gecko should provide a callback for SpiderMonkey to 2015-04-22 09:43:02 -07:00
DeferredFinalize.cpp Bug 1137536, part 3 - Move the top level DeferredFinalize functions into their own file. r=smaug 2015-03-18 11:36:03 -07:00
DeferredFinalize.h Bug 1174796 - Make sure ReleaseNow releases everything. r=smaug 2015-06-16 14:19:07 -07:00
ErrorList.h Bug 1173912 Fail opaque responses for client requests. r=ehsan 2015-07-14 13:11:26 -07:00
ErrorNames.cpp Bug 1151541, part 2 - Fix mode lines in xpcom/. r=froydnj 2015-04-09 10:25:05 -07:00
ErrorNames.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
HoldDropJSObjects.cpp Bug 1119482, part 4 - Move IsJSHolder into HoldDropJSObjects. r=smaug 2015-03-10 16:41:38 -07:00
HoldDropJSObjects.h Bug 1119482, part 4 - Move IsJSHolder into HoldDropJSObjects. r=smaug 2015-03-10 16:41:38 -07:00
JSObjectHolder.cpp Bug 1179924 - Create a more modern JS object holder for cross-thread references to JS objects. r=smaug 2015-07-21 11:31:44 -07:00
JSObjectHolder.h Bug 1179924 - Create a more modern JS object holder for cross-thread references to JS objects. r=smaug 2015-07-21 11:31:44 -07:00
LinuxUtils.cpp Bug 1056962 - Part 1: Move GetThreadName to LinuxUtils. r=jld 2014-08-22 16:35:29 -07:00
LinuxUtils.h Bug 1056962 - Part 1: Move GetThreadName to LinuxUtils. r=jld 2014-08-22 16:35:29 -07:00
moz.build Bug 1190823 - Move OwningNonNull.h to xpcom/base/; r=froydnj 2015-08-05 15:28:27 +03:00
nsAgg.h Bug 1122999 - Mark the fOuter member defined by NS_DECL_AGGREGATED as unsafe; r=froydnj 2015-01-19 10:00:32 -05:00
nsAlgorithm.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
nsAllocator.h
nsAutoPtr.h Bug 1189231 - Impl operator->* to nsAutoPtr. r=nfroyd 2015-07-30 21:02:00 -04:00
nsAutoRef.h Bug 1118486 - Part 1: Use = delete instead of MOZ_DELETE directly; r=Waldo 2015-01-08 23:19:05 -05:00
nsCom.h
nsConsoleMessage.cpp Bug 1060171 - Part 1: Add log levels to nsIConsoleMessage. r=froydnj 2014-09-22 15:32:21 -07:00
nsConsoleMessage.h Bug 1145631 - Part 1: Replace MOZ_OVERRIDE and MOZ_FINAL with override and final in the tree; r=froydnj 2015-03-21 12:28:04 -04:00
nsConsoleService.cpp Bug 1152574: Fix console service discarding to run when it is actually safe to do so (off of inner-window-destroyed). Also add a backstop at xpcom-shutdown to discard any cycle collected messages before it is too late. r=froydnj 2015-07-31 06:49:27 -07:00
nsConsoleService.h Bug 1152574: Fix console service discarding to run when it is actually safe to do so (off of inner-window-destroyed). Also add a backstop at xpcom-shutdown to discard any cycle collected messages before it is too late. r=froydnj 2015-07-31 06:49:27 -07:00
nscore.h Bug 1024259: Use NS_FREE_PERMANENT_DATA more consistently. r=mccr8 2015-07-31 12:11:48 -07:00
nsCrashOnException.cpp
nsCrashOnException.h
nsCycleCollector.cpp Bug 1189122 - Assert when we Suspect() when a CC scan is in progress. r=smaug 2015-07-29 20:48:00 +02:00
nsCycleCollector.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
nsDebugImpl.cpp Bug 1171931 - Refactor duplicated code using XRE_IsParent/ContentProcess. r=froydnj 2015-07-03 18:29:00 -07:00
nsDebugImpl.h Bug 1163916 (part 1) - Avoid a static nsDebugImpl constructor. r=froydnj. 2015-05-13 16:47:55 -07:00
nsDumpUtils.cpp Bug 1171931 - Refactor duplicated code using XRE_IsParent/ContentProcess. r=froydnj 2015-07-03 18:29:00 -07:00
nsDumpUtils.h Bug 1145631 - Part 1: Replace MOZ_OVERRIDE and MOZ_FINAL with override and final in the tree; r=froydnj 2015-03-21 12:28:04 -04:00
nsError.h Bug 1128273 - Stop using |typedef enum class tag_nsresult { ... } nsresult;| trick. r=froydnj 2015-02-02 23:44:25 +09:00
nsErrorService.cpp Bug 1046841 - Fix more style violations in previously touched .cpp files in xpcom/. r=froydnj 2014-08-25 12:17:15 -07:00
nsErrorService.h Bug 1145631 - Part 1: Replace MOZ_OVERRIDE and MOZ_FINAL with override and final in the tree; r=froydnj 2015-03-21 12:28:04 -04:00
nsGZFileWriter.cpp Bug 956961 - Open content processes' DMD log files in the parent process. r=njn 2014-07-02 15:59:02 -07:00
nsGZFileWriter.h Bug 1145631 - Part 1: Replace MOZ_OVERRIDE and MOZ_FINAL with override and final in the tree; r=froydnj 2015-03-21 12:28:04 -04:00
nsIConsoleListener.idl
nsIConsoleMessage.idl Bug 1060171 - Part 1: Add log levels to nsIConsoleMessage. r=froydnj 2014-09-22 15:32:21 -07:00
nsIConsoleService.idl Bug 1152574: Fix console service discarding to run when it is actually safe to do so (off of inner-window-destroyed). Also add a backstop at xpcom-shutdown to discard any cycle collected messages before it is too late. r=froydnj 2015-07-31 06:49:27 -07:00
nsICycleCollectorListener.idl Bug 1163006, part 4 - De-COM the nsICycleCollectorListener methods we only call from C++. r=smaug 2015-06-04 14:41:31 -07:00
nsIDebug2.idl Bug 1155643 - Removed nsIDebug.idl, moved methods of nsIDebug to nsIDebug2. r=paolo 2015-05-07 10:58:37 +05:30
nsIErrorService.idl
nsIException.idl Bug 1140435 - Part 2 - Allow JS code to provide an async stack when calling a function. r=bz 2015-03-07 13:30:34 +00:00
nsIGZFileWriter.idl Bug 956961 - Open content processes' DMD log files in the parent process. r=njn 2014-07-02 15:59:02 -07:00
nsIID.h
nsIInterfaceRequestor.idl
nsIMacUtils.idl
nsIMemory.idl Bug 1181518 - Change the reason for memory-pressure fired during priority change. r=gsvelto 2015-07-15 17:07:39 +08:00
nsIMemoryInfoDumper.idl Bug 1044709 - Improve the comment describing the memory report file format. r=mccr8. 2014-09-28 18:35:14 -07:00
nsIMemoryReporter.idl Bug 986302 - Add memory reporting for HPACK tables r=hurley r=njn 2015-07-17 14:38:10 -07:00
nsIMessageLoop.idl
nsIMutable.idl
nsInterfaceRequestorAgg.cpp Bug 1145631 - Part 1: Replace MOZ_OVERRIDE and MOZ_FINAL with override and final in the tree; r=froydnj 2015-03-21 12:28:04 -04:00
nsInterfaceRequestorAgg.h
nsIProgrammingLanguage.idl Bug 1150917 - Remove all values from nsIProgrammingLanguage except UNKNOWN and JAVASCRIPT. r=froydnj 2015-04-08 17:16:30 -07:00
nsISecurityConsoleMessage.idl
nsISizeOf.h
nsIStatusReporter.idl Bug 1148527 - Indentation fix after bug 1145631, r=ehsan 2015-03-27 18:52:19 +00:00
nsISupports.idl
nsISupportsBase.h
nsIUUIDGenerator.idl
nsIVersionComparator.idl
nsIWeakReference.idl
nsMacUtilsImpl.cpp Bug 1191100 - Remove XPIDL signature comments in .cpp files. r=ehsan 2015-08-04 16:17:36 -07:00
nsMacUtilsImpl.h Bug 1145631 - Part 1: Replace MOZ_OVERRIDE and MOZ_FINAL with override and final in the tree; r=froydnj 2015-03-21 12:28:04 -04:00
nsMemoryImpl.cpp Bug 1134923 - Remove NS_Alloc/NS_Realloc/NS_Free. r=nfroyd 2015-05-01 09:40:30 +09:00
nsMemoryImpl.h Bug 1145631 - Part 1: Replace MOZ_OVERRIDE and MOZ_FINAL with override and final in the tree; r=froydnj 2015-03-21 12:28:04 -04:00
nsMemoryInfoDumper.cpp Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
nsMemoryInfoDumper.h Bug 1156632 - Remove unused forward class declarations - patch 6 - the rest of the tree, r=ehsan 2015-04-22 08:29:24 +02:00
nsMemoryReporterManager.cpp Bug 986302 - Add memory reporting for HPACK tables r=hurley r=njn 2015-07-17 14:38:10 -07:00
nsMemoryReporterManager.h Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
nsMessageLoop.cpp Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
nsMessageLoop.h
nsObjCExceptions.h
nsQueryObject.h Bug 1188696 - Hoist nsRefPtr.h into MFBT. r=froydnj 2015-07-29 10:44:59 -07:00
nsrootidl.idl
nsSecurityConsoleMessage.cpp
nsSecurityConsoleMessage.h Bug 1145631 - Part 1: Replace MOZ_OVERRIDE and MOZ_FINAL with override and final in the tree; r=froydnj 2015-03-21 12:28:04 -04:00
nsSetDllDirectory.h Bug 1046841 - Fix more style violations in previously touched .h files in xpcom/. r=froydnj 2014-08-25 12:17:24 -07:00
nsStatusReporterManager.cpp
nsStatusReporterManager.h Bug 1145631 - Part 1: Replace MOZ_OVERRIDE and MOZ_FINAL with override and final in the tree; r=froydnj 2015-03-21 12:28:04 -04:00
nsSystemInfo.cpp Bug 1182996 - Fix and add missing namespace comments. rs=ehsan 2015-07-13 08:25:42 -07:00
nsSystemInfo.h Bug 1145631 - Part 1: Replace MOZ_OVERRIDE and MOZ_FINAL with override and final in the tree; r=froydnj 2015-03-21 12:28:04 -04:00
nsTraceRefcnt.cpp Bug 1171931 - Refactor duplicated code using XRE_IsParent/ContentProcess. r=froydnj 2015-07-03 18:29:00 -07:00
nsTraceRefcnt.h Bug 1004593 - Remove the unused nsTraceRefCnt::Startup(). r=froydnj 2014-08-01 10:02:30 -07:00
nsUUIDGenerator.cpp Bug 1134923 - Remove NS_Alloc/NS_Realloc/NS_Free. r=nfroyd 2015-05-01 09:40:30 +09:00
nsUUIDGenerator.h Bug 1145631 - Part 1: Replace MOZ_OVERRIDE and MOZ_FINAL with override and final in the tree; r=froydnj 2015-03-21 12:28:04 -04:00
nsVersionComparatorImpl.cpp Bug 1046841 - Fix more style violations in previously touched .cpp files in xpcom/. r=froydnj 2014-08-25 12:17:15 -07:00
nsVersionComparatorImpl.h Bug 1145631 - Part 1: Replace MOZ_OVERRIDE and MOZ_FINAL with override and final in the tree; r=froydnj 2015-03-21 12:28:04 -04:00
nsWeakPtr.h
nsWindowsHelpers.h Bug 1039866 - Rip out a bunch of metro-only code. r=jimm,gavin,rstrong 2015-04-23 15:10:30 -04:00
OwningNonNull.h Bug 1190823 - Move OwningNonNull.h to xpcom/base/; r=froydnj 2015-08-05 15:28:27 +03:00
StaticMutex.h Bug 1151541, part 2 - Fix mode lines in xpcom/. r=froydnj 2015-04-09 10:25:05 -07:00
StaticPtr.h Bug 1120062 - Part 1: Remove most Nullptr.h includes. r=waldo 2015-01-11 11:34:52 +09:00
SystemMemoryReporter.cpp Bug 1185470: Remove 'Get' prefixes from hashtable iterator methods. r=froydnj 2015-07-20 20:21:28 +08:00
SystemMemoryReporter.h