Commit Graph

65 Commits

Author SHA1 Message Date
Chris Fronk
dfcd4afc6e Bug 1433142 - Add support for hashing enum values. r=jwalden
Differential Revision: https://phabricator.services.mozilla.com/D70647
2020-05-27 23:44:51 +00:00
André Bargull
ccbf88b7b0 Bug 1626587 - Part 4: Remove mozilla::IsPod for HashMapEntry. r=jwalden
The `mozilla::IsPod<HashMapEntry` specialisation was only needed for the static
assertions in "js/src/frontend/NameCollections.h". Part 3 removed those, so we
can now also remove `mozilla::IsPod<HashMapEntry`.

Drive-by change:
- Remove no longer needed "mozilla/PodOperations.h" include in mfbt/HashTable.h.
- And then fix up previously transitively included files for RootingAPI.h,
  jsfriendapi.h, and Bench.cpp.

Differential Revision: https://phabricator.services.mozilla.com/D69201
2020-04-27 12:00:48 +00:00
André Bargull
9de017ffb8 Bug 1625138 - Part 33: Replace mozilla::IntegralConstant with std::integral_constant. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D68552

--HG--
extra : moz-landing-system : lando
2020-03-28 13:57:19 +00:00
André Bargull
32cb16fc45 Bug 1625138 - Part 32: Replace mozilla::RemoveConst with std::remove_const. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D68551

--HG--
extra : moz-landing-system : lando
2020-03-28 13:57:19 +00:00
Simon Giesecke
ad6c02c994 Bug 1613985 - Use default for equivalent-to-default constructors/destructors in mfbt. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D62542

--HG--
extra : moz-landing-system : lando
2020-02-13 11:20:27 +00:00
Mihai Alexandru Michis
395eb2050d Backed out changeset f3d9fbb2daf1 (bug 1613985) for causing hazard bustages on Linux.
CLOSED TREE
2020-02-12 16:43:30 +02:00
Simon Giesecke
066ea869b7 Bug 1613985 - Use default for equivalent-to-default constructors/destructors in mfbt. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D62542

--HG--
extra : moz-landing-system : lando
2020-02-12 11:13:24 +00:00
Emilio Cobos Álvarez
256c124f94 Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:

This was done by applying:

```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
         from subprocess import Popen, PIPE, check_output, CalledProcessError

         diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
-        args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+        args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']

         if not output_file:
             args.append("-i")
```

Then running `./mach clang-format -c <commit-hash>`

Then undoing that patch.

Then running check_spidermonkey_style.py --fixup

Then running `./mach clang-format`

I had to fix four things:

 * I needed to move <utility> back down in GuardObjects.h because I was hitting
   obscure problems with our system include wrappers like this:

0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94              ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94     MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94                                ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)

   Which I really didn't feel like digging into.

 * I had to restore the order of TrustOverrideUtils.h and related files in nss
   because the .inc files depend on TrustOverrideUtils.h being included earlier.

 * I had to add a missing include to RollingNumber.h

 * Also had to partially restore include order in JsepSessionImpl.cpp to avoid
   some -WError issues due to some static inline functions being defined in a
   header but not used in the rest of the compilation unit.

Differential Revision: https://phabricator.services.mozilla.com/D60327

--HG--
extra : moz-landing-system : lando
2020-01-20 16:19:48 +00:00
Emilio Cobos Álvarez
aa3a695712 Bug 1609996 - Remove mozilla/Move.h. r=froydnj
rg -l 'mozilla/Move.h' | xargs sed -i 's/#include "mozilla\/Move.h"/#include <utility>/g'

Further manual fixups and cleanups to the include order incoming.

Differential Revision: https://phabricator.services.mozilla.com/D60323

--HG--
extra : moz-landing-system : lando
2020-01-20 16:18:20 +00:00
Emilio Cobos Álvarez
5cd5e6f148 Bug 1609996 - Remove mozilla::Swap in favor of std::swap. r=froydnj
Now mfbt/Move.h is empty except for that excellent comment about move
semantics... Should we put it somewhere else and delete the header as a
follow-up? Or just delete the header and carry on?

Differential Revision: https://phabricator.services.mozilla.com/D60297

--HG--
extra : moz-landing-system : lando
2020-01-20 16:17:06 +00:00
Cosmin Sabou
5057d205bc Backed out changeset 310c4bf09003 (bug 1604585) for build bustages on ReentrancyGuard.h 2019-12-17 20:58:26 +02:00
Emilio Cobos Álvarez
54fad3fb32 Bug 1604585 - Remove HashTable::mEntered, as it is write-only. r=froydnj
And while at it, initialize mMutationCount in the declaration, to remove an
ugly ifdef block.

Differential Revision: https://phabricator.services.mozilla.com/D57506

--HG--
extra : moz-landing-system : lando
2019-12-17 18:45:27 +00:00
Emilio Cobos Álvarez
61a790403f Bug 1604574 - Fix HashTable move constructor, and remove silly ifdefs. r=froydnj
Also add a test for the hash table, because we seem to have zero of them :(

Call clearAndCompact() so that we get minimum capacity on re-growth.

Differential Revision: https://phabricator.services.mozilla.com/D57501

--HG--
extra : moz-landing-system : lando
2019-12-17 18:36:58 +00:00
Miko Mynttinen
3d352aa73a Bug 1601483 - Avoid HashTable lookups when the table is empty r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D55882

--HG--
extra : moz-landing-system : lando
2019-12-17 18:01:42 +00:00
Noemi Erli
383f77dead Backed out changeset 642c6ef227f1 (bug 1601483) for causing assertion in HashTable.h CLOSED TREE 2019-12-05 15:31:06 +02:00
Miko Mynttinen
47dde82de0 Bug 1601483 - Avoid HashTable lookups when the table is empty r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D55882

--HG--
extra : moz-landing-system : lando
2019-12-05 01:57:22 +00:00
Jeff Walden
b7e760c953 Bug 1590907 - Use a static assert in HashTable that doesn't depend on configure. r=sfink
Differential Revision: https://phabricator.services.mozilla.com/D53921

--HG--
extra : moz-landing-system : lando
2019-11-25 21:55:56 +00:00
Jeff Walden
7d74f15a31 Bug 1592325 - Fix an unsigned-integer underflow in HashTable.h that's super-easy to trigger using affirmatively wrapping operations. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D50960

--HG--
extra : moz-landing-system : lando
2019-10-29 16:42:15 +00:00
Sylvestre Ledru
e77bfc655d Bug 1519636 - Reformat recent changes to the Google coding style r=Ehsan
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D38057

--HG--
extra : moz-landing-system : lando
2019-07-16 07:33:44 +00:00
Jon Coppeard
26039d2f3b Bug 1561866 - Refactor HashTable move constructor/assignment operator as per review comments, missed from previous push r=jwalden 2019-07-02 10:55:29 +01:00
Jon Coppeard
afdba4e113 Bug 1561866 - Move alloc policies where possible r=jwalden
Patch to use std::move when passing AllocPolicy instances to constructors. This also fixes HashTable move constuction/assignment that previously PodAssigned the whole object including the AllocPolicy base.

Differential Revision: https://phabricator.services.mozilla.com/D36175
2019-06-27 11:56:26 +01:00
Sylvestre Ledru
d57d4905f1 Bug 1519636 - Reformat recent changes to the Google coding style r=Ehsan
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D30883

--HG--
extra : moz-landing-system : lando
2019-05-25 17:46:15 +00:00
arthur.iakab
af8e458c5f Backed out changeset a296439a25ff (bug 1519636) for frequent Windows cppunit failures CLOSED TREE 2019-05-24 14:26:01 +03:00
Sylvestre Ledru
c82ea97226 Bug 1519636 - Reformat recent changes to the Google coding style r=Ehsan
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D30883

--HG--
extra : moz-landing-system : lando
2019-05-24 09:59:17 +00:00
Jon Coppeard
dd429306b0 Bug 1550009 - Make HashTable call templated alloc/free methods with the same type r=froydnj?
Differential Revision: https://phabricator.services.mozilla.com/D30371

--HG--
extra : moz-landing-system : lando
2019-05-08 16:42:06 +00:00
Coroiu Cristina
716cbf554c Backed out 2 changesets (bug 1257982) for build bustage at build/src/js/src/frontend/ParseContext.h on a CLOSED TREE
Backed out changeset e73fdb7ff05d (bug 1257982)
Backed out changeset 13425f1eca22 (bug 1257982)
2019-03-19 10:35:21 +02:00
Steve Fink
c10602d229 Bug 1257982 - [hazards] Inherit template attrs for plain HashMap/HashSet r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D23619

--HG--
extra : moz-landing-system : lando
2019-03-18 21:37:04 +00:00
Nicholas Nethercote
f476546aaa Bug 1530311 - Add a length check to HashTable::reserve(). r=luke
Also add an assertion to a similar function in PLDHashTable.cpp.

Differential Revision: https://phabricator.services.mozilla.com/D21167

--HG--
extra : moz-landing-system : lando
2019-02-27 00:08:13 +00:00
Nathan Froyd
0c1169eedc Bug 1508873 - part 3 - reorganize HashTable's internal storage; r=luke
As discussed in the previous commit message, HashTableEntry wastes space
for common entry types.  This commit reorganizes the internal storage to
store all the hashes packed together, followed by all the entries, which
eliminates the aforementioned waste.
2018-12-13 12:21:19 -05:00
Nathan Froyd
6b20e36d68 Bug 1508873 - part 2 - convert HashTable to work primarily in terms of slots; r=luke
HashTableEntry's data layout currently wastes a fair amount of space due
to ABI-mandated padding.  For instance, HashTableEntry<T*> on a 64-bit
platform looks like:

class HashTableEntry {
  HashNumber mKeyHash;
  // Four bytes of wasted space here to pad mValueData to the correct place.
  unsigned char mValueData[sizeof(T*)];
};

This wasted space means that sets of pointers backed by
mozilla::HashTable waste a quarter of their entry storage space.  Maps
of pointers to pointers waste a sixth of their entry storage space.
We'd like to fix this by packing all the cached hashes together,
followed by all the hash table entries.

As a first step to laying out the hash table storage differently, we
have to make HashTable not access entries directly, but go through an
abstraction that represents the key and the entry.  We call this
abstraction "slots".  This commit is similar to the change done for
PLDHashTable previously.

Parts of HashTable still work in terms of Entry; the creation and
destruction of tables was not worth changing here.  We'll address that
in the next commit.
2018-12-13 12:21:19 -05:00
Nathan Froyd
1d59bcc108 Bug 1508873 - part 1 - statically assert alignment for hashtable entries; r=luke
We do this to make our lives easier in later patches; this check
guarantees that we don't need padding between the block of cached hash
values and the block of entries immediately after it.
2018-12-13 12:21:19 -05:00
Cosmin Sabou
46fe1d73a2 Backed out 3 changesets (bug 1508873) for spidermonkey build bustages. CLOSED TREE
Backed out changeset a356b2566ae2 (bug 1508873)
Backed out changeset 4bb5dd072865 (bug 1508873)
Backed out changeset a6657732fdbe (bug 1508873)
2018-12-12 22:09:30 +02:00
Nathan Froyd
ba32deb674 Bug 1508873 - part 3 - reorganize HashTable's internal storage; r=luke
As discussed in the previous commit message, HashTableEntry wastes space
for common entry types.  This commit reorganizes the internal storage to
store all the hashes packed together, followed by all the entries, which
eliminates the aforementioned waste.
2018-12-12 14:57:21 -05:00
Nathan Froyd
27902c8e43 Bug 1508873 - part 2 - convert HashTable to work primarily in terms of slots; r=luke
HashTableEntry's data layout currently wastes a fair amount of space due
to ABI-mandated padding.  For instance, HashTableEntry<T*> on a 64-bit
platform looks like:

class HashTableEntry {
  HashNumber mKeyHash;
  // Four bytes of wasted space here to pad mValueData to the correct place.
  unsigned char mValueData[sizeof(T*)];
};

This wasted space means that sets of pointers backed by
mozilla::HashTable waste a quarter of their entry storage space.  Maps
of pointers to pointers waste a sixth of their entry storage space.
We'd like to fix this by packing all the cached hashes together,
followed by all the hash table entries.

As a first step to laying out the hash table storage differently, we
have to make HashTable not access entries directly, but go through an
abstraction that represents the key and the entry.  We call this
abstraction "slots".  This commit is similar to the change done for
PLDHashTable previously.

Parts of HashTable still work in terms of Entry; the creation and
destruction of tables was not worth changing here.  We'll address that
in the next commit.
2018-12-12 14:57:21 -05:00
Nathan Froyd
05c72d126b Bug 1508873 - part 1 - statically assert alignment for hashtable entries; r=luke
We do this to make our lives easier in later patches; this check
guarantees that we don't need padding between the block of cached hash
values and the block of entries immediately after it.
2018-12-12 14:57:21 -05:00
Sylvestre Ledru
265e672179 Bug 1511181 - Reformat everything to the Google coding style r=ehsan a=clang-format
# ignore-this-changeset

--HG--
extra : amend_source : 4d301d3b0b8711c4692392aa76088ba7fd7d1022
2018-11-30 11:46:48 +01:00
Nathan Froyd
213e4e231d Bug 1509927 - use a little more KnownNotNull placement new in MFBT; r=njn
This change avoids some useless null checks.
2018-11-26 18:51:35 -05:00
Nicholas Nethercote
de3b7e3af9 Bug 1483182 - Do report OOM failures in HashTable::reserve(). r=luke
This fixes a typo.

--HG--
extra : rebase_source : bc5d5eaa187797aa1167790c2bddd2db2110bf01
2018-08-21 19:07:20 +10:00
Nicholas Nethercote
d4f517f3e2 Bug 1483182 - Don't allocate in HashTable::lookupOrAdd(). r=luke
Currently lookupOrAdd() will allocate if the table has no storage. But it
doesn't report an error if the allocation fails, which can cause problems.

This patch changes things so that lookupOrAdd() doesn't allocate when the table
has no storage. Instead, it returns an AddPtr that is not *valid* (its mTable
is empty) but it is *live*, and can be used in add(), whereupon the allocation
will occur.

The patch also makes Ptr::isValid() and AddPtr::isValid() non-public, because
the valid vs. live distinction is non-obvious and best kept hidden within the
classes.

--HG--
extra : rebase_source : 95d58725d92cc83332e27a61f98fa61185440e26
2018-08-21 13:49:17 +10:00
Nicholas Nethercote
2b8aa56d1e Bug 1483062 - Trivial comment fixes. r=me
--HG--
extra : rebase_source : 81beeb90397bc6dbfac21b3e0adccaf63978f437
2018-08-16 09:45:44 +10:00
Nicholas Nethercote
70253e2770 Bug 1483062 - Inline and remove HashTable::{over,under}loaded(). r=luke
Because they each only have a single call site, and the "too many items
removed?" test is already encapsulated within rehashIfOverloaded().

--HG--
extra : rebase_source : f6550c483477c2839764e7f657b542c24c82b1e8
2018-08-16 09:10:17 +10:00
Nicholas Nethercote
14551e3f43 Bug 1483062 - Merge HashTable::wouldBeUnderloaded() into underloaded(). r=luke
--HG--
extra : rebase_source : ed0ecbc871048b416452a7612991bcff98c91a06
2018-08-15 11:11:13 +10:00
Nicholas Nethercote
1c305db7ce Bug 1483062 - Inline and remove HashTable::overRemoved(). r=luke
--HG--
extra : rebase_source : c7dbdbe38bf0f44f27bda7f134bbf0d865149200
2018-08-15 11:10:56 +10:00
Nicholas Nethercote
eb0a51a708 Bug 1483062 - Rename HashTable::rehashIfOverRemoved(). r=luke
infallibleRehashIfOverloaded() actually matches what it does.

Also, the patch removes the `overloaded()` test within the function, because
`rehashIfOverloaded()` has the same test.

--HG--
extra : rebase_source : 2799e623fbdd4b8bb82f8b83166752e02a0f9202
2018-08-14 11:56:55 +10:00
Nicholas Nethercote
d12003b7e5 Bug 1483062 - Rename some HashTable methods. r=luke
Specifically:
- checkOverloaded  -> rehashIfOverloaded
- checkUnderloaded -> shrinkIfUnderloaded
- checkOverRemoved -> rehashIfOverRemoved

Because I've always found that the `check` prefix doesn't clearly explain that
the table might be changed,

And:
- shouldCompressTable -> overRemoved

Because that matches `overloaded` and `underloaded`.

--HG--
extra : rebase_source : 56e9edd012f4a400ac366895d05ea93fb09ec6b3
2018-08-14 11:19:39 +10:00
Nicholas Nethercote
d378adb5b7 Bug 1483062 - Rename HashTable::findFreeEntry() as findNonLiveEntry(). r=luke
Because that's a more accurate description of what it does -- it finds free
*and* removed entries.

--HG--
extra : rebase_source : 72b049f44c61a7406d9691a9d9b6405dd696848c
2018-08-14 09:36:00 +10:00
Nicholas Nethercote
44dd70d7d6 Bug 1483062 - Remove HashTable::maybeCreateTable. r=luke
It's dead.

--HG--
extra : rebase_source : c1a6aca3340c09cbe5e9f3ac9a5ea1ae5901ea4e
2018-08-09 14:19:49 +10:00
Nicholas Nethercote
b9e071e2e8 Bug 1481998 - Make mozilla::Hash{Map,Set}'s entry storage allocation lazy. r=luke,sfink
Entry storage allocation now occurs on the first lookupForAdd()/put()/putNew().
This removes the need for init() and initialized(), and matches how
PLDHashTable/nsTHashtable work. It also removes the need for init() functions
in a lot of types that are built on top of mozilla::Hash{Map,Set}.

Pros:

- No need for init() calls and subsequent checks.

- No memory allocated for empty tables, which are not that uncommon.

Cons:

- An extra branch in lookup() and lookupForAdd(), but not in put()/putNew(),
  because the existing checkOverloaded() can handle it.

Specifics:

- Construction now can take a length parameter.

- init() is removed. Explicit length-setting, when necessary, now occurs in the
  constructors.

- initialized() is removed.

- capacity() now returns zero when the entry storage is absent.

- lookupForAdd() is no longer `const`, because it can instantiate the storage,
  which requires modifications.

- lookupForAdd() can now return an invalid AddPtr in two cases:

  - old: hashing failure (due to OOM in the hasher)

  - new: OOM while instantiating entry storage

  The existing failure handling paths for the old case work for the new case.

- clear(), finish(), and clearAndShrink() are replaced by clear(), compact(),
  and reserve(). The old compactIfUnderloaded() is also removed.

- Capacity computation code is now in its own functions, bestCapacity() and
  hashShift(). setTableSizeLog2() is removed.

- uint32_t is used throughout for capacities, instead of size_t, for
  consistency with other similar values.

- changeTableSize() now takes a capacity instead of a deltaLog2, and it can now
  handle !mTable.

Measurements:

- Total source code size is reduced by over 900 lines. Also, lots of existing
  lines got shorter (i.e. two checks were reduced to one).

- Executable size barely changed, down by 2 KiB on Linux64. The extra branches
  are compensated for by the lack of init() calls.

- Speed changed negligibly. The instruction count for Bench_Cpp_MozHash
  increased from 2.84 billion to 2.89 billion but any execution time change was
  well below noise.
2018-08-10 18:00:29 +10:00
Nicholas Nethercote
a04c29f828 Bug 1481998 - Define lookup() in terms of readonlyThreadsafeLookup(). r=luke
The two functions are almost identical. This change minimizes duplication.

--HG--
extra : rebase_source : 08bb79d21084eec63702525ce6179e22686bec5c
2018-08-10 15:35:13 +10:00
Nicholas Nethercote
dcd7d4327c Bug 1481138 - Clarify that Hash{Map,Set}::putNew() can be used if elements have been removed. r=luke
Hash{Map,Set}::putNew() can be used on a table that has had elements removed,
despite some comments to the contrary.

This patch fixes those comments. It also clarifies when putNewInfallible() can
be used.

This patch also removes the !isRemoved() assertion in findFreeEntry(), which is
confusing -- !isLive() would be more precise, but also obvious from the
surrounding code.

MozReview-Commit-ID: q4qwKGBsHx

--HG--
extra : rebase_source : 94331879f9a1484159e030de93bd0ab222b54385
2018-08-06 12:01:28 +10:00