Bug 1365194 - Compile mozjemalloc as C++. r=njn

The source file is renamed too, because the build system doesn't handle
sources changing suffix very well (at least not without a clobber).

The _GNU_SOURCE define is removed because GCC/Clang set it by default in
C++ mode.

--HG--
rename : memory/mozjemalloc/jemalloc.c => memory/mozjemalloc/mozjemalloc.cpp
extra : rebase_source : f57dbb0a66b25e70fe8c724e9250cc0d8b14f1c1
This commit is contained in:
Mike Hommey 2017-05-12 21:52:25 +09:00
parent 12cfad23f4
commit 14503d2c39
2 changed files with 37 additions and 43 deletions

View File

@ -9,7 +9,7 @@ EXPORTS += [
]
SOURCES += [
'jemalloc.c',
'mozjemalloc.cpp',
]
FINAL_LIBRARY = 'memory'
@ -29,8 +29,10 @@ LOCAL_INCLUDES += [
'/memory/build',
]
if CONFIG['GNU_CC']:
CFLAGS += ['-Wno-unused'] # too many annoying warnings from mfbt/ headers
if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wno-unused'] # too many annoying warnings from mfbt/ headers
if CONFIG['_MSC_VER']:
CFLAGS += ['-wd4273'] # inconsistent dll linkage (bug 558163)
CXXFLAGS += ['-wd4273'] # inconsistent dll linkage (bug 558163)
DISABLE_STL_WRAPPING = True

View File

@ -100,6 +100,9 @@
*******************************************************************************
*/
#include "mozmemory_wrap.h"
#include "mozilla/Sprintf.h"
#ifdef MOZ_MEMORY_ANDROID
#define NO_TLS
#endif
@ -164,10 +167,6 @@
# define MALLOC_SYSV
#endif
#if defined(MOZ_MEMORY_LINUX) && !defined(MOZ_MEMORY_ANDROID)
#define _GNU_SOURCE /* For mremap(2). */
#endif
#include <sys/types.h>
#include <errno.h>
@ -185,17 +184,13 @@
#include <io.h>
#include <windows.h>
#include <intrin.h>
#include <algorithm>
#pragma warning( disable: 4267 4996 4146 )
#define bool BOOL
#define false FALSE
#define true TRUE
#define inline __inline
#define SIZE_T_MAX SIZE_MAX
#define STDERR_FILENO 2
#define PATH_MAX MAX_PATH
#define vsnprintf _vsnprintf
#ifndef NO_TLS
static unsigned long tlsIndex = 0xffffffff;
@ -306,9 +301,8 @@ typedef long ssize_t;
#include "jemalloc_types.h"
#include "linkedlist.h"
#include "mozmemory_wrap.h"
extern void moz_abort();
extern "C" void moz_abort();
/* Some tools, such as /dev/dsp wrappers, LD_PRELOAD libraries that
* happen to override mmap() and call dlsym() from their overridden
@ -1175,23 +1169,21 @@ static void *huge_palloc(size_t size, size_t alignment, bool zero);
static void *huge_ralloc(void *ptr, size_t size, size_t oldsize);
static void huge_dalloc(void *ptr);
static void malloc_print_stats(void);
#ifndef MOZ_MEMORY_WINDOWS
#ifdef MOZ_MEMORY_WINDOWS
extern "C"
#else
static
#endif
bool malloc_init_hard(void);
#ifndef MOZ_MEMORY_DARWIN
static
#ifdef MOZ_MEMORY_DARWIN
#define FORK_HOOK extern "C"
#else
#define FORK_HOOK static
#endif
void _malloc_prefork(void);
#ifndef MOZ_MEMORY_DARWIN
static
#endif
void _malloc_postfork_parent(void);
#ifndef MOZ_MEMORY_DARWIN
static
#endif
void _malloc_postfork_child(void);
FORK_HOOK void _malloc_prefork(void);
FORK_HOOK void _malloc_postfork_parent(void);
FORK_HOOK void _malloc_postfork_child(void);
/*
* End function prototypes.
@ -1290,7 +1282,7 @@ void (*_malloc_message)(const char *p1, const char *p2, const char *p3,
#ifdef MOZ_MEMORY_ANDROID
// Android's pthread.h does not declare pthread_atfork() until SDK 21.
extern MOZ_EXPORT
extern "C" MOZ_EXPORT
int pthread_atfork(void (*)(void), void (*)(void), void(*)(void));
#endif
@ -1498,7 +1490,7 @@ malloc_printf(const char *format, ...)
va_list ap;
va_start(ap, format);
vsnprintf(buf, sizeof(buf), format, ap);
VsprintfLiteral(buf, format, ap);
va_end(ap);
_malloc_message(buf, "", "", "");
}
@ -1516,14 +1508,14 @@ pages_decommit(void *addr, size_t size)
* go may not be valid. However, since we allocate at least a chunk at a
* time, we may touch any region in chunksized increments.
*/
size_t pages_size = min(size, chunksize -
size_t pages_size = std::min(size, chunksize -
CHUNK_ADDR2OFFSET((uintptr_t)addr));
while (size > 0) {
if (!VirtualFree(addr, pages_size, MEM_DECOMMIT))
moz_abort();
addr = (void *)((uintptr_t)addr + pages_size);
size -= pages_size;
pages_size = min(size, chunksize);
pages_size = std::min(size, chunksize);
}
#else
if (mmap(addr, size, PROT_NONE, MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1,
@ -1544,14 +1536,14 @@ pages_commit(void *addr, size_t size)
* go may not be valid. However, since we allocate at least a chunk at a
* time, we may touch any region in chunksized increments.
*/
size_t pages_size = min(size, chunksize -
size_t pages_size = std::min(size, chunksize -
CHUNK_ADDR2OFFSET((uintptr_t)addr));
while (size > 0) {
if (!VirtualAlloc(addr, pages_size, MEM_COMMIT, PAGE_READWRITE))
moz_abort();
addr = (void *)((uintptr_t)addr + pages_size);
size -= pages_size;
pages_size = min(size, chunksize);
pages_size = std::min(size, chunksize);
}
# else
if (mmap(addr, size, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE |
@ -2266,13 +2258,13 @@ pages_purge(void *addr, size_t length)
* go may not be valid. However, since we allocate at least a chunk at a
* time, we may touch any region in chunksized increments.
*/
size_t pages_size = min(length, chunksize -
size_t pages_size = std::min(length, chunksize -
CHUNK_ADDR2OFFSET((uintptr_t)addr));
while (length > 0) {
VirtualAlloc(addr, pages_size, MEM_RESET, PAGE_READWRITE);
addr = (void *)((uintptr_t)addr + pages_size);
length -= pages_size;
pages_size = min(length, chunksize);
pages_size = std::min(length, chunksize);
}
unzeroed = true;
# else
@ -4700,7 +4692,7 @@ malloc_init(void)
#endif
#if defined(MOZ_MEMORY_DARWIN)
extern void register_zone(void);
extern "C" void register_zone(void);
#endif
#if !defined(MOZ_MEMORY_WINDOWS)
@ -5164,11 +5156,9 @@ RETURN:
#ifdef MOZ_MEMORY_ELF
#define MEMALIGN memalign_internal
extern "C"
#else
#define MEMALIGN memalign_impl
#endif
#ifndef MOZ_MEMORY_ELF
MOZ_MEMORY_API
#endif
void *
@ -5846,10 +5836,12 @@ jemalloc_darwin_init(void)
* passed an extra argument for the caller return address, which will be
* ignored.
*/
MOZ_MEMORY_API void (*__free_hook)(void *ptr) = free_impl;
MOZ_MEMORY_API void *(*__malloc_hook)(size_t size) = malloc_impl;
MOZ_MEMORY_API void *(*__realloc_hook)(void *ptr, size_t size) = realloc_impl;
MOZ_MEMORY_API void *(*__memalign_hook)(size_t alignment, size_t size) = MEMALIGN;
extern "C" {
MOZ_EXPORT void (*__free_hook)(void *ptr) = free_impl;
MOZ_EXPORT void *(*__malloc_hook)(size_t size) = malloc_impl;
MOZ_EXPORT void *(*__realloc_hook)(void *ptr, size_t size) = realloc_impl;
MOZ_EXPORT void *(*__memalign_hook)(size_t alignment, size_t size) = MEMALIGN;
}
# elif defined(RTLD_DEEPBIND)
/*