Commit Graph

1052 Commits

Author SHA1 Message Date
Mike Hommey
3cc5f23c76 Bug 1401099 - Move arena_run_trim_head to a method of arena_t. r=njn
--HG--
extra : rebase_source : 2a2d2b9d454d69d0d1924f60d4771b39a1dddfb2
2017-09-15 18:11:12 +09:00
Mike Hommey
b6e66b7b02 Bug 1401099 - Move arena_run_split to a method of arena_t. r=njn
--HG--
extra : rebase_source : 919dc2b9980ae59340553bcbfa029ba9c1bf9479
2017-09-15 18:08:23 +09:00
Mike Hommey
99d28b4355 Bug 1401099 - Move arena_run_dalloc to a method of arena_t. r=njn
--HG--
extra : rebase_source : 5cf37d39b6d8bdb591352051b3f37a2e3982dc69
2017-09-15 18:01:27 +09:00
Mike Hommey
7cb9914a15 Bug 1401099 - Move arena_run_alloc to a method of arena_t. r=njn
--HG--
extra : rebase_source : 6a683f4d0cf5ad68c670dbe8ea9d3a34acf11549
2017-09-15 17:57:11 +09:00
Mike Hommey
d2ba03c881 Bug 1401099 - Move arena_chunk_dealloc to a method of arena_t. r=njn
--HG--
extra : rebase_source : 973b8764903f4e9c65aaaa053bb394a8a9ff2acb
2017-09-15 17:50:48 +09:00
Mike Hommey
d6d578553d Bug 1401099 - Move arena_chunk_init to a method of arena_t. r=njn
--HG--
extra : rebase_source : d30e062f7117743a0c88fdf0325b0a395bff5658
2017-09-15 17:43:36 +09:00
Mike Hommey
11cfd193d1 Bug 1401099 - Move arena_new to a method of arena_t. r=njn
--HG--
extra : rebase_source : d0a9a0cebb4e8a1a74c5a48e42fb952310798604
2017-09-15 17:38:58 +09:00
Mike Hommey
beb406f1a7 Bug 1401099 - Move hard_purge_arena to a method of arena_t. r=njn
--HG--
extra : rebase_source : af20d24ba0dd8ce6c9e42703688c1bca98594b4d
2017-09-15 17:34:53 +09:00
Mike Hommey
a980219f16 Bug 1401099 - Move arena_purge to a method of arena_t. r=njn
--HG--
extra : rebase_source : d48623ce7ea7be5489c89a575bc1409de34e834a
2017-09-15 17:32:21 +09:00
Mike Hommey
cb3efd88ef Bug 1401099 - Use Gecko style names for arena_t members. r=njn
--HG--
extra : rebase_source : cefcbc29323145557faed6c676867500c21c6ba4
2017-09-15 17:20:01 +09:00
Mike Hommey
707bc83a01 Bug 1401875 - Replace MALLOC_DECL_VOID with a clever use of templates. r=njn
This effectively means malloc_hook_table_t is now C++ only, which is not
a big problem.

This also makes some functions use a return construct with functions
that don't return a value (such as free). While that is not allowed in
ISO C, it's allowed in C++, so the simplification is welcome (although,
retrospectively, it turns out C compilers don't complain about it
without -pedantic).

--HG--
extra : rebase_source : defd88ca3f6d478e61a4b970393dba60fb6ca81d
2017-09-21 15:27:12 +09:00
Mike Hommey
4a2740def4 Bug 1401453 - Don't keep libmemory.a separate anymore. r=gps
This was done in bug 736564 for the xulrunner SDK, which later became
the firefox SDK, which is now gone. So we don't actually need to keep it
separate anymore (except for logalloc/replay, which still needs to link
it directly, so we keep the library definition intact so it can be
referenced ; we just don't DIST_INSTALL it anymore, and always make it
linked into mozglue)

--HG--
extra : rebase_source : e4d0627ec907fe0139df5c0b2b9f7d04b43c7c78
2017-09-20 14:23:57 +09:00
Sebastian Hengst
bc68e8f407 merge mozilla-inbound to mozilla-central. r=merge a=merge
MozReview-Commit-ID: 9Z3Ly8icnvh
2017-09-20 11:48:02 +02:00
Mike Hommey
7bbdb00059 No bug - Remove a comment that has no significance after bug 1395776. r=me 2017-09-20 11:53:00 +09:00
Mike Hommey
d4a847cce0 Bug 1401101 - Remove the generic replace-malloc library. r=njn
It is one of the moving parts when adding new memory allocation APIs.

It was added in bug 1168719 and the only thing that actually used it
was the sampling-based memory profiler, which was removed in bug
1385953. We however keep the replace-malloc bridge entry point so that
something else, in the future, may still provide the feature.

--HG--
extra : rebase_source : dd4a226171429e2a4ab5666b0873e7b945f161e6
2017-09-19 15:58:33 +09:00
Mike Hommey
078c8d1896 Bug 1399921 - Register zone allocator independently, and delay jemalloc initialization on mac. r=njn
In bug 1361258, we unified the initialization sequence on mac, and
chose to make the zone registration happen after jemalloc
initialization.

The order between jemalloc init and zone registration shouldn't actually
matter, because jemalloc initializes the first time the allocator is
actually used.

On the other hand, in some build setups (e.g. with light optimization),
the initialization of the thread_arena thread local variable can happen
after the forced jemalloc initialization because of the order the
corresponding static initializers run. In some levels of optimization,
the thread_arena initializer resets the value the jemalloc
initialization has set, which subsequently makes choose_arena() return
a bogus value (or hit an assertion in ThreadLocal.h on debug builds).

So instead of initializing jemalloc from a static initializer, which
then registers the zone, we instead register the zone and let jemalloc
initialize itself when used, which increases the chances of the
thread_arena initializer running first.

--HG--
extra : rebase_source : 4d9a5340d097ac8528dc4aaaf0c05bbef40b59bb
2017-09-15 07:34:48 +09:00
Mike Hommey
50182c9f53 Bug 1400146 - Gracefully handle the allocator not being initialized in isalloc_validate. r=njn
isalloc_validate is the function behind malloc_usable_size. If for some
reason malloc_usable_size is called before mozjemalloc is initialized,
this can lead to an unexpected crash.

The chance of this actually happening is rather slim on Linux
and Windows (although still possible), and impossible on Mac, due to the
fact the earlier something can end up calling it is after the
mozjemalloc zone is registered, which happens after initialization.

... except with bug 1399921, which reorders that initialization, and
puts the zone registration first. There's then a slim chance for the
zone allocator to call into zone_size, which calls malloc_usable_size,
to determine whether a pointer allocated by some other zone belongs to
mozjemalloc's.

And it turns out that does happen, during the startup of the
plugin-container process on OSX 10.10 (but not more recent versions).

--HG--
extra : rebase_source : 331d093b03add7b2c2ce440593f5aeccaaf4dd1f
2017-09-15 15:13:52 +09:00
Mike Hommey
f3bff41d59 Bug 1400096 - Don't define the operator new/delete functions as mangled in mozmem_wrap.cpp. r=njn
Now that this is a C++ file, and that the function names are not
mangled, we can just use the actual C++ names.

We do however need to replace MOZ_MEMORY_API, which implies extern "C",
with MFBT_API.

Also use the correct type for the size given to operator new. It
happened to work before because the generated code would just jump to
malloc without touching any register, but on aarch64, unsigned int was
the wrong type.

--HG--
extra : rebase_source : 8045f30e9c609dd7d922c77d85ac017638df6961
2017-09-15 10:28:33 +09:00
Mike Hommey
9741c8e076 Bug 1400096 - Build mozmemory_wrap as C++. r=njn
And since the build system doesn't handle transitions from foo.c to
foo.cpp properly without a clobber, we work around the issue by
switching to unified sources.

--HG--
rename : memory/build/mozmemory_wrap.c => memory/build/mozmemory_wrap.cpp
extra : rebase_source : 3f074b4ccab255bb0eb16841f79582060fafbc86
2017-09-15 10:19:37 +09:00
Mike Hommey
747992864b Bug 1400096 - Annotate mozmemory_wrap.c windows functions as MOZ_MEMORY_API. r=njn
It happens to work because of mozglue.def, but we might as well have the
right annotations (which will also make things correct when building this
file to C++)

--HG--
extra : rebase_source : 61056dc21c9c29bab62ad5d648e94dd56dc53b14
2017-09-15 10:12:24 +09:00
Mike Hommey
57ecf449b4 Bug 1400096 - Remove mozmem_malloc_impl wrapping for operator methods exposed in mozmemory_wrap.c. r=njn
This used to be necessary because those functions might be prefixed with
__wrap_, and linked against with -Wl,--wrap, but that's not been the case
since bug 1077366. Furthermore, mozmem_malloc_impl nowadays only does
something on Windows, and those operators are only exposed on Android.

--HG--
extra : rebase_source : ca34442bfbc5fc8be20ffcfacb9afa0f2f818b82
2017-09-15 09:54:01 +09:00
Phil Ringnalda
eab70d0a07 Backed out changeset 0e349b74bfc6 (bug 1399921) for failure to thrive on Mac
MozReview-Commit-ID: HoBhxzIzn2d
2017-09-14 20:36:41 -07:00
Mike Hommey
c53e695a6e Bug 1399921 - Register zone allocator independently, and delay jemalloc initialization on mac. r=njn
In bug 1361258, we unified the initialization sequence on mac, and
chose to make the zone registration happen after jemalloc
initialization.

The order between jemalloc init and zone registration shouldn't actually
matter, because jemalloc initializes the first time the allocator is
actually used.

On the other hand, in some build setups (e.g. with light optimization),
the initialization of the thread_arena thread local variable can happen
after the forced jemalloc initialization because of the order the
corresponding static initializers run. In some levels of optimization,
the thread_arena initializer resets the value the jemalloc
initialization has set, which subsequently makes choose_arena() return
a bogus value (or hit an assertion in ThreadLocal.h on debug builds).

So instead of initializing jemalloc from a static initializer, which
then registers the zone, we instead register the zone and let jemalloc
initialize itself when used, which increases the chances of the
thread_arena initializer running first.

--HG--
extra : rebase_source : 4d9a5340d097ac8528dc4aaaf0c05bbef40b59bb
2017-09-15 07:34:48 +09:00
Mike Hommey
e4f4d5fc59 Bug 1400063 - Automatically declare jemalloc_* functions in mozmemory.h. r=njn
There is a lot of churn involved in adding new API surface to
mozjemalloc, and mozmemory.h is one. Instead of declaring
everything manually in there, "generate" the declarations through
malloc_decls.h.

--HG--
extra : rebase_source : 1416fa972319c419112c4a8b16759d90692db5b2
2017-09-14 18:28:12 +09:00
Ryan VanderMeulen
277d6a438f Merge m-c to inbound. a=merge 2017-09-14 10:52:18 -04:00
Nathan Froyd
f8fda5a9b5 Bug 1396889 - don't warn about infinite recursion in mozalloc_abort; r=glandium
mozalloc_abort is not marked as a noreturn function on ARM, so clang
complains when abort calls mozalloc_abort, which calls MOZ_CRASH, which
calls abort().  We know this is OK, so just disable the warning.
2017-09-14 09:52:50 -04:00
Mike Hommey
9f3c42a57e Bug 1397101 - Only use a thread local arena for small sizes. r=njn
The bin-unused count in memory reports indicates how much memory is
used by runs of small and sub-page allocations that is not actually
allocated. This is generally thought as an indicator of fragmentation.

While this is generally true, with the use of thread local arenas by
stylo, combined with how stylo allocates memory, it ends up also being
an indicator of wasted memory.

For instance, over the lifetime of an AWSY iteration, there are only a
few allocations that ends up in the bucket for 2048 allocated bytes. In
the "worst" case, there's only one. But the run size for such
allocations is 132KiB. Which means just because we're allocating one
buffer of size between 1024 and 2048 bytes, we end up wasting 130+KiB.
Per thread.

Something similar happens with size classes of 512 and 1024, where the
run size is respectively 32KiB and 64KiB, and where there's at most a
handful of allocations of each class ever happening per thread.

Overall, an allocation log from a full AWSY iteration reveals that there
are only 448 of 860700 allocations happening on the stylo arenas that
involve sizes above (and excluding) 512 bytes, so 0.05%.

While there are improvements that can be done to mozjemalloc so that it
doesn't waste more than one page per sub-page size class, they are
changes that are too low-level to land at this time of the release
cycle. However, considering the numbers above and the fact that the
stylo arenas are only really meant to avoid lock contention during the
heavy parallel work involved, a short term, low risk, strategy is to
just delegate all sub-page (> 512, < 4096) and large (>= 4096) to the
main arena. Technically speaking, only sub-page allocations are causing
this waste, but it's more consistent to just delegate everything above
512 bytes.

This should save 132KiB + 64KiB = 196KiB per stylo thread.

--HG--
extra : rebase_source : c7233d60305365e76aa124045b1c9492068d9415
2017-09-14 07:36:39 +09:00
Mike Hommey
965981b68d Bug 1397101 - Reduce the number of dirty pages we allow to be kept in thread local arenas. r=njn
Until bug 1361258, there was only ever one mozjemalloc arena, and the
number of dirty pages we allow to be kept dirty, fixed to 1MB per arena,
was, in fact, 1MB for an entire process.

With stylo using thread local arenas, we now can have multiple arenas
per process, multiplying that number of dirty pages.

While those dirty pages may be reused later on, when other allocations
end up filling them later on, the fact that a relatively large number of
them is kept around for each stylo thread (in proportion to the amount of
memory ever allocated by stylo), combined with the fact that the memory
use from stylo depends on the workload generated by the pages being
visited, those dirty pages may very well not be used for a rather long
time. This is less of a problem with the main arena, used for most
everything else.

So, for each arena except the main one, we decrease the number of dirty
pages we allow to be kept around to 1/8 of the current value. We do this
by introducing a per-arena configuration of that maximum number.

--HG--
extra : rebase_source : 75eebb175b3746d5ca1c371606cface50ec70f2f
2017-09-14 07:26:30 +09:00
Mike Hommey
f98e560253 Bug 1399031 - Use mozilla/ThreadLocal.h in mozjemalloc. r=njn
--HG--
extra : rebase_source : 46e7abf6f46939cfa0862930feea5f245935b8d4
2017-09-12 16:29:11 +09:00
Mike Hommey
1e26a193e9 Bug 1399031 - Remove the setting of NO_TLS when PIC is not defined in mozjemalloc: it's always defined. r=njn
But it's also useless besides that test, so remove the PIC define.

--HG--
extra : rebase_source : 87b8934c1f8b6ed94e5ba3e2150f92dab9285769
2017-09-12 16:06:56 +09:00
Mike Hommey
05e3823899 Bug 1399350 - Remove jemalloc_*_impl macros. r=njn
Those macros are one more thing that needs to be added when the
mozjemalloc API surface is increased, but after bug 1399350, nothing
actually needs them, so remove them.

--HG--
extra : rebase_source : 2bf62cc6c179540482722a72b0d0c134d2ac2a19
2017-09-13 14:25:21 +09:00
Sebastian Hengst
6af41593df merge mozilla-central to mozilla-inbound. r=merge a=merge 2017-09-12 11:37:58 +02:00
Mike Hommey
6981b76dbc No bug - Remove the TODO item that was implemented in bug 1300948. r=me 2017-09-12 16:34:43 +09:00
Mike Hommey
8cdad036f1 Bug 1398965 - Fold memory/mozjemalloc into memory/build. r=njn
The files relevant to the memory allocator are currently spread between
memory/mozjemalloc and memory/build, and the distinction was
historically from sharing some Mozilla-specific things between
mozjemalloc and jemalloc3. That distinction is not useful anymore, so
we fold everything together.

As we will likely rename the allocator at some point in the future, it
is preferable to move away from the mozjemalloc directory rather than in
its direction.

--HG--
rename : memory/mozjemalloc/Makefile.in => memory/build/Makefile.in
rename : memory/mozjemalloc/mozjemalloc.cpp => memory/build/mozjemalloc.cpp
rename : memory/mozjemalloc/mozjemalloc.h => memory/build/mozjemalloc.h
rename : memory/mozjemalloc/mozjemalloc_types.h => memory/build/mozjemalloc_types.h
rename : memory/mozjemalloc/rb.h => memory/build/rb.h
2017-09-12 13:14:35 +09:00
Mike Hommey
175ddd015f Bug 1398965 - Remove MOZ_JEMALLOC_IMPL in favor of MOZ_MEMORY_IMPL. r=njn
In practice, they mean the same thing, and there's only one place where
MOZ_JEMALLOC_IMPL was used.
2017-09-12 13:06:43 +09:00
Mike Hommey
be1493b6fc Bug 1396723 - Use DoublyLinkedList in mozjemalloc. r=froydnj
Mozjemalloc uses its own doubly linked list, which, being inherited from
C code, doesn't do much type checking, and, in practice, is rather
similar to DoublyLinkedList, so use the latter instead.

--HG--
extra : rebase_source : 9eb7334b6dde05f9af0eaea4184e532c69d0264e
2017-09-02 08:55:42 +09:00
Chris Manchester
fab07bc443 Bug 1386876 - Replace all uses of NO_VISIBILITY_FLAGS with a template and remove NO_VISIBILITY_FLAGS. r=glandium
MozReview-Commit-ID: 194U1WMCAM0

--HG--
extra : rebase_source : 365b68b0a1772d238ae9b84966e53dcd1197fd85
2017-05-01 18:12:35 -07:00
Chris Manchester
c0a229d4c3 Bug 1386876 - Replace all uses of DISABLE_STL_WRAPPING with a template, remove DISABLE_STL_WRAPPING. r=glandium
MozReview-Commit-ID: FMEtb5PY7iP

--HG--
extra : rebase_source : 3cdee7528846462c758e623d6bcd2e6e17dbabff
2017-09-11 11:33:26 -07:00
Nathan Froyd
c88ec30451 Bug 1396892 - turn off -Wtautological-pointer-compare in memory/build/ for Android; r=njn
clang warns about this code in mozmemory_wrap.c in the reimplementation
of vasprintf, complaining that `fmt` cannot be null:

    if (str == NULL || fmt == NULL) {
                       ^~~    ~~~~

clang is apparently exploiting knowledge about the requirements of
vasprintf here, but defensive programming on the part of our
reimplementation seems like the wiser course.  Let's turn off the
warning.
2017-09-07 08:20:12 -04:00
Mike Hommey
938f8a3862 Bug 1396681 - Remove some typedefs in mozjemalloc. r=njn
Previously being a C codebase, mozjemalloc was using typedefs, avoiding
long "struct foo" uses. C++ doesn't need typedefs to achieve that, so we
can remove all that. We however keep a few typedefs in headers that are
still included from other C source files.

--HG--
extra : rebase_source : d0d807bcb76078c0ce36e4554b10803bfb36ddbb
2017-09-02 08:15:39 +09:00
Mike Hommey
acb85e2b41 Bug 1396361 - Avoid crashing when some system library calls malloc_zone_free(zone, NULL). r=njn
Some system libraries call malloc_zone_free directly instead of free,
and sometimes they do that with the wrong zone. When that happens, we
circle back, trying to find the right zone, and call malloc_zone_free
with the right one, but when we can't find one, we crash, which matches
what the system free() would do. Except in one case where the pointer
we're being passed is NULL, in which case we can't trace it back to any
zone, but shouldn't crash (system free() explicitly doesn't crash in
that case).

--HG--
extra : rebase_source : 17efdcd80f1a53be7ab6b7293bfb6060a9aa4a48
2017-09-04 07:32:42 +09:00
Mike Hommey
e8e9ecbd5d Bug 1395776 - Make _recalloc, _expand and _msize go through replace-malloc when enabled. r=njn
--HG--
extra : rebase_source : 454d6dc58681a9bde3564216d013746c0f189add
2017-08-31 14:17:49 +09:00
Mike Hommey
551fcf616e Bug 1395776 - Share the posix_memalign, aligned_alloc and valloc implementations between mozjemalloc and replace-malloc. r=njn
--HG--
extra : rebase_source : ed41b23993cdee89d28b835ee0ee196c15977427
2017-08-31 14:17:19 +09:00
Mike Hommey
e77f51a721 Bug 1395776 - Fold replace-malloc into mozjemalloc. r=njn
Add the MPL 2.0 license header per bug 1395449.

--HG--
extra : rebase_source : c85544a178aba7e77b5b8031851b8e16b22a3848
2017-08-31 12:02:01 +09:00
Mike Hommey
24484e3284 Bug 1395776 - Remove useless goto. r=njn
--HG--
extra : rebase_source : 760898d1521d2c27658e0494677cfecd0375894f
2017-08-31 11:47:22 +09:00
Mike Hommey
89443bb39f Bug 1395776 - Add a level of indirection on top of mozjemalloc. r=njn
Practically speaking, with code inlining, this doesn't change anything,
but will allow, in a subsequent change, to easily divert the exported
allocation functions (malloc, etc.) in order to inject replace-malloc
in the pipeline.

The added macro magic is copied from replace-malloc.c.

At the same time, reformat the functions we're touching.

--HG--
extra : rebase_source : f615909101f832f3cc471e23a3cc44a60886843f
2017-08-31 10:29:11 +09:00
Mike Hommey
dfc6786a68 Bug 1395776 - Move usable_ptr_t definition to mozjemalloc_types.h. r=njn
Because malloc_decls.h is meant to be included multiple times, it
shouldn't actually declare things itself.

--HG--
extra : rebase_source : 9d6f9b2c61407265377845963a19ace2614160f4
2017-08-31 09:51:23 +09:00
Mike Hommey
72d9b36a8c Bug 1395776 - Uniformize valloc implementations in replace-malloc and mozjemalloc. r=njn
valloc is supposed to page-align data, but mozjemalloc's definition of
pagesize is statically compiled in and might not match the actual page
size at runtime (because of MALLOC_STATIC_SIZES). We change valloc in
mozjemalloc to use the runtime page size.

--HG--
extra : rebase_source : c5b1b56e783b311ac1620a87d910e019e3f18b49
2017-08-31 11:36:09 +09:00
Mike Hommey
b0303d9e77 Bug 1395776 - Uniformize posix_memalign implementations in replace-malloc and mozjemalloc. r=njn
--HG--
extra : rebase_source : bbbee18feef2d11b71d5d5a48e98017bfae78722
2017-08-31 11:35:24 +09:00
Sebastian Hengst
43bc951ac7 merge mozilla-inbound to mozilla-central. r=merge a=merge
MozReview-Commit-ID: ES9rKhiQo10
2017-09-01 10:38:51 +02:00
Nicholas Nethercote
c419d5fa48 Bug 1389305 (attempt 2) - Add jemalloc_ptr_info() and moz_malloc_enclosing_size_of(). r=glandium.
--HG--
extra : rebase_source : 93a6cfcc916fb239581c2892f24b24c6fc65ac71
2017-09-01 11:52:23 +10:00
Mike Hommey
01f5dbf93d Bug 1395070 - Replace MOZ_MEMORY_BSD with __FreeBSD_kernel__. r=njn
While MOZ_MEMORY_BSD is set for kFreeBSD, FreeBSD and NetBSD, the only
use of MOZ_MEMORY_BSD is along a check for __GLIBC__ which can only be
true on GNU/kFreeBSD, which doesn't have a XP_ macro, but which we
usually match with __FreeBSD_kernel__.

--HG--
extra : rebase_source : 2f143f8ed641f4e338024a58e20c62b2b30e653a
2017-08-30 16:58:42 +09:00
Mike Hommey
214207b152 Bug 1395070 - Replace MOZ_MEMORY_SOLARIS with XP_SOLARIS. r=njn
--HG--
extra : rebase_source : 5ce65228f7d45da354f6447b3e54781a8553e33b
2017-08-30 16:57:46 +09:00
Mike Hommey
c5dc8a36e4 Bug 1395070 - Replace MOZ_MEMORY_ANDROID with ANDROID. r=njn
For some reason, we don't have a XP_ macro for Android, and we generally use
ANDROID or MOZ_WIDGET_ANDROID. The former is more appropriate.

--HG--
extra : rebase_source : 50576584f194aaf6b090fd530598ce9954e170b3
2017-08-30 16:56:42 +09:00
Mike Hommey
c50122ffb7 Bug 1395070 - Replace MOZ_MEMORY_LINUX with XP_LINUX. r=njn
--HG--
extra : rebase_source : 013c8019777cd87663e60def10a2df549c9308a2
2017-08-30 16:55:30 +09:00
Mike Hommey
2367bdac74 Bug 1395070 - Replace MOZ_MEMORY_DARWIN with XP_DARWIN. r=njn
--HG--
extra : rebase_source : 9e92062072cc45c524d30e9b2e28930687bf45a4
2017-08-30 16:54:17 +09:00
Mike Hommey
e290647690 Bug 1395070 - Replace MOZ_MEMORY_WINDOWS with XP_WIN. r=njn
--HG--
extra : rebase_source : 1c63dca430aa6c81472463d27df41f2acdc2df88
2017-08-30 16:53:10 +09:00
Mike Hommey
57c65279a0 Bug 1395088 - Remove the jemalloc_bool type. r=njn
Back when it was added (for Windows CE, in bug 488608), mozjemalloc was
C and all the supported compilers didn't support C99 bools. Now
mozjemalloc is C++, and all the supported compilers support C99 bools
for the cases where the type is used from C.

--HG--
extra : rebase_source : b9c710a0c48dc36cb473af59e3119131d13523ce
2017-08-30 18:04:47 +09:00
Mike Hommey
0eb2652011 Bug 1395063 - Use MOZ_CRASH directly in mozjemalloc. r=njn
Back when mozjemalloc was considered third-party, and before bug
1365194, mozjemalloc was calling abort() and that was redirectory to
MOZ_CRASH through a moz_abort() function. Bug 1365194 changed that so
that moz_abort is called directly instead of abort, but the indirection
is actually not necessary anymore.

So we just kill moz_abort, which is unused anywhere else, and use
MOZ_CRASH directly.

Note this will (obviously) change crash signatures involving moz_abort.

--HG--
extra : rebase_source : 67698ffd8c5e52e62b9a0b7f28efb0352c8fe8ce
2017-08-30 16:20:08 +09:00
Sylvestre Ledru
64ca35fefe Bug 1387572 - Silent the -Wuninitialized warning r=glandium
MozReview-Commit-ID: DjUumKhNQHz

--HG--
extra : rebase_source : 5bec2af822a54ff2c40b5944d3360b7c889c5ccb
2017-08-04 21:51:18 +02:00
Tom Ritter
1243cb04e0 Bug 1392594 Make variable DebugOnly to address unused variable warning r=glandium
MozReview-Commit-ID: 1qQQGjeWeel

--HG--
extra : rebase_source : f527762cc8d0b572c5315d2a6a11db8e69fbc999
2017-08-24 22:55:35 -05:00
David Major
406287685a Bug 1391420: Set NO_PGO on a bunch of binaries that we don't ship. r=ted 2017-08-23 15:05:40 -04:00
Sebastian Hengst
142b3bf28b Backed out changeset 109e89a7d561 (bug 1391420) for busting Linux pgo builds. r=backout on a CLOSED TREE
--HG--
extra : amend_source : 6a4421254e4de31071785b73abdd1186638e31f2
2017-08-23 18:12:46 +02:00
David Major
8cb2cb650a Bug 1391420: Set NO_PGO on a bunch of binaries that we don't ship. r=ted 2017-08-23 11:10:39 -04:00
Eric Rahm
0938982c90 Bug 1389598 - Part 4: Remove remaining gonk refs. r=froydnj
--HG--
extra : rebase_source : 063c7f95dda063eafabfa1921366bd1957b8fe73
2017-08-11 17:45:18 -07:00
Nicholas Nethercote
57c26c9834 Bug 1387956 - Overhaul ComputedValues measurement, and add style structs measurement. r=bholley.
This patch moves measurement of ComputedValues objects from Rust to C++.
Measurement now happens (a) via DOM elements and (b) remaining elements via
the frame tree. Likewise for the style structs hanging off ComputedValues
objects.

Here is an example of the output.

> ├──27,600,448 B (26.49%) -- active/window(https://en.wikipedia.org/wiki/Barack_Obama)
> │  ├──12,772,544 B (12.26%) -- layout
> │  │  ├───4,483,744 B (04.30%) -- frames
> │  │  │   ├──1,653,552 B (01.59%) ── nsInlineFrame
> │  │  │   ├──1,415,760 B (01.36%) ── nsTextFrame
> │  │  │   ├────431,376 B (00.41%) ── nsBlockFrame
> │  │  │   ├────340,560 B (00.33%) ── nsHTMLScrollFrame
> │  │  │   ├────302,544 B (00.29%) ── nsContinuingTextFrame
> │  │  │   ├────156,408 B (00.15%) ── nsBulletFrame
> │  │  │   ├─────73,024 B (00.07%) ── nsPlaceholderFrame
> │  │  │   ├─────27,656 B (00.03%) ── sundries
> │  │  │   ├─────23,520 B (00.02%) ── nsTableCellFrame
> │  │  │   ├─────16,704 B (00.02%) ── nsImageFrame
> │  │  │   ├─────15,488 B (00.01%) ── nsTableRowFrame
> │  │  │   ├─────13,776 B (00.01%) ── nsTableColFrame
> │  │  │   └─────13,376 B (00.01%) ── nsTableFrame
> │  │  ├───3,412,192 B (03.28%) -- servo-style-structs
> │  │  │   ├──1,288,224 B (01.24%) ── Display
> │  │  │   ├────742,400 B (00.71%) ── Position
> │  │  │   ├────308,736 B (00.30%) ── Font
> │  │  │   ├────226,512 B (00.22%) ── Background
> │  │  │   ├────218,304 B (00.21%) ── TextReset
> │  │  │   ├────214,896 B (00.21%) ── Text
> │  │  │   ├────130,560 B (00.13%) ── Border
> │  │  │   ├─────81,408 B (00.08%) ── UIReset
> │  │  │   ├─────61,440 B (00.06%) ── Padding
> │  │  │   ├─────38,176 B (00.04%) ── UserInterface
> │  │  │   ├─────29,232 B (00.03%) ── Margin
> │  │  │   ├─────21,824 B (00.02%) ── sundries
> │  │  │   ├─────20,080 B (00.02%) ── Color
> │  │  │   ├─────20,080 B (00.02%) ── Column
> │  │  │   └─────10,320 B (00.01%) ── Effects
> │  │  ├───2,227,680 B (02.14%) -- computed-values
> │  │  │   ├──1,182,928 B (01.14%) ── non-dom
> │  │  │   └──1,044,752 B (01.00%) ── dom
> │  │  ├───1,500,016 B (01.44%) ── text-runs
> │  │  ├─────492,640 B (00.47%) ── line-boxes
> │  │  ├─────326,688 B (00.31%) ── frame-properties
> │  │  ├─────301,760 B (00.29%) ── pres-shell
> │  │  ├──────27,648 B (00.03%) ── pres-contexts
> │  │  └─────────176 B (00.00%) ── style-sets

The 'servo-style-structs' and 'computed-values' sub-trees are new. (Prior to
this patch, ComputedValues under DOM elements were tallied under the the
'dom/element-nodes' sub-tree, and ComputedValues not under DOM element were
ignored.) 'servo-style-structs/sundries' aggregates all the style structs that
are smaller than 8 KiB.

Other notable things done by the patch are as follows.

- It significantly changes the signatures of the methods measuring nsINode and
  its subclasses, in order to handle the tallying of style structs separately
  from element-nodes. Likewise for nsIFrame.

- It renames the 'layout/style-structs' sub-tree as
  'layout/gecko-style-structs', to clearly distinguish it from the new
  'layout/servo-style-structs' sub-tree.

- It adds some FFI functions to access various Rust-side data structures from
  C++ code.

- There is a nasty hack used twice to measure Arcs, by stepping backwards from
  an interior pointer to a base pointer. It works, but I want to replace it
  with something better eventually. The "XXX WARNING" comments have details.

- It makes DMD print a line to the console if it sees a pointer it doesn't
  recognise. This is useful for detecting when we are measuring an interior
  pointer instead of a base pointer, which is bad but easy to do when Arcs are
  involved.

- It removes the Rust code for measuring CVs, because it's now all done on the
  C++ side.

MozReview-Commit-ID: BKebACLKtCi

--HG--
extra : rebase_source : 4d9a8c6b198a0ff025b811759a6bfa9f33a260ba
2017-08-11 16:37:33 +10:00
Mike Hommey
fda40761ff Bug 1388935 - Avoid overflowing the chunk recycling limit with very large chunks. r=njn
When recycling chunks, mozjemalloc tries to avoid keeping around more
than 128MB worth of chunks around, but it doesn't actually look at the
size of the chunks that are recycled, so if chunk larger than 128MB is
recycled, it is kept as a whole, going well over the limit.

The chunks are still properly reused, and further recycling doesn't
occur, but that can limit other mmap users from getting enough address
space.

With this change, mozjemalloc now doesn't keep more than 128MB, by
splitting the chunks it recycles if they are too large.

Note this was not a problem on Windows, where chunks larger than 1MB are
never recycled (per CAN_RECYCLE).

--HG--
extra : rebase_source : 6765fd30b78ca5ddc7d55aac861355d960e47828
2017-08-10 09:22:55 +09:00
Mike Hommey
b0f2504373 Bug 1388935 - Inline chunk_dalloc_mmap into chunk_dealloc. r=njn
--HG--
extra : rebase_source : 3348f221f1f577c3af6c1b213a692e58ce347ead
2017-08-10 08:49:51 +09:00
Phil Ringnalda
fe1932364b Backed out 2 changesets (bug 1388935) for gtest crashes
Backed out changeset 208572c7abae (bug 1388935)
Backed out changeset dfb4a15b0c32 (bug 1388935)

MozReview-Commit-ID: HRttV7AIlNT
2017-08-09 22:21:37 -07:00
Mike Hommey
44b527c7d7 Bug 1388935 - Avoid overflowing the chunk recycling limit with very large chunks. r=njn
When recycling chunks, mozjemalloc tries to avoid keeping around more
than 128MB worth of chunks around, but it doesn't actually look at the
size of the chunks that are recycled, so if chunk larger than 128MB is
recycled, it is kept as a whole, going well over the limit.

The chunks are still properly reused, and further recycling doesn't
occur, but that can limit other mmap users from getting enough address
space.

With this change, mozjemalloc now doesn't keep more than 128MB, by
splitting the chunks it recycles if they are too large.

Note this was not a problem on Windows, where chunks larger than 1MB are
never recycled (per CAN_RECYCLE).

--HG--
extra : rebase_source : f81e94c6960ba253037f77de1a39c9ff74651e80
2017-08-10 09:22:55 +09:00
Mike Hommey
b206b3c597 Bug 1388935 - Inline chunk_dalloc_mmap into chunk_dealloc. r=njn
--HG--
extra : rebase_source : f6abde118d26552a681faf7df302b791d39e466a
2017-08-10 08:49:51 +09:00
Nicholas Nethercote
710682624c Bug 1387940 - Make --max-frames=8 the default for dmd.py. r=mccr8.
The current default is 24, which is equal to the maximum number of stack frames
that DMD will record. And that's a terrible value because it splits up too many
related stack traces into separate records. There is no single best value, but
8 is a much better default.

--HG--
extra : rebase_source : c423fc4fe0e490ff6d58fa8f7116bc01c86a366e
2017-08-07 14:56:15 +10:00
Wes Kocher
baf6cddc4c Merge inbound to central, a=merge
MozReview-Commit-ID: 9NFjSEt96iT
2017-08-02 17:11:51 -07:00
Nicholas Nethercote
406a9ed175 Bug 1384819 (part 3) - Remove the return value from the stack walker functions. r=glandium.
Just one caller (in DMD) actually looks at it, and that's in an unimportant way
-- if the return value was false, mLength would be zero anyway.

--HG--
extra : rebase_source : 0463ab3765744742a9e854964342d631095fa55f
2017-07-27 16:46:55 +10:00
Nicholas Nethercote
8a20eb82d2 Bug 1384819 (part 2) - Tweak FramePointerStackWalk() arguments. r=glandium.
This patch does he following.

- Avoids some unnecessary casting.

- Renames the |bp| parameter as |aBp|.

- Makes the no-op FramePointerStackWalk() signature match the real one.
  (Clearly it's dead code in all built configurations!)

--HG--
extra : rebase_source : 3fe606d1ff9b063294f4028ff884c20661ed9e0a
2017-07-27 16:46:33 +10:00
Nicholas Nethercote
08e54b7c13 Bug 1384819 (part 1) - Split MozStackWalk(). r=glandium.
MozStackWalk() is different on Windows to the other platforms. It has two extra
arguments, which can be used to walk the stack of a different thread.

This patch makes those differences clearer. Instead of having a single function
and forbidding those two arguments on non-Windows, it removes those arguments
from MozStackWalk, and splits off MozStackWalkThread() which retains them. This
also allows those arguments to have more appropriate types (HANDLE instead of
uintptr_t; CONTEXT* instead of than void*) and names (aContext instead of
aPlatformData).

The patch also removes unnecessary reinterpret_casts for the aClosure argument
at a couple of MozStackWalk() callsites.

--HG--
extra : rebase_source : 111ab7d6426d7be921facc2264f6db86c501d127
2017-07-27 12:46:47 +10:00
Botond Ballo
b93629ee1d Bug 1383919 - Use |noexcept| instead of an exception-specification in mozalloc.h. r=glandium
MozReview-Commit-ID: DwrE8cmZOQN

--HG--
extra : rebase_source : e45f35dd009a3a8a94f50afc55177976c532f16a
2017-07-24 19:19:07 -04:00
Mike Hommey
4aaef7b18a Bug 1395032 - Remove remainder of the VS CRT allocator mismatch hack. r=gps
Bug 1186064 removed most of it when we started requiring VS 2015u2, but
the "frex" function exported through mozglue.def.in was only used
through the MSVCRT being patched by fixcrt.py, which is not done anymore.
So the "frex" export is not used anymore, and so the "dumb_free_thunk"
function is not used anymore as well.

--HG--
extra : rebase_source : 879c469c317c8b6749410a4a476d6c951c9a1d0f
2017-08-30 14:06:13 +09:00
Nicholas Nethercote
f7a538edd4 Bug 1382076 - Use FramePointerStackWalk() in DMD on Win32. r=erahm.
The patch also uses a better value for skipFrames on Win64.

--HG--
extra : rebase_source : ef3d6d68fbea45e7fd571db2ba78904d97f5e21e
2017-07-20 11:33:31 +10:00
Nicholas Nethercote
7d699f9fa4 Bug 1382099 - Remove MOZ_WIDGET_GONK from memory/. r=glandium.
--HG--
extra : rebase_source : 641de85945cb2f0ccdb9d6f5207bdd22b597b318
2017-07-19 18:39:00 +10:00
Mike Hommey
4956a3cafa Bug 1379897 - Remove opt_abort. r=njn
It causes abort() on errors from munmap/VirtualFree (which in practice
don't happen except maybe in case of memory corruption), and was only
enabled on debug builds.

--HG--
extra : rebase_source : fb0c8c82dc1e2d1f14a588a82144cf82e4f4f773
2017-07-11 14:24:35 +09:00
Carsten "Tomcat" Book
31311070d9 merge mozilla-inbound to mozilla-central a=merge 2017-07-11 12:51:59 +02:00
Mike Hommey
1246710041 Bug 1379890 - Remove unused mozjemalloc stats. r=njn
Since bug 1378258 remove malloc_print_stats, there are a bunch of
allocator stats that are now unused, reducing the memory footprint of
allocator metadata.

--HG--
extra : rebase_source : 337ef3b647c20119334b6576d591006f6bb3dd16
2017-07-11 14:42:57 +09:00
Mike Hommey
1ecc9df3fc Bug 1379878 - Use C++ templates to make _malloc_message calls cleaner. r=njn
--HG--
extra : rebase_source : 695fd9ce6b1f216a8bda29b849e1372601a43fe4
2017-07-11 14:15:04 +09:00
Mike Hommey
26fb8eb7b0 Bug 1379878 - Remove umax2s, its last use was removed in bug 1378258. r=njn
--HG--
extra : rebase_source : d9cb0631662ec0015e9c6d268884adb31c5a38bb
2017-07-11 14:09:09 +09:00
Mike Hommey
860374cbca Bug 1360772 - Allow to initialize non-zeroed arena chunks. r=njn
When initializing a new chunk for use as an arena, we started by zeroing
out the chunk (if that wasn't the case) and then initializing a new
arena chunk in there. It turns out this can have a noticeable overhead,
especially when e.g. the new arena chunk is used for a large allocation
filled out by something that is realloc()ated.

OTOH, the chunk recycle code only ever keeps zeroed or arena chunks
around (there is a "recycled" type too, but in practice, at the moment,
this means they were arena chunks before). Arena chunks that were
recycled were totally emptied, so all the runs they may contain will
contain zeroed-out or poisoned data. They also contain a header, that is
overwritten by the new arena chunk initialization.

This means we can get away with reusing non-zeroed recycled chunks
without zeroing them, as long as the arena chunk header marks the runs
as madvised instead of zeroed.

Code-wise, this would benefit from getting a ChunkType out of
chunk_alloc, but this would require more refactoring than I'm willing to
do at the moment.
2017-07-11 13:55:26 +09:00
Mike Hommey
e6c1516607 Bug 1360772 - Indicate to chunk_recycle callers that pages_commit has zeroed the chunk. r=njn
Before returning a chunk, chunk_recycle calls pages_commit (when
MALLOC_DECOMMIT is enabled), which is guaranteed to zero the chunk.

The code further zeroing the chunk afterwards, which is now moved out to
chunk_alloc callers, never took advantage of that fact, duplicating the
effort of zeroing the chunk on Windows.

By indicating to the callers that the chunk has already been zeroed, we
allow callers to skip zeroing on their own.
2017-07-11 13:44:40 +09:00
Mike Hommey
78a584db8a Bug 1360772 - Make chunk_alloc callers handle zeroing when they need it. r=njn
The current code only allows chunk_calloc() callers to tell whether they
want zeroed memory or not, but some might be okay either way, assuming
they act accordingly afterwards. So move the zeroing out of chunk_alloc.
2017-07-11 13:44:39 +09:00
Mike Hommey
f26f174a0e Bug 1360772 - Store the chunk type in chunk recycling queue. r=njn 2017-07-11 13:44:21 +09:00
Mike Hommey
0380bc7b32 Bug 1360772 - Make pages_purge return whether the pages were purged. r=njn
Many functions in the mozjemalloc codebase like to return the opposite
boolean one would tend to expect. Pages_purge is one of them, and this
reverses the logic to match expectations.

Also make it static.
2017-07-11 13:11:55 +09:00
Mike Hommey
bf7a9e79f6 Bug 1379139 - Instead of not recycling huge chunks, zero them. r=njn
It turns out that not recycling some kinds of chunk can lead to the
recycle queue being starved in some scenarios. When that happens, we end
up mmap()ing new memory, but that turns out to be significantly slower.

So instead of not recycling huge chunks, we force-clean them, before
madvising so that the pages can still be reclaimed in case of memory
pressure.

--HG--
extra : rebase_source : 2dbd028daca92c9cd7c8079eb3dc5a0cfa06495b
2017-07-10 06:41:17 +09:00
Nicholas Nethercote
4325ae218a Bug 1371397 - Use FramePointerStackWalk() in DMD on Mac. r=erahm.
This avoids MozStackWalk(), which has become unusably slow on Mac due to
changes in libunwind, and gets us back to decent speed.

The code for getting the frame pointer and stack end was copied from the Gecko
Profiler, which also uses FramePointerStackWalk() on Mac.

--HG--
extra : rebase_source : 58c32c2df8716c7c8123a4a8fb692182d066caca
2017-07-07 07:08:08 +10:00
Carsten "Tomcat" Book
b5c809a8bc merge mozilla-inbound to mozilla-central a=merge 2017-07-07 10:35:44 +02:00
Mike Hommey
19448fe709 Bug 1356701 - Export unprefixed malloc and duplication functions on OSX. r=njn
Going through the system zone allocator for every call to realloc/free
on OSX is costly, because the zone allocator needs to first verify that
the allocations do belong to the allocator it invokes (which ends up
calling jemalloc's malloc_usable_size), which is unnecessary when we
expect the allocations to belong to jemalloc.

So, we export the malloc/realloc/free/etc. symbols from
libmozglue.dylib, such that libraries and programs linked against it
call directly into jemalloc instead of going through the system zone
allocator, effectively shortcutting the allocator verification.

The risk is that some things in Gecko try to realloc/free pointers it
got from system libraries, if those were allocated with a system zone
that is not jemalloc.

--HG--
extra : rebase_source : ee0b29e1275176f52e64f4648dfa7ce25d61292e
2017-07-04 15:01:50 +09:00
Mike Hommey
ed863255b4 Bug 1378592 - Remove MOZ_REPLACE_MALLOC_LINKAGE. r=froydnj
MOZ_REPLACE_MALLOC_LINKAGE was added back when there were problems with
getting weak references working properly for replace-malloc.

Versions of OSX < 10.6 needed flat namespace, but aren't supported
anymore.

Versions of Xcode < 4.5 required flat namespace + a dummy library in
order to produce proper weak references. There is virtually nobody still
building with such an ancient toolchain.

Keeping those around doesn't /really/ hurt, except recent versions of
Xcode don't expose dyldinfo in /usr/bin, used for the configure test.
Consequently, MOZ_REPLACE_MALLOC_LINKAGE ended up being set to use the
dummy library setup, which, by using flat namespace, now causes harm in
bug 1356701, causing bug 1378332.

--HG--
extra : rebase_source : e3edc1f2cf905943c33fafeb631f2f88fc87167e
2017-07-06 10:26:04 +09:00
Mike Hommey
a02826e8ee Bug 1378278 - Use nullptr in mozjemalloc. r=njn
At the same time:
- replace "(nullptr)" with "nullptr",
- replace "x == nullptr" with "!x",
- replace "x != nullptr" with "x".

--HG--
extra : rebase_source : 5bc5577d0de53244afae9ebadb84962f38306368
2017-07-05 14:02:50 +09:00
Ryan VanderMeulen
5e1e8d2f24 Backed out changeset 261d61f4eeec (bug 1356701) for causing bug 1378339. 2017-07-05 12:58:39 -04:00
Mike Hommey
230dccc3d5 Bug 1378258 - Remove malloc_print_stats. r=njn
malloc_print_stats is designed as a end-of-process dump of malloc stats,
but it has limited value in Firefox itself. It has some usefulness as
something to invoke from a debugger while Firefox is running (after
manually setting opt_print_stats to true), but it also lacks information
about live allocations, which would make it more useful.

All in all, if we want some stats about jemalloc allocations in a more
useful way, we'd be better off augmenting the jemalloc_stats() API and
make the data available to e.g. about:memory, than keeping
malloc_print_stats.

--HG--
extra : rebase_source : f6fbc97dfddd52c8620e37e2e189ae0087a845b0
2017-07-05 10:07:43 +09:00
Mike Hommey
c65bedc1c8 Bug 1356701 - Export unprefixed malloc and duplication functions on OSX. r=njn
Going through the system zone allocator for every call to realloc/free
on OSX is costly, because the zone allocator needs to first verify that
the allocations do belong to the allocator it invokes (which ends up
calling jemalloc's malloc_usable_size), which is unnecessary when we
expect the allocations to belong to jemalloc.

So, we export the malloc/realloc/free/etc. symbols from
libmozglue.dylib, such that libraries and programs linked against it
calls directly into jemalloc instead of going through the system zone
allocator, effectively shortcutting the allocator verification.

The risk is that some things in Gecko try to realloc/free pointers it
got from system libraries, if those were allocated with a system zone
that is not jemalloc.

--HG--
extra : rebase_source : 45b9b98499760a7f946878d41d2fdaadb6dff4d6
2017-07-04 15:01:50 +09:00
Petr Sumbera
a393f2a6cf Bug 1375467 - Redefining abort() in C++ requires extern "C". r=glandium 2017-06-22 05:09:05 -07:00
Jeff Gilbert
58ae26fbc7 Bug 1376057 - Replace MSVC wrappers with std::exception::_Set_raise_handler. - r=froydnj
MozReview-Commit-ID: MG5c4bzDlI
2017-06-27 11:51:34 -07:00
Mike Hommey
7ccc8afe84 Bug 1378658 - When page_purges doesn't zero pages, only record arena chunks or previously recycled chunks for future recycling. r=njn 2017-07-07 09:18:03 +09:00
Mike Hommey
29524a9451 Bug 1369626 - Remove MALLOC_XMALLOC. r=njn
Setting MALLOC_XMALLOC enables a runtime toggle that allows to make
allocations abort() on OOM instead of returning NULL. In other words,
it enables a toggle that allows to turn all allocations into infallible
allocations.

The toggle however still defaults to being disabled, which means even
when MALLOC_XMALLOC is defined when building mozjemalloc, there is no
change in behavior, unless a MALLOC_OPTIONS is set.

Even if this were useful to anyone (MALLOC_XMALLOC is only defined on
debug builds, limiting the usefulness), this is something
replace-malloc, in Firefox, is meant to be used for.

So let's remove this feature, and possibly add an equivalent
replace-malloc later if deemed necessary.

--HG--
extra : rebase_source : 1ccc893e9a8e842c3fa90e91f076a528df2f7dfe
2017-06-02 15:19:20 +09:00
Mike Hommey
1b12c351f2 Bug 1368932 - Add a testcase for a replace-malloc library that doesn't implement all functions. r=njn
--HG--
rename : memory/replace/logalloc/moz.build => memory/replace/logalloc/logalloc.mozbuild
rename : memory/replace/logalloc/replay/replay.log => memory/replace/logalloc/replay/expected_output_minimal.log
extra : rebase_source : 94f8fb4444e2e0ecda61e5ffd283ab560d1e9dfe
2017-05-31 15:04:32 +09:00
Mike Hommey
4ae1509807 Bug 1368932 - Handle missing replace_posix_memalign at the replace-malloc level. r=njn
Replace-malloc libraries, such as DMD, don't really need to care about
the details of implementing all the variants of aligned memory
allocation functions. Currently, by defining MOZ_REPLACE_ONLY_MEMALIGN
before including replace_malloc.h, they get predefined functions.

Instead of making that an opt-in at build time, we make the
replace-malloc initialization just fill the replace-malloc
malloc_table_t with implementations that rely on the replace_memalign
the library provides.

--HG--
extra : rebase_source : 0842a67d9bc27a9a86c33d14d98b9c25f39982fb
2017-05-31 13:47:17 +09:00
Mike Hommey
7fd2c94e79 Bug 1368932 - Move the replace_malloc_init_funcs function around. r=njn
--HG--
extra : rebase_source : 4e3b3bbd18a37a3ee01d6ec30449249be5481b77
2017-05-31 13:47:11 +09:00
Mike Hommey
565f74102e Bug 1368932 - Fill the replace-malloc malloc_table_t with the real allocator as a fallback. r=njn
Until now, the malloc implementation functions would call the
replace-malloc functions if they exist, and fallback to the real
allocator in no such function exists. Instead of doing this, we now
fill the empty slots in the malloc_table_t with the real allocator
functions.

--HG--
extra : rebase_source : b54634f23188906939e4dc01fc5a3007de0f3f2c
2017-05-30 15:57:28 +09:00
Mike Hommey
1a6ac2f8fb Bug 1368932 - Use a malloc_table_t for most replace-malloc function pointers, on all platforms. r=njn
We make replace_malloc_init_funcs called on all platforms and fill out a
malloc_table_t for the replace-malloc functions with what comes from
dlsym/GetProcAddress on Android/Windows, and from the dynamically linked
weak symbols replace_* on other platforms.

replace_malloc.h contains definitions of *_impl_t types for each of the
functions in the malloc_table_t, which is redundant with the
replace_*_impl_t types we were creating, so we remove those typedefs,
except for the two functions (init and get_bridge) that don't have such
a typedef. Those functions don't appear in malloc_table_t.

--HG--
extra : rebase_source : 3705a99ee07f63dbaa66973eef19ddab224e0911
2017-05-30 15:57:28 +09:00
Mike Hommey
409495f283 Bug 1368932 - Refactor such that there is only one definition of replace_malloc_init_funcs. r=njn
We want, in a subsequent patch, to have replace_malloc_init_funcs be
called on all platforms (including those relying on the replace-malloc
library being loaded already) and perform more initialization.

To prepare for that, we move the non-platform-specific pieces out.

--HG--
extra : rebase_source : 239ed363ee168bf4f8a96e0a1ca52981cb941b71
2017-05-30 15:57:28 +09:00
Mike Hommey
37b66db19d Bug 1368932 - Generate all the _impl functions with macros in replace-malloc. r=njn
All the _impl functions in replace-malloc.c are largely identical. This
replaces all of them with macro expansions.

--HG--
extra : rebase_source : 67a1809b0b0fc4645ea5041154fa3a6dcb6cce6b
2017-05-25 16:47:57 +09:00
Mike Hommey
e4fddc104f Bug 1368932 - Add argument names to malloc implementation declarations in replace-malloc. r=njn
This transforms the declarations from e.g.:
    void *realloc(void *, size_t);
into:
    void *realloc(void *arg1, size_t arg2);

--HG--
extra : rebase_source : 627eb833a98d11f044c776f9d29715ccad31174d
2017-05-25 16:04:46 +09:00
Mike Hommey
2357f45d41 Bug 1368932 - Don't rely on the default MALLOC_DECL_VOID for malloc function declarations in replace-malloc. r=njn
In practice, this induces no change in what the expanded code looks
like.

--HG--
extra : rebase_source : 0df6a5dd3ca5161c0969c814e4222eeb51f9f9a2
2017-05-25 15:58:56 +09:00
Mike Hommey
7cd6d8b45d Bug 1368932 - Factor out function declarations for malloc implementation. r=njn
--HG--
extra : rebase_source : a8df78c7ade473eb5d7c71228f0939cce4554f57
2017-05-25 15:54:05 +09:00
Mike Hommey
16215c85f1 Bug 1368932 - Remove void argument from declarations in malloc_decls.h. r=njn
This makes no significant difference in practice in the macro
expansions, but will help down the line.

--HG--
extra : rebase_source : 6d61c1f28c558321478d7e5f26390d27ae8ae3ac
2017-05-25 13:56:40 +09:00
Mike Hommey
f9a4ab0e55 Bug 1367695 - Remove leftovers from jemalloc4. r=njn
MOZ_REPLACE_JEMALLOC was only defined when building jemalloc4 as a
replace-malloc library.

--HG--
extra : rebase_source : fa5c402da07fa96448c170b6db99629469691efe
2017-05-25 16:24:13 +09:00
Mike Hommey
fade48cbe6 Bug 1365206 - Remove Sun Studio compiler optimization flags for mozjemalloc. r=gps
We don't support that compiler anymore.
2017-05-19 08:29:05 +09:00
Mike Hommey
fbbe2d361d Bug 1365460 - Remove function prototypes but keep necessary forward declarations. r=njn
--HG--
extra : rebase_source : 670aecc65cf709f2312a29c80e3c3171ccb2c8c2
2017-05-18 16:27:06 +09:00
Mike Hommey
1dfc7df618 Bug 1365460 - Make umax2s support only base 10. r=njn
Other bases are never used.

--HG--
extra : rebase_source : 6c8edcbde86480995b2d96ac513724e3212457cf
2017-05-18 16:22:10 +09:00
Mike Hommey
eaa9da1203 Bug 1365460 - Avoid unused variables. r=njn
--HG--
extra : rebase_source : 18cd68afc595aca1177e453f6c60a65de1d0dece
2017-05-18 12:24:57 +09:00
Mike Hommey
be0c2ffbc5 Bug 1365460 - Remove warning exceptions for MSVC and work around them. r=njn
--HG--
extra : rebase_source : 182c1e5583950f52a5eadc9fcf5d0b72ba4c56a9
2017-05-18 12:13:34 +09:00
Mike Hommey
61860e7f63 Bug 1365460 - Don't define integer types that MSVC >= 2015 know about. r=njn
--HG--
extra : rebase_source : 6a13970a477fda647eaed1dc381ecb993297922f
2017-05-18 12:09:38 +09:00
Mike Hommey
d3f17931b7 Bug 1365460 - Remove JEMALLOC_USES_MAP_ALIGN. r=njn
It's a Solaris-only optimization that was used as a workaround for some
infinite loop in pages_map (bug 457189). In the meanwhile, the way
pages_map works has changed in such a way the infinite loop can't happen
anymore.

Specifically, the original problem was that pages_map would try to
allocate something larger than a chunk, then deallocate it, and
reallocate at a hinted aligned address near the address of the now
deallocated mapping, hopefully getting an aligned chunk. But Solaris
would ignore the hint and the chunk would never be aligned, causing the
infinite loop.

What the code does now it over-allocate, find an aligned chunk in there,
and deallocate what ends up not being needed. Which leaves no room for
the original infinite loop.

We thus remove the workaround and put Solaris in par with other Unix
platforms.

--HG--
extra : rebase_source : 9ce4509d9c5ac6123cedabf87c5738672af35d1b
2017-05-18 11:30:52 +09:00
Mike Hommey
3dce495fff Bug 1365460 - Use MOZ_DIAGNOSTIC_ASSERT where mozjemalloc uses RELEASE_ASSERT. r=njn
In Gecko code, MOZ_RELEASE_ASSERT means assertions that happen on all
types of builds.

In mozjemalloc, RELEASE_ASSERT means assertions that happen when
MOZ_JEMALLOC_HARD_ASSERTS is set, otherwise normal assertions. Which is
confusing. On the other hand, it's very similar to
MOZ_DIAGNOSTIC_ASSERT, and we may just want to use that instead.

Moreover, with release promotion, the check setting
MOZ_JEMALLOC_HARD_ASSERTS means releases (promoted from beta) would end
up with those asserts while they're not meant to, so
MOZ_DIAGNOSTIC_ASSERT is actually closer to the intent. It however means
we'd lose the beta population running those assertions.

--HG--
extra : rebase_source : 606ab47af8d9ee793b13b806acadb9781c99a078
2017-05-18 10:57:43 +09:00
Mike Hommey
175a4c0a2a Bug 1365460 - Replace assert with MOZ_ASSERT. r=njn
--HG--
extra : rebase_source : fab2172c763518c8f08efd99b0f9d9c3fdde42af
2017-05-18 10:52:00 +09:00
Mike Hommey
7c28b3d25e Bug 1365460 - Expand the __crtInitCritSecAndSpinCount macro and remove it. r=njn
--HG--
extra : rebase_source : 1149b2446447a423704f147dad8e404792e83938
2017-05-18 10:39:08 +09:00
Mike Hommey
77cecfcb4b Bug 1365460 - Replace __DECONST with const_cast. r=njn
--HG--
extra : rebase_source : 5222652581d27e68a6af71ec8b9e2c30446c18d2
2017-05-18 10:37:08 +09:00
Mike Hommey
fdda7f976a Bug 1365460 - Remove JEMALLOC_MUNMAP/config_munmap, they are always true. r=njn
--HG--
extra : rebase_source : 420913999fc1c49ec8b6134f9768ced4355b4a2d
2017-05-18 10:34:38 +09:00
Mike Hommey
139dee33bb Bug 1365460 - Remove JEMALLOC_RECYCLE/config_recycle, they are always true. r=njn
--HG--
extra : rebase_source : de942f6ffaec1d17239a76606590f5cc2477a405
2017-05-18 10:32:30 +09:00
Mike Hommey
c6aa8aa7c7 Bug 1365460 - Remove runtime support for SysV malloc semantics. r=njn
Support for them was only enabled on debug builds, and required an
opt-in through e.g. MALLOC_OPTIONS to actually enable at runtime.

--HG--
extra : rebase_source : 60c27585c2901a73eb790cec124b880c93da6ef7
2017-05-18 10:28:28 +09:00
Mike Hommey
92ba43731c Bug 1365460 - Replace MOZ_MEMORY_DEBUG, MALLOC_DEBUG and !MALLOC_PRODUCTION with MOZ_DEBUG. r=njn
--HG--
extra : rebase_source : eeae81907bb80f78d0ab83343cc514f483d5ddc0
2017-05-18 10:22:20 +09:00
Mike Hommey
72d4bc9cc3 Bug 1365460 - Define _malloc_message as a function instead of a pointer to a function. r=njn
--HG--
extra : rebase_source : ea3088ad12ae2e0879beceac48f01ecdeb5c8f3a
2017-05-18 10:18:36 +09:00
Mike Hommey
d1b9ff45e8 Bug 1365460 - Remove support for /etc/malloc.conf. r=njn
While it makes sense for a global system allocator, it's not really
interesting for Firefox to respect that. Plus, newer versions of
jemalloc, which are more likely to be used as a global system allocator
use a different format for the options passed through that file.

--HG--
extra : rebase_source : 0f2283cf5660bc437bd097bf48c2b5989fa08011
2017-05-18 10:12:18 +09:00
Mike Hommey
f3762790b7 Bug 1365460 - Remove the inline extra malloc options. r=njn
Those options, complementing the MALLOC_OPTIONS environment variable,
were always empty since the removal of b2g.

--HG--
extra : rebase_source : 0e34cfce0b537ebb8ed3902bd46180dc205cb0e4
2017-05-18 10:06:29 +09:00
Mike Hommey
937023c28a Bug 1365460 - Remove the possibility to disable free() poisoning at runtime. r=njn
--HG--
extra : rebase_source : 1d98488d73bc8015ad1fd057ae0655b0f847d679
2017-05-18 10:03:43 +09:00
Mike Hommey
5858dd93d2 Bug 1365460 - Replace literal 0xe4/0xe5 junk/poison values with constants. r=njn
--HG--
extra : rebase_source : 085fd31f00e4afef8c990d54f77c0301b2502f3d
2017-05-18 10:02:36 +09:00
Mike Hommey
91f81f5e20 Bug 1365460 - Remove unused qr.h and ql.h headers. r=njn
--HG--
extra : rebase_source : b585b93c9523996400e50e29faa346618601cf28
2017-05-17 11:25:45 +09:00
Mike Hommey
4933268c6e Bug 1365460 - Remove unused macros from rb.h. r=njn
--HG--
extra : rebase_source : b3730f71ac83e106233ed42195a6f44fd32380a4
2017-05-17 11:23:10 +09:00
Iris Hsiao
0bbdca7c50 Merge mozilla-central to autoland
--HG--
rename : memory/mozjemalloc/jemalloc.c => memory/mozjemalloc/mozjemalloc.cpp
2017-05-18 14:15:19 +08:00
Jim Chen
9579d51797 Bug 1360321 - 3. Don't use mmap2 on Android AArch64 in mozjemalloc; r=glandium
Android NDK defines SYS_mmap2 but it expands to a nonexistent symbol.
mmap2 may not be supported in any case in some AArch64 kernels, so we
should just use mmap.

MozReview-Commit-ID: 5Vjuja5fLIL
2017-05-17 13:06:21 -04:00
Carsten "Tomcat" Book
f55349994f Backed out changeset 484c5137e19f (bug 1365194) to clean up spidermonkey 2017-05-17 11:44:17 +02:00
Carsten "Tomcat" Book
766c2581c8 Backed out changeset d8de424663b7 (bug 1365194) 2017-05-17 11:43:28 +02:00
Carsten "Tomcat" Book
9c3f61e278 Backed out changeset b56224bf370d (bug 1365194) 2017-05-17 11:43:26 +02:00
Carsten "Tomcat" Book
d0e69c4bdb Backed out changeset 4b9c2fb40653 (bug 1365194) 2017-05-17 11:43:24 +02:00
Carsten "Tomcat" Book
c994a231f0 Backed out changeset 9711f5bbda3b (bug 1365194)
--HG--
rename : memory/mozjemalloc/mozjemalloc.cpp => memory/mozjemalloc/jemalloc.c
2017-05-17 11:43:22 +02:00
Carsten "Tomcat" Book
921529ef63 Backed out changeset 4553b67c794f (bug 1365473) for breaking spidermonkey with illegal token on right side of..
--HG--
rename : memory/mozjemalloc/mozjemalloc_types.h => memory/mozjemalloc/jemalloc_types.h
2017-05-17 11:31:32 +02:00
Mike Hommey
e7764f68e0 Bug 1365473 - Rename jemalloc_types.h to mozjemalloc_types.h. r=njn
--HG--
rename : memory/mozjemalloc/jemalloc_types.h => memory/mozjemalloc/mozjemalloc_types.h
extra : rebase_source : 542d0f115f54099517f3eb9a2e0f93f8987f4f63
2017-05-12 21:52:25 +09:00
Mike Hommey
b302af7bc0 Bug 1365473 - Rename jemalloc_types.h to mozjemalloc_types.h. r=njn
--HG--
rename : memory/mozjemalloc/jemalloc_types.h => memory/mozjemalloc/mozjemalloc_types.h
extra : rebase_source : 542d0f115f54099517f3eb9a2e0f93f8987f4f63
2017-05-12 21:52:25 +09:00
Mike Hommey
67a2475101 Bug 1365194 - Compile mozjemalloc as C++. r=njn
The source file is renamed too, because the build system doesn't handle
sources changing suffix very well (at least not without a clobber).

The _GNU_SOURCE define is removed because GCC/Clang set it by default in
C++ mode.

--HG--
rename : memory/mozjemalloc/jemalloc.c => memory/mozjemalloc/mozjemalloc.cpp
extra : rebase_source : f57dbb0a66b25e70fe8c724e9250cc0d8b14f1c1
2017-05-12 21:52:25 +09:00
Mike Hommey
cfcf835a7f Bug 1365194 - Remove parts of the hacks for memalign in mozjemalloc. r=njn
The hack dates back from the originally imported jemalloc code, which
couldn't assume it's built for Firefox. Now, we can assume that, which
means the code is always built with hidden visibility by default,
removing the need for the explicit hidden visibility.

Correspondingly, when building on Solaris with GCC, the default
visibility should also prevent the inlining, making the noinline
attribute redundant. And the Sun Studio path is useless since the
compiler is not supported anymore.

--HG--
extra : rebase_source : dab0ac68af56b1f9432d312665d4ff3df01fb58a
2017-05-16 20:01:55 +09:00
Mike Hommey
0400284f88 Bug 1365194 - Make extern "C" part of MOZ_MEMORY_API and MOZ_JEMALLOC_API. r=njn
This avoids many additions of `extern "C"` in C++ code and will avoid
having to do the same to mozjemalloc once built as C++.

--HG--
extra : rebase_source : af55696262f40a9dd16a19c29edcb9bb307d4957
2017-05-16 18:46:02 +09:00
Mike Hommey
966b5bb639 Bug 1365194 - Remove MOZ_JEMALLOC_API from _malloc_options and _malloc_message. r=njn
MOZ_JEMALLOC_API makes those symbols exported, but we're going to make
MOZ_JEMALLOC_API include `extern "C"`, which GCC warns about in this
case (can't use extern on a variable that is initialized).

While we could get around this in some way, there is not much use for
those variables being exported altogether: the only reason they are is
to allow an override when linking mozjemalloc into executables, but
doing that in Firefox requires patching the build system or passing some
specific LDFLAGS. People who really need to do that might as well apply
a patch.

They also allow run-time override through LD_PRELOAD, but one might as
well use the MALLOC_OPTIONS environment variable for _malloc_options.
As for _malloc_message, it doesn't seem very useful to override, and
probably noone ever overrode it at runtime.

Note, we may want to remove them in a followup.

--HG--
extra : rebase_source : f2dbe5dbf0bbdb369cd7c6255f624f16b8e37209
2017-05-16 18:55:24 +09:00
Mike Hommey
bbdb5a1a9c Bug 1365194 - Call moz_abort directly instead of using a macro to override abort. r=njn
Using -Dabort=moz_abort actually makes the build fail in some libstdc++
headers when building as C++.

--HG--
extra : rebase_source : 77828d5c42f231372a8e75f5e3cd6af135d1d5e8
2017-05-12 21:51:16 +09:00
Mike Hommey
14503d2c39 Bug 1365194 - Compile mozjemalloc as C++. r=njn
The source file is renamed too, because the build system doesn't handle
sources changing suffix very well (at least not without a clobber).

The _GNU_SOURCE define is removed because GCC/Clang set it by default in
C++ mode.

--HG--
rename : memory/mozjemalloc/jemalloc.c => memory/mozjemalloc/mozjemalloc.cpp
extra : rebase_source : f57dbb0a66b25e70fe8c724e9250cc0d8b14f1c1
2017-05-12 21:52:25 +09:00
Mike Hommey
12cfad23f4 Bug 1365194 - Remove parts of the hacks for memalign in mozjemalloc. r=njn
The hack dates back from the originally imported jemalloc code, which
couldn't assume it's built for Firefox. Now, we can assume that, which
means the code is always built with hidden visibility by default,
removing the need for the explicit hidden visibility.

Correspondingly, when building on Solaris with GCC, the default
visibility should also prevent the inlining, making the noinline
attribute redundant. And the Sun Studio path is useless since the
compiler is not supported anymore.

--HG--
extra : rebase_source : dab0ac68af56b1f9432d312665d4ff3df01fb58a
2017-05-16 20:01:55 +09:00
Mike Hommey
2bd75405bc Bug 1365194 - Make extern "C" part of MOZ_MEMORY_API and MOZ_JEMALLOC_API. r=njn
This avoids many additions of `extern "C"` in C++ code and will avoid
having to do the same to mozjemalloc once built as C++.

--HG--
extra : rebase_source : af55696262f40a9dd16a19c29edcb9bb307d4957
2017-05-16 18:46:02 +09:00
Mike Hommey
e05de96ab1 Bug 1365194 - Remove MOZ_JEMALLOC_API from _malloc_options and _malloc_message. r=njn
MOZ_JEMALLOC_API makes those symbols exported, but we're going to make
MOZ_JEMALLOC_API include `extern "C"`, which GCC warns about in this
case (can't use extern on a variable that is initialized).

While we could get around this in some way, there is not much use for
those variables being exported altogether: the only reason they are is
to allow an override when linking mozjemalloc into executables, but
doing that in Firefox requires patching the build system or passing some
specific LDFLAGS. People who really need to do that might as well apply
a patch.

They also allow run-time override through LD_PRELOAD, but one might as
well use the MALLOC_OPTIONS environment variable for _malloc_options.
As for _malloc_message, it doesn't seem very useful to override, and
probably noone ever overrode it at runtime.

Note, we may want to remove them in a followup.

--HG--
extra : rebase_source : f2dbe5dbf0bbdb369cd7c6255f624f16b8e37209
2017-05-16 18:55:24 +09:00
Mike Hommey
782764a6fd Bug 1365194 - Call moz_abort directly instead of using a macro to override abort. r=njn
Using -Dabort=moz_abort actually makes the build fail in some libstdc++
headers when building as C++.

--HG--
extra : rebase_source : 77828d5c42f231372a8e75f5e3cd6af135d1d5e8
2017-05-12 21:51:16 +09:00
Mike Hommey
c530406a95 Bug 1365191 - Remove dead code hidden behind the never set NEEDS_PTHREAD_MMAP_UNALIGNED_TSD. r=njn
--HG--
extra : rebase_source : 79efaa1e0922c356469655f88f86b255ccc72141
2017-05-11 18:05:14 +09:00
Mike Hommey
03a5ae85e0 Bug 1365191 - Remove MALLOC_FILL from mozjemalloc. r=njn
It's always set.

--HG--
extra : rebase_source : 1f3249a8210b0e339bda0c79932fa129cebec27a
2017-05-11 17:57:30 +09:00
Mike Hommey
9fa3e56ddf Bug 1365191 - Remove MALLOC_STATS from mozjemalloc. r=njn
It's always set.

--HG--
extra : rebase_source : 221f1b8ded2f08f0608ca065cf5029f841a4915f
2017-05-11 17:55:21 +09:00
Mike Hommey
9f69a922af Bug 1365191 - Remove MALLOC_UTRACE from mozjemalloc. r=njn
It's always unset, and Firefox has the logalloc replace-malloc library
for something similar.

--HG--
extra : rebase_source : cfe66c004df0d6e5db749f01feb9af591e3d1569
2017-05-11 17:47:02 +09:00
Mike Hommey
7a7f8c62a2 Bug 1365191 - Remove MALLOC_VALIDATE in mozjemalloc. r=njn
It's always set.

--HG--
extra : rebase_source : 926b016495867e99f8a4e22dd15f91ec4c7a1b21
2017-05-11 17:39:56 +09:00
Mike Hommey
6be3fc2ba1 Bug 1365191 - Remove !MOZ_MEMORY sections in mozjemalloc. r=njn
MOZ_MEMORY is always defined when building mozjemalloc. Due to the
origin of the code, this was all FreeBSD-specific code, and if we want
to add FreeBSD support, we will probably need to add some of it, but I'd
rather avoid keeping the difference between FreeBSD and other posix
systems if we can.

--HG--
extra : rebase_source : 3afe0136e35e25361e9e1802a9738d82b97e99e5
2017-05-11 17:34:54 +09:00
Mike Hommey
7696439eba Bug 1365191 - Remove #if 0 sections in mozjemalloc. r=njn
--HG--
extra : rebase_source : 71ff171980a1e8d629230d1d92709f0abb78199c
2017-05-11 17:23:02 +09:00
Mike Hommey
cde3e9b853 Bug 1364358 - Keep track of mozjemalloc thread-local arenas. r=erahm
jemalloc_stats, as well as pre/post-fork hooks are using the `arenas`
list along the `narenas` count to iterate over all arenas setup by
mozjemalloc. Up until previous commit, that was used for automatic
multiple arenas support, which is now removed.

But mozjemalloc still supports running with multiple arenas, in the form
of opted-in, per-thread arenas. After bug 1361258, those arenas weren't
tracked, and now that `arenas` only contains the default arena, we can
now fill it with those thread-local arenas.

Keeping the automatic multiple arenas support, which we don't use and
don't really plan to, would have meant using a separate list for them.

--HG--
extra : rebase_source : f4eb55a65df8cdebff84ca709738f906d0c3c6f5
2017-05-12 21:21:11 +09:00
Mike Hommey
339b48a5ff Bug 1364358 - Remove mozjemalloc support for automatic multiple arenas. r=erahm
As per explained 2 commits earlier, we remove the support for multiple
arenas. We however keep the `arenas` list and the `narenas` count to
use it them to track the opted-in per-thread arenas.

--HG--
extra : rebase_source : 6e05cddd3dd385a0cd6a22fb028ab311b0c00678
2017-05-11 17:21:36 +09:00
Mike Hommey
938d371ff2 Bug 1364358 - Remove mozjemalloc check for multithreading. r=erahm
mozjemalloc had an optimization that shortcuts using mutexes when the
program is single-threaded. But with code evolution, the check whether
the program had multiple threads running was meant to be true all the
time.

In order to simplify the code, we just remove those checks and dead code
they were hiding in some cases.

--HG--
extra : rebase_source : 3c7a256bffef50761f6fcd6ec876ebabfcf3fdae
2017-05-11 17:18:59 +09:00
Mike Hommey
ef98dbfba5 Bug 1364358 - Remove mozjemalloc arena balancing. r=erahm
After bug 1361258, mozjemalloc uses a main arena for all allocations,
and specific threads can opt-in to use a different arena for that thread
only. Going forward, this is how we expect to support scaling across
different threads that require lots of concurrent allocations.

To simplify the mozjemalloc code, we'll remove the support for multiple
arenas.

This is the first step towards that, removing the support for arena
balancing. Everything behind the MALLOC_BALANCE macro has never been used
in practice.

--HG--
extra : rebase_source : e7ab669312f1e26a91375d11f5ad488e870bd354
2017-05-11 17:13:44 +09:00
Mike Hommey
782725e19a Bug 1363992 - Remove jemalloc 4. r=njn
--HG--
extra : rebase_source : 9794320e96279cbb8b7b66db6720c959eaa6a95b
2017-05-11 13:23:07 +09:00
Mike Hommey
02a06f7958 Bug 1363992 - Remove support for making jemalloc4 the default. r=njn
--HG--
extra : rebase_source : 77e1c13aa329637d0ec875439d572ee06e6919fa
2017-05-11 13:16:00 +09:00
Mike Hommey
1a9d4c6f33 Bug 1363992 - Remove support for system jemalloc. r=njn
--HG--
extra : rebase_source : 9141402b6f9e84c67afc14303633d328eb5b652c
2017-05-11 13:03:20 +09:00
Bobby Holley
43faf047c5 Bug 1361258 - Backout 2214b3c57c9c (bug 1291356), disabling multiple jemalloc arenas. r=glandium 2017-05-13 08:21:05 +02:00
Mike Hommey
fcd9a5550a Bug 1361258 - Use Thread Local Storage in mozjemalloc on mac. r=erahm
NO_TLS used to be hardcoded on mac because up to 10.6, __thread was not
supported. Until recently, we still supported for 10.6, and it's not the
case anymore, so we could make mac builds use __thread.

Unfortunately, on OSX, __thread circles back calling malloc to allocate
storage on first access, so we have an infinite loop problem here.
Fortunately, pthread_keys don't have this property, so we can use that
instead. It doesn't appear to have significantly more overhead (and TLS
overhead is small anyways compared to the amount of work involved in
allocating memory with mozjemalloc).

At the same time, we uniformize the initialization sequence between
mozjemalloc and mozjemalloc+replace-malloc, such that we have less
occasions for surprises when riding the trains (replace-malloc being
nightly only), ensuring the zone registration happens at the end of
mozjemalloc's initialization.
2017-05-12 18:12:20 +09:00
Mike Hommey
f5461de678 Bug 1361258 - Initial implementation for jemalloc_thread_local_arena. r=erahm
The function, when passed `true`, creates a new arena with no attachment
in the global list of arenas, and assigns it to the current thread.
When passed `false`, it restores the default arena.

Some details are left out because they don't matter yet, as the sole
initial use of the API is going to invoke the function when stylo rayon
threads start up, which happens exactly once per thread, and at thread
exit time, which happens at shutdown, if ever.

This simplifies things, and leaves those details to followup(s):
- Arenas can't simply be killed when the function is called with `false`
  again (or when the thread dies) because they may still contain valid
  allocations that could have been passed to other threads. Those arenas
  should be kept until they are empty.
- jemalloc_stats doesn't know about them and will under-report memory
  usage.
- pre/post fork hooks don't know about them and will not force-unlock
  their locks. In practice, until those arenas are used for something
  else than the style system, this can't lead to the dead-locks that
  these hooks help prevent because nothing should be touching pointers
  allocated through them after fork.
2017-05-12 18:12:15 +09:00
Julian Seward
83969e88eb Bug 1361258 - Add a jemalloc_thread_local_arena API with a binding for rust. r=glandium
The intent of the API is to allow threads to opt-in to use a separate
mozjemalloc arena.

This indroduces a dummy shell with no actual implementation.
2017-05-12 18:08:08 +09:00
Tom Tromey
b4f2234e87 Bug 1334286 - use MOZ_FORMAT_PRINTF in DMD; r=njn
Add MOZ_FORMAT_PRINTF to the appropriate spots in DMD and fix up the
one (trivial) error that this pointed out.

MozReview-Commit-ID: LS0UWV5YRoM

--HG--
extra : rebase_source : eb09be39df61a51acd46ed72a1461c495727af79
2017-04-21 15:54:05 -06:00
Tom Ritter
f8036e08d5 Bug 1332747 Change MOZ_ALWAYS_INLINE to MOZ_ALWAYS_INLINE_EVEN_DEBUG to fix MinGW Debug build r=froydnj
MozReview-Commit-ID: 7CkreJM1mHr

--HG--
extra : rebase_source : 8dc51c9c1b0e10bd7b40f3c6f65b2495dfe22cb1
2017-04-11 12:53:58 -05:00
Alex Gaynor
ce06b5614f Bug 1353847 - Updated the jemalloc mozilla README to reflect its new git url r=glandium
r=glandium

MozReview-Commit-ID: 2jqQoQAwtBW

--HG--
extra : rebase_source : 1998a05be2d153e61d3476fc8fa73cf2d93f3e49
2017-04-05 15:19:19 -04:00
Alex Gaynor
d304ba72b3 Bug 1353752 - Fixed building with jemalloc4 r=glandium
It was broken by 516551993d16.

r=glandium

MozReview-Commit-ID: BvejKjAPB84

--HG--
extra : rebase_source : efaf5c0afb7454ecc75a733e184c82cbd16c5e5f
2017-04-05 13:05:43 -04:00
Eric Rahm
3d78211d31 Bug 1349002 - Build DMD with unified sources. r=njn
DMD can be built with unified sources, additionally it doesn't need NSPR's
strcpy to build properly.

MozReview-Commit-ID: 9hZFlpWdt7
2017-03-21 12:24:43 -07:00
Wes Kocher
9b58353afe Backed out changeset 2f6d3cbedd12 (bug 1349002) for build bustage a=backout
MozReview-Commit-ID: DY4OupKVBlS
2017-03-20 18:08:43 -07:00
Eric Rahm
5b55122df3 Bug 1349002 - Build DMD with unified sources. r=njn
DMD can be built with unified sources, additionally it doesn't need NSPR's
strcpy to build properly.

MozReview-Commit-ID: 9hZFlpWdt7
2017-03-20 17:24:34 -07:00
Bevis Tseng
2a318e8c71 Bug 1332491 - Delete SelectorCacheKey synchronously. r=bz
1. The current asynchronous behavior is pointless, because we still remove the
   hashtable entry synchronously, which deletes the value, and it's the value
   we're using.
2. Trying to asynchronously delete the value is difficult, and not currently
   needed because we can't get a memory-pressure notification while we're using
   the value, and hence can't expire it from the expiration tracker.
   Note: we can't get this memory-pressure notification because the stage 2 of
   mozalloc_handle_oom() to reclaim memory when OOM is not implemented yet.
2017-03-13 14:37:19 +08:00
Joel Maher
52797e0f80 Bug 1344471 - add BUG_COMPONENT to memory/* files. r=glandium
MozReview-Commit-ID: FiUCPht3MEJ
2017-03-08 11:17:11 -05:00
Ryan VanderMeulen
90e0fe11c9 Bug 1343432 - Update jemalloc 4 to version 4.5.0. r=glandium 2017-03-01 21:06:24 -05:00
Iris Hsiao
73bf12810d Backed out changeset 24bea8bde57d (bug 1343432) for build bustage 2017-03-02 11:23:28 +08:00
Ryan VanderMeulen
5d6e7cab50 Bug 1343432 - Update jemalloc 4 to version 4.5.0. r=glandium
--HG--
extra : rebase_source : 0113418a6ba808bf2b3a60bf6e98740791bf02e4
2017-03-01 21:06:24 -05:00
Eric Rahm
6bb5fd3d99 Bug 1341621 - Avoid deadlocks in DMD when forking. r=njn
In order to avoid the possibility of a deadlock if the DMD state lock is
currently acquired when forking a |pthread_atfork| hook is added to wait for
and acquire the lock prior to forking, then release it after forking.
2017-02-23 17:47:02 -08:00
David Major
bb5fe68fae Bug 419470: Re-enable PGO for Linux mozjemalloc. r=glandium
It only took nine years.

MozReview-Commit-ID: 2zsCBMTJ6O1

--HG--
extra : rebase_source : e3be1bd1c930d32d3c7a9e2d707ed3fe6bc0936f
2017-02-22 09:46:06 +13:00
Emanuel Hoogeveen
51fc28feca Bug 1338574 - Part 8: Use MOZ_ASSERT and MOZ_CRASH_UNSAFE_OOL in mozjemalloc. r=glandium
--HG--
extra : rebase_source : 73f61842eb44bd0bfe7d3eca9267cfa10f771295
2017-02-21 18:02:07 +01:00
Emanuel Hoogeveen
9c7c14c872 Bug 1338574 - Part 1: Add MOZ_CRASH_UNSAFE_OOL and MOZ_CRASH_UNSAFE_PRINTF to crash with a runtime generated explanation string. r=froydnj
--HG--
extra : rebase_source : 3ba633aa77ab96f763ea03a8308c539c9c2aeda0
2017-02-21 18:01:41 +01:00
Wes Kocher
017c515285 Merge inbound to m-c a=merge
MozReview-Commit-ID: IKI0zVtF1n9
2017-02-15 16:18:13 -08:00
Emanuel Hoogeveen
00c7d04549 Bug 1339441 - Take the arena lock earlier in arena_dalloc(). r=glandium
--HG--
extra : rebase_source : 95e8f744a9f77381270fd8f8942765b144b844a2
2017-02-15 09:48:00 -05:00
Sylvestre Ledru
6fd3084f65 Bug 1338086 - Remove useless else blocks in order to reduce complexity in memory/ r=njn
MozReview-Commit-ID: G7jBKlDHshQ

--HG--
extra : rebase_source : 4317651e0cc87b0be1230b19ceb844cfcb4842bc
2017-02-09 11:24:39 +01:00
Benjamin Smedberg
ca77995f5d Bug 1333826 - Remove SDK_FILES, SDK_LIBRARY, and related is_sdk support in the build goop, r=mshal
MozReview-Commit-ID: 52vPyDXdFte

--HG--
extra : rebase_source : c3217730bb70eb7319152dd07536b12f49d6a597
2017-01-30 11:24:10 -05:00
Dimitry Andric
8b0557b033 Bug 1329520 - Fix "memory/mozalloc/throw_gcc.h:35:1: note: declaration missing '[[noreturn]]' (libc++ 4.0)" r=nfroyd 2017-01-27 13:55:00 +01:00
Mike Hommey
c9370d609b Bug 1332508 - Reinitialize allocator mutexes in fork() child processes. r=njn
Adapted from
4e2e3dd9cf
and
d9f7b2a430

As per the latter commit, it would seem unlocking, in fork() child
processes, mutexes that were locked in the parent process is not really
well supported on OSX 10.12. The addition of the zone_reinit_lock
function in 10.12 supports this idea.

--HG--
extra : rebase_source : b3b58558cc195d63200078085c7e9b6c9b8d83ff
2017-01-20 10:06:41 +09:00
Mike Hommey
dbc87ab49d Bug 1286613 - Update jemalloc 4 to c6943ac. r=njn
This picks the same changes as the ones we just did to
memory/build/zone.c, plus a oneliner for sparc64.

--HG--
extra : rebase_source : ca917461472e8188fbfc6e2a971b228b68014e38
2017-01-18 15:47:53 +09:00
Mike Hommey
4e8f02fe22 Bug 1286613 - Add dummy implementations for most remaining OSX zone allocator functions. r=njn
Some system libraries are using malloc_default_zone() and then using
some of the malloc_zone_* API. Under normal conditions, those functions
check the malloc_zone_t/malloc_introspection_t struct for the values
that are allowed to be NULL, so that a NULL deref doesn't happen.

As of OSX 10.12, malloc_default_zone() doesn't return the actual default
zone anymore, but returns a fake, wrapper zone. The wrapper zone defines
all the possible functions in the malloc_zone_t/malloc_introspection_t
struct (almost), and calls the function from the registered default zone
(jemalloc in our case) on its own. Without checking whether the pointers
are NULL.

This means that a system library that calls e.g.
malloc_zone_batch_malloc(malloc_default_zone(), ...) ends up trying to
call jemalloc_zone.batch_malloc, which is NULL, and crash follows.

So as of OSX 10.12, the default zone is required to have all the
functions available (really, the same as the wrapper zone), even if they
do nothing.

This is arguably a bug in libsystem_malloc in OSX 10.12, but jemalloc
still needs to work in that case.

[Adapted from
c6943acb3c]

--HG--
extra : rebase_source : 7d7a5b47fa18f56183e99c3655aee003c9be161e
2017-01-18 14:35:11 +09:00
Mike Hommey
dae510ade1 Bug 1286613 - Don't rely on OSX SDK malloc/malloc.h for malloc_zone struct definitions. r=njn
The SDK jemalloc is built against might be not be the latest for various
reasons, but the resulting binary ought to work on newer versions of
OSX.

In order to ensure this, we need the fullest definitions possible, so
copy what we need from the latest version of malloc/malloc.h available
on opensource.apple.com.

[Adapted from
c68bb41793]

--HG--
extra : rebase_source : ab19c478b568ea24095a3be62c39fb81efc1920a
2017-01-18 13:50:35 +09:00