Commit Graph

491 Commits

Author SHA1 Message Date
Jason Evans
4eeb52f080 Remove vsnprintf() and strtoumax() validation.
Remove code that validates malloc_vsnprintf() and malloc_strtoumax()
against their namesakes.  The validation code has adequately served its
usefulness at this point, and it isn't worth dealing with the different
formatting for %p with glibc versus other implementations for NULL
pointers ("(nil)" vs. "0x0").

Reported by Mike Hommey.
2012-04-02 02:30:24 -07:00
Jason Evans
f2296deb57 Clean up tsd (no functional changes). 2012-03-30 12:36:52 -07:00
Jason Evans
09a0769ba7 Work around TLS deallocation via free().
glibc uses memalign()/free() to allocate/deallocate TLS, which means
that it is unsafe to set TLS variables as a side effect of free() --
they may already be deallocated.  Work around this by avoiding
tcache_create() within free().

Reported by Mike Hommey.
2012-03-30 12:11:03 -07:00
Mike Hommey
3c2ba0dcbc Avoid crashes when system libraries use the purgeable zone allocator 2012-03-30 11:03:20 -07:00
Mike Hommey
71a93b8725 Move zone registration to zone.c 2012-03-30 10:53:00 -07:00
Mike Hommey
2cfe6d67ef Change AC_COMPILE_IFELSE into AC_LINK_IFELSE for the __sync_{add, sub}_and_fetch() test
With the Android NDK, __sync_{add,sub}_and_fetch() compile fine for uint64_t,
but the corresponding libgcc function aren't there.
2012-03-30 10:25:59 -07:00
Mike Hommey
1a0e777024 Add a SYS_write definition on systems where it is not defined in headers
Namely, in the Android NDK headers, SYS_write is not defined; but
__NR_write is.
2012-03-30 10:21:41 -07:00
Mike Hommey
e77fa59ece Don't use pthread_atfork to register prefork/postfork handlers on OSX
OSX libc calls zone allocators' force_lock/force_unlock already.
2012-03-28 16:17:21 -07:00
Jason Evans
d4be8b7b6e Add the "thread.tcache.enabled" mallctl. 2012-03-26 19:02:49 -07:00
Jason Evans
fd4fcefa00 Force the lazy-lock feature on FreeBSD.
Force the lazy-lock feature on FreeBSD in order to avoid pthread_self(),
because it causes allocation.  (This change was mistakenly omitted from
41b6afb834b1f5250223678c52bd4f013d4234f6.)
2012-03-23 17:40:58 -07:00
Jason Evans
2465bdf493 Check for NULL ptr in malloc_usable_size().
Check for NULL ptr in malloc_usable_size(), rather than just asserting
that ptr is non-NULL.  This matches behavior of other implementations
(e.g., glibc and tcmalloc).
2012-03-26 13:13:55 -07:00
Mike Hommey
5b3db098f7 Make zone_{free, realloc, free_definite_size} fallback to the system allocator if they are called with a pointer that jemalloc didn't allocate
It turns out some OSX system libraries (like CoreGraphics on 10.6) like
to call malloc_zone_* functions, but giving them pointers that weren't
allocated with the zone they are using.

Possibly, they do malloc_zone_malloc(malloc_default_zone()) before we
register the jemalloc zone, and malloc_zone_realloc(malloc_default_zone())
after. malloc_default_zone() returning a different value in both cases.
2012-03-26 12:54:25 -07:00
Mike Hommey
5c89c50d18 Fix glibc hooks when using both --with-jemalloc-prefix and --with-mangling 2012-03-26 12:43:05 -07:00
Mike Hommey
c1e567bda0 Use __sync_add_and_fetch and __sync_sub_and_fetch when they are available
These functions may be available as inlines or as libgcc functions. In the
former case, a __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macro is defined. But we
still want to use these functions in the latter case, when we don't have
our own implementation.
2012-03-26 11:51:13 -07:00
Jason Evans
1e6138c88c Remove malloc_mutex_trylock().
Remove malloc_mutex_trylock(); it has not been used for quite some time.
2012-03-24 19:36:27 -07:00
Jason Evans
41b6afb834 Port to FreeBSD.
Use FreeBSD-specific functions (_pthread_mutex_init_calloc_cb(),
_malloc_{pre,post}fork()) to avoid bootstrapping issues due to
allocation in libc and libthr.

Add malloc_strtoumax() and use it instead of strtoul().  Disable
validation code in malloc_vsnprintf() and malloc_strtoumax() until
jemalloc is initialized.  This is necessary because locale
initialization causes allocation for both vsnprintf() and strtoumax().

Force the lazy-lock feature on in order to avoid pthread_self(),
because it causes allocation.

Use syscall(SYS_write, ...) rather than write(...), because libthr wraps
write() and causes allocation.  Without this workaround, it would not be
possible to print error messages in malloc_conf_init() without
substantially reworking bootstrapping.

Fix choose_arena_hard() to look at how many threads are assigned to the
candidate choice, rather than checking whether the arena is
uninitialized.  This bug potentially caused more arenas to be
initialized than necessary.
2012-02-02 23:09:53 -08:00
Jason Evans
6da5418ded Remove ephemeral mutexes.
Remove ephemeral mutexes from the prof machinery, and remove
malloc_mutex_destroy().  This simplifies mutex management on systems
that call malloc()/free() inside pthread_mutex_{create,destroy}().

Add atomic_*_u() for operation on unsigned values.

Fix prof_printf() to call malloc_vsnprintf() rather than
malloc_snprintf().
2012-03-23 18:05:51 -07:00
Jason Evans
b80581d309 Forcibly disable TLS on OS X.
Forcibly disable TLS on OS X.  gcc and llvm-gcc on OS X do not support
TLS, but clang does.  Unfortunately, the implementation calls malloc()
internally during TLS initialization, which causes an unresolvable
bootstrapping issue.
2012-03-23 16:17:43 -07:00
Jason Evans
9022bf9bfd Remove -no-cpp-precomp compiler flag for OS X.
Remove the -no-cpp-precomp compiler flag when compiling on OS X.  clang
does not support the flag, and gcc works fine without it.
2012-03-23 16:14:08 -07:00
Jason Evans
06304a9785 Restructure atomic_*_z().
Restructure atomic_*_z() so that no casting within macros is necessary.
This avoids warnings when compiling with clang.
2012-03-23 16:09:56 -07:00
Jason Evans
9225a1991a Add JEMALLOC_CC_SILENCE_INIT().
Add JEMALLOC_CC_SILENCE_INIT(), which provides succinct syntax for
initializing a variable to avoid a spurious compiler warning.
2012-03-23 15:39:07 -07:00
Jason Evans
cd9a1346e9 Implement tsd.
Implement tsd, which is a TLS/TSD abstraction that uses one or both
internally.  Modify bootstrapping such that no tsd's are utilized until
allocation is safe.

Remove malloc_[v]tprintf(), and use malloc_snprintf() instead.

Fix %p argument size handling in malloc_vsnprintf().

Fix a long-standing statistics-related bug in the "thread.arena"
mallctl that could cause crashes due to linked list corruption.
2012-03-23 15:14:55 -07:00
Mike Hommey
154829d256 Improve zone support for OSX
I tested a build from 10.7 run on 10.7 and 10.6, and a build from 10.6
run on 10.6.  The AC_COMPILE_IFELSE limbo is to avoid running a program
during configure, which presumably makes it work when cross compiling
for iOS.
2012-03-20 11:52:50 -07:00
Mike Hommey
f4d0fc310e Unbreak mac after commit 4e2e3dd 2012-03-20 11:48:42 -07:00
Jason Evans
650285d5be Generalize dlsym() configuration.
Generalize dlsym() configuration to succeed if dlsym() is in libc rather
than libdl.
2012-03-19 10:25:27 -07:00
Jason Evans
e24c7af35d Invert NO_TLS to JEMALLOC_TLS. 2012-03-19 10:21:17 -07:00
Jason Evans
f3e139a1ef Use AC_LINK_IFELSE() rather than AC_RUN_IFELSE() in JE_COMPILABLE().
Reported by Mike Hommey.
2012-03-19 09:54:20 -07:00
Jason Evans
7091b415bb Fix various documentation formatting regressions. 2012-03-19 09:36:44 -07:00
Jason Evans
e7b8fa18d2 Rename the "tcache.flush" mallctl to "thread.tcache.flush". 2012-03-16 17:09:32 -07:00
Jason Evans
39006f9907 Look for pthreads functionality in libc.
If there is no libpthread, look for pthreads functionality in libc
before failing to configure pthreads.  This is necessary on at least the
Android platform.

Reported by Mike Hommey.
2012-03-16 16:57:02 -07:00
Jason Evans
6508bc6931 Remove #include <sys/sysctl.h>.
Remove #include <sys/sysctl.h>, which is no longer needed (now using
sysconf(3) to get number of CPUs).
2012-03-15 17:07:42 -07:00
Jason Evans
4e2e3dd9cf Fix fork-related bugs.
Acquire/release arena bin locks as part of the prefork/postfork.  This
bug made deadlock in the child between fork and exec a possibility.

Split jemalloc_postfork() into jemalloc_postfork_{parent,child}() so
that the child can reinitialize mutexes rather than unlocking them.  In
practice, this bug tended not to cause problems.
2012-03-13 16:31:41 -07:00
Jason Evans
824d34e5b7 Modify malloc_vsnprintf() validation code.
Modify malloc_vsnprintf() validation code to verify that output is
identical to vsnprintf() output, even if both outputs are truncated due
to buffer exhaustion.
2012-03-13 13:19:04 -07:00
Jason Evans
0a0bbf63e5 Implement aligned_alloc().
Implement aligned_alloc(), which was added in the C11 standard.  The
function is weakly specified to the point that a minimally compliant
implementation would be painful to use (size must be an integral
multiple of alignment!), which in practice makes posix_memalign() a
safer choice.
2012-03-13 12:55:21 -07:00
Jason Evans
4c2faa8a7c Fix a regression in JE_COMPILABLE().
Revert JE_COMPILABLE() so that it detects link errors.  Cross-compiling
should still work as long as a valid configure cache is provided.

Clean up some comments/whitespace.
2012-03-13 11:09:23 -07:00
Jason Evans
eb2398106f Fix malloc_stats_print() option support.
Fix malloc_stats_print() to honor 'b' and 'l' in the opts parameter.
2012-03-13 08:46:12 -07:00
Jason Evans
025d861186 Update config.guess and config.sub. 2012-03-12 15:57:24 -07:00
Jason Evans
08fc3b2d51 Fix --with-mangling/--with-jemalloc-prefix interaction.
Fix --with-mangling to remove mangled symbols from the set of functions
to apply a prefix to.  Prior to this change, the interaction was correct
with autoconf 2.59, but incorrect with autoconf 2.65.
2012-03-12 15:07:53 -07:00
Jason Evans
2bb6c7a632 s/PRIx64/PRIxPTR/ for uintptr_t printf() argument. 2012-03-12 13:38:55 -07:00
Jason Evans
125b93e43f Remove bashism.
Submitted by Mike Hommey.
2012-03-12 11:33:59 -07:00
Jason Evans
7cca608575 Remove extra '}'. 2012-03-12 11:31:54 -07:00
Jason Evans
d81e4bdd5c Implement malloc_vsnprintf().
Implement malloc_vsnprintf() (a subset of vsnprintf(3)) as well as
several other printing functions based on it, so that formatted printing
can be relied upon without concern for inducing a dependency on floating
point runtime support.  Replace malloc_write() calls with
malloc_*printf() where doing so simplifies the code.

Add name mangling for library-private symbols in the data and BSS
sections.  Adjust CONF_HANDLE_*() macros in malloc_conf_init() to expose
all opt_* variable use to cpp so that proper mangling occurs.
2012-03-07 16:19:19 -08:00
Jason Evans
4507f34628 Remove the lg_tcache_gc_sweep option.
Remove the lg_tcache_gc_sweep option, because it is no longer
very useful.  Prior to the addition of dynamic adjustment of tcache fill
count, it was possible for fill/flush overhead to be a problem, but this
problem no longer occurs.
2012-03-05 14:34:37 -08:00
Jason Evans
b8c8be7f8a Use UINT64_C() rather than LLU for 64-bit constants. 2012-03-05 12:26:26 -08:00
Jason Evans
3492daf1ce Add SH4 and mips architecture support.
Submitted by Andreas Vinsander.
2012-03-05 12:16:57 -08:00
Jason Evans
6684cacfa8 Tweak configure.ac to support cross-compiling.
Submitted by Andreas Vinsander.
2012-03-05 12:15:36 -08:00
Jason Evans
c71b9946ce Unify license.
Update Facebook's software license (with permission from Facebook) to
merge with that of the other copyright holders.
2012-03-04 10:46:12 -08:00
Jason Evans
1af52cfe64 Update copyright dates. 2012-03-02 17:51:26 -08:00
Jason Evans
7e77eaffff Add the --disable-experimental option. 2012-03-02 17:47:37 -08:00
Jason Evans
7b398aca3b Add fine-grained build/install targets. 2012-03-02 16:38:37 -08:00