File tree Expand file tree Collapse file tree 2 files changed +27
-10
lines changed Expand file tree Collapse file tree 2 files changed +27
-10
lines changed Original file line number Diff line number Diff line change @@ -425,18 +425,16 @@ func (p *Program) typeHeap() {
425
425
}
426
426
427
427
// Get typings starting at roots.
428
- for _ , r := range p .globals {
429
- p .typeObject (r .Addr , r .Type , p .proc , add )
430
- }
431
428
fr := & frameReader {p : p }
432
- for _ , g := range p . goroutines {
433
- for _ , f := range g . frames {
434
- fr .live = f . live
435
- for _ , r := range f . roots {
436
- p . typeObject ( r . Addr , r . Type , fr , add )
437
- }
429
+ p . ForEachRoot ( func ( r * Root ) bool {
430
+ if r . Live != nil {
431
+ fr .live = r . Live
432
+ p . typeObject ( r . Addr , r . Type , fr , add )
433
+ } else {
434
+ p . typeObject ( r . Addr , r . Type , p . proc , add )
438
435
}
439
- }
436
+ return true
437
+ })
440
438
441
439
// Propagate typings through the heap.
442
440
for len (work ) > 0 {
Original file line number Diff line number Diff line change @@ -196,6 +196,25 @@ func (p *Program) ForEachObject(fn func(x Object) bool) {
196
196
}
197
197
}
198
198
199
+ // ForEachRoot calls fn with each garbage collection root.
200
+ // If fn returns false, ForEachRoot returns immediately.
201
+ func (p * Program ) ForEachRoot (fn func (r * Root ) bool ) {
202
+ for _ , r := range p .globals {
203
+ if ! fn (r ) {
204
+ return
205
+ }
206
+ }
207
+ for _ , g := range p .goroutines {
208
+ for _ , f := range g .frames {
209
+ for _ , r := range f .roots {
210
+ if ! fn (r ) {
211
+ return
212
+ }
213
+ }
214
+ }
215
+ }
216
+ }
217
+
199
218
// Addr returns the starting address of x.
200
219
func (p * Program ) Addr (x Object ) core.Address {
201
220
return core .Address (x )
You can’t perform that action at this time.
0 commit comments