Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 3be5f0a

Browse files
committed
Backed out changeset f4c8b3de527e (bug 1286895) for crashing in test_bug1241485.html. r=backout
1 parent 70fd734 commit 3be5f0a

6 files changed

Lines changed: 26 additions & 235 deletions

File tree

dom/workers/RuntimeService.cpp

Lines changed: 20 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,6 @@ using mozilla::Preferences;
9090
// Half the size of the actual C stack, to be safe.
9191
#define WORKER_CONTEXT_NATIVE_STACK_LIMIT 128 * sizeof(size_t) * 1024
9292

93-
// The maximum number of hardware concurrency, overridable via pref.
94-
#define MAX_HARDWARE_CONCURRENCY 8
95-
96-
// The maximum number of threads to use for workers, overridable via pref.
97-
#define MAX_WORKERS_PER_DOMAIN 512
98-
99-
static_assert(MAX_WORKERS_PER_DOMAIN >= 1,
100-
"We should allow at least one worker per domain.");
101-
10293
// The default number of seconds that close handlers will be allowed to run for
10394
// content workers.
10495
#define MAX_SCRIPT_RUN_TIME_SEC 10
@@ -110,8 +101,6 @@ static_assert(MAX_WORKERS_PER_DOMAIN >= 1,
110101
#define MAX_IDLE_THREADS 20
111102

112103
#define PREF_WORKERS_PREFIX "dom.workers."
113-
#define PREF_WORKERS_MAX_PER_DOMAIN PREF_WORKERS_PREFIX "maxPerDomain"
114-
#define PREF_WORKERS_MAX_HARDWARE_CONCURRENCY "dom.maxHardwareConcurrency"
115104

116105
#define PREF_MAX_SCRIPT_RUN_TIME_CONTENT "dom.max_script_run_time"
117106
#define PREF_MAX_SCRIPT_RUN_TIME_CHROME "dom.max_chrome_script_run_time"
@@ -148,9 +137,6 @@ namespace {
148137

149138
const uint32_t kNoIndex = uint32_t(-1);
150139

151-
uint32_t gMaxWorkersPerDomain = MAX_WORKERS_PER_DOMAIN;
152-
uint32_t gMaxHardwareConcurrency = MAX_HARDWARE_CONCURRENCY;
153-
154140
// Does not hold an owning reference.
155141
RuntimeService* gRuntimeService = nullptr;
156142

@@ -1371,7 +1357,6 @@ RuntimeService::RegisterWorker(WorkerPrivate* aWorkerPrivate)
13711357

13721358
const bool isServiceWorker = aWorkerPrivate->IsServiceWorker();
13731359
const bool isSharedWorker = aWorkerPrivate->IsSharedWorker();
1374-
const bool isDedicatedWorker = aWorkerPrivate->IsDedicatedWorker();
13751360
if (isServiceWorker) {
13761361
AssertIsOnMainThread();
13771362
Telemetry::Accumulate(Telemetry::SERVICE_WORKER_SPAWN_ATTEMPTS, 1);
@@ -1393,13 +1378,6 @@ RuntimeService::RegisterWorker(WorkerPrivate* aWorkerPrivate)
13931378
NS_ASSERTION(!sharedWorkerScriptSpec.IsEmpty(), "Empty spec!");
13941379
}
13951380

1396-
bool exemptFromPerDomainMax = false;
1397-
if (isServiceWorker) {
1398-
AssertIsOnMainThread();
1399-
exemptFromPerDomainMax = Preferences::GetBool("dom.serviceWorkers.exemptFromPerDomainMax",
1400-
false);
1401-
}
1402-
14031381
const nsCString& domain = aWorkerPrivate->Domain();
14041382

14051383
WorkerDomainInfo* domainInfo;
@@ -1415,34 +1393,14 @@ RuntimeService::RegisterWorker(WorkerPrivate* aWorkerPrivate)
14151393
mDomainMap.Put(domain, domainInfo);
14161394
}
14171395

1418-
queued = gMaxWorkersPerDomain &&
1419-
domainInfo->ActiveWorkerCount() >= gMaxWorkersPerDomain &&
1420-
!domain.IsEmpty() &&
1421-
!exemptFromPerDomainMax;
1422-
1423-
if (queued) {
1424-
domainInfo->mQueuedWorkers.AppendElement(aWorkerPrivate);
1425-
1426-
// Worker spawn gets queued due to hitting max workers per domain
1427-
// limit so let's log a warning.
1428-
WorkerPrivate::ReportErrorToConsole("HittingMaxWorkersPerDomain2");
1429-
1430-
if (isServiceWorker) {
1431-
Telemetry::Accumulate(Telemetry::SERVICE_WORKER_SPAWN_GETS_QUEUED, 1);
1432-
} else if (isSharedWorker) {
1433-
Telemetry::Accumulate(Telemetry::SHARED_WORKER_SPAWN_GETS_QUEUED, 1);
1434-
} else if (isDedicatedWorker) {
1435-
Telemetry::Accumulate(Telemetry::DEDICATED_WORKER_SPAWN_GETS_QUEUED, 1);
1436-
}
1437-
}
1438-
else if (parent) {
1396+
if (parent) {
14391397
domainInfo->mChildWorkerCount++;
14401398
}
14411399
else if (isServiceWorker) {
1442-
domainInfo->mActiveServiceWorkers.AppendElement(aWorkerPrivate);
1400+
domainInfo->mServiceWorkers.AppendElement(aWorkerPrivate);
14431401
}
14441402
else {
1445-
domainInfo->mActiveWorkers.AppendElement(aWorkerPrivate);
1403+
domainInfo->mWorkers.AppendElement(aWorkerPrivate);
14461404
}
14471405

14481406
if (isSharedWorker) {
@@ -1556,50 +1514,26 @@ RuntimeService::UnregisterWorker(WorkerPrivate* aWorkerPrivate)
15561514
NS_ERROR("Don't have an entry for this domain!");
15571515
}
15581516

1559-
// Remove old worker from everywhere.
1560-
uint32_t index = domainInfo->mQueuedWorkers.IndexOf(aWorkerPrivate);
1561-
if (index != kNoIndex) {
1562-
// Was queued, remove from the list.
1563-
domainInfo->mQueuedWorkers.RemoveElementAt(index);
1564-
}
1565-
else if (parent) {
1517+
if (parent) {
15661518
MOZ_ASSERT(domainInfo->mChildWorkerCount, "Must be non-zero!");
15671519
domainInfo->mChildWorkerCount--;
15681520
}
15691521
else if (aWorkerPrivate->IsServiceWorker()) {
1570-
MOZ_ASSERT(domainInfo->mActiveServiceWorkers.Contains(aWorkerPrivate),
1522+
MOZ_ASSERT(domainInfo->mServiceWorkers.Contains(aWorkerPrivate),
15711523
"Don't know about this worker!");
1572-
domainInfo->mActiveServiceWorkers.RemoveElement(aWorkerPrivate);
1524+
domainInfo->mServiceWorkers.RemoveElement(aWorkerPrivate);
15731525
}
15741526
else {
1575-
MOZ_ASSERT(domainInfo->mActiveWorkers.Contains(aWorkerPrivate),
1527+
MOZ_ASSERT(domainInfo->mWorkers.Contains(aWorkerPrivate),
15761528
"Don't know about this worker!");
1577-
domainInfo->mActiveWorkers.RemoveElement(aWorkerPrivate);
1529+
domainInfo->mWorkers.RemoveElement(aWorkerPrivate);
15781530
}
15791531

15801532
if (aWorkerPrivate->IsSharedWorker()) {
15811533
RemoveSharedWorker(domainInfo, aWorkerPrivate);
15821534
}
15831535

1584-
// See if there's a queued worker we can schedule.
1585-
if (domainInfo->ActiveWorkerCount() < gMaxWorkersPerDomain &&
1586-
!domainInfo->mQueuedWorkers.IsEmpty()) {
1587-
queuedWorker = domainInfo->mQueuedWorkers[0];
1588-
domainInfo->mQueuedWorkers.RemoveElementAt(0);
1589-
1590-
if (queuedWorker->GetParent()) {
1591-
domainInfo->mChildWorkerCount++;
1592-
}
1593-
else if (queuedWorker->IsServiceWorker()) {
1594-
domainInfo->mActiveServiceWorkers.AppendElement(queuedWorker);
1595-
}
1596-
else {
1597-
domainInfo->mActiveWorkers.AppendElement(queuedWorker);
1598-
}
1599-
}
1600-
16011536
if (domainInfo->HasNoWorkers()) {
1602-
MOZ_ASSERT(domainInfo->mQueuedWorkers.IsEmpty());
16031537
mDomainMap.Remove(domain);
16041538
}
16051539
}
@@ -1880,15 +1814,6 @@ RuntimeService::Init()
18801814
NS_WARNING("Failed to register timeout cache!");
18811815
}
18821816

1883-
int32_t maxPerDomain = Preferences::GetInt(PREF_WORKERS_MAX_PER_DOMAIN,
1884-
MAX_WORKERS_PER_DOMAIN);
1885-
gMaxWorkersPerDomain = std::max(0, maxPerDomain);
1886-
1887-
int32_t maxHardwareConcurrency =
1888-
Preferences::GetInt(PREF_WORKERS_MAX_HARDWARE_CONCURRENCY,
1889-
MAX_HARDWARE_CONCURRENCY);
1890-
gMaxHardwareConcurrency = std::max(0, maxHardwareConcurrency);
1891-
18921817
rv = InitOSFileConstants();
18931818
if (NS_FAILED(rv)) {
18941819
return rv;
@@ -2080,26 +2005,18 @@ RuntimeService::AddAllTopLevelWorkersToArray(nsTArray<WorkerPrivate*>& aWorkers)
20802005
WorkerDomainInfo* aData = iter.UserData();
20812006

20822007
#ifdef DEBUG
2083-
for (uint32_t index = 0; index < aData->mActiveWorkers.Length(); index++) {
2084-
MOZ_ASSERT(!aData->mActiveWorkers[index]->GetParent(),
2008+
for (uint32_t index = 0; index < aData->mWorkers.Length(); index++) {
2009+
MOZ_ASSERT(!aData->mWorkers[index]->GetParent(),
20852010
"Shouldn't have a parent in this list!");
20862011
}
2087-
for (uint32_t index = 0; index < aData->mActiveServiceWorkers.Length(); index++) {
2088-
MOZ_ASSERT(!aData->mActiveServiceWorkers[index]->GetParent(),
2012+
for (uint32_t index = 0; index < aData->mServiceWorkers.Length(); index++) {
2013+
MOZ_ASSERT(!aData->mServiceWorkers[index]->GetParent(),
20892014
"Shouldn't have a parent in this list!");
20902015
}
20912016
#endif
20922017

2093-
aWorkers.AppendElements(aData->mActiveWorkers);
2094-
aWorkers.AppendElements(aData->mActiveServiceWorkers);
2095-
2096-
// These might not be top-level workers...
2097-
for (uint32_t index = 0; index < aData->mQueuedWorkers.Length(); index++) {
2098-
WorkerPrivate* worker = aData->mQueuedWorkers[index];
2099-
if (!worker->GetParent()) {
2100-
aWorkers.AppendElement(worker);
2101-
}
2102-
}
2018+
aWorkers.AppendElements(aData->mWorkers);
2019+
aWorkers.AppendElements(aData->mServiceWorkers);
21032020
}
21042021
}
21052022

@@ -2124,7 +2041,7 @@ RuntimeService::CancelWorkersForWindow(nsPIDOMWindowInner* aWindow)
21242041
{
21252042
AssertIsOnMainThread();
21262043

2127-
AutoTArray<WorkerPrivate*, MAX_WORKERS_PER_DOMAIN> workers;
2044+
nsTArray<WorkerPrivate*> workers;
21282045
GetWorkersForWindow(aWindow, workers);
21292046

21302047
if (!workers.IsEmpty()) {
@@ -2146,7 +2063,7 @@ RuntimeService::FreezeWorkersForWindow(nsPIDOMWindowInner* aWindow)
21462063
AssertIsOnMainThread();
21472064
MOZ_ASSERT(aWindow);
21482065

2149-
AutoTArray<WorkerPrivate*, MAX_WORKERS_PER_DOMAIN> workers;
2066+
nsTArray<WorkerPrivate*> workers;
21502067
GetWorkersForWindow(aWindow, workers);
21512068

21522069
for (uint32_t index = 0; index < workers.Length(); index++) {
@@ -2160,7 +2077,7 @@ RuntimeService::ThawWorkersForWindow(nsPIDOMWindowInner* aWindow)
21602077
AssertIsOnMainThread();
21612078
MOZ_ASSERT(aWindow);
21622079

2163-
AutoTArray<WorkerPrivate*, MAX_WORKERS_PER_DOMAIN> workers;
2080+
nsTArray<WorkerPrivate*> workers;
21642081
GetWorkersForWindow(aWindow, workers);
21652082

21662083
for (uint32_t index = 0; index < workers.Length(); index++) {
@@ -2174,7 +2091,7 @@ RuntimeService::SuspendWorkersForWindow(nsPIDOMWindowInner* aWindow)
21742091
AssertIsOnMainThread();
21752092
MOZ_ASSERT(aWindow);
21762093

2177-
AutoTArray<WorkerPrivate*, MAX_WORKERS_PER_DOMAIN> workers;
2094+
nsTArray<WorkerPrivate*> workers;
21782095
GetWorkersForWindow(aWindow, workers);
21792096

21802097
for (uint32_t index = 0; index < workers.Length(); index++) {
@@ -2188,7 +2105,7 @@ RuntimeService::ResumeWorkersForWindow(nsPIDOMWindowInner* aWindow)
21882105
AssertIsOnMainThread();
21892106
MOZ_ASSERT(aWindow);
21902107

2191-
AutoTArray<WorkerPrivate*, MAX_WORKERS_PER_DOMAIN> workers;
2108+
nsTArray<WorkerPrivate*> workers;
21922109
GetWorkersForWindow(aWindow, workers);
21932110

21942111
for (uint32_t index = 0; index < workers.Length(); index++) {
@@ -2465,9 +2382,7 @@ RuntimeService::ClampedHardwareConcurrency() const
24652382
if (numberOfProcessors <= 0) {
24662383
numberOfProcessors = 1; // Must be one there somewhere
24672384
}
2468-
uint32_t clampedValue = std::min(uint32_t(numberOfProcessors),
2469-
gMaxHardwareConcurrency);
2470-
clampedHardwareConcurrency.compareExchange(0, clampedValue);
2385+
clampedHardwareConcurrency = numberOfProcessors;
24712386
}
24722387

24732388
return clampedHardwareConcurrency;

dom/workers/RuntimeService.h

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,21 @@ class RuntimeService final : public nsIObserver
4242
struct WorkerDomainInfo
4343
{
4444
nsCString mDomain;
45-
nsTArray<WorkerPrivate*> mActiveWorkers;
46-
nsTArray<WorkerPrivate*> mActiveServiceWorkers;
47-
nsTArray<WorkerPrivate*> mQueuedWorkers;
45+
nsTArray<WorkerPrivate*> mWorkers;
46+
nsTArray<WorkerPrivate*> mServiceWorkers;
4847
nsClassHashtable<nsCStringHashKey, SharedWorkerInfo> mSharedWorkerInfos;
4948
uint32_t mChildWorkerCount;
5049

5150
WorkerDomainInfo()
52-
: mActiveWorkers(1), mChildWorkerCount(0)
51+
: mWorkers(1), mChildWorkerCount(0)
5352
{ }
5453

55-
uint32_t
56-
ActiveWorkerCount() const
57-
{
58-
return mActiveWorkers.Length() +
59-
mChildWorkerCount;
60-
}
61-
62-
uint32_t
63-
ActiveServiceWorkerCount() const
64-
{
65-
return mActiveServiceWorkers.Length();
66-
}
67-
6854
bool
6955
HasNoWorkers() const
7056
{
71-
return ActiveWorkerCount() == 0 &&
72-
ActiveServiceWorkerCount() == 0;
57+
return mWorkers.IsEmpty() &&
58+
mServiceWorkers.IsEmpty() &&
59+
!mChildWorkerCount;
7360
}
7461
};
7562

dom/workers/test/mochitest.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ support-files =
144144
[test_bug1132395.html]
145145
skip-if = true # bug 1176225
146146
[test_bug1132924.html]
147-
[test_bug1241485.html]
148147
[test_chromeWorker.html]
149148
[test_clearTimeouts.html]
150149
[test_close.html]

dom/workers/test/test_bug1241485.html

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)