2009-07-06 16:34:04 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2014-08-05 12:32:24 -06:00
|
|
|
// Runtime type representation.
|
2009-07-06 16:34:04 -06:00
|
|
|
|
reflect: add ArrayOf, ChanOf, MapOf, SliceOf
In order to add these, we need to be able to find references
to such types that already exist in the binary. To do that, introduce
a new linker section holding a list of the types corresponding to
arrays, chans, maps, and slices.
To offset the storage cost of this list, and to simplify the code,
remove the interface{} header from the representation of a
runtime type. It was used in early versions of the code but was
made obsolete by the kind field: a switch on kind is more efficient
than a type switch.
In the godoc binary, removing the interface{} header cuts two
words from each of about 10,000 types. Adding back the list of pointers
to array, chan, map, and slice types reintroduces one word for
each of about 500 types. On a 64-bit machine, then, this CL *removes*
a net 156 kB of read-only data from the binary.
This CL does not include the needed support for precise garbage
collection. I have created issue 4375 to track that.
This CL also does not set the 'algorithm' - specifically the equality
and copy functions - for a new array correctly, so I have unexported
ArrayOf for now. That is also part of issue 4375.
Fixes #2339.
R=r, remyoudompheng, mirtchovski, iant
CC=golang-dev
https://golang.org/cl/6572043
2012-11-13 11:06:29 -07:00
|
|
|
typedef struct Type Type;
|
2009-07-06 16:34:04 -06:00
|
|
|
typedef struct UncommonType UncommonType;
|
|
|
|
typedef struct InterfaceType InterfaceType;
|
|
|
|
typedef struct Method Method;
|
|
|
|
typedef struct IMethod IMethod;
|
2009-12-04 22:44:05 -07:00
|
|
|
typedef struct SliceType SliceType;
|
2010-02-03 17:31:34 -07:00
|
|
|
typedef struct FuncType FuncType;
|
2009-07-06 16:34:04 -06:00
|
|
|
|
2014-08-05 12:32:24 -06:00
|
|
|
// Needs to be in sync with ../../cmd/ld/decodesym.c:/^commonsize and pkg/reflect/type.go:/type.
|
reflect: add ArrayOf, ChanOf, MapOf, SliceOf
In order to add these, we need to be able to find references
to such types that already exist in the binary. To do that, introduce
a new linker section holding a list of the types corresponding to
arrays, chans, maps, and slices.
To offset the storage cost of this list, and to simplify the code,
remove the interface{} header from the representation of a
runtime type. It was used in early versions of the code but was
made obsolete by the kind field: a switch on kind is more efficient
than a type switch.
In the godoc binary, removing the interface{} header cuts two
words from each of about 10,000 types. Adding back the list of pointers
to array, chan, map, and slice types reintroduces one word for
each of about 500 types. On a 64-bit machine, then, this CL *removes*
a net 156 kB of read-only data from the binary.
This CL does not include the needed support for precise garbage
collection. I have created issue 4375 to track that.
This CL also does not set the 'algorithm' - specifically the equality
and copy functions - for a new array correctly, so I have unexported
ArrayOf for now. That is also part of issue 4375.
Fixes #2339.
R=r, remyoudompheng, mirtchovski, iant
CC=golang-dev
https://golang.org/cl/6572043
2012-11-13 11:06:29 -07:00
|
|
|
struct Type
|
2009-07-06 16:34:04 -06:00
|
|
|
{
|
|
|
|
uintptr size;
|
|
|
|
uint32 hash;
|
2011-12-05 07:40:22 -07:00
|
|
|
uint8 _unused;
|
2009-07-06 16:34:04 -06:00
|
|
|
uint8 align;
|
|
|
|
uint8 fieldAlign;
|
2009-12-04 22:44:05 -07:00
|
|
|
uint8 kind;
|
2014-08-29 22:40:56 -06:00
|
|
|
void* alg;
|
2014-07-29 01:01:02 -06:00
|
|
|
// gc stores type info required for garbage collector.
|
|
|
|
// If (kind&KindGCProg)==0, then gc directly contains sparse GC bitmap
|
|
|
|
// (no indirection), 4 bits per word.
|
|
|
|
// If (kind&KindGCProg)!=0, then gc[1] points to a compiler-generated
|
|
|
|
// read-only GC program; and gc[0] points to BSS space for sparse GC bitmap.
|
|
|
|
// For huge types (>MaxGCMask), runtime unrolls the program directly into
|
|
|
|
// GC bitmap and gc[0] is not used. For moderately-sized types, runtime
|
|
|
|
// unrolls the program into gc[0] space on first use. The first byte of gc[0]
|
|
|
|
// (gc[0][0]) contains 'unroll' flag saying whether the program is already
|
|
|
|
// unrolled into gc[0] or not.
|
|
|
|
uintptr gc[2];
|
2009-07-06 16:34:04 -06:00
|
|
|
String *string;
|
|
|
|
UncommonType *x;
|
2011-02-24 15:11:20 -07:00
|
|
|
Type *ptrto;
|
2013-12-02 14:05:04 -07:00
|
|
|
byte *zero; // ptr to the zero value for this type
|
2009-07-06 16:34:04 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Method
|
|
|
|
{
|
|
|
|
String *name;
|
|
|
|
String *pkgPath;
|
2010-01-25 19:23:20 -07:00
|
|
|
Type *mtyp;
|
2009-07-06 16:34:04 -06:00
|
|
|
Type *typ;
|
|
|
|
void (*ifn)(void);
|
|
|
|
void (*tfn)(void);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UncommonType
|
|
|
|
{
|
|
|
|
String *name;
|
|
|
|
String *pkgPath;
|
2009-08-25 16:54:25 -06:00
|
|
|
Slice mhdr;
|
2009-07-06 16:34:04 -06:00
|
|
|
Method m[];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct IMethod
|
|
|
|
{
|
|
|
|
String *name;
|
|
|
|
String *pkgPath;
|
|
|
|
Type *type;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct InterfaceType
|
|
|
|
{
|
2014-08-07 07:00:02 -06:00
|
|
|
Type typ;
|
2009-08-25 16:54:25 -06:00
|
|
|
Slice mhdr;
|
2009-07-06 16:34:04 -06:00
|
|
|
IMethod m[];
|
|
|
|
};
|
2009-07-08 14:55:57 -06:00
|
|
|
|
|
|
|
struct MapType
|
|
|
|
{
|
2014-08-07 07:00:02 -06:00
|
|
|
Type typ;
|
2009-07-08 14:55:57 -06:00
|
|
|
Type *key;
|
|
|
|
Type *elem;
|
2014-08-01 15:38:56 -06:00
|
|
|
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
|
2009-07-08 14:55:57 -06:00
|
|
|
};
|
2009-07-08 16:00:54 -06:00
|
|
|
|
|
|
|
struct ChanType
|
|
|
|
{
|
2014-08-07 07:00:02 -06:00
|
|
|
Type typ;
|
2009-07-08 16:00:54 -06:00
|
|
|
Type *elem;
|
|
|
|
uintptr dir;
|
|
|
|
};
|
2009-12-04 22:44:05 -07:00
|
|
|
|
|
|
|
struct SliceType
|
|
|
|
{
|
2014-08-07 07:00:02 -06:00
|
|
|
Type typ;
|
2009-12-04 22:44:05 -07:00
|
|
|
Type *elem;
|
|
|
|
};
|
2010-02-03 17:31:34 -07:00
|
|
|
|
|
|
|
struct FuncType
|
|
|
|
{
|
2014-08-07 07:00:02 -06:00
|
|
|
Type typ;
|
2010-02-03 17:31:34 -07:00
|
|
|
bool dotdotdot;
|
|
|
|
Slice in;
|
|
|
|
Slice out;
|
|
|
|
};
|
2012-10-21 15:41:32 -06:00
|
|
|
|
|
|
|
struct PtrType
|
|
|
|
{
|
2014-08-07 07:00:02 -06:00
|
|
|
Type typ;
|
2012-10-21 15:41:32 -06:00
|
|
|
Type *elem;
|
|
|
|
};
|