Bug 1365460 - Remove runtime support for SysV malloc semantics. r?njn draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 18 May 2017 10:28:28 +0900
changeset 580754 17fe701cb4a730ac4bcef7c0a2132f97c029e214
parent 580753 3c6592e2c5f037657a0861aeed7ed209c08373c5
child 580755 d38a5cc8c044b6c9c80a38ec3de0b7a51732ab16
push id59654
push userbmo:mh+mozilla@glandium.org
push dateThu, 18 May 2017 22:44:22 +0000
reviewersnjn
bugs1365460
milestone55.0a1
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.
memory/mozjemalloc/mozjemalloc.cpp
memory/mozjemalloc/mozjemalloc_types.h
--- a/memory/mozjemalloc/mozjemalloc.cpp
+++ b/memory/mozjemalloc/mozjemalloc.cpp
@@ -130,19 +130,16 @@
  */
 #ifdef MOZ_MEMORY_DARWIN
 #define MALLOC_DOUBLE_PURGE
 #endif
 
 #ifdef MOZ_DEBUG
    /* Support optional abort() on OOM. */
 #  define MALLOC_XMALLOC
-
-   /* Support SYSV semantics. */
-#  define MALLOC_SYSV
 #endif
 
 #include <sys/types.h>
 
 #include <errno.h>
 #include <stdlib.h>
 #include <limits.h>
 #include <stdarg.h>
@@ -1066,19 +1063,16 @@ static bool	opt_print_stats = false;
 #define opt_quantum_2pow	QUANTUM_2POW_MIN
 #define opt_small_max_2pow	SMALL_MAX_2POW_DEFAULT
 #define opt_chunk_2pow		CHUNK_2POW_DEFAULT
 #else
 static size_t	opt_quantum_2pow = QUANTUM_2POW_MIN;
 static size_t	opt_small_max_2pow = SMALL_MAX_2POW_DEFAULT;
 static size_t	opt_chunk_2pow = CHUNK_2POW_DEFAULT;
 #endif
-#ifdef MALLOC_SYSV
-static bool	opt_sysv = false;
-#endif
 #ifdef MALLOC_XMALLOC
 static bool	opt_xmalloc = false;
 #endif
 
 /******************************************************************************/
 /*
  * Begin function prototypes for non-inline static functions.
  */
@@ -4539,19 +4533,16 @@ malloc_print_stats(void)
 #else
 		    "enabled",
 #endif
 		    "\n", "");
 		_malloc_message("Boolean MALLOC_OPTIONS: ",
 		    opt_abort ? "A" : "a", "", "");
 		_malloc_message(opt_junk ? "J" : "j", "", "", "");
 		_malloc_message("P", "", "", "");
-#ifdef MALLOC_SYSV
-		_malloc_message(opt_sysv ? "V" : "v", "", "", "");
-#endif
 #ifdef MALLOC_XMALLOC
 		_malloc_message(opt_xmalloc ? "X" : "x", "", "", "");
 #endif
 		_malloc_message(opt_zero ? "Z" : "z", "", "", "");
 		_malloc_message("\n", "", "", "");
 
 		_malloc_message("Max arenas: ", umax2s(narenas, 10, s), "\n",
 		    "");
@@ -4810,24 +4801,16 @@ MALLOC_OUT:
 						opt_small_max_2pow--;
 					break;
 				case 'S':
 					if (opt_small_max_2pow < pagesize_2pow
 					    - 1)
 						opt_small_max_2pow++;
 					break;
 #endif
-#ifdef MALLOC_SYSV
-				case 'v':
-					opt_sysv = false;
-					break;
-				case 'V':
-					opt_sysv = true;
-					break;
-#endif
 #ifdef MALLOC_XMALLOC
 				case 'x':
 					opt_xmalloc = false;
 					break;
 				case 'X':
 					opt_xmalloc = true;
 					break;
 #endif
@@ -5004,26 +4987,17 @@ malloc_impl(size_t size)
 	void *ret;
 
 	if (malloc_init()) {
 		ret = NULL;
 		goto RETURN;
 	}
 
 	if (size == 0) {
-#ifdef MALLOC_SYSV
-		if (opt_sysv == false)
-#endif
-			size = 1;
-#ifdef MALLOC_SYSV
-		else {
-			ret = NULL;
-			goto RETURN;
-		}
-#endif
+		size = 1;
 	}
 
 	ret = imalloc(size);
 
 RETURN:
 	if (ret == NULL) {
 #ifdef MALLOC_XMALLOC
 		if (opt_xmalloc) {
@@ -5071,26 +5045,17 @@ MEMALIGN(size_t alignment, size_t size)
 	assert(((alignment - 1) & alignment) == 0);
 
 	if (malloc_init()) {
 		ret = NULL;
 		goto RETURN;
 	}
 
 	if (size == 0) {
-#ifdef MALLOC_SYSV
-		if (opt_sysv == false)
-#endif
-			size = 1;
-#ifdef MALLOC_SYSV
-		else {
-			ret = NULL;
-			goto RETURN;
-		}
-#endif
+		size = 1;
 	}
 
 	alignment = alignment < sizeof(void*) ? sizeof(void*) : alignment;
 	ret = ipalloc(alignment, size);
 
 RETURN:
 #ifdef MALLOC_XMALLOC
 	if (opt_xmalloc && ret == NULL) {
@@ -5168,26 +5133,17 @@ calloc_impl(size_t num, size_t size)
 	if (malloc_init()) {
 		num_size = 0;
 		ret = NULL;
 		goto RETURN;
 	}
 
 	num_size = num * size;
 	if (num_size == 0) {
-#ifdef MALLOC_SYSV
-		if ((opt_sysv == false) && ((num == 0) || (size == 0)))
-#endif
-			num_size = 1;
-#ifdef MALLOC_SYSV
-		else {
-			ret = NULL;
-			goto RETURN;
-		}
-#endif
+		num_size = 1;
 	/*
 	 * Try to avoid division here.  We know that it isn't possible to
 	 * overflow during multiplication if neither operand uses any of the
 	 * most significant half of the bits in a size_t.
 	 */
 	} else if (((num | size) & (SIZE_T_MAX << (sizeof(size_t) << 2)))
 	    && (num_size / size != num)) {
 		/* size_t overflow. */
@@ -5214,28 +5170,17 @@ RETURN:
 }
 
 MOZ_MEMORY_API void *
 realloc_impl(void *ptr, size_t size)
 {
 	void *ret;
 
 	if (size == 0) {
-#ifdef MALLOC_SYSV
-		if (opt_sysv == false)
-#endif
-			size = 1;
-#ifdef MALLOC_SYSV
-		else {
-			if (ptr != NULL)
-				idalloc(ptr);
-			ret = NULL;
-			goto RETURN;
-		}
-#endif
+		size = 1;
 	}
 
 	if (ptr != NULL) {
 		assert(malloc_initialized);
 
 		ret = iralloc(ptr, size);
 
 		if (ret == NULL) {
@@ -5263,19 +5208,16 @@ realloc_impl(void *ptr, size_t size)
 				    "memory\n", "", "");
 				moz_abort();
 			}
 #endif
 			errno = ENOMEM;
 		}
 	}
 
-#ifdef MALLOC_SYSV
-RETURN:
-#endif
 	return (ret);
 }
 
 MOZ_MEMORY_API void
 free_impl(void *ptr)
 {
 	size_t offset;
 
@@ -5352,21 +5294,16 @@ jemalloc_stats_impl(jemalloc_stats_t *st
 
 	assert(stats != NULL);
 
 	/*
 	 * Gather runtime settings.
 	 */
 	stats->opt_abort = opt_abort;
 	stats->opt_junk = opt_junk;
-	stats->opt_sysv =
-#ifdef MALLOC_SYSV
-	    opt_sysv ? true :
-#endif
-	    false;
 	stats->opt_xmalloc =
 #ifdef MALLOC_XMALLOC
 	    opt_xmalloc ? true :
 #endif
 	    false;
 	stats->opt_zero = opt_zero;
 	stats->narenas = narenas;
 	stats->quantum = quantum;
--- a/memory/mozjemalloc/mozjemalloc_types.h
+++ b/memory/mozjemalloc/mozjemalloc_types.h
@@ -51,17 +51,16 @@ typedef unsigned char jemalloc_bool;
  * file.
  */
 typedef struct {
 	/*
 	 * Run-time configuration settings.
 	 */
 	jemalloc_bool	opt_abort;	/* abort(3) on error? */
 	jemalloc_bool	opt_junk;	/* Fill allocated memory with kAllocJunk? */
-	jemalloc_bool	opt_sysv;	/* SysV semantics? */
 	jemalloc_bool	opt_xmalloc;	/* abort(3) on OOM? */
 	jemalloc_bool	opt_zero;	/* Fill allocated memory with 0x0? */
 	size_t	narenas;	/* Number of arenas. */
 	size_t	quantum;	/* Allocation quantum. */
 	size_t	small_max;	/* Max quantum-spaced allocation size. */
 	size_t	large_max;	/* Max sub-chunksize allocation size. */
 	size_t	chunksize;	/* Size of each virtual memory mapping. */
 	size_t	dirty_max;	/* Max dirty pages per arena. */