Skip to content

Commit 3024015

Browse files
committed
Bug 1591132 - Make it easy to switch on and off these assertions in different build configurations. r=froydnj
Put them behind a MOZ_HASH_TABLE_CHECKS_ENABLED define, which right now is only defined in DEBUG builds, preserving behavior. MakeImmutable becomes an empty inline function when disabled, which should be zero-cost. Differential Revision: https://phabricator.services.mozilla.com/D50493 --HG-- extra : moz-landing-system : lando
1 parent 9d4e6ee commit 3024015

File tree

7 files changed

+23
-41
lines changed

7 files changed

+23
-41
lines changed

dom/indexedDB/ActorsParent.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14471,13 +14471,9 @@ void VersionChangeTransaction::UpdateMetadata(nsresult aResult) {
1447114471
indexIter.Remove();
1447214472
}
1447314473
}
14474-
#ifdef DEBUG
1447514474
metadata->mIndexes.MarkImmutable();
14476-
#endif
1447714475
}
14478-
#ifdef DEBUG
1447914476
info->mMetadata->mObjectStores.MarkImmutable();
14480-
#endif
1448114477
} else {
1448214478
// Replace metadata pointers for all live databases.
1448314479
info->mMetadata = oldMetadata.forget();
@@ -18611,10 +18607,7 @@ nsresult DatabaseOperationBase::GetUniqueIndexTableForObjectStore(
1861118607
return NS_ERROR_OUT_OF_MEMORY;
1861218608
}
1861318609

18614-
#ifdef DEBUG
1861518610
aMaybeUniqueIndexTable.ref().MarkImmutable();
18616-
#endif
18617-
1861818611
return NS_OK;
1861918612
}
1862018613

@@ -24190,11 +24183,9 @@ bool ObjectStoreAddOrPutRequestOp::Init(TransactionBase* aTransaction) {
2419024183
mUniqueIndexTable.emplace();
2419124184
}
2419224185

24193-
#ifdef DEBUG
2419424186
if (mUniqueIndexTable.isSome()) {
2419524187
mUniqueIndexTable.ref().MarkImmutable();
2419624188
}
24197-
#endif
2419824189

2419924190
const nsTArray<FileAddInfo>& fileAddInfos = mParams.fileAddInfos();
2420024191

toolkit/components/telemetry/core/TelemetryOrigin.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,8 @@ void TelemetryOrigin::InitializeGlobalState() {
319319

320320
// This map shouldn't change at runtime, so make debug builds complain
321321
// if it tries.
322-
#ifdef DEBUG
323322
gOriginToIndexMap->MarkImmutable();
324323
gHashToIndexMap->MarkImmutable();
325-
#endif // DEBUG
326324

327325
gInitDone = true;
328326
}

xpcom/ds/PLDHashTable.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
using namespace mozilla;
2323

24-
#ifdef DEBUG
24+
#ifdef MOZ_HASH_TABLE_CHECKS_ENABLED
2525

2626
class AutoReadOp {
2727
Checker& mChk;
@@ -222,7 +222,7 @@ PLDHashTable& PLDHashTable::operator=(PLDHashTable&& aOther) {
222222
mEntryCount = std::move(aOther.mEntryCount);
223223
mRemovedCount = std::move(aOther.mRemovedCount);
224224
mEntryStore.Set(aOther.mEntryStore.Get(), &mGeneration);
225-
#ifdef DEBUG
225+
#ifdef MOZ_HASH_TABLE_CHECKS_ENABLED
226226
mChecker = std::move(aOther.mChecker);
227227
#endif
228228

@@ -231,7 +231,7 @@ PLDHashTable& PLDHashTable::operator=(PLDHashTable&& aOther) {
231231
// Clear up |aOther| so its destruction will be a no-op and it reports being
232232
// empty.
233233
{
234-
#ifdef DEBUG
234+
#ifdef MOZ_HASH_TABLE_CHECKS_ENABLED
235235
AutoDestructorOp op(mChecker);
236236
#endif
237237
aOther.mEntryCount = 0;
@@ -285,7 +285,7 @@ auto PLDHashTable::SlotForIndex(uint32_t aIndex) const -> Slot {
285285
}
286286

287287
PLDHashTable::~PLDHashTable() {
288-
#ifdef DEBUG
288+
#ifdef MOZ_HASH_TABLE_CHECKS_ENABLED
289289
AutoDestructorOp op(mChecker);
290290
#endif
291291

@@ -495,7 +495,7 @@ PLDHashTable::ComputeKeyHash(const void* aKey) const {
495495
}
496496

497497
PLDHashEntryHdr* PLDHashTable::Search(const void* aKey) const {
498-
#ifdef DEBUG
498+
#ifdef MOZ_HASH_TABLE_CHECKS_ENABLED
499499
AutoReadOp op(mChecker);
500500
#endif
501501

@@ -511,7 +511,7 @@ PLDHashEntryHdr* PLDHashTable::Search(const void* aKey) const {
511511

512512
PLDHashEntryHdr* PLDHashTable::Add(const void* aKey,
513513
const mozilla::fallible_t&) {
514-
#ifdef DEBUG
514+
#ifdef MOZ_HASH_TABLE_CHECKS_ENABLED
515515
AutoWriteOp op(mChecker);
516516
#endif
517517

@@ -593,7 +593,7 @@ PLDHashEntryHdr* PLDHashTable::Add(const void* aKey) {
593593
}
594594

595595
void PLDHashTable::Remove(const void* aKey) {
596-
#ifdef DEBUG
596+
#ifdef MOZ_HASH_TABLE_CHECKS_ENABLED
597597
AutoWriteOp op(mChecker);
598598
#endif
599599

@@ -614,7 +614,7 @@ void PLDHashTable::Remove(const void* aKey) {
614614
}
615615

616616
void PLDHashTable::RemoveEntry(PLDHashEntryHdr* aEntry) {
617-
#ifdef DEBUG
617+
#ifdef MOZ_HASH_TABLE_CHECKS_ENABLED
618618
AutoWriteOp op(mChecker);
619619
#endif
620620

@@ -669,7 +669,7 @@ void PLDHashTable::ShrinkIfAppropriate() {
669669

670670
size_t PLDHashTable::ShallowSizeOfExcludingThis(
671671
MallocSizeOf aMallocSizeOf) const {
672-
#ifdef DEBUG
672+
#ifdef MOZ_HASH_TABLE_CHECKS_ENABLED
673673
AutoReadOp op(mChecker);
674674
#endif
675675

@@ -705,7 +705,7 @@ PLDHashTable::Iterator::Iterator(PLDHashTable* aTable)
705705
mNextsLimit(mTable->EntryCount()),
706706
mHaveRemoved(false),
707707
mEntrySize(aTable->mEntrySize) {
708-
#ifdef DEBUG
708+
#ifdef MOZ_HASH_TABLE_CHECKS_ENABLED
709709
mTable->mChecker.StartReadOp();
710710
#endif
711711

@@ -733,7 +733,7 @@ PLDHashTable::Iterator::Iterator(PLDHashTable* aTable, EndIteratorTag aTag)
733733
mNextsLimit(mTable->EntryCount()),
734734
mHaveRemoved(false),
735735
mEntrySize(aTable->mEntrySize) {
736-
#ifdef DEBUG
736+
#ifdef MOZ_HASH_TABLE_CHECKS_ENABLED
737737
mTable->mChecker.StartReadOp();
738738
#endif
739739

@@ -750,7 +750,7 @@ PLDHashTable::Iterator::Iterator(const Iterator& aOther)
750750
// TODO: Is this necessary?
751751
MOZ_ASSERT(!mHaveRemoved);
752752

753-
#ifdef DEBUG
753+
#ifdef MOZ_HASH_TABLE_CHECKS_ENABLED
754754
mTable->mChecker.StartReadOp();
755755
#endif
756756
}
@@ -760,7 +760,7 @@ PLDHashTable::Iterator::~Iterator() {
760760
if (mHaveRemoved) {
761761
mTable->ShrinkIfAppropriate();
762762
}
763-
#ifdef DEBUG
763+
#ifdef MOZ_HASH_TABLE_CHECKS_ENABLED
764764
mTable->mChecker.EndReadOp();
765765
#endif
766766
}
@@ -820,7 +820,3 @@ void PLDHashTable::Iterator::Remove() {
820820
mTable->RawRemove(mCurrent);
821821
mHaveRemoved = true;
822822
}
823-
824-
#ifdef DEBUG
825-
void PLDHashTable::MarkImmutable() { mChecker.SetNonWritable(); }
826-
#endif

xpcom/ds/PLDHashTable.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
using PLDHashNumber = mozilla::HashNumber;
2424
static const uint32_t kPLDHashNumberBits = mozilla::kHashNumberBits;
2525

26+
#ifdef DEBUG
27+
#define MOZ_HASH_TABLE_CHECKS_ENABLED 1
28+
#endif
29+
2630
class PLDHashTable;
2731
struct PLDHashTableOps;
2832

@@ -52,7 +56,7 @@ struct PLDHashEntryHdr {
5256
friend class PLDHashTable;
5357
};
5458

55-
#ifdef DEBUG
59+
#ifdef MOZ_HASH_TABLE_CHECKS_ENABLED
5660

5761
// This class does three kinds of checking:
5862
//
@@ -378,7 +382,7 @@ class PLDHashTable {
378382
uint32_t mEntryCount; // Number of entries in table.
379383
uint32_t mRemovedCount; // Removed entry sentinels in table.
380384

381-
#ifdef DEBUG
385+
#ifdef MOZ_HASH_TABLE_CHECKS_ENABLED
382386
mutable Checker mChecker;
383387
#endif
384388

@@ -515,12 +519,14 @@ class PLDHashTable {
515519
// Like ShallowSizeOfExcludingThis(), but includes sizeof(*this).
516520
size_t ShallowSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
517521

518-
#ifdef DEBUG
519522
// Mark a table as immutable for the remainder of its lifetime. This
520523
// changes the implementation from asserting one set of invariants to
521524
// asserting a different set.
522-
void MarkImmutable();
525+
void MarkImmutable() {
526+
#ifdef MOZ_HASH_TABLE_CHECKS_ENABLED
527+
mChecker.SetNonWritable();
523528
#endif
529+
}
524530

525531
// If you use PLDHashEntryStub or a subclass of it as your entry struct, and
526532
// if your entries move via memcpy and clear via memset(0), you can use these

xpcom/ds/nsBaseHashtable.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,7 @@ class nsBaseHashtable
511511
nsTHashtable<EntryType>::SwapElements(aOther);
512512
}
513513

514-
#ifdef DEBUG
515514
using nsTHashtable<EntryType>::MarkImmutable;
516-
#endif
517515
};
518516

519517
//

xpcom/ds/nsStaticNameTable.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ nsStaticCaseInsensitiveNameTable::nsStaticCaseInsensitiveNameTable(
134134

135135
entry->mIndex = index;
136136
}
137-
#ifdef DEBUG
138137
mNameTable.MarkImmutable();
139-
#endif
140138
}
141139

142140
nsStaticCaseInsensitiveNameTable::~nsStaticCaseInsensitiveNameTable() {

xpcom/ds/nsTHashtable.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,15 +309,13 @@ class MOZ_NEEDS_NO_VTABLE_TYPE nsTHashtable {
309309
mozilla::Swap(this->mTable, aOther.mTable);
310310
}
311311

312-
#ifdef DEBUG
313312
/**
314313
* Mark the table as constant after initialization.
315314
*
316315
* This will prevent assertions when a read-only hash is accessed on multiple
317316
* threads without synchronization.
318317
*/
319318
void MarkImmutable() { mTable.MarkImmutable(); }
320-
#endif
321319

322320
protected:
323321
PLDHashTable mTable;
@@ -515,10 +513,7 @@ class nsTHashtable<nsPtrHashKey<T>>
515513

516514
using Base::ShallowSizeOfExcludingThis;
517515
using Base::ShallowSizeOfIncludingThis;
518-
519-
#ifdef DEBUG
520516
using Base::MarkImmutable;
521-
#endif
522517

523518
/* Wrapper functions */
524519
EntryType* GetEntry(T* aKey) const {

0 commit comments

Comments
 (0)