Граф коммитов

47 Коммитов

Автор SHA1 Сообщение Дата
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
Nicholas Nethercote 46db021929 Bug 1481138 - Remove HashMap::lookupWithDefault(). r=luke
Because it's quite strange, badly named, not that useful, and barely used.

Also remove WeakMap::lookupWithDefault(), which is similar, but not used at
all.

MozReview-Commit-ID: IhIl4hQ73U1

--HG--
extra : rebase_source : 7da237a56391836ca5d056248f18bd5e2d8b1564
2018-08-06 09:45:38 +10:00
Nicholas Nethercote d9eb003725 Bug 1481138 - Remove the add() variant in HashTable and GCHashTable that uses a default value. r=luke
Because (a) it's kinda weird, and (b) only used in a single test, where it can
be easily replaced with a vanilla add().

MozReview-Commit-ID: L4RoxFb7yGG

--HG--
extra : rebase_source : 515a5ede5d417686907345ad9069c6a41669dd17
2018-08-06 09:10:05 +10:00
Nicholas Nethercote e39fda4c40 Bug 1480668 - Remove js::CStringHashPolicy. r=luke
It's identical to mozilla::CStringHasher.

Also fix a comment at the top of HashTable.h about CStringHasher.

--HG--
extra : rebase_source : 92176c4f6ea8041f309764b4ce0271a494853a7b
2018-08-06 07:55:50 +10:00
Nicholas Nethercote 7b988956cc Bug 1480650 - Remove mozilla::HashTable::Stats. r=luke
I bet nobody has used them in years. The use of ad hoc profiling (printfs plus
post-processing with a tool like https://github.com/nnethercote/counts) is
generally a better approach.

Bug 1179657 did likewise for PLDHashTable.

--HG--
extra : rebase_source : 57ab26c62f2f1eff2eec827564a3c3ff0af12f01
2018-08-03 11:59:26 +10:00
Nicholas Nethercote 5c9b1f5c39 Bug 1480323 - Reorder methods in Hash{Set,Map}. r=luke
And add comments delimiting different operation groups. Together these changes
make Hash{Set,Map} much easier to navigate.

--HG--
extra : rebase_source : 21a7da92f898b318a24085b5f0885da85aa3afd1
2018-08-03 10:25:29 +10:00
Nicholas Nethercote 088ecf7be1 Bug 1480361 - Introduce HashTable::LookupReason. r=luke
Again inspired by PLDHashTable, this makes things a bit clearer than passing 0
or sCollisionBit.

It also guarantees more strongly that we'll end up with appropriately
specialized code for the Add vs. NonAdd cases. (That guarantee isn't currently
needed because the compiler inlines things sufficiently anyway, but it can't
hurt.)

--HG--
extra : rebase_source : c2341d7df85f44a00bd1b52eac0e08ac63525196
2018-08-03 10:03:37 +10:00
Nicholas Nethercote 7cb8d52236 Bug 1480361 - Tweak handling of removed entries in HashTable::lookup(). r=luke
There are two improvements here.

- When we're just doing a lookup (i.e. aCollisionBit==0), we don't need to
  do any special handling of removed entries. (Inlining means that the removed
  entry code is entirely removed for lookups.)

- When we're doing an insertion (i.e. aCollisionBit==sCollisionBit), we now
  stop adding collision markings once we find a removed entry, because they're
  unnecessary after that point.

This change brings the code in alignment with PLDHashTable::SearchTable().

--HG--
extra : rebase_source : 8d6e3a88ac24d0e71a2576997face3bea971c71f
2018-08-03 10:03:31 +10:00
Nicholas Nethercote da4f2681a4 Bug 1478885 - Improve docs for mozilla::Hash{Set,Map}. r=luke
This patch does the following:

- Adds a bunch of useful high-level info at the top of the file, making the
  types easier to use for newcomers.

- Adds a comment to every Hash{Set,Map} method that lacked one.

- Tweaks lots of existing comments for clarity.

- Removes comments in Hash{Set,Map} referring to details within HashTable. That
  dependence is now covered in the top-level comment.

- Tweaks the signatures in hash policy classes to be more consistent.

--HG--
extra : rebase_source : ab9d6ae38b4b73e12151a228107ad3f3f12e36b3
2018-08-03 06:33:21 +10:00
Nicholas Nethercote 95ed5dcb6d Bug 1478879 - Define Range/Enum in terms of Iterator/ModIterator. r=luke
To reduce the code duplication.

--HG--
extra : rebase_source : fb14664f766fc51012e31e626b6313f10b69e9dc
2018-07-31 10:23:03 +10:00
Nicholas Nethercote aea3d9d133 Bug 1478879 - Introduce Iterator and ModIterator in HashTable.h. r=luke
These basically duplicate the existing Range and Enum classes, but use more
familiar terminology, similar to the iterators we have for
PLDHashTable/nsTHashtable:

- Hash{Set,Map}::all()  Hash{Set,Map}::iter()
- Enum constructor      Hash{Set,Map}::modIter()
- Range::front()        Iterator::get()
- Range::popFront()     Iterator::next()
- Range::empty()        Iterator::done()
- Enum::mutableFront()  ModIterator::getMutable()
- Enum::removeFront()   ModIterator::remove()
- Enum::rekeyFront()    ModIterator::rekey()

The next patch will reduce the amount of code duplication.

--HG--
extra : rebase_source : 5787756b144bbaea98f381d5a128cb42edb82c41
2018-07-27 12:17:37 +10:00
Nicholas Nethercote f97954cf65 Bug 1478879 - Remove zero-arg constructor for Range. r=luke
It's only used by InlineTable::Range, and can be avoided by using
mozilla::Maybe.

This also means Range::mTable can be changed from a pointer to a reference,
like Enum::mTable.

--HG--
extra : rebase_source : 35eb5b0bede361c2c765652e1e4c952f128702ef
2018-07-31 10:23:03 +10:00
Nicholas Nethercote 6141e31ef4 Bug 1479954 - Rename Hash{Set,Map}::sizeOf{In,Ex}cludingThis(). r=luke
In PLDHashTable the equivalent functions have a "Shallow" prefix, which makes
it clear that they don't measure things hanging off the table. This patch makes
mozilla::Hash{Set,Map} do likewise.

MozReview-Commit-ID: 3kwCJynhW7d

--HG--
extra : rebase_source : 9c03d11f376a9fd4cfd5cfcdc0c446c00633b210
2018-08-01 09:57:52 +10:00
Nicholas Nethercote e0dbe1b052 Bug 1478896 - Fix HashTable.h style. r=froydnj
This patch converts HashTable.h from SpiderMonkey style to Gecko style.

It was created by first running `./mach clang-format -p mfbt/HashTable.h` to
fix the whitespace, and then doing manual patch-ups, the most significant of
which were:

- Adding braces around single-statement if/else/for/while blocks.

- Renaming class members to `mFoo` form and arguments to `aFoo` form.

- Converting `typedef Old New` to `using New = Old` throughout.

MozReview-Commit-ID: LJ1emPyuAjK
2018-07-31 13:39:31 +10:00
Nicholas Nethercote 234016c13e Bug 1477626 - Document some differences between mozilla::HashTable and PLDHashTable. r=Waldo
MozReview-Commit-ID: DB0KUy99DDM

--HG--
extra : rebase_source : 4d14c47c48cb821f6c69654c1c5d90c48f217e48
2018-07-26 20:15:55 +10:00
Nicholas Nethercote b85493f609 Bug 1477626 - Move js::Hash{Set,Map} into MFBT. r=Waldo
The main change is that the patch copies js/public/HashTable.h to
mfbt/HashTable.h, and then changes it as follows.

- Changes `js` namespaces to `mozilla` (and removes some now-unnecessary
  `mozilla::` qualifiers).

- Changes the default AllocPolicy from the SpiderMonkey-specific
  `TempAllocPolicy` to the generic `MallocAllocPolicy`.

- Adds `#include "AllocPolicy.h"` (like mfbt/Vector.h).

- Changes `JS_DEBUG` use to `DEBUG`.

- Minor comment updates, as necessary.

js/public/HashTable.h is now tiny, holding just a few renamings of things from
the `mozilla` namespace into the `js` namespace to minimize churn elsewhere.
(Those renamings keep `TempAllocPolicy` as the default AllocPolicy for
js::Hash{Set,Map}.)

Also, various template specializations had to be moved from the `js` namespace
to the `mozilla` namespace to avoid compile errors.

MozReview-Commit-ID: GS9Qn9YeYDA

--HG--
rename : js/public/HashTable.h => mfbt/HashTable.h
2018-07-26 20:15:49 +10:00