From: Julian Seward Date: Wed, 20 Oct 2004 18:35:33 +0000 (+0000) Subject: Give the skiplist mechanism its own hacky allocator, so as to get X-Git-Tag: svn/VALGRIND_3_0_1^2~946 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=29c1c9ebce76c36b67e09635089ac2bc37b2e07f;p=thirdparty%2Fvalgrind.git Give the skiplist mechanism its own hacky allocator, so as to get rid of the following call cycle: VG_(mmap) -> VG_(map_fd_segment) -> VG_(map_file_segment) -> VG_(SkipNode_Alloc) -> VG_(arena_malloc) -> newSuperblock -> VG_(get_memory_from_mmap) -> VG_(mmap) git-svn-id: svn://svn.valgrind.org/vex/trunk@388 --- diff --git a/VEX/head20041019/coregrind/vg_skiplist.c b/VEX/head20041019/coregrind/vg_skiplist.c index a02fb65d0a..ae34aa08e0 100644 --- a/VEX/head20041019/coregrind/vg_skiplist.c +++ b/VEX/head20041019/coregrind/vg_skiplist.c @@ -86,6 +86,28 @@ #include +/* ----------------- Hacky allocator -----------------*/ +#define HACKY_SIZE 100000 +static Int hacky_used = 0; +static UChar hacky[HACKY_SIZE]; + +static void* hacky_alloc ( UInt n ) +{ + UChar* p; + n = (n + 3) & ~3; + if (n + hacky_used >= HACKY_SIZE) + VG_(core_panic)("hacky_alloc: HACKY_SIZE too low; increase and recompile"); + p = &hacky[hacky_used]; + hacky_used += n; + return (void*)p; +} + +static void hacky_free ( void* p ) +{ +} +/* ----------------- end Hacky allocator -----------------*/ + + #define SKIPLIST_DEBUG 0 #define SK_MAXHEIGHT 20 /* 2^20 elements */ @@ -223,7 +245,7 @@ void *VG_(SkipNode_Alloc)(const SkipList *l) if (l->arena == -1) *(Short *)&l->arena = VG_AR_TOOL; - ret = VG_(arena_malloc)(l->arena, size); + ret = hacky_alloc(size); if (ret == NULL) return NULL; @@ -246,7 +268,7 @@ void VG_(SkipNode_Free)(const SkipList *l, void *p) p, n); n->magic = 0x55ffaabb; } - VG_(arena_free)(l->arena, p); + hacky_free(p); } void *VG_(SkipNode_First)(const SkipList *l) @@ -367,7 +389,7 @@ void VG_(SkipList_Insert)(SkipList *l, void *data) if (l->arena == -1) *(Short *)&l->arena = VG_AR_TOOL; - l->head = VG_(arena_malloc)(l->arena, size); + l->head = hacky_alloc(size); VG_(memset)(l->head, 0, size); l->head->magic = SKIPLIST_HEAD_MAGIC;