Commit 668a55a8 authored by Keith Randall's avatar Keith Randall

runtime: move constants from map header to map type

A good cleanup anyway, and it makes some room for an additional
field needed for issue 8412.

Update #8412

LGTM=iant
R=iant, khr
CC=golang-codereviews
https://golang.org/cl/112700043
parent 6d20e725
......@@ -192,7 +192,7 @@ mapbucket(Type *t)
// the given map type. This type is not visible to users -
// we include only enough information to generate a correct GC
// program for it.
// Make sure this stays in sync with ../../pkg/runtime/hashmap.c!
// Make sure this stays in sync with ../../pkg/runtime/hashmap.go!
static Type*
hmap(Type *t)
{
......@@ -211,10 +211,6 @@ hmap(Type *t)
offset += 4; // flags
offset += 4; // hash0
offset += 1; // B
offset += 1; // keysize
offset += 1; // valuesize
offset = (offset + 1) / 2 * 2;
offset += 2; // bucketsize
offset = (offset + widthptr - 1) / widthptr * widthptr;
bucketsfield = typ(TFIELD);
......@@ -568,6 +564,7 @@ dextratype(Sym *sym, int off, Type *t, int ptroff)
return off;
// fill in *extraType pointer in header
off = rnd(off, widthptr);
dsymptr(sym, ptroff, sym, off);
n = 0;
......@@ -1090,6 +1087,21 @@ ok:
ot = dsymptr(s, ot, s2, 0);
ot = dsymptr(s, ot, s3, 0);
ot = dsymptr(s, ot, s4, 0);
if(t->down->width > MAXKEYSIZE) {
ot = duint8(s, ot, widthptr);
ot = duint8(s, ot, 1); // indirect
} else {
ot = duint8(s, ot, t->down->width);
ot = duint8(s, ot, 0); // not indirect
}
if(t->type->width > MAXVALSIZE) {
ot = duint8(s, ot, widthptr);
ot = duint8(s, ot, 1); // indirect
} else {
ot = duint8(s, ot, t->type->width);
ot = duint8(s, ot, 0); // not indirect
}
ot = duint16(s, ot, mapbucket(t)->width);
break;
case TPTR32:
......
......@@ -323,11 +323,16 @@ type interfaceType struct {
// mapType represents a map type.
type mapType struct {
rtype `reflect:"map"`
key *rtype // map key type
elem *rtype // map element (value) type
bucket *rtype // internal bucket structure
hmap *rtype // internal map header
rtype `reflect:"map"`
key *rtype // map key type
elem *rtype // map element (value) type
bucket *rtype // internal bucket structure
hmap *rtype // internal map header
keysize uint8 // size of key slot
indirectkey uint8 // store ptr to key instead of key itself
valuesize uint8 // size of value slot
indirectvalue uint8 // store ptr to value instead of value itself
bucketsize uint16 // size of bucket
}
// ptrType represents a pointer type.
......@@ -1454,6 +1459,21 @@ func MapOf(key, elem Type) Type {
mt.key = ktyp
mt.elem = etyp
mt.bucket = bucketOf(ktyp, etyp)
if ktyp.size > maxKeySize {
mt.keysize = uint8(ptrSize)
mt.indirectkey = 1
} else {
mt.keysize = uint8(ktyp.size)
mt.indirectkey = 0
}
if etyp.size > maxValSize {
mt.valuesize = uint8(ptrSize)
mt.indirectvalue = 1
} else {
mt.valuesize = uint8(etyp.size)
mt.indirectvalue = 0
}
mt.bucketsize = uint16(mt.bucket.size)
mt.uncommonType = nil
mt.ptrToThis = nil
mt.zero = unsafe.Pointer(&make([]byte, mt.size)[0])
......@@ -1543,7 +1563,7 @@ const (
bitsPointer = 2
)
// Make sure these routines stay in sync with ../../pkg/runtime/hashmap.c!
// Make sure these routines stay in sync with ../../pkg/runtime/hashmap.go!
// These types exist only for GC, so we only fill out GC relevant info.
// Currently, that's just size and the GC program. We also fill in string
// for possible debugging use.
......
This diff is collapsed.
This diff is collapsed.
......@@ -81,8 +81,13 @@ struct MapType
Type;
Type *key;
Type *elem;
Type *bucket; // internal type representing a hash bucket
Type *hmap; // internal type representing a Hmap
Type *bucket; // internal type representing a hash bucket
Type *hmap; // internal type representing a Hmap
uint8 keysize; // size of key slot
bool indirectkey; // store ptr to key instead of key itself
uint8 valuesize; // size of value slot
bool indirectvalue; // store ptr to value instead of value itself
uint16 bucketsize; // size of bucket
};
struct ChanType
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment