Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r1145:16bd0be67e44 Date: 2014-04-09 08:51 +0200 http://bitbucket.org/pypy/stmgc/changeset/16bd0be67e44/
Log: merge heads diff --git a/c7/gdb/gdb_stm.py b/c7/gdb/gdb_stm.py new file mode 100644 --- /dev/null +++ b/c7/gdb/gdb_stm.py @@ -0,0 +1,49 @@ +""" Adds two built-in functions: $rfs(p=0) and $rgs(p=0). + +Returns the number or the address 'p', offset with the value of +the %fs or %gs register in the current thread. + +Usage: you can for example add this line in your ~/.gdbinit: + + python execfile('/path/to/gdb_stm.py') +""" +import gdb + +def gdb_function(func): + class Func(gdb.Function): + __doc__ = func.__doc__ + invoke = staticmethod(func) + Func(func.__name__) + +# ------------------------------------------------------- + +SEG_FS = 0x1003 +SEG_GS = 0x1004 + +def get_segment_register(which): + v = gdb.parse_and_eval('(long*)malloc(8)') + L = gdb.lookup_type('long') + gdb.parse_and_eval('arch_prctl(%d, %d)' % (which, int(v.cast(L)))) + result = int(v.dereference()) + gdb.parse_and_eval('free(%d)' % (int(v.cast(L)),)) + return result + +def rfsrgs(name, which): + seg = get_segment_register(which) + if name is None: + return seg + tp = name.type + if tp.code == gdb.TYPE_CODE_INT: + return name + seg + assert tp.code == gdb.TYPE_CODE_PTR + L = gdb.lookup_type('long') + return (name.cast(L) + seg).cast(tp) + +@gdb_function +def rfs(name=None): + return rfsrgs(name, SEG_FS) + +@gdb_function +def rgs(name=None): + return rfsrgs(name, SEG_GS) + diff --git a/c7/stm/gcpage.c b/c7/stm/gcpage.c --- a/c7/stm/gcpage.c +++ b/c7/stm/gcpage.c @@ -80,7 +80,6 @@ /* thread-safe: use the lock of pages.c to prevent any remapping from occurring under our feet */ mutex_pages_lock(); - increment_total_allocated(size + LARGE_MALLOC_OVERHEAD); /* Allocate the object with largemalloc.c from the lower addresses. */ char *addr = _stm_large_malloc(size); diff --git a/c7/stm/largemalloc.c b/c7/stm/largemalloc.c --- a/c7/stm/largemalloc.c +++ b/c7/stm/largemalloc.c @@ -52,6 +52,7 @@ #define BOTH_CHUNKS_USED 0 #define CHUNK_HEADER_SIZE offsetof(struct malloc_chunk, d) #define END_MARKER 0xDEADBEEF +#define MIN_ALLOC_SIZE (sizeof(struct malloc_chunk) - CHUNK_HEADER_SIZE) #define chunk_at_offset(p, ofs) ((mchunk_t *)(((char *)(p)) + (ofs))) #define data2chunk(p) chunk_at_offset(p, -CHUNK_HEADER_SIZE) @@ -88,7 +89,7 @@ The additional chunks of a given size are linked "vertically" in the secondary 'u' doubly-linked list. - + +-----+ | 296 | +-----+ @@ -258,8 +259,8 @@ /* it can be very small, but we need to ensure a minimal size (currently 32 bytes) */ - if (request_size < sizeof(struct malloc_chunk) - CHUNK_HEADER_SIZE) - request_size = sizeof(struct malloc_chunk) - CHUNK_HEADER_SIZE; + if (request_size < MIN_ALLOC_SIZE) + request_size = MIN_ALLOC_SIZE; size_t index = largebin_index(request_size); sort_bin(index); @@ -333,6 +334,7 @@ } mscan->size = request_size; mscan->prev_size = BOTH_CHUNKS_USED; + increment_total_allocated(request_size + LARGE_MALLOC_OVERHEAD); return (char *)&mscan->d; } @@ -343,6 +345,9 @@ assert((chunk->size & (sizeof(char *) - 1)) == 0); assert(chunk->prev_size != THIS_CHUNK_FREE); + /* 'size' is at least MIN_ALLOC_SIZE */ + increment_total_allocated(-(chunk->size + LARGE_MALLOC_OVERHEAD)); + #ifndef NDEBUG assert(chunk->size >= sizeof(dlist_t)); assert(chunk->size <= (((char *)last_chunk) - (char *)data)); @@ -554,7 +559,6 @@ chunk = next_chunk(chunk); /* go to the first non-free chunk */ while (chunk != last_chunk) { - /* here, the chunk we're pointing to is not free */ assert(chunk->prev_size != THIS_CHUNK_FREE); @@ -566,8 +570,6 @@ /* use the callback to know if 'chunk' contains an object that survives or dies */ if (!_largemalloc_sweep_keep(chunk)) { - size_t size = chunk->size; - increment_total_allocated(-(size + LARGE_MALLOC_OVERHEAD)); _stm_large_free((char *)&chunk->d); /* dies */ } chunk = mnext; diff --git a/c7/stm/nursery.c b/c7/stm/nursery.c --- a/c7/stm/nursery.c +++ b/c7/stm/nursery.c @@ -243,7 +243,6 @@ } char *realobj = REAL_ADDRESS(pseg->pub.segment_base, item->addr); ssize_t size = stmcb_size_rounded_up((struct object_s *)realobj); - increment_total_allocated(-(size + LARGE_MALLOC_OVERHEAD)); _stm_large_free(stm_object_pages + item->addr); } TREE_LOOP_END; _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit