Commit Graph

135 Commits

Author SHA1 Message Date
Chris Peterson
49c3a0b4ec Bug 1234126 - Add Chaos Mode support for setting thread affinity on OS X and Windows. r=froydnj 2015-11-30 19:16:40 -08:00
Eric Rahm
b50e32cc8e Bug 1174785 - Part 2: Convert xpcom over to LogModule. r=froydnj 2015-10-19 12:50:14 -07:00
Nathan Froyd
9c5965b035 Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat
The bulk of this commit was generated with a script, executed at the top
level of a typical source code checkout.  The only non-machine-generated
part was modifying MFBT's moz.build to reflect the new naming.

CLOSED TREE makes big refactorings like this a piece of cake.

 # The main substitution.
find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \
    xargs perl -p -i -e '
 s/nsRefPtr\.h/RefPtr\.h/g; # handle includes
 s/nsRefPtr ?</RefPtr</g;   # handle declarations and variables
'

 # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h.
perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h

 # Handle nsRefPtr.h itself, a couple places that define constructors
 # from nsRefPtr, and code generators specially.  We do this here, rather
 # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename
 # things like nsRefPtrHashtable.
perl -p -i -e 's/nsRefPtr/RefPtr/g' \
     mfbt/nsRefPtr.h \
     xpcom/glue/nsCOMPtr.h \
     xpcom/base/OwningNonNull.h \
     ipc/ipdl/ipdl/lower.py \
     ipc/ipdl/ipdl/builtin.py \
     dom/bindings/Codegen.py \
     python/lldbutils/lldbutils/utils.py

 # In our indiscriminate substitution above, we renamed
 # nsRefPtrGetterAddRefs, the class behind getter_AddRefs.  Fix that up.
find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \
    xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g'

if [ -d .git ]; then
    git mv mfbt/nsRefPtr.h mfbt/RefPtr.h
else
    hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h
fi
2015-10-18 01:24:48 -04:00
Xidorn Quan
a4ed2acb58 Bug 1186745 part 5 - Make nsThread::Dispatch() always leak the event if it fails. r=froydnj 2015-10-06 13:00:59 +11:00
Xidorn Quan
1c258c6b0b Bug 1186745 part 4 - Make TracedRunnable accept an already_AddRefed instead of a raw pointer. r=froydnj 2015-10-06 13:00:59 +11:00
Xidorn Quan
8eae1acd07 Bug 1186745 part 2 - Move nsThreadSyncDispatch class to its own header file. r=froydnj 2015-10-06 13:00:59 +11:00
Xidorn Quan
42f427fd1f Bug 1186745 part 1 - Add LeakRefPtr for pointer leaking by default. r=froydnj
This class can be used instead of raw pointer for a sound leaking-by-default
behavior. Also it could take advantage of move semantic check in the future.
2015-10-06 13:00:59 +11:00
Wes Kocher
2f8452494f Backed out 6 changesets (bug 1186745) for android Cpp failures
Backed out changeset 237a6acf0709 (bug 1186745)
Backed out changeset 7b530871783a (bug 1186745)
Backed out changeset 73f73b531fc8 (bug 1186745)
Backed out changeset e36909748ddf (bug 1186745)
Backed out changeset 3a31df8787f0 (bug 1186745)
Backed out changeset df9cb8f5f0a5 (bug 1186745)
2015-10-02 10:35:09 -07:00
Xidorn Quan
e23d70ce85 Bug 1186745 part 5 - Make nsThread::Dispatch() always leak the event if it fails. r=froydnj 2015-10-03 00:18:24 +10:00
Xidorn Quan
4cd0000375 Bug 1186745 part 4 - Make TracedRunnable accept an already_AddRefed instead of a raw pointer. r=froydnj 2015-10-03 00:18:24 +10:00
Xidorn Quan
14a5e31220 Bug 1186745 part 2 - Move nsThreadSyncDispatch class to its own header file. r=froydnj 2015-10-03 00:18:24 +10:00
Xidorn Quan
ac39b70ae1 Bug 1186745 part 1 - Add LeakRefPtr for pointer leaking by default. r=froydnj
This class can be used instead of raw pointer for a sound leaking-by-default
behavior. Also it could take advantage of move semantic check in the future.
2015-10-03 00:18:24 +10:00
Phil Ringnalda
e180240230 Back out 6 changesets (bug 1186745) for cpptest failure in runnable_utils_unittest, nrappkit_unittest, test_nr_socket_unittest
Backed out changeset c6142b815de0 (bug 1186745)
Backed out changeset d8f740ef2430 (bug 1186745)
Backed out changeset edc0b56d81fa (bug 1186745)
Backed out changeset 383f8ac033ea (bug 1186745)
Backed out changeset ce960a661987 (bug 1186745)
Backed out changeset 3e9783023fb2 (bug 1186745)
2015-09-28 19:05:02 -07:00
Xidorn Quan
3435ff569e Bug 1186745 part 5 - Make nsThread::Dispatch() always leak the event if it fails. r=froydnj 2015-09-29 09:28:22 +10:00
Xidorn Quan
1f58dae0e0 Bug 1186745 part 4 - Make TracedRunnable accept an already_AddRefed instead of a raw pointer. r=froydnj 2015-09-29 09:28:22 +10:00
Xidorn Quan
2c7ed2222d Bug 1186745 part 2 - Move nsThreadSyncDispatch class to its own header file. r=froydnj 2015-09-29 09:28:22 +10:00
Xidorn Quan
af1edf4c69 Bug 1186745 part 1 - Add LeakRefPtr for pointer leaking by default. r=froydnj
This class can be used instead of raw pointer for a sound leaking-by-default
behavior. Also it could take advantage of move semantic check in the future.
2015-09-29 09:28:22 +10:00
Nathan Froyd
0230fc538f Bug 1202497 - part 7 - make nsEventQueue use external locking; r=gerald
We want to ensure that nsThread's use of nsEventQueue uses locking done
in nsThread instead of nsEventQueue, for efficiency's sake: we only need
to lock once in nsThread, rather than the current situation of locking
in nsThread and additionally in nsEventQueue.  With the current
structure of nsEventQueue, that would mean that nsThread should be using
a Monitor internally, rather than a Mutex.

Which would be well and good, except that DOM workers use nsThread's
mutex to protect their own, internal CondVar.  Switching nsThread to use
a Monitor would mean that either:

- DOM workers drop their internal CondVar in favor of nsThread's
  Monitor-owned CondVar.  This change seems unlikely to work out well,
  because now the Monitor-owned CondVar is performing double duty:
  tracking availability of events in nsThread's event queue and
  additionally whatever DOM workers were using a CondVar for.  Having a
  single CondVar track two things in such a fashion is for Experts Only.

- DOM workers grow their own Mutex to protect their own CondVar.  Adding
  a mutex like this would change locking in subtle ways and seems
  unlikely to lead to success.

Using a Monitor in nsThread is therefore untenable, and we would like to
retain the current Mutex that lives in nsThread.  Therefore, we need to
have nsEventQueue manage its own condition variable and push the
required (Mutex) locking to the client of nsEventQueue.  This scheme
also seems more fitting: external clients merely need synchronized
access to the event queue; the details of managing notifications about
events in the event queue should be left up to the event queue itself.

Doing so also forces us to merge nsEventQueueBase and nsEventQueue:
there's no way to have nsEventQueueBase require an externally-defined
Mutex and then have nsEventQueue subclass nsEventQueueBase and provide
its own Mutex to the superclass.  C++ initialization rules (and the way
things like CondVar are constructed) simply forbid it.  But that's OK,
because we want a world where nsEventQueue is externally locked anyway,
so there's no reason to have separate classes here.

One casualty of this work is removing ChaosMode support from
nsEventQueue.  nsEventQueue had support to delay placing events into the
queue, theoretically giving other threads the chance to put events there
first.  Unfortunately, since the thread would have been holding a lock
(as is evident from the MutexAutoLock& parameter required), sleeping in
PutEvent accomplishes nothing but delaying the thread from getting
useful work done.  We should support this, but it's complicated to
figure out how to reasonably support this right now.

A wrinkle in this overall pleasant refactoring is that nsThreadPool's
threads wait for limited amounts of time for new events to be placed in
the event queue, so that they can shut themselves down if no new events
are appearing.  Setting limits on the number of threads also needs to be
able to wake up all threads, so threads can shut themselves down if
necessary.

Unfortunately, with the transition to nsEventQueue managing its own
condition variable, there's no way for nsThreadPool to perform these
functions, since there's no Monitor to wait on.  Therefore, we add a
private API for accessing the condition variable and performing the
tasks nsThreadPool needs.

Prior to all the previous patches, placing items in an nsThread's event
queue required three lock/unlock pairs: one for nsThread's Mutex, one to
enter nsEventQueue's ReentrantMonitor, and one to exit nsEventQueue's
ReentrantMonitor.  The upshot of all this work is that we now only
require one lock/unlock pair in nsThread itself, as things should be.
2015-09-20 05:13:09 -04:00
Nathan Froyd
68102938d6 Bug 1202497 - part 5 - make the locking requirements of nsChainedEventQueue explicit; r=gerald
This patch is a no-op in terms of functionality.  It ensures that we're
always holding nsThread's mutex when we touch mEvents, as dictated by
the comments.  Putting this addition into its own patch will help make
the change to having nsEventQueue by guarded by a Mutex, rather than a
Monitor, somewhat clearer.
2015-09-20 04:59:56 -04:00
Nathan Froyd
2ee968b041 Bug 1202497 - part 4 - lock around call to nsChainedEventQueue::HasPendingEvent; r=gerald
This is another case of an access to mEvents not being protected by
mLock.  Future patches will make this locking requirement explicit in
nsChainedEventQueue, so we won't have problems like this.  (Since
nsEventQueue has its own locking at this point, this omission didn't
matter much, but the omission will most certainly matter later.)
2015-09-20 04:47:10 -04:00
Nathan Froyd
ce3131e557 Bug 1202497 - part 3 - remove nsThread::GetEvent; r=gerald
GetEvent was only called from one place, so it wasn't terribly useful as
an abstraction.  It also broke the invariant that we protect accesses to
mEvents with mLock, as documented in nsThread.h.  While upcoming patches
could have just updated GetEvent to do the necessary locking on its own,
it seemed just as easy to make the locking requirements at the callsite,
as will be done for other accesses to mEvents.
2015-09-20 04:44:51 -04:00
Kyle Huey
464d141cc4 Bug 1200922: Add the ability to shut down a thread asynchronously. r=froydnj 2015-09-14 18:24:43 -07:00
Nathan Froyd
ff957ed4a4 Bug 1202828 - use nsEventQueue::HasPendingEvent in nsThread.cpp; r=mccr8
nsEventQueue's HasPending event is defined to simply:

  return GetEvent(false, nullptr);

So we can substitute HasPendingEvent for this particular GetEvent call
to make the code clearer.
2015-09-04 20:39:10 -04:00
Cervantes Yu
665099fb75 Bug 1166207 - Load preload.js in the Nuwa process. r=khuey 2015-08-28 17:57:44 +08:00
Kyle Huey
1ffb03e8dc 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
Benoit Girard
2e648924e7 Bug 1182516 - Add Chaos Mode environment variable MOZ_CHAOSMODE. r=roc 2015-07-14 17:29:23 -04:00
Randell Jesup
efc08ab894 Bug 1155059: Patch 4 - invoke NS_ASSERTION if DispatchToMainThread fails to get MainThread ptr r=froydnj 2015-07-09 23:21:46 -04:00
Randell Jesup
37ad9bc8b6 Bug 1155059: Patch 1&2 - Convert Dispatch() and friends to already_AddRefed<> r=froydnj
Modify Dispatch IDL and code to deal with MSVC issues with overloaded templates r=froydnj
2015-07-09 23:21:46 -04:00
Bill McCloskey
b162c4e892 Bug 1177013 - Use CancelCurrentTransaction to avoid crashes (r=dvander) 2015-07-06 19:58:44 -07:00
Juan Gomez
21d73728f3 Bug 1171931 - Refactor duplicated code using XRE_IsParent/ContentProcess. r=froydnj 2015-07-03 18:29:00 -07:00
Phil Ringnalda
6d43ab4967 Back out 12 changesets (bug 1177013) on suspicion of causing b2g emulator debug test bustage
CLOSED TREE

Backed out changeset 912aae0815f8 (bug 1177013)
Backed out changeset 3b6448172e50 (bug 1177013)
Backed out changeset 2af18bef5703 (bug 1177013)
Backed out changeset e6bf35115c11 (bug 1177013)
Backed out changeset 4d7f5205b60b (bug 1177013)
Backed out changeset f7de893911bc (bug 1177013)
Backed out changeset de79eba232f0 (bug 1177013)
Backed out changeset 978a77b60f2a (bug 1177013)
Backed out changeset f5b52fa19511 (bug 1177013)
Backed out changeset e14a7b70b6fa (bug 1177013)
Backed out changeset d0f5a3474659 (bug 1177013)
Backed out changeset bff9f07dad52 (bug 1177013)
2015-07-02 22:08:54 -07:00
Bill McCloskey
af77069eb7 Bug 1177013 - Use CancelCurrentTransaction to avoid crashes (r=dvander) 2015-07-02 17:18:10 -07:00
Ryan VanderMeulen
55b2086097 Backed out changeset 8b4e4083639e (bug 1171931) for B2G debug emulator bustage. 2015-06-25 19:48:42 -04:00
Juan Gomez
98461fc4a4 Bug 1171931 - Refactor duplicated code using XRE_IsParent/ContentProcess. r=froydnj 2015-06-24 14:11:00 -04:00
Benoit Girard
fa09f0548c Bug 1172216 - Move nsStackwalk to mozglue. r=glandium 2015-06-10 16:32:45 -04:00
Shelly Lin
da24650cb8 Bug 1113562 - Expected delay time of tasks should not be the latency of those kind. r=sinker 2015-06-16 10:57:19 +08:00
Eric Rahm
29f00ac208 Bug 1165515 - Part 13-2: Replace usage of PRLogModuleLevel and PR_LOG_*. rs=froydnj
This is straightforward mapping of PR_LOG levels to their LogLevel
counterparts:
  PR_LOG_ERROR   -> LogLevel::Error
  PR_LOG_WARNING -> LogLevel::Warning
  PR_LOG_WARN    -> LogLevel::Warning
  PR_LOG_INFO    -> LogLevel::Info
  PR_LOG_DEBUG   -> LogLevel::Debug
  PR_LOG_NOTICE  -> LogLevel::Debug
  PR_LOG_VERBOSE -> LogLevel::Verbose

Instances of PRLogModuleLevel were mapped to a fully qualified
mozilla::LogLevel, instances of PR_LOG levels in #defines were mapped to a
fully qualified mozilla::LogLevel::* level, and all other instances were
mapped to us a shorter format of LogLevel::*.

Bustage for usage of the non-fully qualified LogLevel were fixed by adding
|using mozilla::LogLevel;| where appropriate.
2015-06-03 15:25:57 -07:00
Carsten "Tomcat" Book
e2f82674b8 Backed out 14 changesets (bug 1165515) for linux x64 e10s m2 test failures
Backed out changeset d68dcf2ef372 (bug 1165515)
Backed out changeset 7c3b45a47811 (bug 1165515)
Backed out changeset b668b617bef2 (bug 1165515)
Backed out changeset d0916e1283a2 (bug 1165515)
Backed out changeset ac4dc7489942 (bug 1165515)
Backed out changeset e9632ce8bc65 (bug 1165515)
Backed out changeset c16d215cc7e4 (bug 1165515)
Backed out changeset e4d474f3c51a (bug 1165515)
Backed out changeset d87680bf9f7c (bug 1165515)
Backed out changeset b3c0a45ba99e (bug 1165515)
Backed out changeset 9370fa197674 (bug 1165515)
Backed out changeset 50970d668ca1 (bug 1165515)
Backed out changeset ffa4eb6d24b9 (bug 1165515)
Backed out changeset 5fcf1203cc1d (bug 1165515)
2015-06-02 13:05:56 +02:00
Eric Rahm
18bd3de863 Bug 1165515 - Part 13-2: Replace usage of PRLogModuleLevel and PR_LOG_*. rs=froydnj
This is straightforward mapping of PR_LOG levels to their LogLevel
counterparts:
  PR_LOG_ERROR   -> LogLevel::Error
  PR_LOG_WARNING -> LogLevel::Warning
  PR_LOG_WARN    -> LogLevel::Warning
  PR_LOG_INFO    -> LogLevel::Info
  PR_LOG_DEBUG   -> LogLevel::Debug
  PR_LOG_NOTICE  -> LogLevel::Debug
  PR_LOG_VERBOSE -> LogLevel::Verbose

Instances of PRLogModuleLevel were mapped to a fully qualified
mozilla::LogLevel, instances of PR_LOG levels in #defines were mapped to a
fully qualified mozilla::LogLevel::* level, and all other instances were
mapped to us a shorter format of LogLevel::*.

Bustage for usage of the non-fully qualified LogLevel were fixed by adding
|using mozilla::LogLevel;| where appropriate.
2015-06-01 22:17:33 -07:00
Wes Kocher
bd796581dc Backed out 14 changesets (bug 1165515) for b2g mochitest-6 permafail CLOSED TREE
Backed out changeset 9b97e2aa2ed9 (bug 1165515)
Backed out changeset 150606c022a2 (bug 1165515)
Backed out changeset 4e875a488349 (bug 1165515)
Backed out changeset 467e7feeb546 (bug 1165515)
Backed out changeset d6b6cc373197 (bug 1165515)
Backed out changeset 0615265b593c (bug 1165515)
Backed out changeset fafd1dce9f08 (bug 1165515)
Backed out changeset d1df869245f9 (bug 1165515)
Backed out changeset 6876a7c63611 (bug 1165515)
Backed out changeset b7841c94a9a3 (bug 1165515)
Backed out changeset e5e3617f7c73 (bug 1165515)
Backed out changeset 39be3db95978 (bug 1165515)
Backed out changeset 0ec74176f8de (bug 1165515)
Backed out changeset 5b928dd10d71 (bug 1165515)
2015-06-01 17:57:58 -07:00
Eric Rahm
ae32743ed2 Bug 1165515 - Part 13-2: Replace usage of PRLogModuleLevel and PR_LOG_*. rs=froydnj
This is straightforward mapping of PR_LOG levels to their LogLevel
counterparts:
  PR_LOG_ERROR   -> LogLevel::Error
  PR_LOG_WARNING -> LogLevel::Warning
  PR_LOG_WARN    -> LogLevel::Warning
  PR_LOG_INFO    -> LogLevel::Info
  PR_LOG_DEBUG   -> LogLevel::Debug
  PR_LOG_NOTICE  -> LogLevel::Debug
  PR_LOG_VERBOSE -> LogLevel::Verbose

Instances of PRLogModuleLevel were mapped to a fully qualified
mozilla::LogLevel, instances of PR_LOG levels in #defines were mapped to a
fully qualified mozilla::LogLevel::* level, and all other instances were
mapped to us a shorter format of LogLevel::*.

Bustage for usage of the non-fully qualified LogLevel were fixed by adding
|using mozilla::LogLevel;| where appropriate.
2015-06-01 14:31:01 -07:00
Ryan VanderMeulen
ecdd625f1a Merge inbound to m-c. a=merge 2015-05-22 14:02:47 -04:00
Cervantes Yu
a5bfba878f Backout change 39e167bbd14c, a80140872ea5, adae9be2294d and b71ccef9c674 (bug 970307). 2015-05-19 14:31:25 +08:00
Eric Rahm
ccf1ec07c6 Bug 1165515 - Part 1: Convert PR_LOG to MOZ_LOG. r=froydnj 2015-05-21 13:22:04 -07:00
Eric Rahm
c5e63515bf Bug 1165518 - Part 2: Replace prlog.h with Logging.h. rs=froydnj 2015-05-19 11:15:34 -07:00
Eric Rahm
cff4ae713b Bug 1162242 - Part 1: Remove instances of #ifdef PR_LOGGING. r=froydnj
PR_LOGGING is now always defined, we can remove #ifdefs checking for it.
2015-05-07 09:43:35 -07:00
Nathan Froyd
6460d3e650 Bug 1158320 - rename nsThread::mRunningEvent to mNestedEventLoopDepth; r=bsmedberg
The current name reads to me like a boolean variable, even though it's
actually a counter.  Try to make that property more explicit at its uses
by renaming it to something more evocative of counter-ness.
2015-04-24 16:04:50 -04:00
Randall Barker
70c940e622 Bug 1093934 - Create a XPCOM library that can be used to support standalone WebRTC. r=nfroyd 2015-04-03 15:52:00 +02:00
Andrew McCreight
8ca644d24c Bug 1149807 - Remove some unused nsIProgrammingLanguage.h includes. r=froydnj 2015-04-02 14:54:46 -07:00
Atif Iqbal
970f215f7e Bug 1150197 - Remove useless null checks after allocating memory with new from xpcom/threads/; r=froydnj 2015-04-02 14:57:46 -04:00