Skip to content

Commit

Permalink
Bug 1477512: Part 5 - Rearrange the fields of nsThread for better pac…
Browse files Browse the repository at this point in the history
…king. r=erahm

This takes 16 bytes off of the allocated size of each instance.

MozReview-Commit-ID: AhfN6MWvVL1

--HG--
extra : rebase_source : badc6ab690f2c4e0184ac0b51b29f81fb11279c6
extra : absorb_source : 0f685515a6946c89e9467c8b1e8548c989b1907b
extra : histedit_source : 7bfb5db39b23c1d262819c22a6e5fcd884c52504
  • Loading branch information
kmaglione committed Jul 21, 2018
1 parent 8a135e1 commit 616ee87
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
20 changes: 10 additions & 10 deletions xpcom/threads/nsThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,18 +650,18 @@ nsThread::nsThread(NotNull<SynchronizedEventQueue*> aQueue,
uint32_t aStackSize)
: mEvents(aQueue.get())
, mEventTarget(new ThreadEventTarget(mEvents.get(), aMainThread == MAIN_THREAD))
, mShutdownContext(nullptr)
, mScriptObserver(nullptr)
, mPriority(PRIORITY_NORMAL)
, mThread(nullptr)
, mNestedEventLoopDepth(0)
, mStackSize(aStackSize)
, mShutdownContext(nullptr)
, mNestedEventLoopDepth(0)
, mCurrentEventLoopDepth(-1)
, mShutdownRequired(false)
, mIsMainThread(aMainThread)
, mPriority(PRIORITY_NORMAL)
, mIsMainThread(uint8_t(aMainThread))
, mCanInvokeJS(false)
, mCurrentEvent(nullptr)
, mCurrentEventStart(TimeStamp::Now())
, mCurrentEventLoopDepth(-1)
, mCurrentPerformanceCounter(nullptr)
{
}
Expand Down Expand Up @@ -1093,7 +1093,7 @@ nsThread::ProcessNextEvent(bool aMayWait, bool* aResult)
bool reallyWait = aMayWait && (mNestedEventLoopDepth > 0 || !ShuttingDown());

Maybe<Scheduler::EventLoopActivation> activation;
if (mIsMainThread == MAIN_THREAD) {
if (IsMainThread()) {
DoMainThreadSpecificProcessing(reallyWait);
activation.emplace();
}
Expand Down Expand Up @@ -1138,7 +1138,7 @@ nsThread::ProcessNextEvent(bool aMayWait, bool* aResult)
if (event) {
LOG(("THRD(%p) running [%p]\n", this, event.get()));

if (MAIN_THREAD == mIsMainThread) {
if (IsMainThread()) {
BackgroundHangMonitor().NotifyActivity();
}

Expand All @@ -1158,12 +1158,12 @@ nsThread::ProcessNextEvent(bool aMayWait, bool* aResult)
Array<char, kRunnableNameBufSize> restoreRunnableName;
restoreRunnableName[0] = '\0';
auto clear = MakeScopeExit([&] {
if (MAIN_THREAD == mIsMainThread) {
if (IsMainThread()) {
MOZ_ASSERT(NS_IsMainThread());
sMainThreadRunnableName = restoreRunnableName;
}
});
if (MAIN_THREAD == mIsMainThread) {
if (IsMainThread()) {
nsAutoCString name;
GetLabeledRunnableName(event, name, priority);

Expand Down Expand Up @@ -1361,7 +1361,7 @@ nsThread::SetScriptObserver(mozilla::CycleCollectedJSContext* aScriptObserver)
void
nsThread::DoMainThreadSpecificProcessing(bool aReallyWait)
{
MOZ_ASSERT(mIsMainThread == MAIN_THREAD);
MOZ_ASSERT(IsMainThread());

ipc::CancelCPOWs();

Expand Down
32 changes: 21 additions & 11 deletions xpcom/threads/nsThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,31 +176,41 @@ class nsThread
RefPtr<mozilla::SynchronizedEventQueue> mEvents;
RefPtr<mozilla::ThreadEventTarget> mEventTarget;

// The shutdown contexts for any other threads we've asked to shut down.
nsTArray<nsAutoPtr<struct nsThreadShutdownContext>> mRequestedShutdownContexts;
// The shutdown context for ourselves.
struct nsThreadShutdownContext* mShutdownContext;

mozilla::CycleCollectedJSContext* mScriptObserver;

int32_t mPriority;
uint32_t mThreadId;
PRThread* mThread;
uint32_t mNestedEventLoopDepth;
uint32_t mStackSize;
void* mStackBase = nullptr;
uint32_t mStackSize;
uint32_t mThreadId;

// The shutdown context for ourselves.
struct nsThreadShutdownContext* mShutdownContext;
// The shutdown contexts for any other threads we've asked to shut down.
nsTArray<nsAutoPtr<struct nsThreadShutdownContext>> mRequestedShutdownContexts;
uint32_t mNestedEventLoopDepth;
uint32_t mCurrentEventLoopDepth;

mozilla::Atomic<bool> mShutdownRequired;
MainThreadFlag mIsMainThread;

int8_t mPriority;

uint8_t mIsMainThread;

bool IsMainThread() const
{
return MainThreadFlag(mIsMainThread) == MAIN_THREAD;
}

// Set to true if this thread creates a JSRuntime.
bool mCanInvokeJS;

mozilla::TimeStamp mNextIdleDeadline;
// Used to track which event is being executed by ProcessNextEvent
nsCOMPtr<nsIRunnable> mCurrentEvent;

mozilla::TimeStamp mCurrentEventStart;
uint32_t mCurrentEventLoopDepth;
mozilla::TimeStamp mNextIdleDeadline;

RefPtr<mozilla::PerformanceCounter> mCurrentPerformanceCounter;
};

Expand Down

0 comments on commit 616ee87

Please sign in to comment.