aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorDavid Crawshaw <crawshaw@golang.org>2016-03-14 21:30:43 -0400
committerDavid Crawshaw <crawshaw@golang.org>2016-03-15 19:57:40 +0000
commitf2772a49353e09e4e00121ca4e538a3b3302a1de (patch)
tree244e520d9ceb1fec43c6af6ead045b71b0703c8d /src/cmd
parent1b9f168f73c44b2743338a16e8122a13203e8e9b (diff)
downloadgo-f2772a49353e09e4e00121ca4e538a3b3302a1de.tar.xz
cmd/compile: compute second method type at runtime
The type information for a method includes two variants: a func without the receiver, and a func with the receiver as the first parameter. The former is used as part of the dynamic interface checks, but the latter is only returned as a type in the reflect.Method struct. Instead of computing it at compile time, construct it at run time with reflect.FuncOf. Using cl/20701 as a baseline, cmd/go: -480KB, (4.4%) jujud: -5.6MB, (7.8%) For #6853. Change-Id: I1b8c73f3ab894735f53d00cb9c0b506d84d54e92 Reviewed-on: https://go-review.googlesource.com/20709 Run-TryBot: David Crawshaw <crawshaw@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/compile/internal/gc/reflect.go1
-rw-r--r--src/cmd/link/internal/ld/deadcode.go19
-rw-r--r--src/cmd/link/internal/ld/decodesym.go4
3 files changed, 8 insertions, 16 deletions
diff --git a/src/cmd/compile/internal/gc/reflect.go b/src/cmd/compile/internal/gc/reflect.go
index 8dc1e6cd0b..dda876d65f 100644
--- a/src/cmd/compile/internal/gc/reflect.go
+++ b/src/cmd/compile/internal/gc/reflect.go
@@ -505,7 +505,6 @@ func dextratypeData(s *Sym, ot int, t *Type) int {
ot = dgopkgpath(s, ot, a.pkg)
ot = dmethodptr(s, ot, dtypesym(a.mtype))
- ot = dmethodptr(s, ot, dtypesym(a.type_))
ot = dmethodptr(s, ot, a.isym)
ot = dmethodptr(s, ot, a.tsym)
}
diff --git a/src/cmd/link/internal/ld/deadcode.go b/src/cmd/link/internal/ld/deadcode.go
index 9367375102..9ed9c56f99 100644
--- a/src/cmd/link/internal/ld/deadcode.go
+++ b/src/cmd/link/internal/ld/deadcode.go
@@ -95,7 +95,7 @@ func deadcode(ctxt *Link) {
// and setting those fields to nil. Doing so
// would reduce the binary size of typical
// programs like cmd/go by ~2%.
- d.markMethodType(m)
+ d.mark(m.mtyp(), m.src)
rem = append(rem, m)
} else {
rem = append(rem, m)
@@ -171,18 +171,17 @@ var markextra = []string{
}
// methodref holds the relocations from a receiver type symbol to its
-// method. There are four relocations, one for each of the fields in
-// the reflect.method struct: mtyp, typ, ifn, and tfn.
+// method. There are three relocations, one for each of the fields in
+// the reflect.method struct: mtyp, ifn, and tfn.
type methodref struct {
m methodsig
src *LSym // receiver type symbol
- r [4]*Reloc // R_METHOD relocations to fields of runtime.method
+ r [3]*Reloc // R_METHOD relocations to fields of runtime.method
}
func (m methodref) mtyp() *LSym { return m.r[0].Sym }
-func (m methodref) typ() *LSym { return m.r[1].Sym }
-func (m methodref) ifn() *LSym { return m.r[2].Sym }
-func (m methodref) tfn() *LSym { return m.r[3].Sym }
+func (m methodref) ifn() *LSym { return m.r[1].Sym }
+func (m methodref) tfn() *LSym { return m.r[2].Sym }
func (m methodref) isExported() bool {
for _, r := range m.m {
@@ -233,12 +232,6 @@ func (d *deadcodepass) markMethod(m methodref) {
}
}
-// markMethodType marks just a method's types as reachable.
-func (d *deadcodepass) markMethodType(m methodref) {
- d.mark(m.mtyp(), m.src)
- d.mark(m.typ(), m.src)
-}
-
// init marks all initial symbols as reachable.
// In a typical binary, this is INITENTRY.
func (d *deadcodepass) init() {
diff --git a/src/cmd/link/internal/ld/decodesym.go b/src/cmd/link/internal/ld/decodesym.go
index 98590d3677..00e1a79a83 100644
--- a/src/cmd/link/internal/ld/decodesym.go
+++ b/src/cmd/link/internal/ld/decodesym.go
@@ -350,7 +350,7 @@ func decodetype_methods(s *LSym) []methodsig {
if r.Sym != s {
panic(fmt.Sprintf("method slice pointer in %q leads to a different symbol", s.Name))
}
- off = int(r.Add) // array of reflect.method values
- sizeofMethod := 6 * Thearch.Ptrsize
+ off = int(r.Add) // array of reflect.method values
+ sizeofMethod := 5 * Thearch.Ptrsize // sizeof reflect.method in program
return decode_methodsig(s, off, sizeofMethod, numMethods)
}