[Avida-cvs] [avida-svn] r526 - in development: Avida.xcodeproj source/platform/tcmalloc
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Fri Mar 24 13:32:25 PST 2006
Author: brysonda
Date: 2006-03-24 16:32:24 -0500 (Fri, 24 Mar 2006)
New Revision: 526
Modified:
development/Avida.xcodeproj/project.pbxproj
development/source/platform/tcmalloc/system-alloc.cc
development/source/platform/tcmalloc/tcmalloc-config.h
development/source/platform/tcmalloc/tcmalloc.cc
Log:
Some compile fixes to tcmalloc.
Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj 2006-03-24 21:18:38 UTC (rev 525)
+++ development/Avida.xcodeproj/project.pbxproj 2006-03-24 21:32:24 UTC (rev 526)
@@ -116,6 +116,9 @@
7073165D097C6C8F00815164 /* cParser.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7073165B097C6C8F00815164 /* cParser.cc */; };
70731665097C6DF500815164 /* cASLibrary.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70731663097C6DF500815164 /* cASLibrary.cc */; };
7073166B097C6E0C00815164 /* cASSymbol.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70731669097C6E0C00815164 /* cASSymbol.cc */; };
+ 70AA941A09D486CA006A24C8 /* system-alloc.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCF50209CFB0B400924128 /* system-alloc.cc */; };
+ 70AA941B09D486CB006A24C8 /* tcmalloc-logging.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCF57F09CFBD3D00924128 /* tcmalloc-logging.cc */; };
+ 70AA941C09D486CD006A24C8 /* tcmalloc.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCF56309CFBB9500924128 /* tcmalloc.cc */; };
70B0865908F4974300FC65FE /* cLandscape.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0865108F4974300FC65FE /* cLandscape.cc */; };
70B0865C08F4974300FC65FE /* cLocalMutations.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0865408F4974300FC65FE /* cLocalMutations.cc */; };
70B0865E08F4974300FC65FE /* cMutationLib.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0865608F4974300FC65FE /* cMutationLib.cc */; };
@@ -636,6 +639,7 @@
70731668097C6E0C00815164 /* cASSymbol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cASSymbol.h; sourceTree = "<group>"; };
70731669097C6E0C00815164 /* cASSymbol.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cASSymbol.cc; sourceTree = "<group>"; };
707A687408E3750300576968 /* cHardwareTracer_SMT.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cHardwareTracer_SMT.h; sourceTree = "<group>"; };
+ 70AA941909D486AE006A24C8 /* libtcmalloc.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libtcmalloc.a; sourceTree = BUILT_PRODUCTS_DIR; };
70B0864808F4972600FC65FE /* cLandscape.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cLandscape.h; sourceTree = "<group>"; };
70B0864B08F4972600FC65FE /* cLocalMutations.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cLocalMutations.h; sourceTree = "<group>"; };
70B0864C08F4972600FC65FE /* cMutation.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cMutation.h; sourceTree = "<group>"; };
@@ -1019,6 +1023,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
+ 70AA941709D486AE006A24C8 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
70DCAD07097AF7CC002F8733 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
@@ -1715,12 +1726,23 @@
DCC3164D07626CF3008F7A48 /* avida */,
700E2B83085DE50C00CF158A /* avida-viewer */,
70DCAD1C097AF7CC002F8733 /* avida-s */,
+ 70AA941909D486AE006A24C8 /* libtcmalloc.a */,
);
name = Products;
sourceTree = "<group>";
};
/* End PBXGroup section */
+/* Begin PBXHeadersBuildPhase section */
+ 70AA941509D486AE006A24C8 /* Headers */ = {
+ isa = PBXHeadersBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXHeadersBuildPhase section */
+
/* Begin PBXNativeTarget section */
700E2AF3085DE50C00CF158A /* avida-viewer */ = {
isa = PBXNativeTarget;
@@ -1761,6 +1783,31 @@
productReference = 700E2B83085DE50C00CF158A /* avida-viewer */;
productType = "com.apple.product-type.tool";
};
+ 70AA941809D486AE006A24C8 /* tcmalloc */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 70AA942509D48715006A24C8 /* Build configuration list for PBXNativeTarget "tcmalloc" */;
+ buildPhases = (
+ 70AA941509D486AE006A24C8 /* Headers */,
+ 70AA941609D486AE006A24C8 /* Sources */,
+ 70AA941709D486AE006A24C8 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ buildSettings = {
+ GCC_ENABLE_FIX_AND_CONTINUE = YES;
+ GCC_MODEL_TUNING = G5;
+ INSTALL_PATH = /usr/local/lib;
+ PREBINDING = NO;
+ PRODUCT_NAME = tcmalloc;
+ ZERO_LINK = YES;
+ };
+ dependencies = (
+ );
+ name = tcmalloc;
+ productName = tcmalloc;
+ productReference = 70AA941909D486AE006A24C8 /* libtcmalloc.a */;
+ productType = "com.apple.product-type.library.static";
+ };
70DCAC9D097AF7CC002F8733 /* avida-s */ = {
isa = PBXNativeTarget;
buildConfigurationList = 70DCAD17097AF7CC002F8733 /* Build configuration list for PBXNativeTarget "avida-s" */;
@@ -1861,6 +1908,7 @@
DCC3164C07626CF3008F7A48 /* avida */,
70DCAC9D097AF7CC002F8733 /* avida-s */,
700E2AF3085DE50C00CF158A /* avida-viewer */,
+ 70AA941809D486AE006A24C8 /* tcmalloc */,
);
};
/* End PBXProject section */
@@ -2032,6 +2080,16 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
+ 70AA941609D486AE006A24C8 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 70AA941A09D486CA006A24C8 /* system-alloc.cc in Sources */,
+ 70AA941B09D486CB006A24C8 /* tcmalloc-logging.cc in Sources */,
+ 70AA941C09D486CD006A24C8 /* tcmalloc.cc in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
70DCAC9F097AF7CC002F8733 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
@@ -2392,6 +2450,59 @@
};
name = "Deployment-G4";
};
+ 70AA942609D48715006A24C8 /* Development */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ COPY_PHASE_STRIP = NO;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_CPP_EXCEPTIONS = YES;
+ GCC_ENABLE_CPP_RTTI = NO;
+ GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
+ GCC_MODEL_TUNING = G5;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_THREADSAFE_STATICS = NO;
+ INSTALL_PATH = /usr/local/lib;
+ PREBINDING = NO;
+ PRODUCT_NAME = tcmalloc;
+ ZERO_LINK = YES;
+ };
+ name = Development;
+ };
+ 70AA942709D48715006A24C8 /* Deployment-G4 */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_CPP_RTTI = NO;
+ GCC_INLINES_ARE_PRIVATE_EXTERN = YES;
+ GCC_MODEL_TUNING = G4;
+ GCC_THREADSAFE_STATICS = NO;
+ PRODUCT_NAME = tcmalloc;
+ };
+ name = "Deployment-G4";
+ };
+ 70AA942809D48715006A24C8 /* Deployment-G5 */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_CPP_RTTI = NO;
+ GCC_INLINES_ARE_PRIVATE_EXTERN = YES;
+ GCC_MODEL_TUNING = G5;
+ GCC_THREADSAFE_STATICS = NO;
+ PRODUCT_NAME = tcmalloc;
+ };
+ name = "Deployment-G5";
+ };
+ 70AA942909D48715006A24C8 /* Profile */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_CPP_RTTI = NO;
+ GCC_MODEL_TUNING = G5;
+ GCC_THREADSAFE_STATICS = NO;
+ PRODUCT_NAME = tcmalloc;
+ };
+ name = Profile;
+ };
70B393DC0944CA6F0018F09D /* Deployment-G5 */ = {
isa = XCBuildConfiguration;
buildSettings = {
@@ -2498,6 +2609,7 @@
GCC_AUTO_VECTORIZATION = YES;
GCC_DYNAMIC_NO_PIC = YES;
GCC_FAST_MATH = YES;
+ GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 3;
GCC_PREPROCESSOR_DEFINITIONS = (
NDEBUG,
@@ -2505,6 +2617,7 @@
);
GCC_STRICT_ALIASING = YES;
GCC_UNROLL_LOOPS = YES;
+ OTHER_CFLAGS = "-falign-loops=16";
WARNING_CFLAGS = (
"-Wmost",
"-Wno-four-char-constants",
@@ -2581,6 +2694,17 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = "Deployment-G4";
};
+ 70AA942509D48715006A24C8 /* Build configuration list for PBXNativeTarget "tcmalloc" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 70AA942609D48715006A24C8 /* Development */,
+ 70AA942709D48715006A24C8 /* Deployment-G4 */,
+ 70AA942809D48715006A24C8 /* Deployment-G5 */,
+ 70AA942909D48715006A24C8 /* Profile */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = "Deployment-G4";
+ };
70DCAD17097AF7CC002F8733 /* Build configuration list for PBXNativeTarget "avida-s" */ = {
isa = XCConfigurationList;
buildConfigurations = (
Modified: development/source/platform/tcmalloc/system-alloc.cc
===================================================================
--- development/source/platform/tcmalloc/system-alloc.cc 2006-03-24 21:18:38 UTC (rev 525)
+++ development/source/platform/tcmalloc/system-alloc.cc 2006-03-24 21:32:24 UTC (rev 526)
@@ -7,8 +7,6 @@
*
*/
-#include "system-alloc.h"
-
// Copyright (c) 2005, Google Inc.
// All rights reserved.
//
@@ -43,14 +41,7 @@
#include "tcmalloc-config.h"
-#if defined HAVE_STDINT_H
#include <stdint.h>
-#elif defined HAVE_INTTYPES_H
-#include <inttypes.h>
-#else
-#include <sys/types.h>
-#endif
-
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
@@ -58,6 +49,10 @@
#include "spinlock.h"
#include "tcmalloc-logging.h"
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS MAP_ANON
+#endif
+
// Structure for discovering alignment
union MemoryAligner {
void* p;
@@ -99,7 +94,7 @@
static void* TrySbrk(size_t size, size_t alignment) {
// sbrk will release memory if passed a negative number, so we do
// a strict check here
- if (static_cast<ptrdiff_t>(size + alignment) < 0) return NULL;
+ if (static_cast<uintptr_t>(size + alignment) < 0) return NULL;
size = ((size + alignment - 1) / alignment) * alignment;
void* result = sbrk(size);
@@ -276,7 +271,7 @@
// Try twice, once avoiding allocators that failed before, and once
// more trying all allocators even if they failed before.
-// @not_used - for (int i = 0; i < 2; i++) {
+ for (int i = 0; i < 2; i++) {
// @not_used - if (use_devmem && !devmem_failure) {
// @not_used - void* result = TryDevMem(size, alignment);
// @not_used - if (result != NULL) return result;
@@ -301,5 +296,6 @@
sbrk_failure = false;
mmap_failure = false;
}
+
return NULL;
}
Modified: development/source/platform/tcmalloc/tcmalloc-config.h
===================================================================
--- development/source/platform/tcmalloc/tcmalloc-config.h 2006-03-24 21:18:38 UTC (rev 525)
+++ development/source/platform/tcmalloc/tcmalloc-config.h 2006-03-24 21:32:24 UTC (rev 526)
@@ -11,49 +11,15 @@
#if PLATFORM(DARWIN)
-#define HAVE_ERRNO_H 1
-#define HAVE_FUNC_ISINF 1
-#define HAVE_FUNC_ISNAN 1
#define HAVE_MMAP 1
#define HAVE_SBRK 1
-#define HAVE_STRINGS_H 1
-#define HAVE_SYS_PARAM_H 1
-#define HAVE_SYS_TIME_H 1
-#define HAVE_SYS_TIMEB_H 1
+#define PRIuS "u"
-#elif PLATFORM(WIN_OS)
-
-#define HAVE_FLOAT_H 1
-#define HAVE_FUNC__FINITE 1
-#define HAVE_SYS_TIMEB_H 1
-
-
-#define USE_SYSTEM_MALLOC 1
-
#else
-// FIXME: is this actually used or do other platforms generate their
-// own config.h?
-
-#define HAVE_ERRNO_H 1
-#define HAVE_FUNC_ISINF 1
-#define HAVE_FUNC_ISNAN 1
#define HAVE_MMAP 1
#define HAVE_SBRK 1
-#define HAVE_STRINGS_H 1
-#define HAVE_SYS_PARAM_H 1
-#define HAVE_SYS_TIME_H 1
+#define PRIuS "u"
#endif
-// FIXME: if all platforms have these, do they really need #defines?
-#define HAVE_STDINT_H 1
-#define HAVE_STRING_H 1
-
-#define KXC_CHANGES 1
-
-#ifdef __cplusplus
-#undef new
-#undef delete
-#include <kxmlcore/FastMalloc.h>
-#endif
Modified: development/source/platform/tcmalloc/tcmalloc.cc
===================================================================
--- development/source/platform/tcmalloc/tcmalloc.cc 2006-03-24 21:18:38 UTC (rev 525)
+++ development/source/platform/tcmalloc/tcmalloc.cc 2006-03-24 21:32:24 UTC (rev 526)
@@ -76,14 +76,8 @@
#include <new>
#include <stdio.h>
#include <stddef.h>
-#if defined HAVE_STDINT_H
#include <stdint.h>
-#elif defined HAVE_INTTYPES_H
-#include <inttypes.h>
-#else
-#include <sys/types.h>
-#endif
-#include <malloc.h>
+#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
@@ -91,7 +85,7 @@
#include <stdarg.h>
#include "tcmalloc-logging.h"
-#include "tcmalloc-spinlock.h"
+#include "spinlock.h"
#include "pagemap.h"
#include "system-alloc.h"
@@ -587,13 +581,13 @@
return list->next == list;
}
-static int DLL_Length(const Span* list) {
- int result = 0;
- for (Span* s = list->next; s != list; s = s->next) {
- result++;
- }
- return result;
-}
+//static int DLL_Length(const Span* list) {
+// int result = 0;
+// for (Span* s = list->next; s != list; s = s->next) {
+// result++;
+// }
+// return result;
+//}
#if 0 /* Not needed at the moment -- causes compiler warnings if not used */
static void DLL_Print(const char* label, const Span* list) {
@@ -646,7 +640,7 @@
// from the system. Useful for finding allocation sites that cause
// increase in the footprint of the system. The linked list pointer
// is stored in trace->stack[kMaxStackDepth-1].
-static StackTrace* growth_stacks = NULL;
+// @not_used -static StackTrace* growth_stacks = NULL;
// -------------------------------------------------------------------------
// Map from page-id to per-page data
@@ -950,13 +944,13 @@
// @not_used - (cumulative << kPageShift) / 1048576.0);
// @not_used -}
-static void RecordGrowth(size_t growth) {
- StackTrace* t = stacktrace_allocator.New();
- t->depth = GetStackTrace(t->stack, kMaxStackDepth-1, 3);
- t->size = growth;
- t->stack[kMaxStackDepth-1] = reinterpret_cast<void*>(growth_stacks);
- growth_stacks = t;
-}
+// @not_used -static void RecordGrowth(size_t growth) {
+// @not_used - StackTrace* t = stacktrace_allocator.New();
+// @not_used - t->depth = GetStackTrace(t->stack, kMaxStackDepth-1, 3);
+// @not_used - t->size = growth;
+// @not_used - t->stack[kMaxStackDepth-1] = reinterpret_cast<void*>(growth_stacks);
+// @not_used - growth_stacks = t;
+// @not_used -}
bool TCMalloc_PageHeap::GrowHeap(Length n) {
ASSERT(kMaxPages >= kMinSystemAlloc);
@@ -970,7 +964,7 @@
}
if (ptr == NULL) return false;
}
- RecordGrowth(ask << kPageShift);
+// @not_used - RecordGrowth(ask << kPageShift);
uint64_t old_system_bytes = system_bytes_;
system_bytes_ += (ask << kPageShift);
@@ -1668,7 +1662,7 @@
if (!tsd_inited) {
InitModule();
} else {
- ptr = perftools_pthread_getspecific(heap_key);
+ ptr = pthread_getspecific(heap_key);
}
if (ptr == NULL) ptr = CreateCacheIfNecessary();
return reinterpret_cast<TCMalloc_ThreadCache*>(ptr);
@@ -1680,7 +1674,7 @@
inline TCMalloc_ThreadCache* TCMalloc_ThreadCache::GetCacheIfPresent() {
if (!tsd_inited) return NULL;
return reinterpret_cast<TCMalloc_ThreadCache*>
- (perftools_pthread_getspecific(heap_key));
+ (pthread_getspecific(heap_key));
}
void TCMalloc_ThreadCache::PickNextSample() {
@@ -1721,7 +1715,7 @@
void TCMalloc_ThreadCache::InitTSD() {
ASSERT(!tsd_inited);
- perftools_pthread_key_create(&heap_key, DeleteCache);
+ pthread_key_create(&heap_key, DeleteCache);
tsd_inited = true;
// We may have used a fake pthread_t for the main thread. Fix it.
@@ -1778,7 +1772,7 @@
// pthread_setspecific() if we are already inside pthread_setspecific().
if (!heap->in_setspecific_ && tsd_inited) {
heap->in_setspecific_ = true;
- perftools_pthread_setspecific(heap_key, heap);
+ pthread_setspecific(heap_key, heap);
heap->in_setspecific_ = false;
}
return heap;
@@ -1832,41 +1826,41 @@
uint64_t metadata_bytes; // Bytes alloced for metadata
};
-// Get stats into "r". Also get per-size-class counts if class_count != NULL
-static void ExtractStats(TCMallocStats* r, uint64_t* class_count) {
- r->central_bytes = 0;
- r->transfer_bytes = 0;
- for (int cl = 0; cl < kNumClasses; ++cl) {
- const int length = central_cache[cl].length();
- const int tc_length = central_cache[cl].tc_length();
- r->central_bytes += static_cast<uint64_t>(ByteSizeForClass(cl)) * length;
- r->transfer_bytes +=
- static_cast<uint64_t>(ByteSizeForClass(cl)) * tc_length;
- if (class_count) class_count[cl] = length + tc_length;
- }
+//// Get stats into "r". Also get per-size-class counts if class_count != NULL
+//static void ExtractStats(TCMallocStats* r, uint64_t* class_count) {
+// r->central_bytes = 0;
+// r->transfer_bytes = 0;
+// for (int cl = 0; cl < kNumClasses; ++cl) {
+// const int length = central_cache[cl].length();
+// const int tc_length = central_cache[cl].tc_length();
+// r->central_bytes += static_cast<uint64_t>(ByteSizeForClass(cl)) * length;
+// r->transfer_bytes +=
+// static_cast<uint64_t>(ByteSizeForClass(cl)) * tc_length;
+// if (class_count) class_count[cl] = length + tc_length;
+// }
+//
+// // Add stats from per-thread heaps
+// r->thread_bytes = 0;
+// { // scope
+// SpinLockHolder h(&pageheap_lock);
+// for (TCMalloc_ThreadCache* h = thread_heaps; h != NULL; h = h->next_) {
+// r->thread_bytes += h->Size();
+// if (class_count) {
+// for (int cl = 0; cl < kNumClasses; ++cl) {
+// class_count[cl] += h->freelist_length(cl);
+// }
+// }
+// }
+// }
+//
+// { //scope
+// SpinLockHolder h(&pageheap_lock);
+// r->system_bytes = pageheap->SystemBytes();
+// r->metadata_bytes = metadata_system_bytes;
+// r->pageheap_bytes = pageheap->FreeBytes();
+// }
+//}
- // Add stats from per-thread heaps
- r->thread_bytes = 0;
- { // scope
- SpinLockHolder h(&pageheap_lock);
- for (TCMalloc_ThreadCache* h = thread_heaps; h != NULL; h = h->next_) {
- r->thread_bytes += h->Size();
- if (class_count) {
- for (int cl = 0; cl < kNumClasses; ++cl) {
- class_count[cl] += h->freelist_length(cl);
- }
- }
- }
- }
-
- { //scope
- SpinLockHolder h(&pageheap_lock);
- r->system_bytes = pageheap->SystemBytes();
- r->metadata_bytes = metadata_system_bytes;
- r->pageheap_bytes = pageheap->FreeBytes();
- }
-}
-
//// WRITE stats to "out"
//static void DumpStats(TCMalloc_Printer* out, int level) {
// TCMallocStats stats;
@@ -2116,74 +2110,74 @@
// not be invoked very often. This requirement simplifies our
// implementation and allows us to tune for expected allocation
// patterns.
-// @not_used -static void* do_memalign(size_t align, size_t size) {
-// @not_used - ASSERT((align & (align - 1)) == 0);
-// @not_used - ASSERT(align > 0);
-// @not_used - if (size + align < size) return NULL; // Overflow
-// @not_used -
-// @not_used - if (pageheap == NULL) TCMalloc_ThreadCache::InitModule();
-// @not_used -
-// @not_used - // Allocate at least one byte to avoid boundary conditions below
-// @not_used - if (size == 0) size = 1;
-// @not_used -
-// @not_used - if (size <= kMaxSize && align < kPageSize) {
-// @not_used - // Search through acceptable size classes looking for one with
-// @not_used - // enough alignment. This depends on the fact that
-// @not_used - // InitSizeClasses() currently produces several size classes that
-// @not_used - // are aligned at powers of two. We will waste time and space if
-// @not_used - // we miss in the size class array, but that is deemed acceptable
-// @not_used - // since memalign() should be used rarely.
-// @not_used - int cl = SizeClass(size);
-// @not_used - while (cl < kNumClasses && ((class_to_size[cl] & (align - 1)) != 0)) {
-// @not_used - cl++;
-// @not_used - }
-// @not_used - if (cl < kNumClasses) {
-// @not_used - TCMalloc_ThreadCache* heap = TCMalloc_ThreadCache::GetCache();
-// @not_used - return heap->Allocate(class_to_size[cl]);
-// @not_used - }
-// @not_used - }
-// @not_used -
-// @not_used - // We will allocate directly from the page heap
-// @not_used - SpinLockHolder h(&pageheap_lock);
-// @not_used -
-// @not_used - if (align <= kPageSize) {
-// @not_used - // Any page-level allocation will be fine
-// @not_used - // TODO: We could put the rest of this page in the appropriate
-// @not_used - // TODO: cache but it does not seem worth it.
-// @not_used - Span* span = pageheap->New(pages(size));
-// @not_used - if (span == NULL) return NULL;
-// @not_used - return reinterpret_cast<void*>(span->start << kPageShift);
-// @not_used - }
-// @not_used -
-// @not_used - // Allocate extra pages and carve off an aligned portion
-// @not_used - const int alloc = pages(size + align);
-// @not_used - Span* span = pageheap->New(alloc);
-// @not_used - if (span == NULL) return NULL;
-// @not_used -
-// @not_used - // Skip starting portion so that we end up aligned
-// @not_used - int skip = 0;
-// @not_used - while ((((span->start+skip) << kPageShift) & (align - 1)) != 0) {
-// @not_used - skip++;
-// @not_used - }
-// @not_used - ASSERT(skip < alloc);
-// @not_used - if (skip > 0) {
-// @not_used - Span* rest = pageheap->Split(span, skip);
-// @not_used - pageheap->Delete(span);
-// @not_used - span = rest;
-// @not_used - }
-// @not_used -
-// @not_used - // Skip trailing portion that we do not need to return
-// @not_used - const int needed = pages(size);
-// @not_used - ASSERT(span->length >= needed);
-// @not_used - if (span->length > needed) {
-// @not_used - Span* trailer = pageheap->Split(span, needed);
-// @not_used - pageheap->Delete(trailer);
-// @not_used - }
-// @not_used - return reinterpret_cast<void*>(span->start << kPageShift);
-// @not_used -}
+static void* do_memalign(size_t align, size_t size) {
+ ASSERT((align & (align - 1)) == 0);
+ ASSERT(align > 0);
+ if (size + align < size) return NULL; // Overflow
+ if (pageheap == NULL) TCMalloc_ThreadCache::InitModule();
+ // Allocate at least one byte to avoid boundary conditions below
+ if (size == 0) size = 1;
+ if (size <= kMaxSize && align < kPageSize) {
+ // Search through acceptable size classes looking for one with
+ // enough alignment. This depends on the fact that
+ // InitSizeClasses() currently produces several size classes that
+ // are aligned at powers of two. We will waste time and space if
+ // we miss in the size class array, but that is deemed acceptable
+ // since memalign() should be used rarely.
+ int cl = SizeClass(size);
+ while (cl < kNumClasses && ((class_to_size[cl] & (align - 1)) != 0)) {
+ cl++;
+ }
+ if (cl < kNumClasses) {
+ TCMalloc_ThreadCache* heap = TCMalloc_ThreadCache::GetCache();
+ return heap->Allocate(class_to_size[cl]);
+ }
+ }
+
+ // We will allocate directly from the page heap
+ SpinLockHolder h(&pageheap_lock);
+
+ if (align <= kPageSize) {
+ // Any page-level allocation will be fine
+ // TODO: We could put the rest of this page in the appropriate
+ // TODO: cache but it does not seem worth it.
+ Span* span = pageheap->New(pages(size));
+ if (span == NULL) return NULL;
+ return reinterpret_cast<void*>(span->start << kPageShift);
+ }
+
+ // Allocate extra pages and carve off an aligned portion
+ const int alloc = pages(size + align);
+ Span* span = pageheap->New(alloc);
+ if (span == NULL) return NULL;
+
+ // Skip starting portion so that we end up aligned
+ int skip = 0;
+ while ((((span->start+skip) << kPageShift) & (align - 1)) != 0) {
+ skip++;
+ }
+ ASSERT(skip < alloc);
+ if (skip > 0) {
+ Span* rest = pageheap->Split(span, skip);
+ pageheap->Delete(span);
+ span = rest;
+ }
+
+ // Skip trailing portion that we do not need to return
+ const int needed = pages(size);
+ ASSERT(span->length >= needed);
+ if (span->length > needed) {
+ Span* trailer = pageheap->Split(span, needed);
+ pageheap->Delete(trailer);
+ }
+ return reinterpret_cast<void*>(span->start << kPageShift);
+}
+
+
+
// The constructor allocates an object to ensure that initialization
// runs before main(), and therefore we do not have a chance to become
// multi-threaded before initialization. We also create the TSD key
@@ -2367,7 +2361,7 @@
}
void operator delete(void* p, const std::nothrow_t&) OP_THROWNOTHING {
- MallocHook::InvokeDeleteHook(p);
+// @not_used - MallocHook::InvokeDeleteHook(p);
do_free(p);
}
@@ -2439,30 +2433,30 @@
return 1; // Indicates error
}
-extern "C" struct mallinfo mallinfo(void) {
- TCMallocStats stats;
- ExtractStats(&stats, NULL);
+// @not_used -extern "C" struct mallinfo mallinfo(void) {
+// @not_used - TCMallocStats stats;
+// @not_used - ExtractStats(&stats, NULL);
+// @not_used -
+// @not_used - // Just some of the fields are filled in.
+// @not_used - struct mallinfo info;
+// @not_used - memset(&info, 0, sizeof(info));
+// @not_used -
+// @not_used - // Unfortunately, the struct contains "int" field, so some of the
+// @not_used - // size values will be truncated.
+// @not_used - info.arena = static_cast<int>(stats.system_bytes);
+// @not_used - info.fsmblks = static_cast<int>(stats.thread_bytes
+// @not_used - + stats.central_bytes
+// @not_used - + stats.transfer_bytes);
+// @not_used - info.fordblks = static_cast<int>(stats.pageheap_bytes);
+// @not_used - info.uordblks = static_cast<int>(stats.system_bytes
+// @not_used - - stats.thread_bytes
+// @not_used - - stats.central_bytes
+// @not_used - - stats.transfer_bytes
+// @not_used - - stats.pageheap_bytes);
+// @not_used -
+// @not_used - return info;
+// @not_used -}
- // Just some of the fields are filled in.
- struct mallinfo info;
- memset(&info, 0, sizeof(info));
-
- // Unfortunately, the struct contains "int" field, so some of the
- // size values will be truncated.
- info.arena = static_cast<int>(stats.system_bytes);
- info.fsmblks = static_cast<int>(stats.thread_bytes
- + stats.central_bytes
- + stats.transfer_bytes);
- info.fordblks = static_cast<int>(stats.pageheap_bytes);
- info.uordblks = static_cast<int>(stats.system_bytes
- - stats.thread_bytes
- - stats.central_bytes
- - stats.transfer_bytes
- - stats.pageheap_bytes);
-
- return info;
-}
-
//-------------------------------------------------------------------
// Some library routines on RedHat 9 allocate memory using malloc()
// and free it using __libc_free() (or vice-versa). Since we provide
More information about the Avida-cvs
mailing list