Commit Graph

1037 Commits

Author SHA1 Message Date
Phil Ringnalda
6841cb2510 Backed out 4 changesets (bug 1402284) for build bustage
CLOSED TREE

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

--HG--
extra : rebase_source : f814f4a973499c3d7759ea0f17543513fb047f39
2017-10-27 16:33:14 +09:00
Mike Hommey
56e7d2c532 Bug 1412221 - Use pages_unmap instead of repeating the same code. r=njn
--HG--
extra : rebase_source : 374b0536bd5b553594a907bfe50d89e44acb02f1
2017-10-27 16:02:22 +09:00
Mike Hommey
4aef26adda Bug 1412221 - Remove unnecessary parentheses around return values. r=njn
--HG--
extra : rebase_source : cfbba2665a43e956df78ccc4a811c31324836255
2017-10-27 15:37:28 +09:00
Mike Hommey
7df73744bb Bug 1412221 - Fix clang-tidy warnings in mozjemalloc.cpp. r=njn
Also rearrange some code accordingly, but don't fix indentation issues
just yet.

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

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

--HG--
extra : rebase_source : 28b07aca01fd0275127341233755852cccda22fe
2017-10-27 14:57:09 +09:00
Mike Hommey
5bf6af5d52 Bug 1229384 - Make pages_commit fallible. r=njn
This will make allocation operations return nullptr in the face of OOM,
allowing callers to either handle the allocation error or for the normal
OOM machinery, which also records the requested size, to kick in.

--HG--
extra : rebase_source : 723048645cb3f0db269c91f9d023bb06825a817b
2017-10-27 10:31:50 +09:00
Mike Hommey
c77051041e Bug 1229384 - In SplitRun, adjust the set of available runs after committing pages. r=njn
On its own, this change is unnecessary. But it prepares for pages_commit
becoming fallible in next commit, allowing a possibly early return while
leaving metadata in a consistent state: runs are still available for
future use even if they couldn't be committed immediately.

--HG--
extra : rebase_source : 971e5c49882409c00ac61ec641d469dcc94e5cc2
2017-10-26 18:12:04 +09:00
Mike Hommey
8fbdcde064 Bug 1229384 - Invert the meaning of the arena_ralloc_large and arena_t::RallocGrowLarge return type. r=njn
--HG--
extra : rebase_source : 6d0dcf1e8d1051597a542be38fe0a8641fb0acb0
2017-10-27 10:14:04 +09:00
Mike Hommey
8e876fc0b0 Bug 1229384 - Reformat and apply Gecko style to a few functions. r=njn
--HG--
extra : rebase_source : 8f6e51933649b7a0d74457f00ad7491ebedac06e
2017-10-26 11:11:32 +09:00
Nathan Froyd
3096def324 Bug 1396892 - fix tautological pointer comparison warning, for real; r=me
Whoops, the files that we care about in this directory are C++ files, so
we should be turning warnings off in CXXFLAGS, not CFLAGS.
2017-10-27 16:07:47 -04:00
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