Commit Graph

1061 Commits

Author SHA1 Message Date
Mike Hommey
91ec9d43c0 Bug 1414155 - Replace size class related macros and constants. r=njn
Hopefully, this makes things a little clearer.

--HG--
extra : rebase_source : cc36c52bfb00bf1b46488e496eb524a9dc46a3e5
2017-11-03 10:10:50 +09:00
Mike Hommey
18e7756799 Bug 1414155 - Remove SIZE_INV values for QUANTUM_2POW_MIN < 4. r=njn
QUANTUM_2POW_MIN is exactly 4, and we are unlikely to ever make it
smaller. Also turn a MOZ_ASSERT into a static_assert, because it only
uses constants, and will fail if QUANTUM_2POW_MIN is lowered without
touching size_invs.

--HG--
extra : rebase_source : 7c8ee3c0ea30a88bddba816c41c6f63914f7a03c
2017-11-03 11:41:30 +09:00
Mike Hommey
b4b9a5993f Bug 1414155 - Replace the cacheline-related macros with a constant. r=njn
--HG--
extra : rebase_source : 571145f154478b1703be44b73b8562de7973d788
2017-11-01 19:34:41 +09:00
Mike Hommey
26674ebcb7 Bug 1414155 - Consolidate "constant/globals". r=njn
There is a set of "constants" that are actually globals that depend on
the page size that we get at runtime, when compiling without
MALLOC_STATIC_PAGESIZE, but that are actual constants when compiling
with it. Their value was unfortunately duplicated.

We setup a set of macros allowing to make the declarations unique.

--HG--
extra : rebase_source : 56557b7ba01ee60fe85f2cd3c2a0aa910c4c93c6
2017-11-01 18:33:24 +09:00
Mike Hommey
6b7f782847 Bug 1414155 - Define pagesize_2pow in terms of pagesize, not the opposite. r=njn
At the same time, add user-defined literals to make those constants more
legible.

--HG--
extra : rebase_source : ce143ad9d8a6603179042d8cf432f00c815156c5
2017-11-01 18:07:06 +09:00
Mike Hommey
273538b95c Bug 1414155 - Move arena_chunk_map_t and arena_chunk_t around. r=njn
At the moment, while they are used before their declaration, it's from a
macro. It is desirable to replace the macros with C++ constants, which
will require the structures being defined first.

--HG--
extra : rebase_source : 7a351dafea04a7d75b6eec50fa52fb49c135e569
2017-11-01 17:54:31 +09:00
Mike Hommey
1c4a4f48fa Bug 1414155 - Factor out size classes logic for tiny, quantum and sub-page classes. r=njn
We create a new helper class that rounds up allocations sizes and
categorizes them. Compilers are smart enough to elide what they don't
need, like in malloc_good_size, they elide the code related to the
class type enum.

--HG--
extra : rebase_source : 61381e600587b045e720a85a7b46673edeb691b9
2017-11-03 08:53:34 +09:00
Mike Hommey
161c7d7841 Bug 1414155 - Move a few things around. r=njn
--HG--
extra : rebase_source : 11049459c8318e1a9f1cf535dfbce115bf57f918
2017-11-01 19:29:36 +09:00
Mike Hommey
66867e7f34 Bug 1414073 - Rename arena_bin_t fields. r=njn
At the same time, fold malloc_bin_stats_t into it.

--HG--
extra : rebase_source : 38c6a194d100783ecd0f769952de7bb4f71f17b0
2017-11-03 09:26:07 +09:00
Mike Hommey
8f8239d7bf Bug 1413570 - Disable SSE2 when building mozjemalloc on x86 during PGO profile gen phase. r=froydnj
Because of alignment issues due to the system glibc when running the
SSE2 gcov code generated during the PGO profile gen phase, Firefox
crashes when running the PGO profile. We work around the issue by
disabling SSE2 when building mozjemalloc during that phase. That
shouldn't affect the coverage data anyways, which is bound to the
original C++ code, and the profile-use code generation will still emit
SSE2 based on the coverage data if it needs to.

--HG--
extra : rebase_source : 3596fdc795cdef0789f3a2dd8f10b42cde00430f
2017-11-02 10:26:49 +09:00
Mike Hommey
eab43e4a6c Bug 1413475 - Run clang-format on all files in memory/build/. r=njn
--HG--
extra : rebase_source : a0a7ebff22c2387389d2f1dc75f8a5084f76ebb7
2017-11-01 17:20:54 +09:00
Mike Hommey
af14262e54 Bug 1413475 - Change comments to use C++ style // instead of /* */ in memory/build/. r=njn
--HG--
extra : rebase_source : 8d8b85e8123f414cb1e0e1eb067e0d198b3ebb8f
2017-11-01 17:15:12 +09:00
Mike Hommey
1de1ed32d0 Bug 1413475 - Normalize license boilerplates in memory/build/. r=njn
--HG--
extra : rebase_source : 9689f766211fbe1476c5e6d4774f1e95bb8e0208
2017-11-01 16:56:27 +09:00
Mike Hommey
f081d2458b Bug 1413475 - Replace SIZEOF_INT_2POW with LOG2(sizeof(int)). r=njn
--HG--
extra : rebase_source : f1add73810649c8b12e2ee139528fad9186fc20b
2017-11-01 16:47:59 +09:00
Mike Hommey
d07b1b083f Bug 1413475 - Inline STRERROR_BUF in mozjemalloc.cpp. r=njn
It is only used once.

--HG--
extra : rebase_source : 044e7d8ac3e6db834702ab8aedae9b44112d2932
2017-11-01 16:46:44 +09:00
Mike Hommey
7b9d775493 Bug 1413475 - Remove unused MAP_NOSYNC definition in mozjemalloc.cpp. r=njn
--HG--
extra : rebase_source : 95c760647b1c97accfb044961aae6ae1f2113f8e
2017-11-01 16:45:40 +09:00
Mike Hommey
a71adf8fd9 Bug 1413475 - Move MALLOC_DECOMMIT definition closer to that of MALLOC_DOUBLE_PURGE. r=njn
--HG--
extra : rebase_source : 41e4dc84269dfa47c9b7daf4ab587dd41c7eb290
2017-11-01 16:45:24 +09:00
Mike Hommey
485f23d7b1 Bug 1413475 - Reorganize #includes in mozjemalloc.cpp. r=njn
--HG--
extra : rebase_source : 8b03bba78544e1980802c5c7e92ecead738e0408
2017-11-01 16:10:24 +09:00
Mike Hommey
66579f53a7 Bug 1413475 - Inline _CRT_SPINCOUNT in mozjemalloc.cpp. r=njn
It is only used once.

--HG--
extra : rebase_source : 589c078fac563f7e7f057e3a2904970126b6a4b9
2017-11-01 16:06:28 +09:00
Mike Hommey
36809628ea Bug 1413475 - Remove ssize_t definition from mozjemalloc.cpp. r=njn
The only use of ssize_t in mozjemalloc was removed in bug 1403444.

--HG--
extra : rebase_source : 98dde18a08a9a64b2b61698c43cbf3fc7eb74b5d
2017-11-01 15:51:06 +09:00
Mike Hommey
673c2f9373 Bug 1402284 - Separate arenas created from moz_arena_* functions from others. r=njn
We introduce the notion of private arenas, separate from other arenas
(main and thread-local). They are kept in a separate arena tree, and
arena lookups from moz_arena_* functions only access the tree of
private arenas. Iteration still goes through all arenas, private and
non-private.

--HG--
extra : rebase_source : 86c43c7c920b01eb6fa1fa214d612fd9220eac3e
2017-10-31 07:13:39 +09:00
Mike Hommey
4092f53e8a Bug 1402284 - Move arena tree related globals to a static singleton of a new class. r=njn
We create the ArenaCollection class to handle operations on the
arena tree. Ideally, iter() would trigger locking, but the
prefork/postfork code complicates things, so we leave this for later.

--HG--
extra : rebase_source : bd7021098baf0ec01c14063294098edea4473d36
2017-10-28 07:13:58 +09:00
Mike Hommey
e23a5782c2 Bug 1402284 - Initialize arena_t objects via a constructor instead of manually with an Init method. r=njn
Note we use a local variable for fallible allocator because using plain
`new (fallible)` would require some figuring out for non-Firefox builds
(e.g.  standalone js).

--HG--
extra : rebase_source : 2132f98ebc7e37a139b673f80631e672bcf8ed15
2017-10-28 08:42:59 +09:00
Mike Hommey
b4a43c8f3a Bug 1402284 - Make RedBlackTree::{Insert,Remove} work when the type has a constructor. r=njn
RedBlackTree::{Insert,Remove} allocate an object on the stack for its
RedBlackTreeNode, and that shouldn't have side effects if the type
happens to have a constructor. This will allow to add constructors to
some of the mozjemalloc types.

--HG--
extra : rebase_source : 14dbb7d73c86921701d83156186df5d645530dda
2017-10-30 09:55:18 +09:00
Phil Ringnalda
6841cb2510 Backed out 4 changesets (bug 1402284) for build bustage
CLOSED TREE

Backed out changeset f894ea204bb4 (bug 1402284)
Backed out changeset a0c193d65799 (bug 1402284)
Backed out changeset 8f83dc111aed (bug 1402284)
Backed out changeset 7b7818155442 (bug 1402284)

MozReview-Commit-ID: DNthJ588QYa
2017-10-31 20:06:26 -07:00
Mike Hommey
a9fed04a18 Bug 1402284 - Separate arenas created from moz_arena_* functions from others. r=njn
We introduce the notion of private arenas, separate from other arenas
(main and thread-local). They are kept in a separate arena tree, and
arena lookups from moz_arena_* functions only access the tree of
private arenas. Iteration still goes through all arenas, private and
non-private.

--HG--
extra : rebase_source : ec48631a4a65520892331c1fcd62db37ed35ba1d
2017-10-31 07:13:39 +09:00
Mike Hommey
ca87c7c8ba Bug 1402284 - Move arena tree related globals to a static singleton of a new class. r=njn
We create the ArenaCollection class to handle operations on the
arena tree. Ideally, iter() would trigger locking, but the
prefork/postfork code complicates things, so we leave this for later.

--HG--
extra : rebase_source : 90c96575d65c920f75aa621ba119d354d1ce252a
2017-10-28 07:13:58 +09:00
Mike Hommey
bdc5d4ce61 Bug 1402284 - Initialize arena_t objects via a constructor instead of manually with an Init method. r=njn
Note we use the deprecated `new (fallible_t())` form because using `new
(fallible)` would require some figuring out for non-Firefox builds (e.g.
standalone js).

--HG--
extra : rebase_source : 0159d8476a1b5509330517c00af6c387d522722d
2017-10-28 08:42:59 +09:00
Mike Hommey
6d94984475 Bug 1402284 - Make RedBlackTree::{Insert,Remove} work when the type has a constructor. r=njn
RedBlackTree::{Insert,Remove} allocate an object on the stack for its
RedBlackTreeNode, and that shouldn't have side effects if the type
happens to have a constructor. This will allow to add constructors to
some of the mozjemalloc types.

--HG--
extra : rebase_source : 14dbb7d73c86921701d83156186df5d645530dda
2017-10-30 09:55:18 +09:00
Mike Hommey
ef31a72488 Bug 1413096 - Remove SIZEOF_PTR and SIZEOF_PTR_2POW. r=njn
--HG--
extra : rebase_source : e9a7082ebb944352da80face0e5796429aaed340
2017-10-30 11:43:10 +09:00
Mike Hommey
87e49e764d Bug 1413096 - Replace ffs with MathAlgorithms functions. r=njn
- In the cases where it's used on powers of 2, replace it with
  FloorLog2() + 1.
- In the cases where it's used on any kind of number, replace it with
  CountTrailingZeroes, which is `ffs(x) - 1`.
- In the case of tiny allocations in arena_t::MallocSmall, we rearrange
  the code so that the intent is clearer, which also simplifies the
  expression for the mBins offset: mBins[0] is the first tiny bucket,
  for allocations of sizes 1 << TINY_MIN_2POW, mBins[1] for allocations
  of size 1 << (TINY_MIN_2POW + 1), etc. up to small_min. So the offset
  is really the log2 of the normalized size.

--HG--
extra : rebase_source : 954a655dcaa93857dc976078e133704bb141de0d
2017-10-30 17:44:16 +09:00
Mike Hommey
331ef2d1a6 Bug 1413096 - Remove unnecessary call to ffs. r=njn
Comparing ffs(x) == ffs(y), when x and y are guaranteed to be powers of
2 (or 0, or 1), is the same as x == y.

--HG--
extra : rebase_source : d6cc3399d85fa9fda2559435e99adbfb82ac8da0
2017-10-30 17:57:55 +09:00
Mike Hommey
3c71490814 Bug 1413096 - Remove pow2_ceil in favor of RoundUpPow2. r=njn
--HG--
extra : rebase_source : ef24e37398e992e2f64a08ffae30f374babca37f
2017-10-30 17:22:36 +09:00
Mike Hommey
5a7f5e0d8e Bug 1413096 - Use CheckedInt for overflow check in calloc. r=njn
Also use in in _recalloc.

--HG--
extra : rebase_source : 1ecc1f029958cd0b25e6e480f5afb94b56dd1139
2017-10-30 11:28:17 +09:00
Mike Hommey
e30b520850 Bug 1413096 - Add "using namespace mozilla" to mozjemalloc.cpp. r=njn
--HG--
extra : rebase_source : 438f0c3729111e97cf1e5b9cb5e230eda796e7bd
2017-10-30 17:19:44 +09:00
Mike Hommey
19b1e09699 Bug 1413096 - Add missing header guard. r=njn
--HG--
extra : rebase_source : fdb40a44f0ff212a2a5367f4de7663129888f41a
2017-10-30 11:00:46 +09:00
Mike Hommey
26d6ac76c0 Bug 1412722 - Remove RedBlackTree sentinel. r=njn
The sentinel was taking as much space as one element of the tree, while
only really used for its RedBlackTreeNode, wasting space.

This results in some decrease in struct sizes, for example on 64-bits
linux:
- arena_bin_t: 80 -> 56
- arena_t (excluding mBins): 224 -> 144
- arena_t + dynamic size of mBins: 3024 -> 2104

It also decreases the size of several globals:
- gChunksBySize, gChunksByAddress, huge: 64 -> 8
- gArenaTree: 312 -> 8

--HG--
extra : rebase_source : d5bb52f93e064ab4cca3fb07b2c5a77ce57fb7db
2017-10-28 08:36:32 +09:00
Mike Hommey
7f63a01cca Bug 1412717 - Make malloc_initialized atomic. r=njn
Interestingly, this turns single-instruction checks into
two-instructions checks (at least with GCC, from one cmpb to a movl
followed by a testl), but this is due to Atomic<bool> being actually
backed by a uint32_t, not by the use of atomics.

--HG--
extra : rebase_source : cfc0bec2113b44635120216b4abbbbbe9028b286
2017-10-30 09:30:41 +09:00
Mike Hommey
5b2f666e8a Bug 1412235 - Be consistent about the magic number assertions in mozjemalloc. r=njn
- First, MOZ_DIAGNOSTIC_ASSERT_ENABLED is always true when MOZ_DEBUG is
  set, so don't check for MOZ_DEBUG.
- Second, all the magic number assertions should be
  MOZ_DIAGNOSTIC_ASSERTs instead of MOZ_ASSERTs.

--HG--
extra : rebase_source : 5601cd13604e21c46a9f0ad8b0b4d6fc399b853e
2017-10-27 17:29:12 +09:00
Mike Hommey
7fca98c0c3 Bug 1412234 - Make all allocator API entry points handle initialization properly. r=njn
Some need initialization to happen, some can be skipped when the
allocator was not initialized, and others should crash.

--HG--
extra : rebase_source : d6c2697ca27f6110fe52a067440a0583e0ed0ccd
2017-10-27 17:25:18 +09:00
Mike Hommey
5b0f50a0fc Bug 1412234 - Make malloc_init return whether the allocator was successfully initialized. r=njn
--HG--
extra : rebase_source : 744ffd666b626059197bebf90acfe3fd670847d4
2017-10-27 17:05:47 +09:00
Mike Hommey
fc8b83f39a Bug 1412221 - Fix build bustage in mozjemalloc.cpp. r=me 2017-10-29 14:00:28 +01:00
Mike Hommey
7dcb29d53f Bug 1412221 - Run clang-format on mozjemalloc.cpp. r=njn
--HG--
extra : histedit_source : 450ca93d0ee5b0a53a649a1116cf9c2bf22f3eb4
2017-10-29 13:53:37 +01:00
Mike Hommey
7ac11ce77e Bug 1412221 - Change comments to use C++ style // instead of /* */. r=njn
clang-format doesn't handle multi-line /* */ well.

--HG--
extra : histedit_source : 2cf4811a7861072f5039a4139e403283073d7d90
2017-10-29 13:53:31 +01:00
Mike Hommey
d00d68c730 Bug 1412221 - Use pages_unmap instead of repeating the same code. r=njn
--HG--
extra : histedit_source : d23385b0e30046f0f7e0cd145478ba01a66036c3
2017-10-29 13:53:26 +01:00
Mike Hommey
d7db18ae90 Bug 1412221 - Remove unnecessary parentheses around return values. r=njn
--HG--
extra : histedit_source : 20b11718133f9449c562572c0150682f91aa11d9
2017-10-29 13:53:20 +01:00
Mike Hommey
aabcfdd6ab Bug 1412221 - Fix clang-tidy warnings in mozjemalloc.cpp. r=njn
Also rearrange some code accordingly, but don't fix indentation issues
just yet.

Also apply changes from the google-readability-braces-around-statements
check.

But don't apply the modernize-use-nullptr recommendation about
strerror_r because it's wrong (bug #1412214).

--HG--
extra : histedit_source : 2d61af7074fbdc5429902d9c095c69ea30261769
2017-10-29 13:53:14 +01:00
Sebastian Hengst
d9ec2086d0 Backed out changeset 5 changesets (bug 1412221) for build bustage at memory/build/mozjemalloc.cpp:4390: jump to label 'RETURN'. r=backout
Backed out changeset f75f427fde1d
Backed out changeset 6278aa5fec1d
Backed out changeset eefc284bbf13
Backed out changeset e2b391ae4688
Backed out changeset 58070c2511c6

--HG--
extra : histedit_source : d14fa171a5cf4d9400cae7f94d5cc64a1e58b98d%2C856ad5b650074a1dcff2edb0b95adc20aaf38db3
2017-10-29 13:50:49 +01:00
Mike Hommey
5acf4b9bbe Bug 1412221 - Run clang-format on mozjemalloc.cpp. r=njn
--HG--
extra : rebase_source : 5e582f64182131e600e8557b8c7c957ef53c2bcc
2017-10-27 16:48:25 +09:00
Mike Hommey
732a4acab4 Bug 1412221 - Change comments to use C++ style // instead of /* */. r=njn
clang-format doesn't handle multi-line /* */ well.

--HG--
extra : rebase_source : f814f4a973499c3d7759ea0f17543513fb047f39
2017-10-27 16:33:14 +09:00