diff options
author | jasone <jasone@FreeBSD.org> | 2012-04-17 07:22:14 +0000 |
---|---|---|
committer | jasone <jasone@FreeBSD.org> | 2012-04-17 07:22:14 +0000 |
commit | cbeacb7c46f3a3650e5dbefa9a1a18bc9943a8cc (patch) | |
tree | 24efdb5b31d087479e78f72f3b772bd5b02e470c /contrib/jemalloc/FREEBSD-diffs | |
parent | 1bc364bf7eebf6139e4f968987974484d35c5cb4 (diff) | |
download | FreeBSD-src-cbeacb7c46f3a3650e5dbefa9a1a18bc9943a8cc.zip FreeBSD-src-cbeacb7c46f3a3650e5dbefa9a1a18bc9943a8cc.tar.gz |
Import jemalloc 9ef7f5dc34ff02f50d401e41c8d9a4a928e7c2aa (dev branch,
prior to 3.0.0 release) as contrib/jemalloc, and integrate it into libc.
The code being imported by this commit diverged from
lib/libc/stdlib/malloc.c in March 2010, which means that a portion of
the jemalloc 1.0.0 ChangeLog entries are relevant, as are the entries
for all subsequent releases.
Diffstat (limited to 'contrib/jemalloc/FREEBSD-diffs')
-rw-r--r-- | contrib/jemalloc/FREEBSD-diffs | 247 |
1 files changed, 247 insertions, 0 deletions
diff --git a/contrib/jemalloc/FREEBSD-diffs b/contrib/jemalloc/FREEBSD-diffs new file mode 100644 index 0000000..927268c --- /dev/null +++ b/contrib/jemalloc/FREEBSD-diffs @@ -0,0 +1,247 @@ +diff --git a/doc/jemalloc.xml.in b/doc/jemalloc.xml.in +index 98d0ba4..23d2152 100644 +--- a/doc/jemalloc.xml.in ++++ b/doc/jemalloc.xml.in +@@ -51,12 +51,23 @@ + <para>This manual describes jemalloc @jemalloc_version@. More information + can be found at the <ulink + url="http://www.canonware.com/jemalloc/">jemalloc website</ulink>.</para> ++ ++ <para>The following configuration options are enabled in libc's built-in ++ jemalloc: <option>--enable-dss</option>, ++ <option>--enable-experimental</option>, <option>--enable-fill</option>, ++ <option>--enable-lazy-lock</option>, <option>--enable-munmap</option>, ++ <option>--enable-stats</option>, <option>--enable-tcache</option>, ++ <option>--enable-tls</option>, <option>--enable-utrace</option>, and ++ <option>--enable-xmalloc</option>. Additionally, ++ <option>--enable-debug</option> is enabled in development versions of ++ FreeBSD (controlled by the <constant>MALLOC_PRODUCTION</constant> make ++ variable).</para> + </refsect1> + <refsynopsisdiv> + <title>SYNOPSIS</title> + <funcsynopsis> + <funcsynopsisinfo>#include <<filename class="headerfile">stdlib.h</filename>> +-#include <<filename class="headerfile">jemalloc/jemalloc.h</filename>></funcsynopsisinfo> ++#include <<filename class="headerfile">malloc_np.h</filename>></funcsynopsisinfo> + <refsect2> + <title>Standard API</title> + <funcprototype> +@@ -2080,4 +2091,16 @@ malloc_conf = "lg_chunk:24";]]></programlisting></para> + <para>The <function>posix_memalign<parameter/></function> function conforms + to IEEE Std 1003.1-2001 (“POSIX.1”).</para> + </refsect1> ++ <refsect1 id="history"> ++ <title>HISTORY</title> ++ <para>The <function>malloc_usable_size<parameter/></function> and ++ <function>posix_memalign<parameter/></function> functions first appeared in ++ FreeBSD 7.0.</para> ++ ++ <para>The <function>aligned_alloc<parameter/></function>, ++ <function>malloc_stats_print<parameter/></function>, ++ <function>mallctl*<parameter/></function>, and ++ <function>*allocm<parameter/></function> functions first appeared in ++ FreeBSD 10.0.</para> ++ </refsect1> + </refentry> +diff --git a/include/jemalloc/internal/jemalloc_internal.h.in b/include/jemalloc/internal/jemalloc_internal.h.in +index aa21aa5..e0f5fed 100644 +--- a/include/jemalloc/internal/jemalloc_internal.h.in ++++ b/include/jemalloc/internal/jemalloc_internal.h.in +@@ -1,3 +1,6 @@ ++#include "libc_private.h" ++#include "namespace.h" ++ + #include <sys/mman.h> + #include <sys/param.h> + #include <sys/syscall.h> +@@ -33,6 +36,9 @@ + #include <pthread.h> + #include <math.h> + ++#include "un-namespace.h" ++#include "libc_private.h" ++ + #define JEMALLOC_NO_DEMANGLE + #include "../jemalloc@install_suffix@.h" + +diff --git a/include/jemalloc/internal/mutex.h b/include/jemalloc/internal/mutex.h +index c46feee..d7133f4 100644 +--- a/include/jemalloc/internal/mutex.h ++++ b/include/jemalloc/internal/mutex.h +@@ -39,8 +39,6 @@ struct malloc_mutex_s { + + #ifdef JEMALLOC_LAZY_LOCK + extern bool isthreaded; +-#else +-# define isthreaded true + #endif + + bool malloc_mutex_init(malloc_mutex_t *mutex); +diff --git a/include/jemalloc/jemalloc.h.in b/include/jemalloc/jemalloc.h.in +index f0581db..f26d8bc 100644 +--- a/include/jemalloc/jemalloc.h.in ++++ b/include/jemalloc/jemalloc.h.in +@@ -15,6 +15,7 @@ extern "C" { + #define JEMALLOC_VERSION_GID "@jemalloc_version_gid@" + + #include "jemalloc_defs@install_suffix@.h" ++#include "jemalloc_FreeBSD.h" + + #ifdef JEMALLOC_EXPERIMENTAL + #define ALLOCM_LG_ALIGN(la) (la) +diff --git a/include/jemalloc/jemalloc_FreeBSD.h b/include/jemalloc/jemalloc_FreeBSD.h +new file mode 100644 +index 0000000..2c5797f +--- /dev/null ++++ b/include/jemalloc/jemalloc_FreeBSD.h +@@ -0,0 +1,76 @@ ++/* ++ * Override settings that were generated in jemalloc_defs.h as necessary. ++ */ ++ ++#undef JEMALLOC_OVERRIDE_VALLOC ++ ++#ifndef MALLOC_PRODUCTION ++#define JEMALLOC_DEBUG ++#endif ++ ++/* ++ * The following are architecture-dependent, so conditionally define them for ++ * each supported architecture. ++ */ ++#undef CPU_SPINWAIT ++#undef JEMALLOC_TLS_MODEL ++#undef STATIC_PAGE_SHIFT ++#undef LG_SIZEOF_PTR ++#undef LG_SIZEOF_INT ++#undef LG_SIZEOF_LONG ++#undef LG_SIZEOF_INTMAX_T ++ ++#ifdef __i386__ ++# define LG_SIZEOF_PTR 2 ++# define CPU_SPINWAIT __asm__ volatile("pause") ++# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) ++#endif ++#ifdef __ia64__ ++# define LG_SIZEOF_PTR 3 ++#endif ++#ifdef __sparc64__ ++# define LG_SIZEOF_PTR 3 ++# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) ++#endif ++#ifdef __amd64__ ++# define LG_SIZEOF_PTR 3 ++# define CPU_SPINWAIT __asm__ volatile("pause") ++# define JEMALLOC_TLS_MODEL __attribute__((tls_model("initial-exec"))) ++#endif ++#ifdef __arm__ ++# define LG_SIZEOF_PTR 2 ++#endif ++#ifdef __mips__ ++# define LG_SIZEOF_PTR 2 ++#endif ++#ifdef __powerpc64__ ++# define LG_SIZEOF_PTR 3 ++#elif defined(__powerpc__) ++# define LG_SIZEOF_PTR 2 ++#endif ++ ++#ifndef JEMALLOC_TLS_MODEL ++# define JEMALLOC_TLS_MODEL /* Default. */ ++#endif ++#ifdef __clang__ ++# undef JEMALLOC_TLS_MODEL ++# define JEMALLOC_TLS_MODEL /* clang does not support tls_model yet. */ ++#endif ++ ++#define STATIC_PAGE_SHIFT PAGE_SHIFT ++#define LG_SIZEOF_INT 2 ++#define LG_SIZEOF_LONG LG_SIZEOF_PTR ++#define LG_SIZEOF_INTMAX_T 3 ++ ++/* Disable lazy-lock machinery, mangle isthreaded, and adjust its type. */ ++#undef JEMALLOC_LAZY_LOCK ++extern int __isthreaded; ++#define isthreaded ((bool)__isthreaded) ++ ++/* Mangle. */ ++#define open _open ++#define read _read ++#define write _write ++#define close _close ++#define pthread_mutex_lock _pthread_mutex_lock ++#define pthread_mutex_unlock _pthread_mutex_unlock +diff --git a/src/jemalloc.c b/src/jemalloc.c +index 0decd8a..73fad29 100644 +--- a/src/jemalloc.c ++++ b/src/jemalloc.c +@@ -8,6 +8,9 @@ malloc_tsd_data(, arenas, arena_t *, NULL) + malloc_tsd_data(, thread_allocated, thread_allocated_t, + THREAD_ALLOCATED_INITIALIZER) + ++const char *__malloc_options_1_0; ++__sym_compat(_malloc_options, __malloc_options_1_0, FBSD_1.0); ++ + /* Runtime configuration options. */ + const char *je_malloc_conf JEMALLOC_ATTR(visibility("default")); + #ifdef JEMALLOC_DEBUG +@@ -401,7 +404,8 @@ malloc_conf_init(void) + #endif + ; + +- if ((opts = getenv(envname)) != NULL) { ++ if (issetugid() == 0 && (opts = getenv(envname)) != ++ NULL) { + /* + * Do nothing; opts is already initialized to + * the value of the MALLOC_CONF environment +diff --git a/src/mutex.c b/src/mutex.c +index 4b8ce57..7be5fc9 100644 +--- a/src/mutex.c ++++ b/src/mutex.c +@@ -63,6 +63,17 @@ pthread_create(pthread_t *__restrict thread, + #ifdef JEMALLOC_MUTEX_INIT_CB + int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex, + void *(calloc_cb)(size_t, size_t)); ++ ++__weak_reference(_pthread_mutex_init_calloc_cb_stub, ++ _pthread_mutex_init_calloc_cb); ++ ++int ++_pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex, ++ void *(calloc_cb)(size_t, size_t)) ++{ ++ ++ return (0); ++} + #endif + + bool +diff --git a/src/util.c b/src/util.c +index 2aab61f..8b05042 100644 +--- a/src/util.c ++++ b/src/util.c +@@ -60,6 +60,22 @@ wrtmessage(void *cbopaque, const char *s) + void (*je_malloc_message)(void *, const char *s) + JEMALLOC_ATTR(visibility("default")) = wrtmessage; + ++JEMALLOC_CATTR(visibility("hidden"), static) ++void ++wrtmessage_1_0(const char *s1, const char *s2, const char *s3, ++ const char *s4) ++{ ++ ++ wrtmessage(NULL, s1); ++ wrtmessage(NULL, s2); ++ wrtmessage(NULL, s3); ++ wrtmessage(NULL, s4); ++} ++ ++void (*__malloc_message_1_0)(const char *s1, const char *s2, const char *s3, ++ const char *s4) = wrtmessage_1_0; ++__sym_compat(_malloc_message, __malloc_message_1_0, FBSD_1.0); ++ + /* + * glibc provides a non-standard strerror_r() when _GNU_SOURCE is defined, so + * provide a wrapper. |