Bug 1043605 - Fix up DEBUG/JS_DEBUG confusion in HashTable.h. r=jwalden.
authorNicholas Nethercote <nnethercote@mozilla.com>
Sun, 10 Aug 2014 23:17:44 -0700
changeset 198825 e4f87d728f9d0c01b9af79c8f12c081537281f7a
parent 198824 50ac8d9ddf276179e2a4e445d79f2062d9abf4bd
child 198837 bb954a9a154fab69cb9ee0703c0253431fe4e300
push id47499
push usernnethercote@mozilla.com
push dateMon, 11 Aug 2014 06:20:59 +0000
treeherdermozilla-inbound@e4f87d728f9d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs1043605
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1043605 - Fix up DEBUG/JS_DEBUG confusion in HashTable.h. r=jwalden.
js/public/HashTable.h
--- a/js/public/HashTable.h
+++ b/js/public/HashTable.h
@@ -6,17 +6,16 @@
 
 #ifndef js_HashTable_h
 #define js_HashTable_h
 
 #include "mozilla/Alignment.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Casting.h"
-#include "mozilla/DebugOnly.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Move.h"
 #include "mozilla/NullPtr.h"
 #include "mozilla/PodOperations.h"
 #include "mozilla/ReentrancyGuard.h"
 #include "mozilla/TemplateLib.h"
 #include "mozilla/TypeTraits.h"
 
@@ -757,81 +756,89 @@ class HashTable : private AllocPolicy
     // table operations unless |generation()| is tested.
     class Ptr
     {
         friend class HashTable;
         typedef void (Ptr::* ConvertibleToBool)();
         void nonNull() {}
 
         Entry *entry_;
-#ifdef DEBUG
+#ifdef JS_DEBUG
         const HashTable *table_;
         uint32_t generation;
 #endif
 
       protected:
         Ptr(Entry &entry, const HashTable &tableArg)
           : entry_(&entry)
-#ifdef DEBUG
+#ifdef JS_DEBUG
           , table_(&tableArg)
           , generation(tableArg.generation())
 #endif
         {}
 
       public:
         // Leaves Ptr uninitialized.
         Ptr() {
 #ifdef JS_DEBUG
             entry_ = (Entry *)0xbad;
 #endif
         }
 
         bool found() const {
+#ifdef JS_DEBUG
             MOZ_ASSERT(generation == table_->generation());
+#endif
             return entry_->isLive();
         }
 
         operator ConvertibleToBool() const {
             return found() ? &Ptr::nonNull : 0;
         }
 
         bool operator==(const Ptr &rhs) const {
             MOZ_ASSERT(found() && rhs.found());
             return entry_ == rhs.entry_;
         }
 
         bool operator!=(const Ptr &rhs) const {
+#ifdef JS_DEBUG
             MOZ_ASSERT(generation == table_->generation());
+#endif
             return !(*this == rhs);
         }
 
         T &operator*() const {
+#ifdef JS_DEBUG
             MOZ_ASSERT(generation == table_->generation());
+#endif
             return entry_->get();
         }
 
         T *operator->() const {
+#ifdef JS_DEBUG
             MOZ_ASSERT(generation == table_->generation());
+#endif
             return &entry_->get();
         }
     };
 
     // A Ptr that can be used to add a key after a failed lookup.
     class AddPtr : public Ptr
     {
         friend class HashTable;
         HashNumber keyHash;
-#ifdef DEBUG
+#ifdef JS_DEBUG
         uint64_t mutationCount;
 #endif
 
         AddPtr(Entry &entry, const HashTable &tableArg, HashNumber hn)
           : Ptr(entry, tableArg)
           , keyHash(hn)
-#ifdef DEBUG
+#ifdef JS_DEBUG
           , mutationCount(tableArg.mutationCount)
 #endif
         {}
 
       public:
         // Leaves AddPtr uninitialized.
         AddPtr() {}
     };
@@ -843,68 +850,74 @@ class HashTable : private AllocPolicy
     class Range
     {
       protected:
         friend class HashTable;
 
         Range(const HashTable &tableArg, Entry *c, Entry *e)
           : cur(c)
           , end(e)
-#ifdef DEBUG
+#ifdef JS_DEBUG
           , table_(&tableArg)
           , mutationCount(tableArg.mutationCount)
           , generation(tableArg.generation())
           , validEntry(true)
 #endif
         {
             while (cur < end && !cur->isLive())
                 ++cur;
         }
 
         Entry *cur, *end;
-#ifdef DEBUG
+#ifdef JS_DEBUG
         const HashTable *table_;
         uint64_t mutationCount;
         uint32_t generation;
         bool validEntry;
 #endif
 
       public:
         Range()
           : cur(nullptr)
           , end(nullptr)
-#ifdef DEBUG
+#ifdef JS_DEBUG
           , table_(nullptr)
           , mutationCount(0)
           , generation(0)
           , validEntry(false)
 #endif
         {}
 
         bool empty() const {
+#ifdef JS_DEBUG
             MOZ_ASSERT(generation == table_->generation());
             MOZ_ASSERT(mutationCount == table_->mutationCount);
+#endif
             return cur == end;
         }
 
         T &front() const {
+            MOZ_ASSERT(!empty());
+#ifdef JS_DEBUG
             MOZ_ASSERT(validEntry);
-            MOZ_ASSERT(!empty());
             MOZ_ASSERT(generation == table_->generation());
             MOZ_ASSERT(mutationCount == table_->mutationCount);
+#endif
             return cur->get();
         }
 
         void popFront() {
             MOZ_ASSERT(!empty());
+#ifdef JS_DEBUG
             MOZ_ASSERT(generation == table_->generation());
             MOZ_ASSERT(mutationCount == table_->mutationCount);
+#endif
             while (++cur < end && !cur->isLive())
                 continue;
-#ifdef DEBUG
+#ifdef JS_DEBUG
             validEntry = true;
 #endif
         }
     };
 
     // A Range whose lifetime delimits a mutating enumeration of a hash table.
     // Since rehashing when elements were removed during enumeration would be
     // bad, it is postponed until the Enum is destructed.  Since the Enum's
@@ -931,30 +944,30 @@ class HashTable : private AllocPolicy
         //
         //   HashSet<int> s;
         //   for (HashSet<int>::Enum e(s); !e.empty(); e.popFront())
         //     if (e.front() == 42)
         //       e.removeFront();
         void removeFront() {
             table_.remove(*this->cur);
             removed = true;
-#ifdef DEBUG
+#ifdef JS_DEBUG
             this->validEntry = false;
             this->mutationCount = table_.mutationCount;
 #endif
         }
 
         // Removes the |front()| element and re-inserts it into the table with
         // a new key at the new Lookup position.  |front()| is invalid after
         // this operation until the next call to |popFront()|.
         void rekeyFront(const Lookup &l, const Key &k) {
             Ptr p(*this->cur, table_);
             table_.rekeyWithoutRehash(p, l, k);
             rekeyed = true;
-#ifdef DEBUG
+#ifdef JS_DEBUG
             this->validEntry = false;
             this->mutationCount = table_.mutationCount;
 #endif
         }
 
         void rekeyFront(const Key &k) {
             rekeyFront(k, k);
         }
@@ -997,18 +1010,18 @@ class HashTable : private AllocPolicy
   public:
     Entry       *table;                 // entry storage
     uint32_t    gen;                    // entry storage generation number
     uint32_t    entryCount;             // number of entries in table
     uint32_t    removedCount:CAP_BITS;  // removed entry sentinels in table
     uint32_t    hashShift:8;            // multiplicative hash shift
 
 #ifdef JS_DEBUG
-    mozilla::DebugOnly<uint64_t>     mutationCount;
-    mutable mozilla::DebugOnly<bool> mEntered;
+    uint64_t     mutationCount;
+    mutable bool mEntered;
     mutable struct Stats
     {
         uint32_t        searches;       // total number of table searches
         uint32_t        steps;          // hash chain links traversed
         uint32_t        hits;           // searches that found key
         uint32_t        misses;         // searches that didn't find key
         uint32_t        addOverRemoved; // adds that recycled a removed entry
         uint32_t        removes;        // calls to remove
@@ -1080,17 +1093,17 @@ class HashTable : private AllocPolicy
   public:
     explicit HashTable(AllocPolicy ap)
       : AllocPolicy(ap)
       , table(nullptr)
       , gen(0)
       , entryCount(0)
       , removedCount(0)
       , hashShift(sHashBits)
-#ifdef DEBUG
+#ifdef JS_DEBUG
       , mutationCount(0)
       , mEntered(false)
 #endif
     {}
 
     MOZ_WARN_UNUSED_RESULT bool init(uint32_t length)
     {
         MOZ_ASSERT(!initialized());
@@ -1370,17 +1383,17 @@ class HashTable : private AllocPolicy
         if (e.hasCollision()) {
             e.removeLive();
             removedCount++;
         } else {
             METER(stats.removeFrees++);
             e.clearLive();
         }
         entryCount--;
-#ifdef DEBUG
+#ifdef JS_DEBUG
         mutationCount++;
 #endif
     }
 
     void checkUnderloaded()
     {
         if (underloaded()) {
             METER(stats.shrinks++);
@@ -1455,34 +1468,35 @@ class HashTable : private AllocPolicy
             memset(table, 0, sizeof(*table) * capacity());
         } else {
             uint32_t tableCapacity = capacity();
             for (Entry *e = table, *end = table + tableCapacity; e < end; ++e)
                 e->clear();
         }
         removedCount = 0;
         entryCount = 0;
-#ifdef DEBUG
+#ifdef JS_DEBUG
         mutationCount++;
 #endif
     }
 
     void finish()
     {
+#ifdef JS_DEBUG
         MOZ_ASSERT(!mEntered);
-
+#endif
         if (!table)
             return;
 
         destroyTable(*this, table, capacity());
         table = nullptr;
         gen++;
         entryCount = 0;
         removedCount = 0;
-#ifdef DEBUG
+#ifdef JS_DEBUG
         mutationCount++;
 #endif
     }
 
     Range all() const
     {
         MOZ_ASSERT(table);
         return Range(*this, table, table + capacity());
@@ -1564,17 +1578,17 @@ class HashTable : private AllocPolicy
             if (status == RehashFailed)
                 return false;
             if (status == Rehashed)
                 p.entry_ = &findFreeEntry(p.keyHash);
         }
 
         p.entry_->setLive(p.keyHash, mozilla::Forward<U>(u));
         entryCount++;
-#ifdef DEBUG
+#ifdef JS_DEBUG
         mutationCount++;
         p.generation = generation();
         p.mutationCount = mutationCount;
 #endif
         return true;
     }
 
     // Note: |l| may be a reference to a piece of |u|, so this function
@@ -1590,17 +1604,17 @@ class HashTable : private AllocPolicy
         if (entry->isRemoved()) {
             METER(stats.addOverRemoved++);
             removedCount--;
             keyHash |= sCollisionBit;
         }
 
         entry->setLive(keyHash, mozilla::Forward<U>(u));
         entryCount++;
-#ifdef DEBUG
+#ifdef JS_DEBUG
         mutationCount++;
 #endif
     }
 
     // Note: |l| may be a reference to a piece of |u|, so this function
     // must take care not to use |l| after moving |u|.
     template <class U>
     bool putNew(const Lookup &l, U &&u)
@@ -1612,17 +1626,17 @@ class HashTable : private AllocPolicy
         return true;
     }
 
     // Note: |l| may be a reference to a piece of |u|, so this function
     // must take care not to use |l| after moving |u|.
     template <class U>
     bool relookupOrAdd(AddPtr& p, const Lookup &l, U &&u)
     {
-#ifdef DEBUG
+#ifdef JS_DEBUG
         p.generation = generation();
         p.mutationCount = mutationCount;
 #endif
         {
             mozilla::ReentrancyGuard g(*this);
             MOZ_ASSERT(prepareHash(l) == p.keyHash); // l has not been destroyed
             p.entry_ = &lookup(l, p.keyHash, sCollisionBit);
         }