TLS and other features will need an array implementation. We can take
the one from PHC rename it and move it to a new header file.
Differential Revision: https://phabricator.services.mozilla.com/D279246
`mozilla::IsPowerOfTwo` is used in more code than the previous functions, so split
up the updates in three parts. This part updates non-SpiderMonkey code to use
`std::has_single_bit`. The next part updates SpiderMonkey code and the last part
finally removes `mozilla::IsPowerOfTwo`.
Differential Revision: https://phabricator.services.mozilla.com/D286320
This reverts commit eb884a9f65.
Revert "Bug 2020608 - Part 16: Use std::bit_ceil for RoundUpPow2. r=sergesanspaille"
This reverts commit 35a310aa8a.
Revert "Bug 2020608 - Part 15: Require unsigned integral types for CeilingLog2 and FindMostSignificantBit. r=sergesanspaille,nbp"
This reverts commit f682901ca2.
Revert "Bug 2020608 - Part 14: Remove mozilla::IsPowerOfTwo. r=sergesanspaille"
This reverts commit b998e4bd39.
Revert "Bug 2020608 - Part 13: Replace IsPowerOfTwo with std::has_single_bit in js/. r=sergesanspaille"
This reverts commit 00db5e1f32.
Revert "Bug 2020608 - Part 12: Replace IsPowerOfTwo with std::has_single_bit outside of js/. r=sergesanspaille,profiler-reviewers,win-reviewers,gstoll,canaltinova"
This reverts commit cec056f5d6.
Revert "Bug 2020608 - Part 11: Simplify PowerOfTwo. r=sergesanspaille,profiler-reviewers,canaltinova"
This reverts commit a2ee5b9053.
Revert "Bug 2020608 - Part 10: Prefer std::bit_width in MathAlgorithms.h. r=sergesanspaille"
This reverts commit 89d966bb97.
Revert "Bug 2020608 - Part 9: Prefer std::bit_width instead of std::countl_zero in js/src. r=sergesanspaille"
This reverts commit da9a43075a.
Revert "Bug 2020608 - Part 8: Replace CountTrailingZeroes with std::countr_zero. r=sergesanspaille"
This reverts commit d77ca273cb.
Revert "Bug 2020608 - Part 7: Replace CountLeadingZeroes32 with std::countl_zero or std::countl_one. r=sergesanspaille,nbp,profiler-reviewers,canaltinova"
This reverts commit 94929ae729.
Revert "Bug 2020608 - Part 6: Replace CountLeadingZeroes64 with std::countl_zero. r=sergesanspaille,profiler-reviewers,canaltinova"
This reverts commit 9b428168df.
Revert "Bug 2020608 - Part 5: Replace CountTrailingZeroes32 with std::countr_zero. r=sergesanspaille,manuel"
This reverts commit d3e77036b2.
Revert "Bug 2020608 - Part 4: Replace CountTrailingZeroes64 with std::countr_zero or std::countr_one. r=sergesanspaille"
This reverts commit 6a7bcee10e.
Revert "Bug 2020608 - Part 3: Replace CountPopulation32 with std::popcount. r=sergesanspaille"
This reverts commit e7b204177b.
Revert "Bug 2020608 - Part 2: Replace CountPopulation64 with std::popcount. r=sergesanspaille"
This reverts commit 1d6f98a622.
Revert "Bug 2020608 - Part 1: Add <bit> C++20 definitions to std.py. r=sergesanspaille"
This reverts commit 3ee4c6dcab.
`mozilla::IsPowerOfTwo` is used in more code than the previous functions, so split
up the updates in three parts. This part updates non-SpiderMonkey code to use
`std::has_single_bit`. The next part updates SpiderMonkey code and the last part
finally removes `mozilla::IsPowerOfTwo`.
Differential Revision: https://phabricator.services.mozilla.com/D286320
With page size limited to 4KiB and the quantum-wide class covering the
range from 512 bytes to 4KiB, the sub-page size class is unused and can
be removed.
Differential Revision: https://phabricator.services.mozilla.com/D259220
With page size limited to 4KiB and the quantum-wide class covering the
range from 512 bytes to 4KiB, the sub-page size class is unused and can
be removed.
Differential Revision: https://phabricator.services.mozilla.com/D259220
The size of PHC's allocation area is now set when the metadata is
created. The kNumAllocPages symbol is removed, instead a new
NumAllocPages() function will return the length of the AllocInfo array.
The array is protected by the PHC lock so now getting the true size
of the PHC area (rather than the virtual memory reservation that it's
inside) can only be done while holding the lock. Checking the index of
an allocation during free() against the upper bound is now down after
taking the lock.
Differential Revision: https://phabricator.services.mozilla.com/D254944
PHC's metadata size is defined at compile-time. To relax this to
runtime we need to use a different array implementation that stores the
size in a member variable, rather than a template parameter.
Refactor how metadata size is calculated since it must capture the size
of this array. Separate methods like FragmentationBytes() and
AllocationBytes() have been merged to get a consistent read by taking
the lock only once.
Differential Revision: https://phabricator.services.mozilla.com/D254943
To allow the PHC arena size to be dynamic the reserved memory range may
be larger than the actual memory allocated by PHC. To keep the fast-path
as fast as possible this patch replaces the initial PtrKind() query with a
bounds check. The bounds check can be done without a lock. A later
step will determine the PtrKind.
* Use a bounds check on the hot path for free, realloc and other
functions that take a pointer, before calling the corresponding PHC::
methods.
* The PHC method must assume it has a pointer that is in-bounds, but it
can determine the kind of the pointer with GetPtrKind().
* Remove the Nothing PtrKind since it previously represented
out-of-bounds pointers.
* Add branch annotations on the hot paths.
Differential Revision: https://phabricator.services.mozilla.com/D253289
A lot of code from outside the PHC class accesses data/methods within it
through the sPHC global. Instead move this code into the PHC class.
Some functions can be moved directly, others are split up and part of
them is moved.
* Move functions into the PHC class
* Move ReuseDelay into the class definition.
* Merge MaybePageRealloc into its caller.
* Separate moalloc_usable_size into two so the latter half can go into
the PHC class
Differential Revision: https://phabricator.services.mozilla.com/D252476
This was previously a macro, making it a function allows us to
forward-declare it and write the implementation later in the file.
Differential Revision: https://phabricator.services.mozilla.com/D252474
This new method collects less information and also does not need to lock
arenas to access their stats. It may be used on any thread.
The main thread only arenas thread-safety rules have become more complex and
I've added a comment to explain what is safe.
Differential Revision: https://phabricator.services.mozilla.com/D225942
The Arena ID is wrapped in a Maybe, the construction of Nothing() shows up
in profiles. By testing the maybe we show the compiler that it can optimise
away the construction of Nothing when inlining this code.
Differential Revision: https://phabricator.services.mozilla.com/D207680
+ Move sNow into the PHC class and put it next to mMutex, they're
frequently modified together.
+ Reorganise PHC fields to place frequently-updated-together fields
together, and separate them from the seldom-updated fields.
+ The only static fields remaining are write-once.
Differential Revision: https://phabricator.services.mozilla.com/D210468
This change optimises the PHC hot path by reducing updates to sAllocDelay
and sNow:
* tlsAllocDelay has been created to create thread-local allocation delays,
when they expire then the shared sAllocDelay is checked.
* sNow is updated only when not executing the fast path.
This change also:
* Previously the thread that saw sAllocDelay == 0 would be the one to make
the allocation, the ReleaseAquire semantics ensured that exactly one
thread would see this. Now all threads that see sAllocDelay <= 0 will
attempt a PHC allocation, this is later checked by atomically resetting
sAllocDelay.
* Removes the logic that checks if the delay has wrapped
while PHC was disabled on the current thread. This isn't needed anymore
because we now make PHC allocations for all sAllocDelay < 0, assuming
that threads are disabled for less than UINT32_MAX/2 allocations.
* Moves ShouldMakeNewAllocations out of the hot-path.
Differential Revision: https://phabricator.services.mozilla.com/D206469
This patch co-locates mMutex with the data it protects and is accessed
together. It was previously located with global write-once data and updates
to `sMutex` were caused cache misses for `sPHC`.
Making `mMutex` a member variable also makes sense conceptually.
Differential Revision: https://phabricator.services.mozilla.com/D210466