diff options
author | Ian Lance Taylor <iant@golang.org> | 2016-09-21 20:58:51 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2016-09-21 20:58:51 +0000 |
commit | 4a2bb7fcb0c8507b958afb3d22ddfeeba494148a (patch) | |
tree | 843fadb26050988a8c6037662e2d090533437044 /libgo/runtime/mgc0.c | |
parent | 812b1403a88cea3257e120f3234576f236c0921d (diff) | |
download | gcc-4a2bb7fcb0c8507b958afb3d22ddfeeba494148a.zip gcc-4a2bb7fcb0c8507b958afb3d22ddfeeba494148a.tar.gz gcc-4a2bb7fcb0c8507b958afb3d22ddfeeba494148a.tar.bz2 |
compiler, runtime: replace hashmap code with Go 1.7 hashmap
This change removes the gccgo-specific hashmap code and replaces it with
the hashmap code from the Go 1.7 runtime. The Go 1.7 hashmap code is
more efficient, does a better job on details like when to update a key,
and provides some support against denial-of-service attacks.
The compiler is changed to call the new hashmap functions instead of the
old ones.
The compiler now tracks which types are reflexive and which require
updating when used as a map key, and records the information in map type
descriptors.
Map_index_expression is simplified. The special case for a map index on
the right hand side of a tuple expression has been unnecessary for some
time, and is removed. The support for specially marking a map index as
an lvalue is removed, in favor of lowering an assignment to a map index
into a function call. The long-obsolete support for a map index of a
pointer to a map is removed.
The __go_new_map_big function (known to the compiler as
Runtime::MAKEMAPBIG) is no longer needed, as the new runtime.makemap
function takes an int64 hint argument.
The old map descriptor type and supporting expression is removed.
The compiler was still supporting the long-obsolete syntax `m[k] = 0,
false` to delete a value from a map. That is now removed, requiring a
change to one of the gccgo-specific tests.
The builtin len function applied to a map or channel p is now compiled
as `p == nil ? 0 : *(*int)(p)`. The __go_chan_len function (known to
the compiler as Runtime::CHAN_LEN) is removed.
Support for a shared zero value for maps to large value types is
introduced, along the lines of the gc compiler. The zero value is
handled as a common variable.
The hash function is changed to take a seed argument, changing the
runtime hash functions and the compiler-generated hash functions.
Unlike the gc compiler, both the hash and equal functions continue to
take the type length.
Types that can not be compared now store nil for the hash and equal
functions, rather than pointing to functions that throw. Interface hash
and comparison functions now check explicitly for nil. This matches the
gc compiler and permits a simple implementation for ismapkey.
The compiler is changed to permit marking struct and array types as
incomparable, meaning that they have no hash or equal function. We use
this for thunk types, removing the existing special code to avoid
generating hash/equal functions for them.
The C runtime code adds memclr, memequal, and memmove functions.
The hashmap code uses go:linkname comments to make the functions
visible, as otherwise the compiler would discard them.
The hashmap code comments out the unused reference to the address of the
first parameter in the race code, as otherwise the compiler thinks that
the parameter escapes and copies it onto the heap. This is probably not
needed when we enable escape analysis.
Several runtime map tests that ere previously skipped for gccgo are now
run.
The Go runtime picks up type kind information and stubs. The type kind
information causes the generated runtime header file to define some
constants, including `empty`, and the C code is adjusted accordingly.
A Go-callable version of runtime.throw, that takes a Go string, is
added to be called from the hashmap code.
Reviewed-on: https://go-review.googlesource.com/29447
* go.go-torture/execute/map-1.go: Replace old map deletion syntax
with call to builtin delete function.
From-SVN: r240334
Diffstat (limited to 'libgo/runtime/mgc0.c')
-rw-r--r-- | libgo/runtime/mgc0.c | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/libgo/runtime/mgc0.c b/libgo/runtime/mgc0.c index 1f6a40c..341544c 100644 --- a/libgo/runtime/mgc0.c +++ b/libgo/runtime/mgc0.c @@ -69,9 +69,6 @@ typedef struct __go_map Hmap; // Type aka __go_type_descriptor #define string __reflection -#define KindPtr GO_PTR -#define KindNoPointers GO_NO_POINTERS -#define kindMask GO_CODE_MASK // PtrType aka __go_ptr_type #define elem __element_type @@ -216,7 +213,7 @@ static void addstackroots(G *gp, Workbuf **wbufp); static struct { uint64 full; // lock-free list of full blocks - uint64 empty; // lock-free list of empty blocks + uint64 wempty; // lock-free list of empty blocks byte pad0[CacheLineSize]; // prevents false-sharing between full/empty and nproc/nwait uint32 nproc; int64 tstart; @@ -943,16 +940,16 @@ scanblock(Workbuf *wbuf, bool keepworking) // eface->__object if((byte*)eface->__object >= arena_start && (byte*)eface->__object < arena_used) { if(__go_is_pointer_type(t)) { - if((t->__code & KindNoPointers)) + if((t->__code & kindNoPointers)) continue; obj = eface->__object; - if((t->__code & kindMask) == KindPtr) { + if((t->__code & kindMask) == kindPtr) { // Only use type information if it is a pointer-containing type. // This matches the GC programs written by cmd/gc/reflect.c's // dgcsym1 in case TPTR32/case TPTR64. See rationale there. et = ((const PtrType*)t)->elem; - if(!(et->__code & KindNoPointers)) + if(!(et->__code & kindNoPointers)) objti = (uintptr)((const PtrType*)t)->elem->__gc; } } else { @@ -981,16 +978,16 @@ scanblock(Workbuf *wbuf, bool keepworking) if((byte*)iface->__object >= arena_start && (byte*)iface->__object < arena_used) { t = (const Type*)iface->tab[0]; if(__go_is_pointer_type(t)) { - if((t->__code & KindNoPointers)) + if((t->__code & kindNoPointers)) continue; obj = iface->__object; - if((t->__code & kindMask) == KindPtr) { + if((t->__code & kindMask) == kindPtr) { // Only use type information if it is a pointer-containing type. // This matches the GC programs written by cmd/gc/reflect.c's // dgcsym1 in case TPTR32/case TPTR64. See rationale there. et = ((const PtrType*)t)->elem; - if(!(et->__code & KindNoPointers)) + if(!(et->__code & kindNoPointers)) objti = (uintptr)((const PtrType*)t)->elem->__gc; } } else { @@ -1101,7 +1098,7 @@ scanblock(Workbuf *wbuf, bool keepworking) } if(markonly(chan)) { chantype = (ChanType*)pc[2]; - if(!(chantype->elem->__code & KindNoPointers)) { + if(!(chantype->elem->__code & kindNoPointers)) { // Start chanProg. chan_ret = pc+3; pc = chanProg+1; @@ -1114,7 +1111,7 @@ scanblock(Workbuf *wbuf, bool keepworking) case GC_CHAN: // There are no heap pointers in struct Hchan, // so we can ignore the leading sizeof(Hchan) bytes. - if(!(chantype->elem->__code & KindNoPointers)) { + if(!(chantype->elem->__code & kindNoPointers)) { // Channel's buffer follows Hchan immediately in memory. // Size of buffer (cap(c)) is second int in the chan struct. chancap = ((uintgo*)chan)[1]; @@ -1377,7 +1374,7 @@ getempty(Workbuf *b) { if(b != nil) runtime_lfstackpush(&work.full, &b->node); - b = (Workbuf*)runtime_lfstackpop(&work.empty); + b = (Workbuf*)runtime_lfstackpop(&work.wempty); if(b == nil) { // Need to allocate. runtime_lock(&work); @@ -1402,7 +1399,7 @@ putempty(Workbuf *b) if(CollectStats) runtime_xadd64(&gcstats.putempty, 1); - runtime_lfstackpush(&work.empty, &b->node); + runtime_lfstackpush(&work.wempty, &b->node); } // Get a full work buffer off the work.full list, or return nil. @@ -1416,7 +1413,7 @@ getfull(Workbuf *b) runtime_xadd64(&gcstats.getfull, 1); if(b != nil) - runtime_lfstackpush(&work.empty, &b->node); + runtime_lfstackpush(&work.wempty, &b->node); b = (Workbuf*)runtime_lfstackpop(&work.full); if(b != nil || work.nproc == 1) return b; @@ -2129,7 +2126,7 @@ runtime_gc(int32 force) // The atomic operations are not atomic if the uint64s // are not aligned on uint64 boundaries. This has been // a problem in the past. - if((((uintptr)&work.empty) & 7) != 0) + if((((uintptr)&work.wempty) & 7) != 0) runtime_throw("runtime: gc work buffer is misaligned"); if((((uintptr)&work.full) & 7) != 0) runtime_throw("runtime: gc work buffer is misaligned"); @@ -2522,7 +2519,7 @@ runfinq(void* dummy __attribute__ ((unused))) f = &fb->fin[i]; fint = ((const Type**)f->ft->__in.array)[0]; - if((fint->__code & kindMask) == KindPtr) { + if((fint->__code & kindMask) == kindPtr) { // direct use of pointer param = &f->arg; } else if(((const InterfaceType*)fint)->__methods.__count == 0) { |