--- a/memory/mozjemalloc/jemalloc.c
+++ b/memory/mozjemalloc/jemalloc.c
@@ -173,23 +173,16 @@
/* Support optional abort() on OOM. */
# define MALLOC_XMALLOC
/* Support SYSV semantics. */
# define MALLOC_SYSV
#endif
-/*
- * MALLOC_VALIDATE causes malloc_usable_size() to perform some pointer
- * validation. There are many possible errors that validation does not even
- * attempt to detect.
- */
-#define MALLOC_VALIDATE
-
#if defined(MOZ_MEMORY_LINUX) && !defined(MOZ_MEMORY_ANDROID)
#define _GNU_SOURCE /* For mremap(2). */
#endif
#include <sys/types.h>
#include <errno.h>
#include <stdlib.h>
@@ -617,35 +610,33 @@ struct extent_node_s {
};
typedef rb_tree(extent_node_t) extent_tree_t;
/******************************************************************************/
/*
* Radix tree data structures.
*/
-#ifdef MALLOC_VALIDATE
- /*
- * Size of each radix tree node (must be a power of 2). This impacts tree
- * depth.
- */
-# if (SIZEOF_PTR == 4)
-# define MALLOC_RTREE_NODESIZE (1U << 14)
-# else
-# define MALLOC_RTREE_NODESIZE CACHELINE
-# endif
+/*
+ * Size of each radix tree node (must be a power of 2). This impacts tree
+ * depth.
+ */
+#if (SIZEOF_PTR == 4)
+# define MALLOC_RTREE_NODESIZE (1U << 14)
+#else
+# define MALLOC_RTREE_NODESIZE CACHELINE
+#endif
typedef struct malloc_rtree_s malloc_rtree_t;
struct malloc_rtree_s {
malloc_spinlock_t lock;
void **root;
unsigned height;
unsigned level2bits[1]; /* Dynamically sized. */
};
-#endif
/******************************************************************************/
/*
* Arena data structures.
*/
typedef struct arena_s arena_t;
typedef struct arena_bin_s arena_bin_t;
@@ -1031,19 +1022,17 @@ static size_t recycle_limit;
/* The current amount of recycled bytes, updated atomically. */
static size_t recycled_size;
/********/
/*
* Chunks.
*/
-#ifdef MALLOC_VALIDATE
static malloc_rtree_t *chunk_rtree;
-#endif
/* Protects chunk-related data structures. */
static malloc_mutex_t chunks_mtx;
/*
* Trees of chunks that were previously allocated (trees differ only in node
* ordering). These are used when allocating chunks, in an attempt to re-use
* address space. Depending on function, different tree orderings are needed,
@@ -2134,17 +2123,16 @@ pages_copy(void *dest, const void *src,
assert(n >= VM_COPY_MIN);
assert((void *)((uintptr_t)src & ~pagesize_mask) == src);
vm_copy(mach_task_self(), (vm_address_t)src, (vm_size_t)n,
(vm_address_t)dest);
}
#endif
-#ifdef MALLOC_VALIDATE
static inline malloc_rtree_t *
malloc_rtree_new(unsigned bits)
{
malloc_rtree_t *ret;
unsigned bits_per_level, height, i;
bits_per_level = ffs(pow2_ceil((MALLOC_RTREE_NODESIZE /
sizeof(void *)))) - 1;
@@ -2275,17 +2263,16 @@ malloc_rtree_set(malloc_rtree_t *rtree,
/* node is a leaf, so it contains values rather than node pointers. */
bits = rtree->level2bits[i];
subkey = (key << lshift) >> ((SIZEOF_PTR << 3) - bits);
node[subkey] = val;
malloc_spin_unlock(&rtree->lock);
return (false);
}
-#endif
/* pages_trim, chunk_alloc_mmap_slow and chunk_alloc_mmap were cherry-picked
* from upstream jemalloc 3.4.1 to fix Mozilla bug 956501. */
/* Return the offset between a and the nearest aligned address at or below a. */
#define ALIGNMENT_ADDR2OFFSET(a, alignment) \
((size_t)((uintptr_t)(a) & (alignment - 1)))
@@ -2559,24 +2546,22 @@ chunk_alloc(size_t size, size_t alignmen
if (ret != NULL) {
goto RETURN;
}
/* All strategies for allocation failed. */
ret = NULL;
RETURN:
-#ifdef MALLOC_VALIDATE
if (ret != NULL && base == false) {
if (malloc_rtree_set(chunk_rtree, (uintptr_t)ret, ret)) {
chunk_dealloc(ret, size);
return (NULL);
}
}
-#endif
assert(CHUNK_ADDR2BASE(ret) == ret);
return (ret);
}
static void
chunk_record(extent_tree_t *chunks_szad, extent_tree_t *chunks_ad, void *chunk,
size_t size)
@@ -2684,19 +2669,17 @@ static void
chunk_dealloc(void *chunk, size_t size)
{
assert(chunk != NULL);
assert(CHUNK_ADDR2BASE(chunk) == chunk);
assert(size != 0);
assert((size & chunksize_mask) == 0);
-#ifdef MALLOC_VALIDATE
malloc_rtree_set(chunk_rtree, (uintptr_t)chunk, NULL);
-#endif
if (chunk_dalloc_mmap(chunk, size))
chunk_record(&chunks_szad_mmap, &chunks_ad_mmap, chunk, size);
}
/*
* End chunk management functions.
*/
@@ -4004,17 +3987,16 @@ arena_salloc(const void *ptr)
} else {
ret = mapbits & ~pagesize_mask;
RELEASE_ASSERT(ret != 0);
}
return (ret);
}
-#if (defined(MALLOC_VALIDATE) || defined(MOZ_MEMORY_DARWIN))
/*
* Validate ptr before assuming that it points to an allocation. Currently,
* the following validation is performed:
*
* + Check that ptr is not NULL.
*
* + Check that ptr lies within a mapped chunk.
*/
@@ -4045,17 +4027,16 @@ isalloc_validate(const void *ptr)
if (node != NULL)
ret = node->size;
else
ret = 0;
malloc_mutex_unlock(&huge_mtx);
return (ret);
}
}
-#endif
static inline size_t
isalloc(const void *ptr)
{
size_t ret;
arena_chunk_t *chunk;
assert(ptr != NULL);
@@ -5321,21 +5302,19 @@ MALLOC_OUT:
TlsSetValue(tlsIndex, arenas[0]);
#elif defined(MOZ_MEMORY_DARWIN)
pthread_setspecific(tlsIndex, arenas[0]);
#else
arenas_map = arenas[0];
#endif
#endif
-#ifdef MALLOC_VALIDATE
chunk_rtree = malloc_rtree_new((SIZEOF_PTR << 3) - opt_chunk_2pow);
if (chunk_rtree == NULL)
return (true);
-#endif
malloc_initialized = true;
#if !defined(MOZ_MEMORY_WINDOWS) && !defined(MOZ_MEMORY_DARWIN)
/* Prevent potential deadlock on malloc locks after fork. */
pthread_atfork(_malloc_prefork, _malloc_postfork_parent, _malloc_postfork_child);
#endif
@@ -5734,23 +5713,17 @@ malloc_good_size_impl(size_t size)
}
return size;
}
MOZ_MEMORY_API size_t
malloc_usable_size_impl(MALLOC_USABLE_SIZE_CONST_PTR void *ptr)
{
-#ifdef MALLOC_VALIDATE
return (isalloc_validate(ptr));
-#else
- assert(ptr != NULL);
-
- return (isalloc(ptr));
-#endif
}
MOZ_JEMALLOC_API void
jemalloc_stats_impl(jemalloc_stats_t *stats)
{
size_t i, non_arena_mapped, chunk_header_size;
assert(stats != NULL);