Skip to content

Commit 45c2e38

Browse files
committed
cmd/compile: Drop references to Prog structs after each function
Don't accumulate a massive list of Prog structs during compilation and write them all out at the end of compilation. Instead, convert them to code+relocs (or data+relocs) after each function is compiled. Track down a few other places that were keeping Progs alive and nil them out so the Progs get GCd promptly. Saves ~20% in peak memory usage for the compiler. Surprisingly not much help speed-wise (only because we end up doing more GCs. With a compensating GOGC=120, it does help a bit), but this provides a base for more changes (e.g. reusing a cache of Progs). Change-Id: I838e01017c228995a687a8110d0cd67bf8596407 Reviewed-on: https://go-review.googlesource.com/19867 Run-TryBot: Keith Randall <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Josh Bleecher Snyder <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent fdd0179 commit 45c2e38

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

src/cmd/compile/internal/gc/dcl.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,8 +1449,13 @@ func funccompile(n *Node) {
14491449
Funcdepth = n.Func.Depth + 1
14501450
compile(n)
14511451
Curfn = nil
1452+
Pc = nil
1453+
continpc = nil
1454+
breakpc = nil
14521455
Funcdepth = 0
14531456
dclcontext = PEXTERN
1457+
flushdata()
1458+
obj.Flushplist(Ctxt) // convert from Prog list to machine code
14541459
}
14551460

14561461
func funcsym(s *Sym) *Sym {

src/cmd/compile/internal/gc/gsubr.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,18 @@ func dumpdata() {
173173
Clearp(Pc)
174174
}
175175

176+
func flushdata() {
177+
if dfirst == nil {
178+
return
179+
}
180+
newplist()
181+
*Pc = *dfirst
182+
Pc = dpc
183+
Clearp(Pc)
184+
dfirst = nil
185+
dpc = nil
186+
}
187+
176188
// Fixup instructions after allocauto (formerly compactframe) has moved all autos around.
177189
func fixautoused(p *obj.Prog) {
178190
for lp := &p; ; {

src/cmd/internal/obj/objfile.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,16 +302,22 @@ func Flushplist(ctxt *Link) {
302302
ctxt.Arch.Assemble(ctxt, s)
303303
fieldtrack(ctxt, s)
304304
linkpcln(ctxt, s)
305+
s.Text = nil
306+
s.Etext = nil
305307
}
306308

307309
// Add to running list in ctxt.
308-
if ctxt.Etext == nil {
309-
ctxt.Text = text
310-
} else {
311-
ctxt.Etext.Next = text
310+
if text != nil {
311+
if ctxt.Text == nil {
312+
ctxt.Text = text
313+
} else {
314+
ctxt.Etext.Next = text
315+
}
316+
ctxt.Etext = etext
312317
}
313-
ctxt.Etext = etext
314318
ctxt.Plist = nil
319+
ctxt.Plast = nil
320+
ctxt.Curp = nil
315321
}
316322

317323
func Writeobjfile(ctxt *Link, b *Biobuf) {

0 commit comments

Comments
 (0)