Commit Graph

1003 Commits

Author SHA1 Message Date
Mike Hommey
5289738fd4 Bug 1412168 - Replace CHUNK_ADDR2{BASE,OFFSET} with functions. r=njn
--HG--
extra : rebase_source : a7ded5dc74eabd802a30a9266b56cd3343fa5def
2017-10-26 10:34:37 +09:00
Mike Hommey
ce11a1b648 Bug 1411786 - Use mozilla::Atomic for the recycled size count. r=njn
--HG--
extra : rebase_source : e2483afafc85935badbe0448582a0f5bb37c9b8d
2017-10-26 09:51:00 +09:00
Mike Hommey
e5c6d53dcb Bug 1411786 - Rename chunk recycling-related globals. r=njn
--HG--
extra : rebase_source : b82ad235f305f113fdd7c96d884257b51a259709
2017-10-26 09:43:43 +09:00
Mike Hommey
d9ff14e160 Bug 1411786 - Make the chunk size and recycle limit constant. r=njn
Bug 1403843 made more things constant, but missed a few that don't
depend on the page size.

--HG--
extra : rebase_source : 036722744ff7054de9d081bde1f4c7b035fd9501
2017-10-26 09:38:48 +09:00
Mike Hommey
e7924e7a2e Bug 1411786 - More tidying of chunk allocation and recycling code. r=njn
- Move variable declarations to their initialization.
- Remove gotos and use RAII.

--HG--
extra : rebase_source : 9d983452681edf63593d033727ba6faebe418afe
2017-10-26 08:50:49 +09:00
Mike Hommey
c27356ae7a Bug 1411786 - Rename chunk_{recycle,record,alloc,dealloc} arguments. r=njn
Also reformat a few things clang-format left out.

--HG--
extra : rebase_source : 4edd02ae12ae62462b06714a687ecbc49e3af814
2017-10-26 08:48:18 +09:00
Mike Hommey
378bd53e94 Bug 1411786 - clang-format chunk_{recycle,record,alloc,dealloc}. r=njn
--HG--
extra : rebase_source : adeb9db953c3227ee9dbba594282eb0a150d3a64
2017-10-26 08:36:26 +09:00
Mike Hommey
e68fafc392 Bug 1411786 - Use globals for chunk recycling. r=njn
The chunk_recycle and chunk_record functions are never called with
different red-black trees than the globals, so just use them directly
instead of passing them as argument. The functions were already using
the associated global mutex anyways.

At the same time, rename them.

--HG--
extra : rebase_source : c45bb2e584c61b458eab4343562eb3a5a64543a3
2017-10-26 08:29:07 +09:00
Mike Hommey
08a70c0752 Bug 1411786 - Don't call chunk_recycle for base allocations. r=njn
Instead of calling it with a boolean indicating whether the call was for
base allocations or not, and return immediately if it was, avoid the
call altogether.

--HG--
extra : rebase_source : abb2a3d0eaefc16efd2e828f09a330ab2a3b8b1f
2017-10-26 08:24:08 +09:00
Mike Hommey
df85ef19a7 Bug 1300900 - Add a helper around jemalloc_ptr_info for debuggers. r=njn
jemalloc_ptr_info takes an outparam, which makes it harder to use in a
debugger: you'd need to find some memory to use as outparam and pass
that in.

So for convenience, we add a non-exported symbol for use in debuggers,
which just returns a pointer to a static buffer for the result.

lldb:
(lldb) print *Debug::jemalloc_ptr_info($0)
(jemalloc_ptr_info_t) $1 = (tag = TagLiveSmall, addr=0x000000011841dd80, size = 160)

gdb:
(gdb) print *Debug::jemalloc_ptr_info($0)
$1 = {tag = TagLiveSmall, addr = 0x7f8e7ebd0dc0, size = 96}

windbg:
0:040> .call Debug::jemalloc_ptr_info(0x6187880)
Thread is set up for call, 'g' will execute.
WARNING: This can have serious side-effects,
including deadlocks and corruption of the debuggee.
0:040> g
.call returns:
struct jemalloc_ptr_info_t * 0x7501f3f4
   +0x000 tag              : 1 ( TagLiveSmall )
   +0x004 addr             : 0x06187880 Void
   +0x008 size             : 0x20

--HG--
extra : rebase_source : 09aedd48aabee3e273a17000a61b1d09cdd619b9
2017-10-25 08:01:41 +09:00
Mike Hommey
1ab6142261 Bug 1411429 - Remove unused mozjemalloc huge stats. r=njn
Bug 1378258 removed malloc_print_stats and bug 1379890 further removed
the subsequently unused arena stats. It turns out there are also some
huge stats that have been unused since bug 1378258, and that are still
there, so remove them.

--HG--
extra : rebase_source : ae71c7507143503dff8d2e517352a97eb53e4676
2017-10-25 07:20:37 +09:00
Mike Hommey
ffe63a7d7f Bug 1411201 - Don't disable inlining in mozjemalloc on debug builds. r=njn
The way inlining is disabled in mozjemalloc is via a #define of "inline"
to nothing, which is a dubious way to do that. This makes the compiler
trigger warnings we -Werror on for some static functions. While there
are such functions in mozjemalloc.cpp that could be fixed by wrapping
them in the right #ifdefs, there are also others coming from headers,
and it's not something that can be fixed in a satisfactory way.

The right way to disable inlining is to pass the right compiler flags
for that. But inlining is the least of the problems to debug optimized
C++ code, so it feels like if debugging requires some optimization
tweaking, it should be done manually with compile flags when needed,
instead of fiddling with #defines to remove keywords.

--HG--
extra : rebase_source : 962c3409f86060c4d5ddf966778b58b64f89c31d
2017-10-24 18:42:24 +09:00
Mike Hommey
d2222ba092 Bug 1411158 - Remove some warning exceptions in memory/build/moz.build. r=njn
Bug 1403444 massively refactored the red-black tree code, with the
result of removing the warnings the old code was triggering. We can thus
remove the exceptions for those warnings now.

--HG--
extra : rebase_source : 76c7ce7a7282471399c7592601f6986bfb33b256
2017-10-24 14:48:05 +09:00
Mike Hommey
a465ba783c Bug 1411155 - Fix MOZ_DEBUG parts of mozjemalloc. r=njn
--HG--
extra : rebase_source : 5a2005255ad499530f0e01b2e7577e707b1b4446
2017-10-24 14:11:14 +09:00
Mike Hommey
55703dd1f1 Bug 1411084 - Use RAII for mutex locking in mozjemalloc. r=njn
This leaves out a few manual Lock/Unlock calls.

--HG--
extra : rebase_source : ce20e8e63474b43b469b953de0558d9904e2229e
2017-10-06 17:49:40 +09:00
Sylvestre Ledru
d60d69e2cb Bug 1411001 - Remove the +x permissions on cpp & h files r=froydnj
MozReview-Commit-ID: DjDkL20wRg0

--HG--
extra : rebase_source : a343d83d1f4e97e4ba56d0f57fec93079df0b5ea
2017-10-23 20:59:55 +02:00
Mike Hommey
4bc374f630 Bug 1409294 - Make arena_t::Init return whether initialization succeeded. r=njn
--HG--
extra : rebase_source : efd32943313cef9a680fc38b0c2182e3c175c27e
2017-10-17 17:37:50 +09:00
Mike Hommey
79eba188f7 Bug 1409273 - Replace malloc_mutex_* with class methods. r=njn
Ideally, we'd be reusing some Mutex class we have in Gecko, the base one
in mozglue/misc being the best candidate. However, the contraints in
mozjemalloc make that unconvenient:
- Can't have a constructor because malloc_init() would likely run before
  it, and that would mean the mutexes would be re-initialized.
- Can't have a destructor because code will run after static
  destructors, and some of that code likely will invoke the allocator,
  and we can't have destructed mutexes by then.
- Can't use pthread_mutex on OSX because that loops back into the
  allocator.

Accomodating the use of Gecko mutexes around those constraints would
mean much more code than just implementing a new mutex class, so the
latter is preferred.

--HG--
extra : rebase_source : d2e180a5007390c620aa6d7921340b9784c7699f
2017-10-06 17:20:04 +09:00
Mike Hommey
9f2dd4775e Bug 1407468 - Replace multiple !JS_STANDALONE with MOZ_WIDGET_TOOLKIT. r=mshal
--HG--
extra : rebase_source : 4f9f9f583c3422ed0f8d1d65ea8e7575bd9baf2c
2017-10-05 14:50:01 +09:00
Tom Ritter
fdab21a20a Bug 1406197 Declare sized deallocators (that ignore the size) to correct a MinGW warning r=glandium
MozReview-Commit-ID: Dl4uu6evlbs

--HG--
extra : rebase_source : f9b04123b1f09a49155f0bb24704f9e11818ff5a
2017-10-10 13:16:10 -05:00
Mike Hommey
a055106404 Bug 1407469 - Remove malloc_spin_*. r=njn
The malloc_spin_* functions have ended up being strictly identical to
the malloc_mutex_* functions, so use the latter instead of the former.

--HG--
extra : rebase_source : 746bdf57cb4a33fd65335174a748cb567630e05b
2017-10-06 16:50:17 +09:00
Mike Hommey
03333cae7c Bug 1406303 - Don't heap-allocate the global chunk radix tree. r=njn
Now that the radix tree structure has a fixed size, we can just allocate
the chunk radix tree object statically.

--HG--
extra : rebase_source : 6a5f022d46da1b24401b197751e594903987b7f6
2017-10-06 16:18:01 +09:00
Mike Hommey
5ad57b4c9d Bug 1406303 - Make the number of significant bits used by the radix tree a template parameter. r=njn
All the parameters of the radix tree (bits per level, height) are
derived from the aBits argument to ::Create in a straightforward way.
aBits itself is a constant at the call point, making them all constants,
so we can turn all of them as constants at compile time instead of
storing as data.

--HG--
extra : rebase_source : aa1be8e97ed4133d7fc106fb3ea678a759476bef
2017-10-06 15:50:00 +09:00
Mike Hommey
8dd493542b Bug 1406303 - Only store 2 levels of bit sizes for the radix tree. r=njn
All levels except the first are using the same size, and in some cases,
even the first uses the same size. Only storing those two different
sizes allows to fix the class size, while not making the code
significantly more complex.

--HG--
extra : rebase_source : 8028c18de2fa84060c5baff7c95cd0a70e7a3c6b
2017-10-06 15:24:07 +09:00
Mike Hommey
69e46849e9 Bug 1406303 - Simplify the calculation of AddressRadixTree's height. r=njn
The tree height was defined as:
  height = aBits / bits_per_level;
  if (height * bits_per_level != aBits) {
    height++;
  }

What's wanted here is a height that covers all the bits, where the first
level might cover less than bits_per_level.

So aBits / bits_per_level gets us the height covered by levels with
exactly bits_per_level bits. The tree height is one more when there
are remaining bits.

Put differently, we can write aBits as:
  aBits = bits_per_level * x + y

with y < bits_per_level.

We have:
  aBits / bits_per_level = x.
  height = x when y = 0, and x + 1 when y > 0.

We're looking for a number z such that
  height = (aBits + z) / bits_per_level.

Or:
  height = (bits_per_level * x + y + z) / bits_per_level.
         = x + (y + z) / bits_per_level.

So we're looking for a z such that
  (y + z) / bits_per_level = 0 when y = 0
                           = 1 when y > 0

The properties of the integer division are such that the above means:
  0 <= y + z < bits_per_level when y = 0
  bits_per_level <= y + z < 2 * bits_per_level when y > 0

Which gives us:
  0 <= z < bits_per_level
  bits_per_level - y <= z < 2 * bits_per_level - y when y > 0

y being < bit_per_level per the constraint further above,
  2 * bits_per_level - y > bits_per_level.

So all in all, we want a z such that
  bits_per_level - y <= z < bits_per_level with 0 < y < bits_per_level

The largest value where this is true is z = bits_per_level - 1.

In summary,
  height = (aBits + bits_per_level - 1) / bits_per_level

is the same as the height as originally defined.

With that formula, it's self evident that height * bits_per_level is
always >= aBits, so we remove the assertion.

--HG--
extra : rebase_source : 8ca2e5fbad7d4ad537f26508af5aa250483f1f08
2017-10-06 11:32:27 +09:00
Mike Hommey
aaefadc3a4 Bug 1406303 - Simplify the calculation of AddressRadixTree's bits_per_level. r=njn
bits_per_level was defined as:
  ffs(pow2_ceil((kNodeSize / sizeof(void*)))) - 1

kNodeSize is (1U << 14) when SIZEOF_PTR is 4 (sizeof(void*) being the
same). Otherwise, it's CACHELINE, which is (1U << 6).
The most important part, though, is that it's always a power of 2.
And it's divided by sizeof(void*) which is always a power or 2.
The result of that division is thus always a power of 2, as long as
kNodeSize is larger than the size of a pointer, which it is.

The argument to pow2_ceil being a power of 2, pow2_ceil is a noop,
so it can go away. And the argument to ffs being a power of 2, it
returns one more than n that matches 1 << n == value. So overall
the expression returns the number of shifts for
kNodeSize / SIZEOF_PTR.

Transforming kNodeSize to a number of shifts/power of 2, the expression
can then be simplified as kNodeSize2Pow - SIZEOF_PTR_2POW.

--HG--
extra : rebase_source : a22a378ba6622e2a4fbcf28811c7042cea9da24a
2017-09-28 15:35:21 +09:00
Mike Hommey
a814a27087 Bug 1406303 - Turn malloc_rtree_t into a C++ class. r=njn
The only semantic change is in the value returned by Set, which now
returns whether the value could be set or not.

--HG--
extra : rebase_source : a80f5d6fdb3672715887e69215f55df0cedb231e
2017-10-06 10:49:24 +09:00
Mike Hommey
cce7100e5e Bug 1406303 - Refactor malloc_rtree_get/set. r=njn
There is a lot of redundancy between malloc_rtree_get and
malloc_rtree_set. Essentially, they both look up a slot, and either get
a value or set a value in that slot. malloc_rtree_get doesn't create a
tree path for the slot when it doesn't exist. And the
MALLOC_RTREE_GET_GENERATE macro machinery makes malloc_rtree_get retry
with a lock and validate both results agree in debug builds.

By introducing a malloc_rtree_get_slot function that returns a slot,
optionally creating a tree path to it, we remove the redundancy between
_get and _set, and we can avoid the macro machinery as well.

--HG--
extra : rebase_source : bbbdd33e81e8bfdc11c028f882ab877bba26f7f3
2017-09-28 12:18:14 +09:00
Emanuel Hoogeveen
02d10f1bfa Bug 1405159 - Assert against freeing incorrectly offset pointers. r=glandium 2017-10-02 15:39:00 -04:00
Nicholas Nethercote
a6fede36c2 Bug 1384814 - Remove critical address machinery from Mac implementation of MozStackWalk(). r=glandium.
It seemingly hasn't been needed since Mac OS 10.7. A diagnostic assertion that
has been in place for a while hasn't caught any uses of it.

--HG--
extra : rebase_source : 9834849eec9174267c7df8de7fd22840ffa36d8f
2017-10-03 13:53:14 +11:00
Jan Keromnes
30acb879f3 Bug 1403660 - Do not use 'else' after 'break' in /memory/build/rb.h. r=njn 2017-09-28 08:01:00 -04:00
Mike Hommey
fd18ca4367 Bug 1403843 - Disable static sizes on debug builds. r=njn
Because why not, especially now that this only concerns the page size.

--HG--
extra : rebase_source : 9ff92d2551e0bb8633072e0c8d5aa36c570314e1
2017-09-28 15:15:23 +09:00
Mike Hommey
450b12cd79 Bug 1403843 - Make quantum, small and chunk sizes always static. r=njn
Bug 571209 made many different kinds of sizes static at build time, as
opposed to configurable at run-time. While the dynamic sizes can be
useful to quickly test tweaks to e.g. quantum sizes, a
replace-malloc-built allocator could just as well do the same. This
need, however, is very rare, and doesn't justify keeping the sizes
dynamic on platforms where static sizes can't be used for the page size
because page size may vary depending on kernel options.

So we make every size that doesn't depend on the page size static,
whether MALLOC_STATIC_SIZES is enabled or not.

This makes no practical difference on tier-1 platforms, except Android
aarch64, which will benefit from more static sizes.

--HG--
extra : rebase_source : 28243a67e4fe41154c23dc39b45405479854d31d
2017-09-28 15:27:59 +09:00
Mike Hommey
2e77077792 Bug 1403821 - Don't force the allocator to be always compiled with optimizations. r=froydnj
This was done in bug 1104634 because back then the Android NDK had a
broken combination of compiler and libc, where the compiler would emit
calls to the ffs function, but the libc wouldn't contain them, but only
when building without optimization.

Things have changed in the meanwhile, and recent NDK doesn't have this
problem. So we can remove the hack.

--HG--
extra : rebase_source : 22d6c279a60d0d23161ca1addd5b5e9a3411d8ab
2017-09-28 11:27:43 +09:00
Mike Hommey
7ee99ec56b Bug 1403824 - Keep track of arenas in the arena tree. r=njn
Bug 1402174 made all arenas registered in a Red-Black tree. Which means
they are iterable through that tree, making the arenas list now redundant.
The list is also inconvenient, since it needs to be constantly
reallocated, and the allocator in charge of the list doesn't know how to
free things.

Iteration of arenas is not on any hot path anyways, so even though
iterating the RB tree is slower, it doesn't matter.

So we remove the arenas list, and keep a direct pointer to the main
arena for convenience (instead of calling First() on the RB tree every
time)

--HG--
extra : rebase_source : 31f12b2de18a886eb4f8f078e11040aad3fdc800
2017-09-28 08:06:23 +09:00
Mike Hommey
3e25c152cf Bug 1403766 - Always use some sort of thread local storage in the allocator. r=njn
As we're going to enable stylo on Android at some point, we'll have to
have thread local arenas there, which means Android needs to be using
thread local storage. Since Android is the last use of NO_TLS in the
allocator code base, remove it.

--HG--
extra : rebase_source : 658cbc94b4478950f683bd104b7e5da27cd08a2e
2017-09-28 08:28:52 +09:00
Mike Hommey
4877b48a43 Bug 1403765 - Use native TLS in the allocator on Windows. r=njn
--HG--
extra : rebase_source : d6f46f9f4a09079f62f44b6aed6dd4bd8d60530c
2017-09-25 06:47:44 +09:00
Mike Hommey
d8428609d8 Bug 1403444 - Remove typedefs for RedBlackTrees. r=njn
--HG--
extra : rebase_source : 0cc425c0e941108a4387ac594f6f258c68a35f4e
2017-09-28 06:58:37 +09:00
Mike Hommey
33d3d2113b Bug 1403444 - Rename the RedBlackTree member variables. r=njn
--HG--
extra : rebase_source : 5bfc9d0711af7acfbe3f8a6711e82f103ae13ece
2017-09-27 16:11:11 +09:00
Mike Hommey
f0908215f5 Bug 1403444 - Add a helper class to avoid the tree traversal code having to use Trait::GetTreeNode noisily. r=njn
--HG--
extra : rebase_source : b73d82b3529e4910d890cb9dfb08cacdff5b7a64
2017-09-27 16:07:22 +09:00
Mike Hommey
8c16cb5da2 Bug 1403444 - Replace the rb_foreach_* macros with a range iterator. r=njn
--HG--
extra : rebase_source : 6a487f1f660ec15cea8b91e89fc473b8cc17a669
2017-09-27 15:25:19 +09:00
Mike Hommey
cb629a1000 Bug 1403444 - Remove rbp_f_synced. r=njn
Bug 1365460 removed the macros that used it.

--HG--
extra : rebase_source : 6f732916e3cdbf2b1dfd8e929fb9424a1e41352a
2017-09-27 13:50:50 +09:00
Mike Hommey
8f6d19c631 Bug 1403444 - Replace rbp_move_red_left and rbp_move_red_right with private methods. r=njn
--HG--
extra : rebase_source : e93e7256d3c94fc4aad9469fa00cd65f68c0a5e4
2017-09-26 21:21:13 +09:00
Mike Hommey
d5840a27d6 Bug 1403444 - Replace rbp_lean_left and rbp_lean_right with private methods. r=njn
--HG--
extra : rebase_source : 08fd0203f37706563a3c584225bb1790a1bd57b9
2017-09-26 21:14:12 +09:00
Mike Hommey
0938630279 Bug 1403444 - Replace rbp_rotate_left and rbp_rotate_right with private methods. r=njn
--HG--
extra : rebase_source : 1f576d36ae451d03a96b2a7285912c2a2fb4d1e5
2017-09-26 21:08:29 +09:00
Mike Hommey
fb8f789c51 Bug 1403444 - Expand rb_remove. r=njn
At the same time, simplify the expanded code to better fit in the
template.

--HG--
extra : rebase_source : 05be3b680645da9665449e5417efdf862d7e5f96
2017-09-26 17:13:53 +09:00
Mike Hommey
8d2fab69cf Bug 1403444 - Expand rb_insert. r=njn
At the same time, simplify the expanded code to better fit in the
template.

--HG--
extra : rebase_source : 610d774220fd2dbe40872f16e86eca57c11b31c3
2017-09-26 17:07:35 +09:00
Mike Hommey
dcd990824b Bug 1403444 - Expand rbp_first and rbp_last. r=njn
At the same time, simplify the expanded code to better fit in the
template.

--HG--
extra : rebase_source : a61d3eb96da054a50bc016dc6a4969f42adf9dfa
2017-09-26 16:59:02 +09:00
Mike Hommey
3c5e2cba4f Bug 1403444 - Allow First and Last to take a start node, and use that in Next and Prev. r=njn
--HG--
extra : rebase_source : a2d00f91ad98e7bd1478624a0a9b374de52f543b
2017-09-26 16:55:31 +09:00
Mike Hommey
d4ac54ef7d Bug 1403444 - Expand rb_search and rb_nsearch. r=njn
At the same time, simplify the expanded code to better fit in the
template.

--HG--
extra : rebase_source : d68bce212b04b927e32d360b0d606692a336598a
2017-09-26 16:46:43 +09:00