Commit Graph
77 Commits
Author SHA1 Message Date
Paul Bone 1879025654 Bug 2014781 - Restore the sub-page size class r=glandium
This reverts Bug 1980056 part 6.

Differential Revision: https://phabricator.services.mozilla.com/D297237
2026-05-31 23:27:24 +00:00
Silaghi 688b962a0b Revert "Bug 2014781 - gPageSize follows gRealPageSize r=glandium" for causing mochitests failures at toolkit/content
This reverts commit 3c629953cf.

Revert "Bug 2014781 - Restore the sub-page size class r=glandium"

This reverts commit 606f7ea614.
2026-05-14 07:39:36 +00:00
Paul Bone 606f7ea614 Bug 2014781 - Restore the sub-page size class r=glandium
This reverts Bug 1980056 part 6.

Differential Revision: https://phabricator.services.mozilla.com/D297237
2026-05-14 03:15:33 +00:00
Paul Bone a9d015d3b8 Bug 2023471 - Move the array implementation to a new header r=glandium
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
2026-04-15 05:10:07 +00:00
Paul Bone 84251af3d5 Bug 2001241 - Allocation during PHC initalisation is fallible r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D275406
2026-04-14 09:00:12 +00:00
Paul Bone b45428c197 Bug 1976185 - PHC now uses BaseAlloc r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D270991
2026-04-13 01:45:03 +00:00
Sylvestre Ledru f7691d9032 Bug 2023419 - Remove Emacs/Vim modelines from memory/ r=emilio
replaced by .editorconfig
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D287854
2026-03-17 12:05:51 +00:00
André Bargull 22f5b5c7c5 Bug 2020608 - Part 12: Replace IsPowerOfTwo with std::has_single_bit outside of js/. r=sergesanspaille,profiler-reviewers,win-reviewers,gstoll,canaltinova
`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
2026-03-14 14:08:50 +00:00
Atila Butkovits 3578df2975 Revert "Bug 2020608 - Part 17: Use std::rot[lr] for Rotate(Left|Right). r=sergesanspaille" for causing bustages at PowerOfTwo.h.
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.
2026-03-13 21:11:22 +00:00
André Bargull cec056f5d6 Bug 2020608 - Part 12: Replace IsPowerOfTwo with std::has_single_bit outside of js/. r=sergesanspaille,profiler-reviewers,win-reviewers,gstoll,canaltinova
`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
2026-03-13 20:20:10 +00:00
Paul Bone 2ec92a906e Bug 1980056 - pt 6. Remove the sub-page size class r=glandium
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
2026-02-03 04:14:10 +00:00
Paul Bone 4843c615e9 Bug 2003976 - Rename kPageSize in PHC r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D275030
2026-01-19 02:15:01 +00:00
agoloman 15e87a3496 Revert "Bug 1980056 - pt 2. Remove the sub-page size class r=glandium" for causing Bug 2010505.
This reverts commit 784e006a34.

Revert "Bug 1980056 - pt 1. Limit logical page size to 4KiB r=glandium"

This reverts commit 01d083e3c6.
2026-01-16 04:20:26 +00:00
agoloman 12693ddc87 Revert "Bug 2003976 - Rename kPageSize in PHC r=glandium" for causing conflicts.
This reverts commit 9c94bc6162.
2026-01-16 04:18:15 +00:00
Paul Bone 9c94bc6162 Bug 2003976 - Rename kPageSize in PHC r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D275030
2026-01-16 01:12:23 +00:00
Paul Bone 784e006a34 Bug 1980056 - pt 2. Remove the sub-page size class r=glandium
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
2026-01-15 03:30:13 +00:00
Paul Bone 9451691a42 Bug 1969856 - Limit PHC to 128MB of virtual address space r=gsvelto
Differential Revision: https://phabricator.services.mozilla.com/D273369
2025-11-26 02:49:15 +00:00
Atila Butkovits c9b2937147 Revert "Bug 1969856 - Limit PHC to 128MB of virtual address space r=gsvelto" for causing Gtest failures.
This reverts commit fc3765bf0b.
2025-11-24 02:42:42 +00:00
Paul Bone fc3765bf0b Bug 1969856 - Limit PHC to 128MB of virtual address space r=gsvelto
Differential Revision: https://phabricator.services.mozilla.com/D273369
2025-11-24 01:44:31 +00:00
Paul Bone 4dcb947682 Bug 1993227 - Reserve the PHC memory range without allocating RAM r=glandium DONTBUILD
Differential Revision: https://phabricator.services.mozilla.com/D272117
2025-11-18 00:57:32 +00:00
Paul Bone df01e8e26d Bug 1974931 - Initialise PHC from mozjemalloc r=glandium
Call phc_init() from mozjemallocs init_hard() function.  This simpifies
PHC's own checks.

Differential Revision: https://phabricator.services.mozilla.com/D254945
2025-10-02 00:22:07 +00:00
Paul Bone 8d63f4b969 Bug 1867191 - pt 4. Add support for growing PHC's storage r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D255073
2025-09-30 07:08:39 +00:00
Paul Bone d678b8623c Bug 1867191 - pt 3. PHC's size is no-longer fixed at compile time r=glandium
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
2025-09-30 07:08:35 +00:00
Paul Bone 0f5c7ab776 Bug 1867191 - pt 2. Use a custom array implementation for PHC's metadata r=glandium
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
2025-09-30 07:08:31 +00:00
Paul Bone 2f19e759a8 Bug 1867191 - pt 1. Changes to PHC pointer tests r=glandium
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
2025-09-30 07:08:28 +00:00
Paul Bone 114976a21f Bug 1967689 - pt 14. Use FastIsPHCPtr in more places r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D254483
2025-06-26 07:07:22 +00:00
Paul Bone 7b59f77af9 Bug 1967689 - pt 13. AllocVirtualAddresses can fail gracefully r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D253771
2025-06-26 07:07:18 +00:00
Paul Bone f306a05c62 Bug 1967689 - pt 12. Remove duplicate include r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D253770
2025-06-26 07:07:14 +00:00
Paul Bone a51600df5b Bug 1967689 - pt 11. Use mfbt/Array for PHC's page info r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D252803
2025-06-26 07:07:10 +00:00
Paul Bone 56035619e2 Bug 1967689 - pt 10. Move some locking responsability in PHC r=glandium
FragmentationBytes() and GetPageStats() now take the lock instead of
requiring their callers to do it.

Differential Revision: https://phabricator.services.mozilla.com/D252800
2025-06-26 07:07:07 +00:00
Paul Bone be83f650b5 Bug 1967689 - pt 9. Move more code into the PHC class r=glandium
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
2025-06-26 07:07:03 +00:00
Paul Bone 0284c1c2b6 Bug 1967689 - pt 8. Statically allocate PHC::sRegion r=glandium
This was a pointer to a class, making it a statically allocated class
avoids a dereference on the free() hot path.

Differential Revision: https://phabricator.services.mozilla.com/D250893
2025-06-26 07:06:59 +00:00
Paul Bone 8255d726b4 Bug 1967689 - pt 7. Make PHC's debug logging a function r=glandium
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
2025-06-26 07:06:56 +00:00
Paul Bone cea9a5efbe Bug 1967689 - pt 5. Use MOZ_REQUIRES lock annotations in PHC r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D250600
2025-06-26 07:06:48 +00:00
Paul Bone 1989d98c86 Bug 1967689 - pt 4. Move some code into new methods of AllocPageInfo r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D250413
2025-06-26 07:06:44 +00:00
Paul Bone 074fe97ce6 Bug 1967689 - pt 3. Move mFreeTime into AllocPageInfo r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D250599
2025-06-26 07:06:40 +00:00
Paul Bone 5bc69022a4 Bug 1967689 - pt 2. Move AllocPageInfo class definition r=glandium
Move this class to the top level.

Differential Revision: https://phabricator.services.mozilla.com/D250412
2025-06-26 07:06:37 +00:00
Paul Bone b3b936fe21 Bug 1967689 - pt 1. Fix a comment r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D250411
2025-06-26 07:06:33 +00:00
Paul Bone e09cb80c0c Bug 1967891 - Fix PHC_LOGGING compilation errors r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D250579
2025-05-27 06:39:00 +00:00
Paul Bone f2973aa9fb Bug 1806054 - pt 4. Add a jemalloc_stats_lite interface r=glandium
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
2025-01-08 03:15:54 +00:00
serge-sans-paille bcdc6064c3 Bug 1929263 - Use std::clamp instead of min/max chain in memory/build/PHC.cpp r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D227976
2024-11-06 10:13:48 +00:00
Paul Bone 3b05930730 Bug 1899464 - Use a free list to allocate PHC blocks r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D215731
2024-07-09 01:51:43 +00:00
Paul Bone 05e8e4870b Bug 1874022 - pt 14. Seperate arena and non-arena code paths in PHC r=glandium
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
2024-06-26 02:06:42 +00:00
Paul Bone 28602424cf Bug 1874022 - pt 13. Inline the hot path for free r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D214778
2024-06-26 02:06:42 +00:00
Paul Bone 2b1c6144d0 Bug 1874022 - pt 12. Inline the hot path from MaybePageAlloc r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D207678
2024-06-26 02:06:41 +00:00
Paul Bone f2daf476f2 Bug 1874022 - pt 11. Improve cache locality r=glandium
+ 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
2024-06-26 02:06:41 +00:00
Paul Bone 657ff4282a Bug 1874022 - pt 10. maybe_init() uses a single memory access r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D207677
2024-06-26 02:06:40 +00:00
Paul Bone 7147bad45d Bug 1874022 - pt 9. Reduce the cost of updating sAllocDelay r=glandium
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
2024-06-26 02:06:39 +00:00
Paul Bone d198549b49 Bug 1874022 - pt 8. Add a proof of lock argument to ResetRNG r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D210467
2024-06-26 02:06:39 +00:00
Paul Bone e18b3c884e Bug 1874022 - pt 7. Move the mutex to a member variable r=glandium
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
2024-06-26 02:06:39 +00:00