summaryrefslogtreecommitdiffstats
path: root/memory/mozjemalloc/jemalloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'memory/mozjemalloc/jemalloc.c')
-rw-r--r--memory/mozjemalloc/jemalloc.c48
1 files changed, 30 insertions, 18 deletions
diff --git a/memory/mozjemalloc/jemalloc.c b/memory/mozjemalloc/jemalloc.c
index ecc9d2985..47a5a9f5c 100644
--- a/memory/mozjemalloc/jemalloc.c
+++ b/memory/mozjemalloc/jemalloc.c
@@ -100,11 +100,6 @@
*******************************************************************************
*/
-#ifdef MOZ_MEMORY_ANDROID
-#define NO_TLS
-#define _pthread_self() pthread_self()
-#endif
-
/*
* On Linux, we use madvise(MADV_DONTNEED) to release memory back to the
* operating system. If we release 1MB of live pages with MADV_DONTNEED, our
@@ -174,7 +169,7 @@
# define MALLOC_SYSV
#endif
-#if defined(MOZ_MEMORY_LINUX) && !defined(MOZ_MEMORY_ANDROID)
+#ifdef MOZ_MEMORY_LINUX
#define _GNU_SOURCE /* For mremap(2). */
#endif
@@ -498,7 +493,7 @@ static bool malloc_initialized = false;
/* No init lock for Windows. */
#elif defined(MOZ_MEMORY_DARWIN)
static malloc_mutex_t init_lock = {OS_SPINLOCK_INIT};
-#elif defined(MOZ_MEMORY_LINUX) && !defined(MOZ_MEMORY_ANDROID)
+#elif defined(MOZ_MEMORY_LINUX)
static malloc_mutex_t init_lock = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP;
#else
static malloc_mutex_t init_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -1374,12 +1369,6 @@ void (*_malloc_message)(const char *p1, const char *p2, const char *p3,
# define assert(e)
#endif
-#ifdef MOZ_MEMORY_ANDROID
-// Android's pthread.h does not declare pthread_atfork() until SDK 21.
-extern MOZ_EXPORT
-int pthread_atfork(void (*)(void), void (*)(void), void(*)(void));
-#endif
-
#if defined(MOZ_JEMALLOC_HARD_ASSERTS)
# define RELEASE_ASSERT(assertion) do { \
if (!(assertion)) { \
@@ -1404,7 +1393,7 @@ malloc_mutex_init(malloc_mutex_t *mutex)
InitializeSRWLock(mutex);
#elif defined(MOZ_MEMORY_DARWIN)
mutex->lock = OS_SPINLOCK_INIT;
-#elif defined(MOZ_MEMORY_LINUX) && !defined(MOZ_MEMORY_ANDROID)
+#elif defined(MOZ_MEMORY_LINUX)
pthread_mutexattr_t attr;
if (pthread_mutexattr_init(&attr) != 0)
return (true);
@@ -1457,7 +1446,7 @@ malloc_spin_init(malloc_spinlock_t *lock)
InitializeSRWLock(lock);
#elif defined(MOZ_MEMORY_DARWIN)
lock->lock = OS_SPINLOCK_INIT;
-#elif defined(MOZ_MEMORY_LINUX) && !defined(MOZ_MEMORY_ANDROID)
+#elif defined(MOZ_MEMORY_LINUX)
pthread_mutexattr_t attr;
if (pthread_mutexattr_init(&attr) != 0)
return (true);
@@ -1977,7 +1966,7 @@ static void *
pages_map(void *addr, size_t size)
{
void *ret;
-#if defined(__ia64__)
+#if defined(__ia64__) || (defined(__sparc__) && defined(__arch64__) && defined(__linux__))
/*
* The JS engine assumes that all allocated pointers have their high 17 bits clear,
* which ia64's mmap doesn't support directly. However, we can emulate it by passing
@@ -1998,6 +1987,28 @@ pages_map(void *addr, size_t size)
}
#endif
+#if defined(__sparc__) && defined(__arch64__) && defined(__linux__)
+ const uintptr_t start = 0x0000070000000000ULL;
+ const uintptr_t end = 0x0000800000000000ULL;
+
+ /* Copied from js/src/gc/Memory.cpp and adapted for this source */
+
+ uintptr_t hint;
+ void* region = MAP_FAILED;
+ for (hint = start; region == MAP_FAILED && hint + size <= end; hint += chunksize) {
+ region = mmap((void*)hint, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
+ if (region != MAP_FAILED) {
+ if (((size_t) region + (size - 1)) & 0xffff800000000000) {
+ if (munmap(region, size)) {
+ MOZ_ASSERT(errno == ENOMEM);
+ }
+ region = MAP_FAILED;
+ }
+ }
+ }
+ ret = region;
+#else
+
/*
* We don't use MAP_FIXED here, because it can cause the *replacement*
* of existing mappings, and we only want to create new mappings.
@@ -2006,10 +2017,11 @@ pages_map(void *addr, size_t size)
MAP_PRIVATE | MAP_ANON, -1, 0);
assert(ret != NULL);
+#endif
if (ret == MAP_FAILED) {
ret = NULL;
}
-#if defined(__ia64__)
+#if defined(__ia64__) || (defined(__sparc__) && defined(__arch64__) && defined(__linux__))
/*
* If the allocated memory doesn't have its upper 17 bits clear, consider it
* as out of memory.
@@ -2042,7 +2054,7 @@ pages_map(void *addr, size_t size)
MozTagAnonymousMemory(ret, size, "jemalloc");
}
-#if defined(__ia64__)
+#if defined(__ia64__) || (defined(__sparc__) && defined(__arch64__) && defined(__linux__))
assert(ret == NULL || (!check_placement && ret != NULL)
|| (check_placement && ret == addr));
#else