Skip to content

Commit

Permalink
Bug 1275204 - mozjemalloc: Use the JS arm64 allocator on Linux/sparc6…
Browse files Browse the repository at this point in the history
…4. r=glandium
  • Loading branch information
glaubitz authored and glandium committed Jan 11, 2017
1 parent dbf939f commit 4b76f57
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions memory/mozjemalloc/jemalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2419,7 +2419,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
Expand All @@ -2440,18 +2440,40 @@ 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.
*/
ret = mmap(addr, size, PROT_READ | PROT_WRITE,
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.
Expand Down Expand Up @@ -2484,7 +2506,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
Expand Down

0 comments on commit 4b76f57

Please sign in to comment.