b=488608; enable jemalloc on CE6; r+sr=stuart
authorVladimir Vukicevic <vladimir@pobox.com>
Fri, 24 Apr 2009 10:31:18 -0700
changeset 27812 e6675b1c79a8e166dd89b4f5cdf8de0c1bdd87db
parent 27811 e44b672c7e4d801c8c9824a48095da39de934edc
child 27813 4be56d2fd8c9e1015c70d4c7572ce6105b3879fb
push id6725
push uservladimir@mozilla.com
push dateFri, 24 Apr 2009 19:56:46 +0000
treeherdermozilla-central@4be56d2fd8c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs488608
milestone1.9.2a1pre
b=488608; enable jemalloc on CE6; r+sr=stuart
build/wince/shunt/Makefile.in
build/wince/shunt/include/mozce_shunt.h
build/wince/shunt/include/stdlib.h.in
build/wince/shunt/memory.cpp
build/wince/shunt/mozce_shunt.def
config/config.mk
configure.in
js/src/Makefile.in
js/src/shell/Makefile.in
memory/jemalloc/Makefile.in
memory/jemalloc/jemalloc.c
memory/jemalloc/jemalloc.h
--- a/build/wince/shunt/Makefile.in
+++ b/build/wince/shunt/Makefile.in
@@ -67,22 +67,31 @@ EXPORTS = include/windows.h \
   $(NULL)
 
 DIRS += include/sys
 
 ifdef MOZ_MEMORY
 REQUIRES = jemalloc 
 CFLAGS += -DMOZ_MEMORY
 CXXFLAGS += -DMOZ_MEMORY
+EXPORTS += $(topsrcdir)/memory/jemalloc/jemalloc.h
 endif
 
-EXTRA_LIBS += $(JEMALLOC_LIBS)
+DEFFILE = mozce_shunt.def
+
+# We have to include the obj file directly, because we want to export
+# some of its symbols through our def file
+EXTRA_LIBS += $(OBJDIR)/memory/jemalloc/jemalloc.obj
 
 CPPSRCS = \
 	shunt.cpp \
 	environment.cpp \
 	time.cpp \
 	memory.cpp \
 	$(NULL)
 
 DEFINES += -DMOZCE_SHUNT_EXPORTS
 
 include $(topsrcdir)/config/rules.mk
+
+mozce_shunt.def: mozce_shunt.def.in
+	$(PYTHON) $(topsrcdir)/config/Preprocessor.py $(DEFINES) $(ACDEFINES) $^ > $@
+
--- a/build/wince/shunt/include/mozce_shunt.h
+++ b/build/wince/shunt/include/mozce_shunt.h
@@ -30,83 +30,68 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-
 #ifndef MOZCE_SHUNT_H
 #define MOZCE_SHUNT_H
 
-#ifdef MOZCE_SHUNT_EXPORTS
-#define _CRTIMP __declspec(dllexport)
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _WCHAR_T_DEFINED
+typedef unsigned short wchar_t;
+#define _WCHAR_T_DEFINED
+#endif
+
+#ifdef __cplusplus
+}   //extern "C" 
 #endif
 
 #ifdef MOZ_MEMORY
+
 #ifdef __cplusplus
-
-
 #define _NEW_
 void * operator new(size_t _Size);
 void operator delete(void * ptr);
 void *operator new[](size_t size);
 void operator delete[](void *ptr);
 
 extern "C" {
 #endif
 
-extern void* moz_malloc(size_t);
-extern void* moz_valloc(size_t);
-extern void* moz_calloc(size_t, size_t);
-extern void* moz_realloc(void*, unsigned int);
-extern void moz_free(void*);
-  
-void* __cdecl  malloc(size_t);
-void* __cdecl  valloc(size_t);
-void* __cdecl  calloc(size_t, size_t);
-void* __cdecl  realloc(void*, unsigned int);
-void __cdecl  free(void*);
-
- 
-char*
-mozce_strdup(const char*);
-
-MOZCE_SHUNT_API unsigned short* 
-mozce_wcsdup(const unsigned short* );
-
-MOZCE_SHUNT_API char*
-mozce_strndup(const char *, unsigned int);
-
-MOZCE_SHUNT_API unsigned short* 
-mozce_wcsndup(const unsigned short*, unsigned int);
-  
-#ifdef __cplusplus
-}   //extern "C" 
-#endif
-
-
 #undef _strdup
 #undef strdup
 #undef _strndup
 #undef strndup
 #undef _wcsdup
 #undef wcsdup
 #undef _wcsndup
 #undef wcsndup
 
+char * __cdecl
+_strdup(const char*);
 
+wchar_t * __cdecl
+_wcsdup(const wchar_t *);
 
-#define _strdup mozce_strdup
-#define _strndup mozce_strndup
+char * __cdecl
+_strndup(const char *, unsigned int);
 
-#define _wcsdup mozce_wcsdup
-#define _wcsndup mozce_wcsndup
+wchar_t * __cdecl
+_wcsndup(const wchar_t *, unsigned int);
+  
+#ifdef __cplusplus
+}   //extern "C" 
+#endif
 
 #endif
 
 #define strdup  _strdup
 #define strndup _strndup
 #define wcsdup _wcsdup
 #define wcsndup _wcsndup
 
@@ -120,61 +105,61 @@ mozce_wcsndup(const unsigned short*, uns
 #define SHGetPathFromIDListW    SHGetPathFromIDList
 #define FONTENUMPROCW           FONTENUMPROC
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 /* errno and family */
-extern MOZCE_SHUNT_IMPORT_API int errno;
-MOZCE_SHUNT_IMPORT_API char* strerror(int);
+extern int errno;
+char* strerror(int);
 
 /* abort */
-MOZCE_SHUNT_API void abort(void);
+void abort(void);
   
 /* Environment stuff */
-MOZCE_SHUNT_API char* getenv(const char* inName);
-MOZCE_SHUNT_API int putenv(const char *a);
-MOZCE_SHUNT_API char SetEnvironmentVariableW(const unsigned short * name, const unsigned short * value );
-MOZCE_SHUNT_API char GetEnvironmentVariableW(const unsigned short * lpName, unsigned short* lpBuffer, unsigned long nSize);
+char* getenv(const char* inName);
+int putenv(const char *a);
+char SetEnvironmentVariableW(const unsigned short * name, const unsigned short * value );
+char GetEnvironmentVariableW(const unsigned short * lpName, unsigned short* lpBuffer, unsigned long nSize);
   
-MOZCE_SHUNT_API unsigned int ExpandEnvironmentStringsW(const unsigned short* lpSrc,
-                                                       unsigned short* lpDst,
-                                                       unsigned int nSize);
+unsigned int ExpandEnvironmentStringsW(const unsigned short* lpSrc,
+				       unsigned short* lpDst,
+				       unsigned int nSize);
 
 /* File system stuff */
-MOZCE_SHUNT_API unsigned short * _wgetcwd(unsigned short* dir, unsigned long size);
-MOZCE_SHUNT_API unsigned short *_wfullpath( unsigned short *absPath, const unsigned short *relPath, unsigned long maxLength );
-MOZCE_SHUNT_API int _unlink(const char *filename );
+unsigned short * _wgetcwd(unsigned short* dir, unsigned long size);
+unsigned short *_wfullpath( unsigned short *absPath, const unsigned short *relPath, unsigned long maxLength );
+int _unlink(const char *filename );
   
 /* The time stuff should be defined here, but it can't be because it
    is already defined in time.h.
   
- MOZCE_SHUNT_API size_t strftime(char *, size_t, const char *, const struct tm *)
- MOZCE_SHUNT_API struct tm* localtime(const time_t* inTimeT)
- MOZCE_SHUNT_API struct tm* mozce_gmtime_r(const time_t* inTimeT, struct tm* outRetval)
- MOZCE_SHUNT_API struct tm* gmtime(const time_t* inTimeT)
- MOZCE_SHUNT_API time_t mktime(struct tm* inTM)
- MOZCE_SHUNT_API time_t time(time_t *)
- MOZCE_SHUNT_API clock_t clock() 
+ size_t strftime(char *, size_t, const char *, const struct tm *)
+ struct tm* localtime(const time_t* inTimeT)
+ struct tm* mozce_gmtime_r(const time_t* inTimeT, struct tm* outRetval)
+ struct tm* gmtime(const time_t* inTimeT)
+ time_t mktime(struct tm* inTM)
+ time_t time(time_t *)
+ clock_t clock() 
   
 */
   
 /* Locale Stuff */
   
 /* The locale stuff should be defined here, but it can't be because it
    is already defined in locale.h.
   
- MOZCE_SHUNT_API struct lconv * localeconv(void)
+ struct lconv * localeconv(void)
   
 */
 
 
-MOZCE_SHUNT_API unsigned short* mozce_GetEnvironmentCL();
+unsigned short* mozce_GetEnvironmentCL();
 
   /* square root of 1/2, missing from math.h */ 
 #define M_SQRT1_2  0.707106781186547524401
 
 #ifdef __cplusplus
 };
 #endif
 
--- a/build/wince/shunt/include/stdlib.h.in
+++ b/build/wince/shunt/include/stdlib.h.in
@@ -43,34 +43,46 @@
 #undef _strdup
 #undef wcsdup
 #undef _wcsdup
 #undef strndup
 #undef _strndup
 #undef wcsndup
 #undef _wcsndup
 
+#define free orig_free
+#define malloc orig_malloc
+#define calloc orig_calloc
+#define realloc orig_realloc
+#define _wcsdup orig_wcsdup
+#define _strdup orig_strup
+
 #endif
 
 #include "@WINCE_SDK_DIR@/Include/Armv4i/stdlib.h"
 
 #ifdef MOZ_MEMORY
+
+#undef free
+#undef malloc
+#undef calloc
+#undef realloc
+
 #undef strdup
 #undef _strdup
 #undef wcsdup
 #undef _wcsdup
 #undef strndup
 #undef _strndup
 #undef wcsndup
 #undef _wcsndup
 
-#define _strdup mozce_strdup
 #define strdup _strdup
-#define _strndup mozce_strndup
 #define strndup _strndup
-#define _wcsdup mozce_wcsdup
 #define wcsdup _wcsdup
-#define _wcsndup mozce_wcsndup
 #define wcsndup _wcsndup
 
+/* now include jemalloc.h to get the real malloc, free, etc. */
+#include "jemalloc.h"
+
 #endif
 
 #endif
--- a/build/wince/shunt/memory.cpp
+++ b/build/wince/shunt/memory.cpp
@@ -37,71 +37,56 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include "include/mozce_shunt.h"
 #include <stdlib.h>
 
 #ifdef MOZ_MEMORY
 void * operator new(size_t _Size)
 {
-   void *p =  moz_malloc(_Size);
-   return (p);
+  void *p = malloc(_Size);
+  return (p);
 }
 
 void operator delete(void * ptr)
 {
-  moz_free(ptr);  
+  free(ptr);  
 }
 void *operator new[](size_t size)
 {
-  void* p = moz_malloc(size);
+  void* p = malloc(size);
   return (p);
 }
 void operator delete[](void *ptr)
 {
-  moz_free(ptr);
+  free(ptr);
 }
 
 char*
-mozce_strndup( const char *src, size_t len ) {
-  char* dst = (char*)moz_malloc(len + 1);
+_strndup(const char *src, size_t len) {
+  char* dst = (char*)malloc(len + 1);
   if(dst)
     strncpy(dst, src, len + 1);
   return dst;
 }
 
 
 char*
-mozce_strdup(const char *src ) {
+_strdup(const char *src) {
   size_t len = strlen(src);
-  return mozce_strndup(src, len );
+  return _strndup(src, len );
 }
 
-unsigned short* 
-mozce_wcsndup( const unsigned short *src, size_t len ) {
-  wchar_t* dst = (wchar_t*)moz_malloc(sizeof(wchar_t) * (len + 1));
+wchar_t * 
+_wcsndup(const wchar_t *src, size_t len) {
+  wchar_t* dst = (wchar_t*)malloc(sizeof(wchar_t) * (len + 1));
   if(dst)
     wcsncpy(dst, src, len + 1);
   return dst;
 }
 
-unsigned short* 
-mozce_wcsdup( const unsigned short *src ) {
+wchar_t * 
+_wcsdup(const wchar_t *src) {
   size_t len = wcslen(src);
-  return mozce_wcsndup(src, len);
-}
-void* __cdecl malloc(size_t size) {
-  return moz_malloc(size);
-}
-void* __cdecl valloc(size_t size) {
-  return moz_valloc(size);
-}
-void* __cdecl calloc(size_t size, size_t num) {
-  return moz_calloc(size, num);
-}
-void* __cdecl realloc(void* ptr, size_t size) {
-  return moz_realloc(ptr, size);
-}
-void __cdecl free(void* ptr) {
-  return moz_free(ptr);
+  return _wcsndup(src, len);
 }
 #endif
 
deleted file mode 100644
--- a/build/wince/shunt/mozce_shunt.def
+++ /dev/null
@@ -1,21 +0,0 @@
-LIBRARY mozce_shunt.dll
-EXPORTS
-ExpandEnvironmentStringsW
-GetEnvironmentVariableW
-SetEnvironmentVariableW
-_unlink
-_wfullpath
-_wgetcwd
-abort
-clock
-errno
-gmtime
-localeconv
-localtime
-mktime
-mozce_GetEnvironmentCL
-putenv
-getenv
-strerror
-strftime
-time
--- a/config/config.mk
+++ b/config/config.mk
@@ -153,17 +153,17 @@ OS_CONFIG	:= $(OS_ARCH)$(OS_RELEASE)
 FINAL_LINK_LIBS = $(DEPTH)/config/final-link-libs
 FINAL_LINK_COMPS = $(DEPTH)/config/final-link-comps
 FINAL_LINK_COMP_NAMES = $(DEPTH)/config/final-link-comp-names
 
 MOZ_UNICHARUTIL_LIBS = $(LIBXUL_DIST)/lib/$(LIB_PREFIX)unicharutil_s.$(LIB_SUFFIX)
 MOZ_WIDGET_SUPPORT_LIBS    = $(DIST)/lib/$(LIB_PREFIX)widgetsupport_s.$(LIB_SUFFIX)
 
 ifdef MOZ_MEMORY
-ifneq ($(OS_ARCH),WINNT)
+ifneq (,$(filter-out WINNT WINCE,$(OS_ARCH)))
 JEMALLOC_LIBS = $(MKSHLIB_FORCE_ALL) $(call EXPAND_LIBNAME_PATH,jemalloc,$(DIST)/lib) $(MKSHLIB_UNFORCE_ALL)
 endif
 endif
 
 # determine debug-related options
 _DEBUG_CFLAGS :=
 _DEBUG_LDFLAGS :=
 
--- a/configure.in
+++ b/configure.in
@@ -263,17 +263,17 @@ case "$target" in
     echo Building Windows CE Shunt Library and Tool Chain
     echo Using SDK in:
     echo $WINCE_SDK_DIR
 
     ac_exeext=.exe
 
     _pwdw=`pwd -W`
     _pwd=`pwd`
-    make WINCE_SDK_DIR="$WINCE_SDK_DIR" TOPSRCDIR="$srcdir" OBJDIR="$_pwdw" -C $srcdir/build/wince/tools
+    make WINCE_SDK_DIR="$WINCE_SDK_DIR" TOPSRCDIR="$_pwd/$srcdir" OBJDIR="$_pwdw" -C $srcdir/build/wince/tools
 
     CC="$_pwd/dist/sdk/bin/arm-wince-gcc"
     CXX="$_pwd/dist/sdk/bin/arm-wince-gcc"
     CPP="$_pwd/dist/sdk/bin/arm-wince-gcc -E -nologo"
     CXXCPP="$_pwd/dist/sdk/bin/arm-wince-gcc -TP -E -nologo"
     LD="$_pwd/dist/sdk/bin/arm-wince-link"
     AR="$_pwd/dist/sdk/bin/arm-wince-lib"
     AS="$_pwd/dist/sdk/bin/arm-wince-as"
@@ -6632,16 +6632,19 @@ if test "$MOZ_MEMORY"; then
     MOZ_MEMORY_LDFLAGS="-MANIFEST:NO -LIBPATH:\"$WIN32_CUSTOM_CRT_DIR\" -NODEFAULTLIB:msvcrt -NODEFAULTLIB:msvcrtd -DEFAULTLIB:mozcrt19"
     dnl Also pass this to NSPR/NSS
     DLLFLAGS="$DLLFLAGS $MOZ_MEMORY_LDFLAGS"
     export DLLFLAGS
     ;;
   *wince)
     AC_DEFINE(MOZ_MEMORY_WINCE)
     AC_DEFINE(MOZ_MEMORY_WINDOWS)
+    if test "$WINCE_WINDOWS_MOBILE"; then
+      AC_DEFINE(MOZ_MEMORY_WINCE6)
+    fi
     ;;
   *)
     AC_MSG_ERROR([--enable-jemalloc not supported on ${target}])
     ;;
   esac
 fi
 AC_SUBST(MOZ_MEMORY)
 AC_SUBST(MOZ_MEMORY_LDFLAGS)
--- a/js/src/Makefile.in
+++ b/js/src/Makefile.in
@@ -58,20 +58,16 @@ DIRS += shell
 
 MODULE		    = js
 LIBRARY_NAME	    = mozjs
 STATIC_LIBRARY_NAME = js_static
 GRE_MODULE	    = 1
 
 LIBS		= $(NSPR_LIBS) 
 
-ifdef WINCE
-EXTRA_LIBS += $(JEMALLOC_LIBS)
-endif
-
 ifdef GNU_CXX
 ifdef INTEL_CXX
 # icc gets special optimize flags
 ifdef MOZ_PROFILE_GENERATE
 MODULE_OPTIMIZE_FLAGS = -O0
 else
 MODULE_OPTIMIZE_FLAGS = -O2 -ip
 #XXX: do we want different INTERP_OPTIMIZER flags here?
--- a/js/src/shell/Makefile.in
+++ b/js/src/shell/Makefile.in
@@ -51,17 +51,16 @@ DEFINES         += -DEXPORT_JS_API
 
 LIBS      = $(NSPR_LIBS) $(EDITLINE_LIBS) $(DEPTH)/$(LIB_PREFIX)js_static.$(LIB_SUFFIX)
 
 LOCAL_INCLUDES += -I$(topsrcdir) -I..
 
 ifdef _MSC_VER
 ifdef WINCE
 WIN32_EXE_LDFLAGS += -ENTRY:mainACRTStartup
-EXTRA_LIBS += $(JEMALLOC_LIBS)
 endif
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef MOZ_SHARK
 CFLAGS += -F/System/Library/PrivateFrameworks
 CXXFLAGS += -F/System/Library/PrivateFrameworks
--- a/memory/jemalloc/Makefile.in
+++ b/memory/jemalloc/Makefile.in
@@ -44,20 +44,16 @@ VPATH		= @srcdir@
 include $(DEPTH)/config/autoconf.mk
 
 MODULE		= jemalloc
 
 # jemalloc.c properly uses 'static', so don't burden it with manually exposing
 # symbols.
 VISIBILITY_FLAGS=
 
-ifeq (WINCE,$(OS_TARGET))
-DEFINES+= -DMOZCE_SHUNT_H
-endif
-
 ifeq (WINNT,$(OS_TARGET))
 # Building the CRT from source
 CRT_OBJ_DIR = $(CURDIR)/crtsrc
 MOZ_CRT_DLL_NAME = mozcrt19
 MOZ_CRT_STATIC_LIBS = libcmt libcpmt
 MOZ_CRT_DLL = $(CRT_OBJ_DIR)/build/intel/$(MOZ_CRT_DLL_NAME).dll
 MOZ_CRT_IMPORT_LIB = $(CRT_OBJ_DIR)/build/intel/$(MOZ_CRT_DLL_NAME).lib
 
@@ -114,19 +110,18 @@ LIBRARY_NAME	= jemalloc
 # init function is used on that platform.
 ifeq ($(OS_ARCH),Darwin)
 FORCE_SHARED_LIB= 1
 else
 DIST_INSTALL = 1
 FORCE_STATIC_LIB= 1
 endif
 
-CSRCS		= \
-		jemalloc.c \
-		$(NULL)
+EXPORTS = jemalloc.h
+CSRCS   = jemalloc.c
 
 #XXX: PGO on Linux causes problems here
 # See bug 419470
 NO_PROFILE_GUIDED_OPTIMIZE = 1
 endif
 
 include $(topsrcdir)/config/rules.mk
 
--- a/memory/jemalloc/jemalloc.c
+++ b/memory/jemalloc/jemalloc.c
@@ -202,16 +202,17 @@
 #include <string.h>
 
 #ifdef MOZ_MEMORY_WINDOWS
 #ifndef MOZ_MEMORY_WINCE
 #include <cruntime.h>
 #include <internal.h>
 #include <io.h>
 #else
+#include <cmnintrin.h>
 #include <crtdefs.h>
 #define SIZE_MAX UINT_MAX
 #endif
 #include <windows.h>
 
 #pragma warning( disable: 4267 4996 4146 )
 
 #define	false FALSE
@@ -257,48 +258,27 @@ getenv(const char *name)
 {
 
 	if (GetEnvironmentVariableA(name, (LPSTR)&mozillaMallocOptionsBuf,
 		    sizeof(mozillaMallocOptionsBuf)) > 0)
 		return (mozillaMallocOptionsBuf);
 
 	return (NULL);
 }
-#else
-
-static void abort() { 
-	DebugBreak();  
-        exit(-3); 
-}
-
-static int errno = 0;
+
+#else /* WIN CE */
+
 #define ENOMEM          12
 #define EINVAL          22
 
-static char *
-getenv(const char *name)
-{
-	return (NULL);
-}
-
-static int
+static __forceinline int
 ffs(int x)
 {
-        int ret;
-
-        if (x == 0)
-                return 0;
-        ret = 2;
-        if ((x & 0x0000ffff) == 0) { ret += 16; x >>= 16;}
-        if ((x & 0x000000ff) == 0) { ret += 8;  x >>= 8;}
-        if ((x & 0x0000000f) == 0) { ret += 4;  x >>= 4;}
-        if ((x & 0x00000003) == 0) { ret += 2;  x >>= 2;}
-        ret -= (x & 1);
-
-        return (ret);
+
+	return 32 - _CountLeadingZeros((-x) & x);
 }
 #endif
 
 typedef unsigned char uint8_t;
 typedef unsigned uint32_t;
 typedef unsigned long long uint64_t;
 typedef unsigned long long uintmax_t;
 typedef long ssize_t;
@@ -383,26 +363,29 @@ typedef long ssize_t;
 #ifndef MOZ_MEMORY
 #include "un-namespace.h"
 #endif
 
 #endif
 
 #include "jemalloc.h"
 
+#undef bool
+#define bool jemalloc_bool
+
 #ifdef MOZ_MEMORY_DARWIN
 static const bool __isthreaded = true;
 #endif
 
 #if defined(MOZ_MEMORY_SOLARIS) && defined(MAP_ALIGN) && !defined(JEMALLOC_NEVER_USES_MAP_ALIGN)
 #define JEMALLOC_USES_MAP_ALIGN	 /* Required on Solaris 10. Might improve performance elsewhere. */
 #endif
 
-#if defined(MOZ_MEMORY_WINCE)
-#define JEMALLOC_USES_MAP_ALIGN	 /* Required for Windows CE */
+#if defined(MOZ_MEMORY_WINCE) && !defined(MOZ_MEMORY_WINCE6)
+#define JEMALLOC_USES_MAP_ALIGN	 /* Required for Windows CE < 6 */
 #endif
 
 #define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var))
 
 #include "qr.h"
 #include "ql.h"
 #ifdef MOZ_MEMORY_WINDOWS
    /* MSVC++ does not support C99 variable-length arrays. */
@@ -494,17 +477,17 @@ static const bool __isthreaded = true;
 #    undef MALLOC_BALANCE
 #  endif
 #endif
 
 /*
  * Size and alignment of memory chunks that are allocated by the OS's virtual
  * memory system.
  */
-#ifdef MOZ_MEMORY_WINCE
+#if defined(MOZ_MEMORY_WINCE) && !defined(MOZ_MEMORY_WINCE6)
 #define	CHUNK_2POW_DEFAULT	21
 #else
 #define	CHUNK_2POW_DEFAULT	20
 #endif
 /* Maximum number of dirty pages per arena. */
 #define	DIRTY_MAX_DEFAULT	(1U << 10)
 
 /* Default reserve chunks. */
@@ -2205,35 +2188,35 @@ pages_map_align(size_t size, int pfd, si
 	return (ret);
 }
 #endif
 
 static void *
 pages_map(void *addr, size_t size, int pfd)
 {
 	void *ret = NULL;
-#if defined(MOZ_MEMORY_WINCE)
+#if defined(MOZ_MEMORY_WINCE) && !defined(MOZ_MEMORY_WINCE6)
 	void *va_ret;
 	assert(addr == NULL);
 	va_ret = VirtualAlloc(addr, size, MEM_RESERVE, PAGE_NOACCESS);
 	if (va_ret)
 		ret = VirtualAlloc(va_ret, size, MEM_COMMIT, PAGE_READWRITE);
 	assert(va_ret == ret);
-#elif defined(MOZ_MEMORY_WINDOWS)
+#else
 	ret = VirtualAlloc(addr, size, MEM_COMMIT | MEM_RESERVE,
 	    PAGE_READWRITE);
 #endif
 	return (ret);
 }
 
 static void
 pages_unmap(void *addr, size_t size)
 {
 	if (VirtualFree(addr, 0, MEM_RELEASE) == 0) {
-#ifdef MOZ_MEMORY_WINCE
+#if defined(MOZ_MEMORY_WINCE) && !defined(MOZ_MEMORY_WINCE6)
 		if (GetLastError() == ERROR_INVALID_PARAMETER) {
 			MEMORY_BASIC_INFORMATION info;
 			VirtualQuery(addr, &info, sizeof(info));
 			if (VirtualFree(info.AllocationBase, 0, MEM_RELEASE))
 				return;
 		}
 #endif
 		_malloc_message(_getprogname(),
@@ -6137,17 +6120,17 @@ malloc_shutdown()
 #ifdef MOZ_MEMORY_DARWIN
 #  define ZONE_INLINE	inline
 #else
 #  define ZONE_INLINE
 #endif
 
 /* Mangle standard interfaces on Darwin and Windows CE, 
    in order to avoid linking problems. */
-#if defined(MOZ_MEMORY_DARWIN) || defined(MOZ_MEMORY_WINCE)
+#if defined(MOZ_MEMORY_DARWIN)
 #define	malloc(a)	moz_malloc(a)
 #define	valloc(a)	moz_valloc(a)
 #define	calloc(a, b)	moz_calloc(a, b)
 #define	realloc(a, b)	moz_realloc(a, b)
 #define	free(a)		moz_free(a)
 #endif
 
 ZONE_INLINE
--- a/memory/jemalloc/jemalloc.h
+++ b/memory/jemalloc/jemalloc.h
@@ -1,34 +1,72 @@
-#ifndef MOZ_MEMORY_WINDOWS
-#  include <stdbool.h>
+/* -*- Mode: C; tab-width: 8; c-basic-offset: 8 -*- */
+/* vim:set softtabstop=8 shiftwidth=8: */
+/*-
+ * Copyright (C) 2006-2008 Jason Evans <jasone@FreeBSD.org>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice(s), this list of conditions and the following disclaimer as
+ *    the first lines of this file unmodified other than the possible
+ *    addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice(s), this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _JEMALLOC_H_
+#define _JEMALLOC_H_
+
+/* grab size_t */
+#ifdef _MSC_VER
+#include <crtdefs.h>
 #else
-#  include <windows.h>
-#  ifndef bool
-#    define bool BOOL
-#  endif
+#include <stddef.h>
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef unsigned char jemalloc_bool;
+
 extern const char	*_malloc_options;
 
 /*
  * jemalloc_stats() is not a stable interface.  When using jemalloc_stats_t, be
  * sure that the compiled results of jemalloc.c are in sync with this header
  * file.
  */
 typedef struct {
 	/*
 	 * Run-time configuration settings.
 	 */
-	bool	opt_abort;	/* abort(3) on error? */
-	bool	opt_junk;	/* Fill allocated/free memory with 0xa5/0x5a? */
-	bool	opt_utrace;	/* Trace all allocation events? */
-	bool	opt_sysv;	/* SysV semantics? */
-	bool	opt_xmalloc;	/* abort(3) on OOM? */
-	bool	opt_zero;	/* Fill allocated memory with 0x0? */
+	jemalloc_bool	opt_abort;	/* abort(3) on error? */
+	jemalloc_bool	opt_junk;	/* Fill allocated/free memory with 0xa5/0x5a? */
+	jemalloc_bool	opt_utrace;	/* Trace all allocation events? */
+	jemalloc_bool	opt_sysv;	/* SysV semantics? */
+	jemalloc_bool	opt_xmalloc;	/* abort(3) on OOM? */
+	jemalloc_bool	opt_zero;	/* Fill allocated memory with 0x0? */
 	size_t	narenas;	/* Number of arenas. */
 	size_t	balance_threshold; /* Arena contention rebalance threshold. */
 	size_t	quantum;	/* Allocation quantum. */
 	size_t	small_max;	/* Max quantum-spaced allocation size. */
 	size_t	large_max;	/* Max sub-chunksize allocation size. */
 	size_t	chunksize;	/* Size of each virtual memory mapping. */
 	size_t	dirty_max;	/* Max dirty pages per arena. */
 	size_t	reserve_min;	/* reserve_low callback threshold. */
@@ -131,30 +169,30 @@ typedef void reserve_cb_t(void *ctx, res
  *
  * Inputs:
  *   cb: Callback function pointer.
  *   ctx: Opaque application data, passed to cb().
  *
  * Output:
  *   ret: If true, failure due to OOM; success otherwise.
  */
-bool	reserve_cb_register(reserve_cb_t *cb, void *ctx);
+jemalloc_bool	reserve_cb_register(reserve_cb_t *cb, void *ctx);
 
 /*
  * Unregister a callback function.
  *
  * Inputs:
  *   cb: Callback function pointer.
  *   ctx: Opaque application data, same as that passed to reserve_cb_register().
  *
  * Output:
  *   ret: False upon success, true if the {cb,ctx} registration could not be
  *        found.
  */
-bool	reserve_cb_unregister(reserve_cb_t *cb, void *ctx);
+jemalloc_bool	reserve_cb_unregister(reserve_cb_t *cb, void *ctx);
 
 /*
  * Get the current reserve size.
  *
  * ret: Current reserve size.
  */
 size_t	reserve_cur_get(void);
 
@@ -169,9 +207,15 @@ size_t	reserve_min_get(void);
 /*
  * Set the minimum acceptable reserve size.
  *
  * min: Reserve threshold.  This value may be internally rounded up.
  * ret: False if the reserve was successfully resized; true otherwise.  Note
  *      that failure to resize the reserve also results in a RESERVE_CND_LOW
  *      condition.
  */
-bool	reserve_min_set(size_t min);
+jemalloc_bool	reserve_min_set(size_t min);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* _JEMALLOC_H_ */