summaryrefslogtreecommitdiffstats
path: root/memory/build
diff options
context:
space:
mode:
Diffstat (limited to 'memory/build')
-rw-r--r--memory/build/jemalloc_config.cpp154
-rw-r--r--memory/build/moz.build16
-rw-r--r--memory/build/mozjemalloc_compat.c182
-rw-r--r--memory/build/mozmemory_wrap.h64
-rw-r--r--memory/build/replace_malloc.c4
5 files changed, 24 insertions, 396 deletions
diff --git a/memory/build/jemalloc_config.cpp b/memory/build/jemalloc_config.cpp
index 441fd8a2b..0b734d804 100644
--- a/memory/build/jemalloc_config.cpp
+++ b/memory/build/jemalloc_config.cpp
@@ -2,161 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
-#ifdef MOZ_JEMALLOC4
-
-#define MOZ_JEMALLOC_IMPL
-
-/* mozmemory_wrap.h needs to be included before MFBT headers */
-#include "mozmemory_wrap.h"
-#include <mozilla/Assertions.h>
-#include "mozilla/Types.h"
-
-#if defined(MOZ_SYSTEM_JEMALLOC)
-#include MALLOC_H
-#else
-#define DLLEXPORT
-#include "jemalloc/jemalloc.h"
-#endif
-
-#ifdef XP_WIN
-#include <windows.h>
-#endif
-#ifdef XP_DARWIN
-#include <sys/mman.h>
-#endif
-
-/* Override some jemalloc defaults */
-#ifdef DEBUG
-#define MOZ_MALLOC_BUILD_OPTIONS ",junk:true"
-#else
-#define MOZ_MALLOC_BUILD_OPTIONS ",junk:free"
-#endif
-
-#define MOZ_MALLOC_OPTIONS "narenas:1,tcache:false"
-MFBT_DATA const char* je_(malloc_conf) =
- MOZ_MALLOC_OPTIONS MOZ_MALLOC_BUILD_OPTIONS;
-
-#ifdef ANDROID
-#include <android/log.h>
-
-static void
-_je_malloc_message(void* cbopaque, const char* s)
-{
- __android_log_print(ANDROID_LOG_INFO, "GeckoJemalloc", "%s", s);
-}
-
-void (*je_(malloc_message))(void*, const char* s) = _je_malloc_message;
-#endif
-
-/* Jemalloc supports hooks that are called on chunk
- * allocate/deallocate/commit/decommit/purge/etc.
- *
- * We currently only hook commit, decommit and purge. We do this to tweak
- * the way chunks are handled so that RSS stays lower than it normally
- * would with the default jemalloc uses.
- * This somewhat matches the behavior of mozjemalloc, except it doesn't
- * rely on a double purge on mac, instead purging directly. (Yes, this
- * means we can get rid of jemalloc_purge_freed_pages at some point)
- *
- * The default for jemalloc is to do the following:
- * - commit, decommit: nothing
- * - purge: MEM_RESET on Windows, MADV_FREE on Mac/BSD, MADV_DONTNEED on Linux
- *
- * The hooks we setup do the following:
- * on Windows:
- * - commit: MEM_COMMIT
- * - decommit: MEM_DECOMMIT
- * on Mac:
- * - purge: mmap new anonymous memory on top of the chunk
- *
- * We only set the above hooks, others are left with the default.
- */
-#if defined(XP_WIN) || defined(XP_DARWIN)
-class JemallocInit {
-public:
- JemallocInit()
- {
- chunk_hooks_t hooks;
- size_t hooks_len;
- unsigned narenas;
- size_t mib[3];
- size_t size;
-
- size = sizeof(narenas);
- je_(mallctl)("arenas.narenas", &narenas, &size, nullptr, 0);
-
- size = sizeof(mib) / sizeof(mib[0]);
- je_(mallctlnametomib)("arena.0.chunk_hooks", mib, &size);
-
- /* Set the hooks on all the existing arenas. */
- for (unsigned arena = 0; arena < narenas; arena++) {
- mib[1] = arena;
- hooks_len = sizeof(hooks);
- je_(mallctlbymib)(mib, size, &hooks, &hooks_len, nullptr, 0);
-
-#ifdef XP_WIN
- hooks.commit = CommitHook;
- hooks.decommit = DecommitHook;
-#endif
-#ifdef XP_DARWIN
- hooks.purge = PurgeHook;
-#endif
-
- je_(mallctlbymib)(mib, size, nullptr, nullptr, &hooks, hooks_len);
- }
- }
-
-private:
-#ifdef XP_WIN
- static bool
- CommitHook(void* chunk, size_t size, size_t offset, size_t length,
- unsigned arena_ind)
- {
- void* addr = reinterpret_cast<void*>(
- reinterpret_cast<uintptr_t>(chunk) + static_cast<uintptr_t>(offset));
-
- if (!VirtualAlloc(addr, length, MEM_COMMIT, PAGE_READWRITE))
- return true;
-
- return false;
- }
-
- static bool
- DecommitHook(void* chunk, size_t size, size_t offset, size_t length,
- unsigned arena_ind)
- {
- void* addr = reinterpret_cast<void*>(
- reinterpret_cast<uintptr_t>(chunk) + static_cast<uintptr_t>(offset));
-
- if (!VirtualFree(addr, length, MEM_DECOMMIT))
- MOZ_CRASH();
-
- return false;
- }
-#endif
-
-#ifdef XP_DARWIN
- static bool
- PurgeHook(void* chunk, size_t size, size_t offset, size_t length,
- unsigned arena_ind)
- {
- void* addr = reinterpret_cast<void*>(
- reinterpret_cast<uintptr_t>(chunk) + static_cast<uintptr_t>(offset));
-
- void* new_addr = mmap(addr, length, PROT_READ | PROT_WRITE,
- MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0);
- return (new_addr != addr);
- }
-#endif
-};
-
-/* For the static constructor from the class above */
-JemallocInit gJemallocInit;
-#endif
-
-#else
#include <mozilla/Assertions.h>
-#endif /* MOZ_JEMALLOC4 */
/* Provide an abort function for use in jemalloc code */
extern "C" void moz_abort() {
diff --git a/memory/build/moz.build b/memory/build/moz.build
index 8d80561b1..f4fd82878 100644
--- a/memory/build/moz.build
+++ b/memory/build/moz.build
@@ -24,16 +24,6 @@ SOURCES += [
'mozmemory_wrap.c',
]
-if CONFIG['MOZ_JEMALLOC4']:
- SOURCES += [
- 'mozjemalloc_compat.c',
- ]
- LOCAL_INCLUDES += ['!../jemalloc/src/include']
- if CONFIG['_MSC_VER']:
- LOCAL_INCLUDES += ['/memory/jemalloc/src/include/msvc_compat']
- if not CONFIG['HAVE_INTTYPES_H']:
- LOCAL_INCLUDES += ['/memory/jemalloc/src/include/msvc_compat/C99']
-
if CONFIG['MOZ_REPLACE_MALLOC']:
SOURCES += [
'replace_malloc.c',
@@ -46,10 +36,6 @@ if CONFIG['MOZ_GLUE_IN_PROGRAM']:
DIST_INSTALL = True
# Keep jemalloc separated when mozglue is statically linked
-if CONFIG['MOZ_MEMORY'] and (CONFIG['OS_TARGET'] in ('WINNT', 'Darwin', 'Android') or
- CONFIG['MOZ_SYSTEM_JEMALLOC']):
+if CONFIG['MOZ_MEMORY'] and CONFIG['OS_TARGET'] in ('WINNT', 'Darwin', 'Android'):
FINAL_LIBRARY = 'mozglue'
-if CONFIG['MOZ_REPLACE_MALLOC'] and CONFIG['OS_TARGET'] == 'Darwin':
- # The zone allocator for OSX needs some jemalloc internal functions
- LOCAL_INCLUDES += ['/memory/jemalloc/src/include']
diff --git a/memory/build/mozjemalloc_compat.c b/memory/build/mozjemalloc_compat.c
deleted file mode 100644
index 6591892c1..000000000
--- a/memory/build/mozjemalloc_compat.c
+++ /dev/null
@@ -1,182 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef MOZ_JEMALLOC4
-# error Should only compile this file when building with jemalloc 3
-#endif
-
-#define MOZ_JEMALLOC_IMPL
-
-#include "mozmemory_wrap.h"
-#include "jemalloc_types.h"
-#include "mozilla/Types.h"
-
-#include <stdbool.h>
-
-#if defined(MOZ_SYSTEM_JEMALLOC)
-# include MALLOC_H
-#else
-# include "jemalloc/jemalloc.h"
-#endif
-
-/*
- * CTL_* macros are from memory/jemalloc/src/src/stats.c with changes:
- * - drop `t' argument to avoid redundancy in calculating type size
- * - require `i' argument for arena number explicitly
- */
-
-#define CTL_GET(n, v) do { \
- size_t sz = sizeof(v); \
- je_(mallctl)(n, &v, &sz, NULL, 0); \
-} while (0)
-
-#define CTL_I_GET(n, v, i) do { \
- size_t mib[6]; \
- size_t miblen = sizeof(mib) / sizeof(mib[0]); \
- size_t sz = sizeof(v); \
- je_(mallctlnametomib)(n, mib, &miblen); \
- mib[2] = i; \
- je_(mallctlbymib)(mib, miblen, &v, &sz, NULL, 0); \
-} while (0)
-
-#define CTL_IJ_GET(n, v, i, j) do { \
- size_t mib[6]; \
- size_t miblen = sizeof(mib) / sizeof(mib[0]); \
- size_t sz = sizeof(v); \
- je_(mallctlnametomib)(n, mib, &miblen); \
- mib[2] = i; \
- mib[4] = j; \
- je_(mallctlbymib)(mib, miblen, &v, &sz, NULL, 0); \
-} while (0)
-
-/*
- * VARIABLE_ARRAY is copied from
- * memory/jemalloc/src/include/jemalloc/internal/jemalloc_internal.h.in
- */
-#if __STDC_VERSION__ < 199901L
-# ifdef _MSC_VER
-# include <malloc.h>
-# define alloca _alloca
-# else
-# ifdef HAVE_ALLOCA_H
-# include <alloca.h>
-# else
-# include <stdlib.h>
-# endif
-# endif
-# define VARIABLE_ARRAY(type, name, count) \
- type *name = alloca(sizeof(type) * (count))
-#else
-# define VARIABLE_ARRAY(type, name, count) type name[(count)]
-#endif
-
-MOZ_MEMORY_API size_t
-malloc_good_size_impl(size_t size)
-{
- /* je_nallocx crashes when given a size of 0. As
- * malloc_usable_size(malloc(0)) and malloc_usable_size(malloc(1))
- * return the same value, use a size of 1. */
- if (size == 0)
- size = 1;
- return je_(nallocx)(size, 0);
-}
-
-static void
-compute_bin_unused_and_bookkeeping(jemalloc_stats_t *stats, unsigned int narenas)
-{
- size_t bin_unused = 0;
-
- uint32_t nregs; // number of regions per run in the j-th bin
- size_t reg_size; // size of regions served by the j-th bin
- size_t curruns; // number of runs belonging to a bin
- size_t curregs; // number of allocated regions in a bin
-
- unsigned int nbins; // number of bins per arena
- unsigned int i, j;
-
- size_t stats_metadata;
- size_t stats_ametadata = 0; // total internal allocations in all arenas
-
- // narenas also counts uninitialized arenas, and initialized arenas
- // are not guaranteed to be adjacent
- VARIABLE_ARRAY(bool, initialized, narenas);
- size_t isz = sizeof(initialized) / sizeof(initialized[0]);
-
- je_(mallctl)("arenas.initialized", initialized, &isz, NULL, 0);
- CTL_GET("arenas.nbins", nbins);
-
- for (j = 0; j < nbins; j++) {
- CTL_I_GET("arenas.bin.0.nregs", nregs, j);
- CTL_I_GET("arenas.bin.0.size", reg_size, j);
-
- for (i = 0; i < narenas; i++) {
- if (!initialized[i]) {
- continue;
- }
-
- CTL_IJ_GET("stats.arenas.0.bins.0.curruns", curruns, i, j);
- CTL_IJ_GET("stats.arenas.0.bins.0.curregs", curregs, i, j);
-
- bin_unused += (nregs * curruns - curregs) * reg_size;
- }
- }
-
- CTL_GET("stats.metadata", stats_metadata);
-
- /* get the summation for all arenas, i == narenas */
- CTL_I_GET("stats.arenas.0.metadata.allocated", stats_ametadata, narenas);
-
- stats->bookkeeping = stats_metadata - stats_ametadata;
- stats->bin_unused = bin_unused;
-}
-
-MOZ_JEMALLOC_API void
-jemalloc_stats_impl(jemalloc_stats_t *stats)
-{
- unsigned narenas;
- size_t active, allocated, mapped, page, pdirty;
- size_t lg_chunk;
-
- // Refresh jemalloc's stats by updating its epoch, see ctl_refresh in
- // src/ctl.c
- uint64_t epoch = 0;
- size_t esz = sizeof(epoch);
- je_(mallctl)("epoch", &epoch, &esz, &epoch, esz);
-
- CTL_GET("arenas.narenas", narenas);
- CTL_GET("arenas.page", page);
- CTL_GET("stats.active", active);
- CTL_GET("stats.allocated", allocated);
- CTL_GET("stats.mapped", mapped);
- CTL_GET("opt.lg_chunk", lg_chunk);
-
- /* get the summation for all arenas, i == narenas */
- CTL_I_GET("stats.arenas.0.pdirty", pdirty, narenas);
-
- stats->chunksize = (size_t) 1 << lg_chunk;
- stats->mapped = mapped;
- stats->allocated = allocated;
- stats->waste = active - allocated;
- stats->page_cache = pdirty * page;
- compute_bin_unused_and_bookkeeping(stats, narenas);
- stats->waste -= stats->bin_unused;
-}
-
-MOZ_JEMALLOC_API void
-jemalloc_purge_freed_pages_impl()
-{
-}
-
-MOZ_JEMALLOC_API void
-jemalloc_free_dirty_pages_impl()
-{
- unsigned narenas;
- size_t mib[3];
- size_t miblen = sizeof(mib) / sizeof(mib[0]);
-
- CTL_GET("arenas.narenas", narenas);
- je_(mallctlnametomib)("arena.0.purge", mib, &miblen);
- mib[1] = narenas;
- je_(mallctlbymib)(mib, miblen, NULL, NULL, NULL, 0);
-}
diff --git a/memory/build/mozmemory_wrap.h b/memory/build/mozmemory_wrap.h
index 066d57782..5d718e75e 100644
--- a/memory/build/mozmemory_wrap.h
+++ b/memory/build/mozmemory_wrap.h
@@ -36,8 +36,7 @@
* - jemalloc_stats
* - jemalloc_purge_freed_pages
* - jemalloc_free_dirty_pages
- * (these functions are native to mozjemalloc, and have compatibility
- * implementations for jemalloc3)
+ * (these functions are native to mozjemalloc)
*
* These functions are all exported as part of libmozglue (see
* $(topsrcdir)/mozglue/build/Makefile.in), with a few implementation
@@ -87,21 +86,16 @@
* char* strdup_impl(const char *)
* That implementation would call malloc by using "malloc_impl".
*
- * While mozjemalloc uses these "_impl" suffixed helpers, jemalloc3, being
- * third-party code, doesn't, but instead has an elaborate way to mangle
- * individual functions. See under "Run jemalloc configure script" in
- * $(topsrcdir)/configure.in.
- *
*
* When building with replace-malloc support, the above still holds, but
* the malloc implementation and jemalloc specific functions are the
* replace-malloc functions from replace_malloc.c.
*
- * The actual jemalloc/mozjemalloc implementation is prefixed with "je_".
+ * The actual mozjemalloc implementation is prefixed with "je_".
*
* Thus, when MOZ_REPLACE_MALLOC is defined, the "_impl" suffixed macros
- * expand to "je_" prefixed function when building mozjemalloc or
- * jemalloc3/mozjemalloc_compat, where MOZ_JEMALLOC_IMPL is defined.
+ * expand to "je_" prefixed function when building mozjemalloc, where
+ * MOZ_JEMALLOC_IMPL is defined.
*
* In other cases, the "_impl" suffixed macros follow the original scheme,
* except on Windows and MacOSX, where they would expand to "je_" prefixed
@@ -125,43 +119,31 @@
#include "mozilla/Types.h"
-#if !defined(MOZ_SYSTEM_JEMALLOC)
-# ifdef MOZ_MEMORY_IMPL
-# if defined(MOZ_JEMALLOC_IMPL) && defined(MOZ_REPLACE_MALLOC) && !defined(MOZ_REPLACE_JEMALLOC)
-# define mozmem_malloc_impl(a) je_ ## a
-# define mozmem_jemalloc_impl(a) je_ ## a
-# else
-# define MOZ_JEMALLOC_API MFBT_API
-# ifdef MOZ_REPLACE_JEMALLOC
-# define MOZ_MEMORY_API MFBT_API
-# define mozmem_malloc_impl(a) replace_ ## a
-# define mozmem_jemalloc_impl(a) replace_ ## a
-# elif (defined(XP_WIN) || defined(XP_DARWIN))
-# if defined(MOZ_REPLACE_MALLOC)
-# define mozmem_malloc_impl(a) a ## _impl
-# else
-# define mozmem_malloc_impl(a) je_ ## a
-# endif
+#ifdef MOZ_MEMORY_IMPL
+# if defined(MOZ_JEMALLOC_IMPL) && defined(MOZ_REPLACE_MALLOC)
+# define mozmem_malloc_impl(a) je_ ## a
+# define mozmem_jemalloc_impl(a) je_ ## a
+# else
+# define MOZ_JEMALLOC_API MFBT_API
+# if (defined(XP_WIN) || defined(XP_DARWIN))
+# if defined(MOZ_REPLACE_MALLOC)
+# define mozmem_malloc_impl(a) a ## _impl
# else
-# define MOZ_MEMORY_API MFBT_API
-# if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
-# define MOZ_WRAP_NEW_DELETE
-# endif
+# define mozmem_malloc_impl(a) je_ ## a
+# endif
+# else
+# define MOZ_MEMORY_API MFBT_API
+# if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
+# define MOZ_WRAP_NEW_DELETE
# endif
-# endif
-# ifdef XP_WIN
-# define mozmem_dup_impl(a) wrap_ ## a
# endif
# endif
-
-/* All other jemalloc3 functions are prefixed with "je_", except when
- * building against an unprefixed system jemalloc library */
-# define je_(a) je_ ## a
-#else /* defined(MOZ_SYSTEM_JEMALLOC) */
-# define je_(a) a
+# ifdef XP_WIN
+# define mozmem_dup_impl(a) wrap_ ## a
+# endif
#endif
-#if !defined(MOZ_MEMORY_IMPL) || defined(MOZ_SYSTEM_JEMALLOC)
+#if !defined(MOZ_MEMORY_IMPL)
# define MOZ_MEMORY_API MFBT_API
# define MOZ_JEMALLOC_API MFBT_API
#endif
diff --git a/memory/build/replace_malloc.c b/memory/build/replace_malloc.c
index 26dd8c2d6..f4c7eb878 100644
--- a/memory/build/replace_malloc.c
+++ b/memory/build/replace_malloc.c
@@ -10,10 +10,6 @@
# error Should not compile this file when replace-malloc is disabled
#endif
-#ifdef MOZ_SYSTEM_JEMALLOC
-# error Should not compile this file when we want to use native jemalloc
-#endif
-
#include "mozmemory_wrap.h"
/* Declare all je_* functions */