]> Cypherpunks repositories - gostls13.git/commit
cmd/compile, etc: store method tables as offsets
authorDavid Crawshaw <crawshaw@golang.org>
Mon, 28 Mar 2016 14:32:27 +0000 (10:32 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Wed, 13 Apr 2016 13:03:11 +0000 (13:03 +0000)
commit7d469179e6e3dafe16700b7fc1cf8683ad9453fa
tree69ff99cdb375349ed12eb849e1a895da68afcc9c
parente0611b16645dba6768cab405f1ec1b3fce83334a
cmd/compile, etc: store method tables as offsets

This CL introduces the typeOff type and a lookup method of the same
name that can turn a typeOff offset into an *rtype.

In a typical Go binary (built with buildmode=exe, pie, c-archive, or
c-shared), there is one moduledata and all typeOff values are offsets
relative to firstmoduledata.types. This makes computing the pointer
cheap in typical programs.

With buildmode=shared (and one day, buildmode=plugin) there are
multiple modules whose relative offset is determined at runtime.
We identify a type in the general case by the pair of the original
*rtype that references it and its typeOff value. We determine
the module from the original pointer, and then use the typeOff from
there to compute the final *rtype.

To ensure there is only one *rtype representing each type, the
runtime initializes a typemap for each module, using any identical
type from an earlier module when resolving that offset. This means
that types computed from an offset match the type mapped by the
pointer dynamic relocations.

A series of followup CLs will replace other *rtype values with typeOff
(and name/*string with nameOff).

For types created at runtime by reflect, type offsets are treated as
global IDs and reference into a reflect offset map kept by the runtime.

darwin/amd64:
cmd/go:  -57KB (0.6%)
jujud:  -557KB (0.8%)

linux/amd64 PIE:
cmd/go: -361KB (3.0%)
jujud:  -3.5MB (4.2%)

For #6853.

Change-Id: Icf096fd884a0a0cb9f280f46f7a26c70a9006c96
Reviewed-on: https://go-review.googlesource.com/21285
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
12 files changed:
src/cmd/compile/internal/gc/reflect.go
src/cmd/internal/obj/link.go
src/cmd/link/internal/ld/deadcode.go
src/cmd/link/internal/ld/decodesym.go
src/reflect/export_test.go
src/reflect/type.go
src/reflect/value.go
src/runtime/iface.go
src/runtime/proc.go
src/runtime/runtime1.go
src/runtime/symtab.go
src/runtime/type.go