cmd/compile, runtime: emit only GC data for stack objects

Currently, for stack objects, the compiler emits metadata that
includes the offset and type descriptor for each object. The type
descriptor symbol has many fields, and it references many other
symbols, e.g. field/element types, equality functions, names.

Observe that what we actually need at runtime is only the GC
metadata that are needed to scan the object, and the GC metadata
are "leaf" symbols (which doesn't reference other symbols). Emit
only the GC data instead. This avoids bringing live the type
descriptor as well as things referenced by it (if it is not
otherwise live).

This reduces binary sizes:

                     old          new
hello (println)    1187776      1133856 (-4.5%)
hello (fmt)        1902448      1844416 (-3.1%)
cmd/compile       22670432     22438576 (-1.0%)
cmd/link           6346272      6225408 (-1.9%)

No significant change in compiler speed.

name        old time/op       new time/op       delta
Template          184ms ± 2%        186ms ± 5%    ~     (p=0.905 n=9+10)
Unicode          78.4ms ± 5%       76.3ms ± 3%  -2.60%  (p=0.009 n=10+10)
GoTypes           1.09s ± 1%        1.08s ± 1%  -0.73%  (p=0.027 n=10+8)
Compiler         85.6ms ± 3%       84.6ms ± 4%    ~     (p=0.143 n=10+10)
SSA               7.23s ± 1%        7.25s ± 1%    ~     (p=0.780 n=10+9)
Flate             116ms ± 5%        115ms ± 6%    ~     (p=0.912 n=10+10)
GoParser          201ms ± 4%        195ms ± 1%    ~     (p=0.089 n=10+10)
Reflect           455ms ± 1%        458ms ± 2%    ~     (p=0.050 n=9+9)
Tar               155ms ± 2%        155ms ± 3%    ~     (p=0.436 n=10+10)
XML               202ms ± 2%        200ms ± 2%    ~     (p=0.053 n=10+9)

Change-Id: I33a7f383d79afba1a482cac6da0cf5b7de9c0ec4
Reviewed-on: https://go-review.googlesource.com/c/go/+/313514
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Cherry Zhang 2021-04-24 12:41:17 -04:00
parent a9705e157b
commit 02ab8d1a1d
5 changed files with 128 additions and 48 deletions

View file

@ -702,15 +702,15 @@ func adjustframe(frame *stkframe, arg unsafe.Pointer) bool {
// we call into morestack.)
continue
}
t := obj.typ
gcdata := t.gcdata
ptrdata := obj.ptrdata()
gcdata := obj.gcdata
var s *mspan
if t.kind&kindGCProg != 0 {
if obj.useGCProg() {
// See comments in mgcmark.go:scanstack
s = materializeGCProg(t.ptrdata, gcdata)
s = materializeGCProg(ptrdata, gcdata)
gcdata = (*byte)(unsafe.Pointer(s.startAddr))
}
for i := uintptr(0); i < t.ptrdata; i += sys.PtrSize {
for i := uintptr(0); i < ptrdata; i += sys.PtrSize {
if *addb(gcdata, i/(8*sys.PtrSize))>>(i/sys.PtrSize&7)&1 != 0 {
adjustpointer(adjinfo, unsafe.Pointer(p+i))
}
@ -1346,20 +1346,42 @@ var (
abiRegArgsType *_type = efaceOf(&abiRegArgsEface)._type
methodValueCallFrameObjs = []stackObjectRecord{
{
off: -int(alignUp(abiRegArgsType.size, 8)), // It's always the highest address local.
typ: abiRegArgsType,
off: -int32(alignUp(abiRegArgsType.size, 8)), // It's always the highest address local.
size: int32(abiRegArgsType.size),
_ptrdata: int32(abiRegArgsType.ptrdata),
gcdata: abiRegArgsType.gcdata,
},
}
)
func init() {
if abiRegArgsType.kind&kindGCProg != 0 {
throw("abiRegArgsType needs GC Prog, update methodValueCallFrameObjs")
}
}
// A stackObjectRecord is generated by the compiler for each stack object in a stack frame.
// This record must match the generator code in cmd/compile/internal/liveness/plive.go:emitStackObjects.
type stackObjectRecord struct {
// offset in frame
// if negative, offset from varp
// if non-negative, offset from argp
off int
typ *_type
off int32
size int32
_ptrdata int32 // ptrdata, or -ptrdata is GC prog is used
gcdata *byte // pointer map or GC prog of the type
}
func (r *stackObjectRecord) useGCProg() bool {
return r._ptrdata < 0
}
func (r *stackObjectRecord) ptrdata() uintptr {
x := r._ptrdata
if x < 0 {
return uintptr(-x)
}
return uintptr(x)
}
// This is exported as ABI0 via linkname so obj can call it.