diff options
author | sgk@chromium.org <sgk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-25 00:11:08 +0000 |
---|---|---|
committer | sgk@chromium.org <sgk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-25 00:11:08 +0000 |
commit | f8564c104c45f3caca228f73b43a40e4ea72ce02 (patch) | |
tree | 07451dbd5fc442c691b039d462b41ebbe23f06da /third_party/jemalloc/chromium | |
parent | 5ce0b16b97321df662c68124a26d5f7ad6afadc0 (diff) | |
download | chromium_src-f8564c104c45f3caca228f73b43a40e4ea72ce02.zip chromium_src-f8564c104c45f3caca228f73b43a40e4ea72ce02.tar.gz chromium_src-f8564c104c45f3caca228f73b43a40e4ea72ce02.tar.bz2 |
Copy jemalloc vendor branch to chromium branch as base for local changes.
BUG=27911
TEST=none
Review URL: http://codereview.chromium.org/436034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33008 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/jemalloc/chromium')
-rw-r--r-- | third_party/jemalloc/chromium/Makefile.in | 130 | ||||
-rw-r--r-- | third_party/jemalloc/chromium/apply-ed-patches.pl | 84 | ||||
-rw-r--r-- | third_party/jemalloc/chromium/build-crt.py | 20 | ||||
-rw-r--r-- | third_party/jemalloc/chromium/crtsp1.diff | 197 | ||||
-rw-r--r-- | third_party/jemalloc/chromium/ed.exe | bin | 0 -> 116736 bytes | |||
-rw-r--r-- | third_party/jemalloc/chromium/jemalloc.c | 49 | ||||
-rw-r--r-- | third_party/jemalloc/chromium/jemalloc.h | 3 | ||||
-rw-r--r-- | third_party/jemalloc/chromium/ql.h | 1 | ||||
-rw-r--r-- | third_party/jemalloc/chromium/qr.h | 1 | ||||
-rw-r--r-- | third_party/jemalloc/chromium/rb.h | 1 |
10 files changed, 448 insertions, 38 deletions
diff --git a/third_party/jemalloc/chromium/Makefile.in b/third_party/jemalloc/chromium/Makefile.in new file mode 100644 index 0000000..68611bb --- /dev/null +++ b/third_party/jemalloc/chromium/Makefile.in @@ -0,0 +1,130 @@ +# +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is +# Mozilla Foundation +# Portions created by the Initial Developer are Copyright (C) 2008 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Ted Mielczarek <ted.mielczarek@gmail.com> +# +# Alternatively, the contents of this file may be used under the terms of +# either of the GNU General Public License Version 2 or later (the "GPL"), +# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# 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 ***** + +DEPTH = ../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +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 (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 + +# copy the CRT DLL to dist/bin, +# copy the import lib to dist/lib +libs:: $(MOZ_CRT_DLL) $(MOZ_CRT_IMPORT_LIB) + $(INSTALL) $(MOZ_CRT_DLL) $(FINAL_TARGET) + $(INSTALL) $(MOZ_CRT_IMPORT_LIB) $(DIST)/lib + +$(MOZ_CRT_IMPORT_LIB): $(MOZ_CRT_DLL) + +define EXTRACT_CMD +cd $(CRT_OBJ_DIR)/intel/$(i)_lib && lib "-extract:..\\build\\intel\\$(i)_obj\\unhandld.obj" eh.lib + +endef # don't touch the blank line. actually, don't touch anything in this file. + +# patch if necessary +$(CRT_OBJ_DIR)/jemalloc.c: $(srcdir)/crtsp1.diff + rm -rf $(CRT_OBJ_DIR) + cp -R "$(WIN32_CRT_SRC_DIR)" $(CRT_OBJ_DIR) +# per http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1189363&SiteID=1 + $(foreach i,dll mt xdll xmt,$(EXTRACT_CMD)) +# truly awful +#XXX: get ed into mozillabuild, bug 415123 + $(PERL) $(srcdir)/apply-ed-patches.pl $(srcdir)/crtsp1.diff \ + $(CRT_OBJ_DIR) $(srcdir)/ed.exe + +$(MOZ_CRT_DLL): \ + $(CRT_OBJ_DIR)/jemalloc.c $(srcdir)/jemalloc.c $(srcdir)/jemalloc.h \ + $(srcdir)/ql.h $(srcdir)/qr.h $(srcdir)/rb.h + cp $(srcdir)/jemalloc.c $(srcdir)/jemalloc.h $(srcdir)/ql.h \ + $(srcdir)/qr.h $(srcdir)/rb.h $(CRT_OBJ_DIR) +# this pretty much sucks, but nmake and make don't play well together + $(PYTHON) $(srcdir)/build-crt.py $(CRT_OBJ_DIR) +# XXX: these don't link right for some reason; the problem is likely +# that not all the standard symbols are exported; looks like MSFT +# never updated the sample.def files; could probably fix if someone +# were ever bored enough. :-) + rm -f $(addsuffix .lib, $(addprefix $(CRT_OBJ_DIR)/build/intel/, $(MOZ_CRT_STATIC_LIBS))) + rm -f $(addsuffix .pdb, $(addprefix $(CRT_OBJ_DIR)/build/intel/, $(MOZ_CRT_STATIC_LIBS))) + +else # Not Windows + +MODULE_OPTIMIZE_FLAGS = -O2 +ifeq ($(OS_ARCH),SunOS) +ifndef GNU_CC +MODULE_OPTIMIZE_FLAGS = -xO5 +endif +endif + +LIBRARY_NAME = jemalloc + +# Build jemalloc as a shared lib. This is mandatory for Darwin, since a library +# init function is used on that platform. +ifeq ($(OS_ARCH),Darwin) +FORCE_SHARED_LIB= 1 +else +DIST_INSTALL = 1 +FORCE_STATIC_LIB= 1 +endif + +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 + +ifeq (Darwin,$(OS_TARGET)) +LDFLAGS += -init _jemalloc_darwin_init +endif diff --git a/third_party/jemalloc/chromium/apply-ed-patches.pl b/third_party/jemalloc/chromium/apply-ed-patches.pl new file mode 100644 index 0000000..394a4ce --- /dev/null +++ b/third_party/jemalloc/chromium/apply-ed-patches.pl @@ -0,0 +1,84 @@ +#!/bin/perl +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is Mozilla build system. +# +# The Initial Developer of the Original Code is +# Mozilla Foundation. +# Portions created by the Initial Developer are Copyright (C) 2008 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Ted Mielczarek <ted.mielczarek@gmail.com> +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# 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 ***** + +# Usage: apply-ed-patches.pl <source patch> <target directory> <path to ed> + +use FileHandle; + +sub do_patch { + my ($ed, $target_file, $patch_file, $fh) = @_; + # these keep winding up read only for me + chmod 0666, $target_file; + print $fh "w\n"; + $fh->close(); + print "$ed -s $target_file < $patch_file\n"; + system "$ed -s $target_file < $patch_file\n"; +} + +my $header_done = 0; +my ($target_file,$patch_file) = ('',''); +my $source_patch = $ARGV[0]; +my $srcdir = $ARGV[1]; +my $ed = $ARGV[2]; +$srcdir = "$srcdir/" unless $srcdir =~ m|/$|; +my $pfh = new FileHandle($source_patch, 'r'); +while(<$pfh>) { + # skip initial comment header + next if !$header_done && /^#/; + $header_done = 1; + + next if /^Only in/; + if (/^diff -re (\S+)/) { + my $new_file = $1; + $new_file =~ s|^crt/src/||; + $new_file = "$srcdir$new_file"; + my $new_patch_file = "$new_file.patch"; + + if ($target_file ne '') { + do_patch $ed, $target_file, $patch_file, $fh; + } + $target_file = $new_file; + $patch_file = $new_patch_file; + $fh = new FileHandle($patch_file, 'w'); + next; + } + + print $fh $_ if $fh; +} + +do_patch $ed, $target_file, $patch_file, $fh; diff --git a/third_party/jemalloc/chromium/build-crt.py b/third_party/jemalloc/chromium/build-crt.py new file mode 100644 index 0000000..199ab38 --- /dev/null +++ b/third_party/jemalloc/chromium/build-crt.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +import os, sys +from subprocess import Popen, STDOUT, PIPE + +if 'MAKEFLAGS' in os.environ: + del os.environ['MAKEFLAGS'] +proc = Popen(['nmake', 'dll_', 'mt'], stdout=PIPE, stderr=STDOUT, + cwd=sys.argv[1]) + +while True: + line = proc.stdout.readline() + if line == '': + break + line = line.rstrip() + # explicitly ignore this fatal-sounding non-fatal error + if line == "NMAKE : fatal error U1052: file 'makefile.sub' not found" or line == "Stop.": + continue + print line +sys.exit(proc.wait()) diff --git a/third_party/jemalloc/chromium/crtsp1.diff b/third_party/jemalloc/chromium/crtsp1.diff new file mode 100644 index 0000000..ec705eb --- /dev/null +++ b/third_party/jemalloc/chromium/crtsp1.diff @@ -0,0 +1,197 @@ +# The Microsoft C Runtime source code to which this document refers is available +# directly from Microsoft Corporation, under a separate license. +# Please ensure that if you are using that source code, you have appropriate +# rights to use it. By providing you access to this file, Mozilla Corporation +# and its affiliates do not purport to grant any rights in that source code. +# Binaries are available under separate licenses at +# http://www.microsoft.com/downloads/details.aspx?familyid=200b2fd9-ae1a-4a14-984d-389c36f85647&displaylang=en +diff -re crt/src/crt0.c crt-sp1/src/crt0.c +273c + /*
+ * this used to happen in _mtinit, but we need it before malloc
+ */
+ _init_pointers(); /* initialize global function pointers */
+
+ if ( malloc_init_hard() ) /* initialize heap */
+. +101a +extern BOOL malloc_init_hard(void);
+. +diff -re crt/src/_sample_.rc crt-sp1/src/_sample_.rc +41c + VALUE "ProductName", "Mozilla Custom C Runtime"
+. +39c + VALUE "OriginalFilename", "MOZCRT19.DLL"
+. +37c + VALUE "OriginalFilename", "MOZCRT19D.DLL"
+. +33c + VALUE "InternalName", "MOZCRT19.DLL"
+. +31c + VALUE "InternalName", "MOZCRT19D.DLL"
+. +27c + VALUE "CompanyName", "Mozilla Foundation"
+. + +diff -re crt/src/crt0dat.c crt-sp1/src/crt0dat.c +789d +778d +diff -re crt/src/crtexe.c crt-sp1/src/crtexe.c +333,335d +diff -re crt/src/crtheap.c crt-sp1/src/crtheap.c +61c + pv = calloc(count, size);
+. +58,59d +diff -re crt/src/crtlib.c crt-sp1/src/crtlib.c +779,786d +416d +400a + malloc_shutdown();
+
+. +359d +340d +310,311d +300d +287c + /*
+ * this used to happen in _mtinit, but we need it before malloc
+ */
+ _init_pointers(); /* initialize global function pointers */
+
+ if ( malloc_init_hard() ) /* initialize heap */
+. +43a +extern BOOL malloc_init_hard(void);
+extern void malloc_shutdown(void);
+
+. +diff -re crt/src/dllcrt0.c crt-sp1/src/dllcrt0.c +236,237d +183d +173d +158d +153,155d +diff -re crt/src/intel/_sample_.def crt-sp1/src/intel/_sample_.def +1208d +723,724d +669a + posix_memalign
+. +643a + memalign
+. +500a + malloc_usable_size
+. +336,341d +324d +313,314d +81d +9c +LIBRARY MOZCRT19
+. +diff -re crt/src/internal.h crt-sp1/src/internal.h +407a +#endif
+. +403a +#if 0
+. +diff -re crt/src/makefile crt-sp1/src/makefile +1745a +$(DEFFILE_DIR)\$(RETAIL_LIB_NAME).def : $(DEFFILE_DIR)\_sample_.def
+ copy $** $@
+. +1228,1230d +754c +dll_ :: $(OBJROOT) $(OBJCPUDIR) $(OBJDIR_DLL) $(OBJDIR_DLL)\$(PURE_OBJ_DIR) \
+ $(OBJDIR_DLL)\$(CPP_OBJ_DIR) \
+ $(RELDIR_CPU) $(PDBDIR_CPU_DLL) $(MAKE_DIRS_DLL)
+. +334c +CC_OPTS_BASE=-c -nologo -Zlp8 -W3 -GFy -DWIND32
+. +307,309c +LINKER=link
+LINKLIB=link -lib
+LINKIMPLIB=link -lib
+. +302,304c +LINKER=link -nologo
+LINKLIB=link -lib -nologo
+LINKIMPLIB=link -lib -nologo
+. +209d +21,22c +RETAIL_DLL_NAME=MOZCRT19
+RETAIL_LIB_NAME=mozcrt19
+. +diff -re crt/src/makefile.inc crt-sp1/src/makefile.inc +1623a +
+$(OBJDIR)\unhandld.obj: $(PREOBJDIR)\unhandld.obj
+ copy $(PREOBJDIR)\unhandld.obj $@
+. +618d +402d +342,353c + $(OBJDIR)\jemalloc.obj \
+. +334,335d +329,330d +327d +323d +320d +diff -re crt/src/makefile.sub crt-sp1/src/makefile.sub +103c +LIB=link -lib -nologo
+. +69c +CFLAGS=$(CFLAGS) -O2 -DMOZ_MEMORY=1 -DMOZ_MEMORY_WINDOWS=1
+. +diff -re crt/src/malloc.h crt-sp1/src/malloc.h +189a +#endif
+. +177a +
+#if 0
+. +161d +83a +#endif
+. +70a +#if 0
+. +diff -re crt/src/mlock.c crt-sp1/src/mlock.c +274c +#endif
+. +262a +#if 0
+. +diff -re crt/src/new.cpp crt-sp1/src/new.cpp +60d +52,55d +37,38c + break;
+. +diff -re crt/src/nothrownew.cpp crt-sp1/src/nothrownew.cpp +37a +#endif
+. +31a +#if 1
+ break;
+#else
+
+. +diff -re crt/src/tidtable.c crt-sp1/src/tidtable.c +393,394d diff --git a/third_party/jemalloc/chromium/ed.exe b/third_party/jemalloc/chromium/ed.exe Binary files differnew file mode 100644 index 0000000..fc812ea --- /dev/null +++ b/third_party/jemalloc/chromium/ed.exe diff --git a/third_party/jemalloc/chromium/jemalloc.c b/third_party/jemalloc/chromium/jemalloc.c index c616b42..a3952de 100644 --- a/third_party/jemalloc/chromium/jemalloc.c +++ b/third_party/jemalloc/chromium/jemalloc.c @@ -97,13 +97,6 @@ */ /* - * NOTE(mbelshe): Added these defines to fit within chromium build system. - */ -#define MOZ_MEMORY_WINDOWS -#define MOZ_MEMORY -#define DONT_OVERRIDE_LIBC - -/* * MALLOC_PRODUCTION disables assertions and statistics gathering. It also * defaults the A and J runtime options to off. These settings are appropriate * for production systems. @@ -210,8 +203,8 @@ #ifdef MOZ_MEMORY_WINDOWS #ifndef MOZ_MEMORY_WINCE -//#include <cruntime.h> -//#include <internal.h> +#include <cruntime.h> +#include <internal.h> #include <io.h> #else #include <cmnintrin.h> @@ -1422,12 +1415,9 @@ malloc_mutex_init(malloc_mutex_t *mutex) #if defined(MOZ_MEMORY_WINCE) InitializeCriticalSection(mutex); #elif defined(MOZ_MEMORY_WINDOWS) - // XXXMB - //if (__isthreaded) - // if (! __crtInitCritSecAndSpinCount(mutex, _CRT_SPINCOUNT)) - // return (true); - if (!InitializeCriticalSectionAndSpinCount(mutex, 4000)) - return true; + if (__isthreaded) + if (! __crtInitCritSecAndSpinCount(mutex, _CRT_SPINCOUNT)) + return (true); #elif defined(MOZ_MEMORY_DARWIN) mutex->lock = OS_SPINLOCK_INIT; #elif defined(MOZ_MEMORY_LINUX) @@ -1489,10 +1479,9 @@ malloc_spin_init(malloc_spinlock_t *lock) #if defined(MOZ_MEMORY_WINCE) InitializeCriticalSection(lock); #elif defined(MOZ_MEMORY_WINDOWS) - // XXXMB - //if (__isthreaded) - // if (! __crtInitCritSecAndSpinCount(lock, _CRT_SPINCOUNT)) - // return (true); + if (__isthreaded) + if (! __crtInitCritSecAndSpinCount(lock, _CRT_SPINCOUNT)) + return (true); #elif defined(MOZ_MEMORY_DARWIN) lock->lock = OS_SPINLOCK_INIT; #elif defined(MOZ_MEMORY_LINUX) @@ -5538,7 +5527,7 @@ malloc_init(void) static #endif bool -je_malloc_init_hard(void) +malloc_init_hard(void) { unsigned i; char buf[PATH_MAX + 1]; @@ -6136,18 +6125,12 @@ malloc_shutdown() /* Mangle standard interfaces on Darwin and Windows CE, in order to avoid linking problems. */ -#ifdef MOZ_MEMORY_DARWIN -#define DONT_OVERRIDE_LIBC -#endif - -#if defined(DONT_OVERRIDE_LIBC) -#define malloc(a) je_malloc(a) -#define valloc(a) je_valloc(a) -#define calloc(a, b) je_calloc(a, b) -#define realloc(a, b) je_realloc(a, b) -#define free(a) je_free(a) -#define _msize(p) je_msize(p) -#define _recalloc(p, n, s) je_recalloc(p, n, s) +#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 @@ -7027,6 +7010,7 @@ _expand(void *ptr, size_t newsize) size_t _msize(const void *ptr) { + return malloc_usable_size(ptr); } #endif @@ -7273,4 +7257,3 @@ void *(*__memalign_hook)(size_t alignment, size_t size) = memalign; */ # error "Interposing malloc is unsafe on this system without libc malloc hooks." #endif - diff --git a/third_party/jemalloc/chromium/jemalloc.h b/third_party/jemalloc/chromium/jemalloc.h index 8154656..4419bd0f 100644 --- a/third_party/jemalloc/chromium/jemalloc.h +++ b/third_party/jemalloc/chromium/jemalloc.h @@ -2,7 +2,7 @@ /* vim:set softtabstop=8 shiftwidth=8: */ /*- * Copyright (C) 2006-2008 Jason Evans <jasone@FreeBSD.org>. - * All rights reserved. + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -219,4 +219,3 @@ jemalloc_bool reserve_min_set(size_t min); #endif #endif /* _JEMALLOC_H_ */ - diff --git a/third_party/jemalloc/chromium/ql.h b/third_party/jemalloc/chromium/ql.h index f50a64c..000cd23 100644 --- a/third_party/jemalloc/chromium/ql.h +++ b/third_party/jemalloc/chromium/ql.h @@ -112,4 +112,3 @@ struct { \ #define ql_reverse_foreach(a_var, a_head, a_field) \ qr_reverse_foreach((a_var), ql_first(a_head), a_field) - diff --git a/third_party/jemalloc/chromium/qr.h b/third_party/jemalloc/chromium/qr.h index fb780f7..ee60491 100644 --- a/third_party/jemalloc/chromium/qr.h +++ b/third_party/jemalloc/chromium/qr.h @@ -96,4 +96,3 @@ struct { \ (var) != NULL; \ (var) = (((var) != (a_qr)) \ ? (var)->a_field.qre_prev : NULL)) - diff --git a/third_party/jemalloc/chromium/rb.h b/third_party/jemalloc/chromium/rb.h index 09e7ede..43d8569 100644 --- a/third_party/jemalloc/chromium/rb.h +++ b/third_party/jemalloc/chromium/rb.h @@ -980,4 +980,3 @@ a_prefix##remove(a_tree_type *tree, a_type *node) { \ } #endif /* RB_H_ */ - |