diff options
author | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-10-25 08:02:28 +0000 |
---|---|---|
committer | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-10-25 08:02:28 +0000 |
commit | f9a64dbd998f7761e6a06fc71052346d7f76c7f4 (patch) | |
tree | 3608e9a4fa99bbcc7d88dda34b1619a4ac4b122b /libgo/runtime/malloc.h | |
parent | 29a742dc2ec93b766a342fa6fb65da055c5417fc (diff) | |
download | gcc-f9a64dbd998f7761e6a06fc71052346d7f76c7f4.tar.gz |
2012-10-25 Basile Starynkevitch <basile@starynkevitch.net>
MELT branch merged with trunk rev 192797 using svnmerge.py
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@192798 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/runtime/malloc.h')
-rw-r--r-- | libgo/runtime/malloc.h | 97 |
1 files changed, 78 insertions, 19 deletions
diff --git a/libgo/runtime/malloc.h b/libgo/runtime/malloc.h index 96cb609367f..61f0f703a24 100644 --- a/libgo/runtime/malloc.h +++ b/libgo/runtime/malloc.h @@ -85,6 +85,7 @@ typedef struct MHeap MHeap; typedef struct MSpan MSpan; typedef struct MStats MStats; typedef struct MLink MLink; +typedef struct MTypes MTypes; enum { @@ -124,8 +125,8 @@ enum // Max number of threads to run garbage collection. // 2, 3, and 4 are all plausible maximums depending // on the hardware details of the machine. The garbage - // collector scales well to 4 cpus. - MaxGcproc = 4, + // collector scales well to 8 cpus. + MaxGcproc = 8, }; // Maximum memory allocation size, a hint for callers. @@ -282,19 +283,19 @@ struct MCacheList struct MCache { MCacheList list[NumSizeClasses]; - uint64 size; - int64 local_cachealloc; // bytes allocated (or freed) from cache since last lock of heap - int64 local_objects; // objects allocated (or freed) from cache since last lock of heap - int64 local_alloc; // bytes allocated (or freed) since last lock of heap - int64 local_total_alloc; // bytes allocated (even if freed) since last lock of heap - int64 local_nmalloc; // number of mallocs since last lock of heap - int64 local_nfree; // number of frees since last lock of heap - int64 local_nlookup; // number of pointer lookups since last lock of heap + uintptr size; + intptr local_cachealloc; // bytes allocated (or freed) from cache since last lock of heap + intptr local_objects; // objects allocated (or freed) from cache since last lock of heap + intptr local_alloc; // bytes allocated (or freed) since last lock of heap + uintptr local_total_alloc; // bytes allocated (even if freed) since last lock of heap + uintptr local_nmalloc; // number of mallocs since last lock of heap + uintptr local_nfree; // number of frees since last lock of heap + uintptr local_nlookup; // number of pointer lookups since last lock of heap int32 next_sample; // trigger heap sample after allocating this many bytes // Statistics about allocation size classes since last lock of heap struct { - int64 nmalloc; - int64 nfree; + uintptr nmalloc; + uintptr nfree; } local_by_size[NumSizeClasses]; }; @@ -303,6 +304,44 @@ void* runtime_MCache_Alloc(MCache *c, int32 sizeclass, uintptr size, int32 zeroe void runtime_MCache_Free(MCache *c, void *p, int32 sizeclass, uintptr size); void runtime_MCache_ReleaseAll(MCache *c); +// MTypes describes the types of blocks allocated within a span. +// The compression field describes the layout of the data. +// +// MTypes_Empty: +// All blocks are free, or no type information is available for +// allocated blocks. +// The data field has no meaning. +// MTypes_Single: +// The span contains just one block. +// The data field holds the type information. +// The sysalloc field has no meaning. +// MTypes_Words: +// The span contains multiple blocks. +// The data field points to an array of type [NumBlocks]uintptr, +// and each element of the array holds the type of the corresponding +// block. +// MTypes_Bytes: +// The span contains at most seven different types of blocks. +// The data field points to the following structure: +// struct { +// type [8]uintptr // type[0] is always 0 +// index [NumBlocks]byte +// } +// The type of the i-th block is: data.type[data.index[i]] +enum +{ + MTypes_Empty = 0, + MTypes_Single = 1, + MTypes_Words = 2, + MTypes_Bytes = 3, +}; +struct MTypes +{ + byte compression; // one of MTypes_* + bool sysalloc; // whether (void*)data is from runtime_SysAlloc + uintptr data; +}; + // An MSpan is a run of pages. enum { @@ -315,16 +354,17 @@ struct MSpan { MSpan *next; // in a span linked list MSpan *prev; // in a span linked list - MSpan *allnext; // in the list of all spans PageID start; // starting page number uintptr npages; // number of pages in span MLink *freelist; // list of free objects uint32 ref; // number of allocated objects in this span uint32 sizeclass; // size class + uintptr elemsize; // computed from sizeclass or from npages uint32 state; // MSpanInUse etc int64 unusedsince; // First time spotted by GC in MSpanFree state uintptr npreleased; // number of pages released to the OS byte *limit; // end of data in span + MTypes types; // types of allocated objects in this span }; void runtime_MSpan_Init(MSpan *span, PageID start, uintptr npages); @@ -351,6 +391,7 @@ struct MCentral void runtime_MCentral_Init(MCentral *c, int32 sizeclass); int32 runtime_MCentral_AllocList(MCentral *c, int32 n, MLink **first); void runtime_MCentral_FreeList(MCentral *c, int32 n, MLink *first); +void runtime_MCentral_FreeSpan(MCentral *c, MSpan *s, int32 n, MLink *start, MLink *end); // Main malloc heap. // The heap itself is the "free[]" and "large" arrays, @@ -360,7 +401,9 @@ struct MHeap Lock; MSpan free[MaxMHeapList]; // free lists of given length MSpan large; // free lists length >= MaxMHeapList - MSpan *allspans; + MSpan **allspans; + uint32 nspan; + uint32 nspancap; // span lookup MSpan *map[1<<MHeapMap_Bits]; @@ -387,7 +430,7 @@ struct MHeap extern MHeap runtime_mheap; void runtime_MHeap_Init(MHeap *h, void *(*allocator)(uintptr)); -MSpan* runtime_MHeap_Alloc(MHeap *h, uintptr npage, int32 sizeclass, int32 acct); +MSpan* runtime_MHeap_Alloc(MHeap *h, uintptr npage, int32 sizeclass, int32 acct, int32 zeroed); void runtime_MHeap_Free(MHeap *h, MSpan *s, int32 acct); MSpan* runtime_MHeap_Lookup(MHeap *h, void *v); MSpan* runtime_MHeap_LookupMaybe(MHeap *h, void *v); @@ -408,7 +451,12 @@ void runtime_markspan(void *v, uintptr size, uintptr n, bool leftover); void runtime_unmarkspan(void *v, uintptr size); bool runtime_blockspecial(void*); void runtime_setblockspecial(void*, bool); -void runtime_purgecachedstats(M*); +void runtime_purgecachedstats(MCache*); + +void runtime_settype(void*, uintptr); +void runtime_settype_flush(M*, bool); +void runtime_settype_sysfree(MSpan*); +uintptr runtime_gettype(void*); enum { @@ -421,10 +469,21 @@ enum void runtime_MProf_Malloc(void*, uintptr); void runtime_MProf_Free(void*, uintptr); void runtime_MProf_GC(void); -void runtime_MProf_Mark(void (*scan)(byte *, int64)); -int32 runtime_helpgc(bool*); +void runtime_MProf_Mark(void (*addroot)(byte *, uintptr)); +int32 runtime_gcprocs(void); +void runtime_helpgc(int32 nproc); void runtime_gchelper(void); struct __go_func_type; bool runtime_getfinalizer(void *p, bool del, void (**fn)(void*), const struct __go_func_type **ft); -void runtime_walkfintab(void (*fn)(void*), void (*scan)(byte *, int64)); +void runtime_walkfintab(void (*fn)(void*), void (*scan)(byte *, uintptr)); + +enum +{ + TypeInfo_SingleObject = 0, + TypeInfo_Array = 1, + TypeInfo_Map = 2, + + // Enables type information at the end of blocks allocated from heap + DebugTypeAtBlockEnd = 0, +}; |