зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1561715 - Part 1: Remove unused functionality in SchedulerGroup. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D55638 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
d67a32d3cf
Коммит
9dcf7d5237
|
@ -994,8 +994,8 @@ nsresult nsDocShell::DispatchToTabGroup(
|
|||
if (win->GetDocGroup()) {
|
||||
return win->GetDocGroup()->Dispatch(aCategory, runnable.forget());
|
||||
}
|
||||
RefPtr<mozilla::dom::TabGroup> tabGroup = win->TabGroup();
|
||||
return tabGroup->Dispatch(aCategory, runnable.forget());
|
||||
|
||||
return SchedulerGroup::Dispatch(aCategory, runnable.forget());
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -85,9 +85,6 @@ class DocGroup final {
|
|||
|
||||
AbstractThread* AbstractMainThreadFor(TaskCategory aCategory);
|
||||
|
||||
// Ensure that it's valid to access the DocGroup at this time.
|
||||
void ValidateAccess() const { mTabGroup->ValidateAccess(); }
|
||||
|
||||
// Return a pointer that can be continually checked to see if access to this
|
||||
// DocGroup is valid. This pointer should live at least as long as the
|
||||
// DocGroup.
|
||||
|
|
|
@ -6886,17 +6886,6 @@ bool Document::RemoveObserver(nsIDocumentObserver* aObserver) {
|
|||
}
|
||||
|
||||
void Document::BeginUpdate() {
|
||||
// If the document is going away, then it's probably okay to do things to it
|
||||
// in the wrong DocGroup. We're unlikely to run JS or do anything else
|
||||
// observable at this point. We reach this point when cycle collecting a
|
||||
// <link> element and the unlink code removes a style sheet.
|
||||
//
|
||||
// TODO(emilio): Style updates are gone, can this happen now?
|
||||
if (mDocGroup && !mIsGoingAway && !mInUnlinkOrDeletion &&
|
||||
!mIgnoreDocGroupMismatches) {
|
||||
mDocGroup->ValidateAccess();
|
||||
}
|
||||
|
||||
++mUpdateNestLevel;
|
||||
nsContentUtils::AddScriptBlocker();
|
||||
NS_DOCUMENT_NOTIFY_OBSERVERS(BeginUpdate, (this));
|
||||
|
@ -9688,11 +9677,6 @@ EventListenerManager* Document::GetExistingListenerManager() const {
|
|||
}
|
||||
|
||||
void Document::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
|
||||
if (mDocGroup && aVisitor.mEvent->mMessage != eVoidEvent &&
|
||||
!mIgnoreDocGroupMismatches) {
|
||||
mDocGroup->ValidateAccess();
|
||||
}
|
||||
|
||||
aVisitor.mCanHandle = true;
|
||||
// FIXME! This is a hack to make middle mouse paste working also in Editor.
|
||||
// Bug 329119
|
||||
|
|
|
@ -250,23 +250,6 @@ void imgRequestProxy::ClearValidating() {
|
|||
}
|
||||
|
||||
bool imgRequestProxy::IsOnEventTarget() const {
|
||||
// Ensure we are in some main thread context because the scheduler group
|
||||
// methods are only safe to call on the main thread.
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (mTabGroup) {
|
||||
MOZ_ASSERT(mEventTarget);
|
||||
return mTabGroup->IsSafeToRun();
|
||||
}
|
||||
|
||||
if (mListener) {
|
||||
// If we have no scheduler group but we do have a listener, then we know
|
||||
// that the listener requires unlabelled dispatch.
|
||||
MOZ_ASSERT(mEventTarget);
|
||||
return mozilla::SchedulerGroup::IsSafeToRunUnlabeled();
|
||||
}
|
||||
|
||||
// No listener means it is always safe, as there is nothing to do.
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,24 +20,6 @@
|
|||
using namespace mozilla;
|
||||
using mozilla::Runnable;
|
||||
|
||||
class MockSchedulerGroup : public SchedulerGroup {
|
||||
public:
|
||||
explicit MockSchedulerGroup(mozilla::dom::DocGroup* aDocGroup)
|
||||
: mDocGroup(aDocGroup) {}
|
||||
NS_INLINE_DECL_REFCOUNTING(MockSchedulerGroup);
|
||||
|
||||
MOCK_METHOD1(SetValidatingAccess, void(ValidationType aType));
|
||||
mozilla::dom::DocGroup* DocGroup() { return mDocGroup; }
|
||||
|
||||
protected:
|
||||
virtual ~MockSchedulerGroup() = default;
|
||||
|
||||
private:
|
||||
mozilla::dom::DocGroup* mDocGroup;
|
||||
};
|
||||
|
||||
typedef testing::NiceMock<MockSchedulerGroup> MSchedulerGroup;
|
||||
|
||||
/* Timed runnable which simulates some execution time
|
||||
* and can run a nested runnable.
|
||||
*/
|
||||
|
@ -87,7 +69,6 @@ class ThreadMetrics : public ::testing::Test {
|
|||
RefPtr<dom::Document> doc;
|
||||
RefPtr<dom::TabGroup> tabGroup = new dom::TabGroup(false);
|
||||
mDocGroup = tabGroup->AddDocument(key, doc);
|
||||
mSchedulerGroup = new MSchedulerGroup(mDocGroup);
|
||||
mCounter = mDocGroup->GetPerformanceCounter();
|
||||
mThreadMgr = do_GetService("@mozilla.org/thread-manager;1");
|
||||
mOther = DispatchCategory(TaskCategory::Other).GetValue();
|
||||
|
@ -109,8 +90,7 @@ class ThreadMetrics : public ::testing::Test {
|
|||
ProcessAllEvents();
|
||||
nsCOMPtr<nsIRunnable> runnable =
|
||||
new TimedRunnable(aExecutionTime1, aExecutionTime2, aSubExecutionTime);
|
||||
runnable = new SchedulerGroup::Runnable(runnable.forget(), mSchedulerGroup,
|
||||
mDocGroup);
|
||||
runnable = new SchedulerGroup::Runnable(runnable.forget(), mDocGroup);
|
||||
return mDocGroup->Dispatch(TaskCategory::Other, runnable.forget());
|
||||
}
|
||||
|
||||
|
@ -118,7 +98,6 @@ class ThreadMetrics : public ::testing::Test {
|
|||
|
||||
uint32_t mOther;
|
||||
bool mOldPref;
|
||||
RefPtr<MSchedulerGroup> mSchedulerGroup;
|
||||
RefPtr<mozilla::dom::DocGroup> mDocGroup;
|
||||
RefPtr<mozilla::PerformanceCounter> mCounter;
|
||||
nsCOMPtr<nsIThreadManager> mThreadMgr;
|
||||
|
|
|
@ -123,20 +123,16 @@ void SchedulerGroup::MarkVsyncReceived() {
|
|||
/* static */
|
||||
void SchedulerGroup::MarkVsyncRan() { gEarliestUnprocessedVsync = 0; }
|
||||
|
||||
MOZ_THREAD_LOCAL(bool) SchedulerGroup::sTlsValidatingAccess;
|
||||
|
||||
SchedulerGroup::SchedulerGroup() : mIsRunning(false) {
|
||||
if (NS_IsMainThread()) {
|
||||
sTlsValidatingAccess.infallibleInit();
|
||||
}
|
||||
}
|
||||
SchedulerGroup::SchedulerGroup() : mIsRunning(false) {}
|
||||
|
||||
/* static */
|
||||
nsresult SchedulerGroup::DispatchWithDocGroup(
|
||||
TaskCategory aCategory, already_AddRefed<nsIRunnable>&& aRunnable,
|
||||
dom::DocGroup* aDocGroup) {
|
||||
return LabeledDispatch(aCategory, std::move(aRunnable), aDocGroup);
|
||||
}
|
||||
|
||||
/* static */
|
||||
nsresult SchedulerGroup::Dispatch(TaskCategory aCategory,
|
||||
already_AddRefed<nsIRunnable>&& aRunnable) {
|
||||
return LabeledDispatch(aCategory, std::move(aRunnable), nullptr);
|
||||
|
@ -212,13 +208,14 @@ SchedulerGroup* SchedulerGroup::FromEventTarget(nsIEventTarget* aEventTarget) {
|
|||
return target->Dispatcher();
|
||||
}
|
||||
|
||||
/* static */
|
||||
nsresult SchedulerGroup::LabeledDispatch(
|
||||
TaskCategory aCategory, already_AddRefed<nsIRunnable>&& aRunnable,
|
||||
dom::DocGroup* aDocGroup) {
|
||||
nsCOMPtr<nsIRunnable> runnable(aRunnable);
|
||||
if (XRE_IsContentProcess()) {
|
||||
RefPtr<Runnable> internalRunnable =
|
||||
new Runnable(runnable.forget(), this, aDocGroup);
|
||||
new Runnable(runnable.forget(), aDocGroup);
|
||||
return InternalUnlabeledDispatch(aCategory, internalRunnable.forget());
|
||||
}
|
||||
return UnlabeledDispatch(aCategory, runnable.forget());
|
||||
|
@ -252,22 +249,10 @@ nsresult SchedulerGroup::InternalUnlabeledDispatch(
|
|||
return rv;
|
||||
}
|
||||
|
||||
/* static */
|
||||
void SchedulerGroup::SetValidatingAccess(ValidationType aType) {
|
||||
bool validating = aType == StartValidation;
|
||||
sTlsValidatingAccess.set(validating);
|
||||
|
||||
dom::AutoJSAPI jsapi;
|
||||
jsapi.Init();
|
||||
js::EnableAccessValidation(jsapi.cx(), validating);
|
||||
}
|
||||
|
||||
SchedulerGroup::Runnable::Runnable(already_AddRefed<nsIRunnable>&& aRunnable,
|
||||
SchedulerGroup* aGroup,
|
||||
dom::DocGroup* aDocGroup)
|
||||
: mozilla::Runnable("SchedulerGroup::Runnable"),
|
||||
mRunnable(std::move(aRunnable)),
|
||||
mGroup(aGroup),
|
||||
mDocGroup(aDocGroup) {}
|
||||
|
||||
dom::DocGroup* SchedulerGroup::Runnable::DocGroup() const { return mDocGroup; }
|
||||
|
@ -291,15 +276,10 @@ SchedulerGroup::Runnable::GetName(nsACString& aName) {
|
|||
NS_IMETHODIMP
|
||||
SchedulerGroup::Runnable::Run() {
|
||||
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsresult result = mRunnable->Run();
|
||||
|
||||
// The runnable's destructor can have side effects, so try to execute it in
|
||||
// the scope of the TabGroup.
|
||||
mRunnable = nullptr;
|
||||
|
||||
mGroup->SetValidatingAccess(EndValidation);
|
||||
return result;
|
||||
nsCOMPtr<nsIRunnable> runnable(mRunnable.forget());
|
||||
return runnable->Run();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -56,60 +56,17 @@ class SchedulerGroup : public LinkedListElement<SchedulerGroup> {
|
|||
// "background" state.
|
||||
virtual bool IsBackground() const { return false; }
|
||||
|
||||
// This function returns true if it's currently safe to run code associated
|
||||
// with this SchedulerGroup. It will return true either if we're inside an
|
||||
// unlabeled runnable or if we're inside a runnable labeled with this
|
||||
// SchedulerGroup.
|
||||
bool IsSafeToRun() const { return !sTlsValidatingAccess.get() || mIsRunning; }
|
||||
|
||||
// This function returns true if it's currently safe to run unlabeled code
|
||||
// with no known SchedulerGroup. It will only return true if we're inside an
|
||||
// unlabeled runnable.
|
||||
static bool IsSafeToRunUnlabeled() { return !sTlsValidatingAccess.get(); }
|
||||
|
||||
// Ensure that it's valid to access the TabGroup at this time.
|
||||
void ValidateAccess() const { MOZ_ASSERT(IsSafeToRun()); }
|
||||
|
||||
enum EnqueueStatus {
|
||||
NewlyQueued,
|
||||
AlreadyQueued,
|
||||
};
|
||||
|
||||
// Records that this SchedulerGroup had an event enqueued in some
|
||||
// queue. Returns whether the SchedulerGroup was already in a queue before
|
||||
// EnqueueEvent() was called.
|
||||
EnqueueStatus EnqueueEvent() {
|
||||
mEventCount++;
|
||||
return mEventCount == 1 ? NewlyQueued : AlreadyQueued;
|
||||
}
|
||||
|
||||
enum DequeueStatus {
|
||||
StillQueued,
|
||||
NoLongerQueued,
|
||||
};
|
||||
|
||||
// Records that this SchedulerGroup had an event dequeued from some
|
||||
// queue. Returns whether the SchedulerGroup is still in a queue after
|
||||
// DequeueEvent() returns.
|
||||
DequeueStatus DequeueEvent() {
|
||||
mEventCount--;
|
||||
return mEventCount == 0 ? NoLongerQueued : StillQueued;
|
||||
}
|
||||
|
||||
class Runnable final : public mozilla::Runnable, public nsIRunnablePriority {
|
||||
public:
|
||||
Runnable(already_AddRefed<nsIRunnable>&& aRunnable, SchedulerGroup* aGroup,
|
||||
Runnable(already_AddRefed<nsIRunnable>&& aRunnable,
|
||||
dom::DocGroup* aDocGroup);
|
||||
|
||||
SchedulerGroup* Group() const { return mGroup; }
|
||||
dom::DocGroup* DocGroup() const;
|
||||
|
||||
#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY
|
||||
NS_IMETHOD GetName(nsACString& aName) override;
|
||||
#endif
|
||||
|
||||
bool IsBackground() const { return mGroup->IsBackground(); }
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIRUNNABLE
|
||||
NS_DECL_NSIRUNNABLEPRIORITY
|
||||
|
@ -122,15 +79,14 @@ class SchedulerGroup : public LinkedListElement<SchedulerGroup> {
|
|||
~Runnable() = default;
|
||||
|
||||
nsCOMPtr<nsIRunnable> mRunnable;
|
||||
RefPtr<SchedulerGroup> mGroup;
|
||||
RefPtr<dom::DocGroup> mDocGroup;
|
||||
};
|
||||
friend class Runnable;
|
||||
|
||||
bool* GetValidAccessPtr() { return &mIsRunning; }
|
||||
|
||||
virtual nsresult Dispatch(TaskCategory aCategory,
|
||||
already_AddRefed<nsIRunnable>&& aRunnable);
|
||||
static nsresult Dispatch(TaskCategory aCategory,
|
||||
already_AddRefed<nsIRunnable>&& aRunnable);
|
||||
|
||||
virtual nsISerialEventTarget* EventTargetFor(TaskCategory aCategory) const;
|
||||
|
||||
|
@ -152,12 +108,6 @@ class SchedulerGroup : public LinkedListElement<SchedulerGroup> {
|
|||
void SetIsRunning(bool aIsRunning) { mIsRunning = aIsRunning; }
|
||||
bool IsRunning() const { return mIsRunning; }
|
||||
|
||||
enum ValidationType {
|
||||
StartValidation,
|
||||
EndValidation,
|
||||
};
|
||||
static void SetValidatingAccess(ValidationType aType);
|
||||
|
||||
struct EpochQueueEntry {
|
||||
nsCOMPtr<nsIRunnable> mRunnable;
|
||||
uintptr_t mEpochNumber;
|
||||
|
@ -173,9 +123,9 @@ class SchedulerGroup : public LinkedListElement<SchedulerGroup> {
|
|||
}
|
||||
|
||||
protected:
|
||||
nsresult DispatchWithDocGroup(TaskCategory aCategory,
|
||||
already_AddRefed<nsIRunnable>&& aRunnable,
|
||||
dom::DocGroup* aDocGroup);
|
||||
static nsresult DispatchWithDocGroup(
|
||||
TaskCategory aCategory, already_AddRefed<nsIRunnable>&& aRunnable,
|
||||
dom::DocGroup* aDocGroup);
|
||||
|
||||
static nsresult InternalUnlabeledDispatch(
|
||||
TaskCategory aCategory, already_AddRefed<Runnable>&& aRunnable);
|
||||
|
@ -193,9 +143,9 @@ class SchedulerGroup : public LinkedListElement<SchedulerGroup> {
|
|||
// function returns |dispatcher|.
|
||||
static SchedulerGroup* FromEventTarget(nsIEventTarget* aEventTarget);
|
||||
|
||||
nsresult LabeledDispatch(TaskCategory aCategory,
|
||||
already_AddRefed<nsIRunnable>&& aRunnable,
|
||||
dom::DocGroup* aDocGroup);
|
||||
static nsresult LabeledDispatch(TaskCategory aCategory,
|
||||
already_AddRefed<nsIRunnable>&& aRunnable,
|
||||
dom::DocGroup* aDocGroup);
|
||||
|
||||
void CreateEventTargets(bool aNeedValidation);
|
||||
|
||||
|
@ -203,8 +153,6 @@ class SchedulerGroup : public LinkedListElement<SchedulerGroup> {
|
|||
// dispatcher.
|
||||
void Shutdown(bool aXPCOMShutdown);
|
||||
|
||||
static MOZ_THREAD_LOCAL(bool) sTlsValidatingAccess;
|
||||
|
||||
bool mIsRunning;
|
||||
|
||||
// Number of events that are currently enqueued for this SchedulerGroup
|
||||
|
|
Загрузка…
Ссылка в новой задаче