head	1.11;
access;
symbols;
locks; strict;
comment	@# @;


1.11
date	2013.06.04.00.36.05;	author svnexp;	state Exp;
branches;
next	1.10;

1.10
date	2013.01.25.00.28.46;	author svnexp;	state Exp;
branches;
next	1.9;

1.9
date	2012.11.10.01.46.13;	author jasone;	state Exp;
branches;
next	1.8;

1.8
date	2012.08.23.17.58.22;	author dim;	state Exp;
branches;
next	1.7;

1.7
date	2012.05.13.01.33.28;	author jasone;	state Exp;
branches;
next	1.6;

1.6
date	2012.05.12.05.26.49;	author jasone;	state Exp;
branches;
next	1.5;

1.5
date	2012.05.10.18.29.40;	author jasone;	state Exp;
branches;
next	1.4;

1.4
date	2012.04.22.08.49.13;	author jasone;	state Exp;
branches;
next	1.3;

1.3
date	2012.04.21.15.09.22;	author jasone;	state Exp;
branches;
next	1.2;

1.2
date	2012.04.17.22.05.55;	author jasone;	state Exp;
branches;
next	1.1;

1.1
date	2012.04.17.07.22.14;	author jasone;	state Exp;
branches;
next	;


desc
@@


1.11
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/251300
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@diff --git a/doc/jemalloc.xml.in b/doc/jemalloc.xml.in
index abd5e6f..1d7491a 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 &lt;<filename class="headerfile">stdlib.h</filename>&gt;
-#include &lt;<filename class="headerfile">jemalloc/jemalloc.h</filename>&gt;</funcsynopsisinfo>
+#include &lt;<filename class="headerfile">malloc_np.h</filename>&gt;</funcsynopsisinfo>
       <refsect2>
         <title>Standard API</title>
         <funcprototype>
@@@@ -2180,4 +2191,16 @@@@ malloc_conf = "lg_chunk:24";]]></programlisting></para>
     <para>The <function>posix_memalign<parameter/></function> function conforms
     to IEEE Std 1003.1-2001 (&ldquo;POSIX.1&rdquo;).</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 e46ac54..527449d 100644
--- a/include/jemalloc/internal/jemalloc_internal.h.in
+++ b/include/jemalloc/internal/jemalloc_internal.h.in
@@@@ -1,5 +1,8 @@@@
 #ifndef JEMALLOC_INTERNAL_H
 #define JEMALLOC_INTERNAL_H
+#include "libc_private.h"
+#include "namespace.h"
+
 #include <math.h>
 #ifdef _WIN32
 #  include <windows.h>
@@@@ -54,6 +57,9 @@@@ typedef intptr_t ssize_t;
 #endif
 #include <fcntl.h>
 
+#include "un-namespace.h"
+#include "libc_private.h"
+
 #define	JEMALLOC_NO_DEMANGLE
 #include "../jemalloc@@install_suffix@@.h"
 
@@@@ -95,13 +101,7 @@@@ static const bool config_fill =
     false
 #endif
     ;
-static const bool config_lazy_lock =
-#ifdef JEMALLOC_LAZY_LOCK
-    true
-#else
-    false
-#endif
-    ;
+static const bool config_lazy_lock = true;
 static const bool config_prof =
 #ifdef JEMALLOC_PROF
     true
diff --git a/include/jemalloc/internal/mutex.h b/include/jemalloc/internal/mutex.h
index de44e14..564d604 100644
--- a/include/jemalloc/internal/mutex.h
+++ b/include/jemalloc/internal/mutex.h
@@@@ -43,9 +43,6 @@@@ struct malloc_mutex_s {
 
 #ifdef JEMALLOC_LAZY_LOCK
 extern bool isthreaded;
-#else
-#  undef isthreaded /* Undo private_namespace.h definition. */
-#  define isthreaded true
 #endif
 
 bool	malloc_mutex_init(malloc_mutex_t *mutex);
diff --git a/include/jemalloc/internal/private_namespace.h b/include/jemalloc/internal/private_namespace.h
index 65de316..366676b 100644
--- a/include/jemalloc/internal/private_namespace.h
+++ b/include/jemalloc/internal/private_namespace.h
@@@@ -216,7 +216,6 @@@@
 #define	iralloc JEMALLOC_N(iralloc)
 #define	irallocx JEMALLOC_N(irallocx)
 #define	isalloc JEMALLOC_N(isalloc)
-#define	isthreaded JEMALLOC_N(isthreaded)
 #define	ivsalloc JEMALLOC_N(ivsalloc)
 #define	jemalloc_postfork_child JEMALLOC_N(jemalloc_postfork_child)
 #define	jemalloc_postfork_parent JEMALLOC_N(jemalloc_postfork_parent)
diff --git a/include/jemalloc/jemalloc.h.in b/include/jemalloc/jemalloc.h.in
index 31b1304..c3ef2f5 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..e6c8407
--- /dev/null
+++ b/include/jemalloc/jemalloc_FreeBSD.h
@@@@ -0,0 +1,117 @@@@
+/*
+ * 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__
+#ifdef __mips_n64
+#  define LG_SIZEOF_PTR		3
+#else
+#  define LG_SIZEOF_PTR		2
+#endif
+#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
+
+#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. */
+#undef je_malloc
+#undef je_calloc
+#undef je_realloc
+#undef je_free
+#undef je_posix_memalign
+#undef je_malloc_usable_size
+#undef je_allocm
+#undef je_rallocm
+#undef je_sallocm
+#undef je_dallocm
+#undef je_nallocm
+#define	je_malloc		__malloc
+#define	je_calloc		__calloc
+#define	je_realloc		__realloc
+#define	je_free			__free
+#define	je_posix_memalign	__posix_memalign
+#define	je_malloc_usable_size	__malloc_usable_size
+#define	je_allocm		__allocm
+#define	je_rallocm		__rallocm
+#define	je_sallocm		__sallocm
+#define	je_dallocm		__dallocm
+#define	je_nallocm		__nallocm
+#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
+
+#ifdef JEMALLOC_C_
+/*
+ * Define 'weak' symbols so that an application can have its own versions
+ * of malloc, calloc, realloc, free, et al.
+ */
+__weak_reference(__malloc, malloc);
+__weak_reference(__calloc, calloc);
+__weak_reference(__realloc, realloc);
+__weak_reference(__free, free);
+__weak_reference(__posix_memalign, posix_memalign);
+__weak_reference(__malloc_usable_size, malloc_usable_size);
+__weak_reference(__allocm, allocm);
+__weak_reference(__rallocm, rallocm);
+__weak_reference(__sallocm, sallocm);
+__weak_reference(__dallocm, dallocm);
+__weak_reference(__nallocm, nallocm);
+#endif
+
diff --git a/src/jemalloc.c b/src/jemalloc.c
index bc350ed..352c98e 100644
--- a/src/jemalloc.c
+++ b/src/jemalloc.c
@@@@ -8,6 +8,10 @@@@ malloc_tsd_data(, arenas, arena_t *, NULL)
 malloc_tsd_data(, thread_allocated, thread_allocated_t,
     THREAD_ALLOCATED_INITIALIZER)
 
+/* Work around <http://llvm.org/bugs/show_bug.cgi?id=12623>: */
+const char	*__malloc_options_1_0 = NULL;
+__sym_compat(_malloc_options, __malloc_options_1_0, FBSD_1.0);
+
 /* Runtime configuration options. */
 const char	*je_malloc_conf;
 bool	opt_abort =
@@@@ -471,7 +475,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 55e18c2..6b6f438 100644
--- a/src/mutex.c
+++ b/src/mutex.c
@@@@ -66,6 +66,17 @@@@ pthread_create(pthread_t *__restrict thread,
 #ifdef JEMALLOC_MUTEX_INIT_CB
 JEMALLOC_EXPORT 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 b3a0114..df1c5d5 100644
--- a/src/util.c
+++ b/src/util.c
@@@@ -58,6 +58,22 @@@@ wrtmessage(void *cbopaque, const char *s)
 
 JEMALLOC_EXPORT void	(*je_malloc_message)(void *, const char *s);
 
+JEMALLOC_ATTR(visibility("hidden"))
+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);
+
 /*
  * Wrapper around malloc_message() that avoids the need for
  * je_malloc_message(...) throughout the code.
@


1.10
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/245868
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d2 1
a2 1
index 0930580..d45fa3d 100644
d30 1
a30 1
@@@@ -2173,4 +2184,16 @@@@ malloc_conf = "lg_chunk:24";]]></programlisting></para>
d48 1
a48 1
index c606c12..0d46d9d 100644
d100 1
a100 1
index 903fb4d..d6638df 100644
d125 1
a125 1
index 0000000..9c97a13
d128 1
a128 1
@@@@ -0,0 +1,76 @@@@
d199 22
d227 19
d247 1
a247 1
index c117685..665d98f 100644
d261 1
a261 1
@@@@ -453,7 +457,8 @@@@ malloc_conf_init(void)
@


1.9
log
@SVN rev 242844 on 2012-11-10 01:46:13Z by jasone

Import jemalloc 3.2.0.
@
text
@d2 1
a2 1
index 54b8747..91c4a4e 100644
d30 1
a30 1
@@@@ -2170,4 +2181,16 @@@@ malloc_conf = "lg_chunk:24";]]></programlisting></para>
d48 1
a48 1
index 475821a..73306ac 100644
d100 1
a100 1
index 06241cd..7b19906 100644
d103 1
a103 1
@@@@ -204,7 +204,6 @@@@
d206 1
a206 1
index 8a667b6..aaf5012 100644
d219 2
a220 2
 #ifdef JEMALLOC_DEBUG
@@@@ -448,7 +452,8 @@@@ malloc_conf_init(void)
@


1.8
log
@SVN rev 239618 on 2012-08-23 17:58:22Z by dim

Since our clang now supports the tls_model attribute, remove the
workaround for it in jemalloc_FreeBSD.h.

Reviewed by:	jasone
@
text
@d2 1
a2 1
index 877c500..7d659a7 100644
d30 1
a30 1
@@@@ -2101,4 +2112,16 @@@@ malloc_conf = "lg_chunk:24";]]></programlisting></para>
d48 1
a48 1
index 268cd14..2acd2eb 100644
d100 1
a100 1
index b816647..b8ce6b1 100644
d103 1
a103 2
@@@@ -186,7 +186,6 @@@@
 #define	iqalloc JEMALLOC_N(iqalloc)
d105 1
d112 1
a112 1
index ad06948..505dd38 100644
d125 1
a125 1
index 0000000..9efab93
d206 1
a206 1
index bc54cd7..fa9fcf0 100644
d220 1
a220 1
@@@@ -429,7 +433,8 @@@@ malloc_conf_init(void)
d231 1
a231 1
index 37a843e..4a90a05 100644
d236 1
a236 1
 int	_pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
d253 1
a253 1
index 9b73c3e..f94799f 100644
@


1.7
log
@SVN rev 235385 on 2012-05-13 01:33:28Z by jasone

Fix config_lazy_lock so that thread caching isn't used for
single-threaded applications.
@
text
@d128 1
a128 1
@@@@ -0,0 +1,80 @@@@
a186 4
+#ifdef __clang__
+#  undef JEMALLOC_TLS_MODEL
+#  define JEMALLOC_TLS_MODEL	/* clang does not support tls_model yet. */
+#endif
@


1.6
log
@SVN rev 235322 on 2012-05-12 05:26:49Z by jasone

Import jemalloc 3.0.0.  This fixes memory zeroing bugs that manifested as
jemalloc assertion failures for debug builds, or as calloc() sometimes
returning non-zeroed memory for production builds.
@
text
@d48 1
a48 1
index 268cd14..cfb1fb9 100644
d70 15
@


1.5
log
@SVN rev 235238 on 2012-05-10 18:29:40Z by jasone

Import jemalloc 37b6f95dcd866f51c91488531a2efc3ed4c2b754 (dev branch,
prior to 3.0.0 release).  This version is likely very close to what will be
3.0.0.
@
text
@d2 1
a2 1
index 93c16dc..b5c5595 100644
d195 1
a195 1
index d42e91d..cdf6222 100644
@


1.4
log
@SVN rev 234569 on 2012-04-22 08:49:13Z by jasone

Import jemalloc a8f8d7540d66ddee7337db80c92890916e1063ca (dev branch,
prior to 3.0.0 release).  This fixes several bugs related to memory
initialization.

Mangle __jemalloc_a0{malloc,calloc,free}() just like all the other
library-internal symbols in jemalloc, and adjust the tls allocation code
in libc to use the mangled names.
@
text
@d2 1
a2 1
index e8a5722..cec85b5 100644
d30 1
a30 1
@@@@ -2091,4 +2102,16 @@@@ malloc_conf = "lg_chunk:24";]]></programlisting></para>
d48 1
a48 1
index b61abe8..edbb437 100644
a56 5
 #include <sys/mman.h>
 #include <sys/param.h>
 #include <sys/syscall.h>
@@@@ -35,6 +38,9 @@@@
 #include <pthread.h>
d58 5
d71 1
a71 1
index 8837ef5..d7133f4 100644
d74 1
a74 1
@@@@ -39,9 +39,6 @@@@ struct malloc_mutex_s {
d85 1
a85 1
index bb1b63e..00eb169 100644
d88 1
a88 1
@@@@ -165,7 +165,6 @@@@
d97 1
a97 1
index f0581db..f26d8bc 100644
d110 1
a110 1
index 0000000..2c5797f
d113 1
a113 1
@@@@ -0,0 +1,76 @@@@
d157 3
d162 1
d195 1
a195 1
index f9c8916..8e24a5a 100644
d198 1
a198 1
@@@@ -8,6 +8,9 @@@@ malloc_tsd_data(, arenas, arena_t *, NULL)
d202 2
a203 1
+const char	*__malloc_options_1_0;
d207 1
a207 1
 const char	*je_malloc_conf JEMALLOC_ATTR(visibility("default"));
d209 1
a209 1
@@@@ -401,7 +404,8 @@@@ malloc_conf_init(void)
d220 1
a220 1
index 4b8ce57..7be5fc9 100644
d223 1
a223 1
@@@@ -63,6 +63,17 @@@@ pthread_create(pthread_t *__restrict thread,
d242 1
a242 1
index 99ae26d..b80676c 100644
d245 3
a247 3
@@@@ -60,6 +60,22 @@@@ wrtmessage(void *cbopaque, const char *s)
 void	(*je_malloc_message)(void *, const char *s)
     JEMALLOC_ATTR(visibility("default")) = wrtmessage;
d249 1
a249 1
+JEMALLOC_CATTR(visibility("hidden"), static)
d266 2
a267 2
  * glibc provides a non-standard strerror_r() when _GNU_SOURCE is defined, so
  * provide a wrapper.
@


1.3
log
@SVN rev 234543 on 2012-04-21 15:09:22Z by jasone

Import jemalloc 606f1fdc3cdbc700717133ca56685313caea24bb (dev branch,
prior to 3.0.0 release), and mangle internal symbols.
@
text
@d2 1
a2 1
index f78f423..ce6df80 100644
d85 1
a85 1
index 15fe3c5..be94eb8 100644
d88 1
a88 8
@@@@ -1,6 +1,3 @@@@
-#define	a0calloc JEMALLOC_N(a0calloc)
-#define	a0free JEMALLOC_N(a0free)
-#define	a0malloc JEMALLOC_N(a0malloc)
 #define	arena_alloc_junk_small JEMALLOC_N(arena_alloc_junk_small)
 #define	arena_bin_index JEMALLOC_N(arena_bin_index)
 #define	arena_bin_info JEMALLOC_N(arena_bin_info)
@@@@ -167,7 +164,6 @@@@
d191 1
a191 1
index 00c2b23..729f4e1 100644
@


1.2
log
@SVN rev 234402 on 2012-04-17 22:05:55Z by jasone

Import jemalloc b57d3ec571c6551231be62b7bf92c084a8c8291c (dev branch,
prior to 3.0.0 release), which supports atomic operations based on atomic(9).
This should fix build failures for several platforms.
@
text
@d2 1
a2 1
index 98d0ba4..23d2152 100644
d30 1
a30 1
@@@@ -2080,4 +2091,16 @@@@ malloc_conf = "lg_chunk:24";]]></programlisting></para>
d48 1
a48 1
index 905653a..b235a0d 100644
d71 1
a71 1
index c46feee..d7133f4 100644
d74 1
a74 1
@@@@ -39,8 +39,6 @@@@ struct malloc_mutex_s {
d79 1
d84 19
d198 1
a198 1
index 0decd8a..73fad29 100644
d244 1
a244 1
index 2aab61f..8b05042 100644
@


1.1
log
@SVN rev 234370 on 2012-04-17 07:22:14Z by jasone

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.
@
text
@d48 1
a48 1
index aa21aa5..e0f5fed 100644
d51 3
a53 1
@@@@ -1,3 +1,6 @@@@
d60 1
a60 1
@@@@ -33,6 +36,9 @@@@
@

