Skip to content

Commit

Permalink
Add ForEachRoot iterator.
Browse files Browse the repository at this point in the history
  • Loading branch information
randall77 committed Oct 3, 2017
1 parent 88784b5 commit e4301ca
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
18 changes: 8 additions & 10 deletions gocore/dwarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,18 +425,16 @@ func (p *Program) typeHeap() {
}

// Get typings starting at roots.
for _, r := range p.globals {
p.typeObject(r.Addr, r.Type, p.proc, add)
}
fr := &frameReader{p: p}
for _, g := range p.goroutines {
for _, f := range g.frames {
fr.live = f.live
for _, r := range f.roots {
p.typeObject(r.Addr, r.Type, fr, add)
}
p.ForEachRoot(func(r *Root) bool {
if r.Live != nil {
fr.live = r.Live
p.typeObject(r.Addr, r.Type, fr, add)
} else {
p.typeObject(r.Addr, r.Type, p.proc, add)
}
}
return true
})

// Propagate typings through the heap.
for len(work) > 0 {
Expand Down
19 changes: 19 additions & 0 deletions gocore/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,25 @@ func (p *Program) ForEachObject(fn func(x Object) bool) {
}
}

// ForEachRoot calls fn with each garbage collection root.
// If fn returns false, ForEachRoot returns immediately.
func (p *Program) ForEachRoot(fn func(r *Root) bool) {
for _, r := range p.globals {
if !fn(r) {
return
}
}
for _, g := range p.goroutines {
for _, f := range g.frames {
for _, r := range f.roots {
if !fn(r) {
return
}
}
}
}
}

// Addr returns the starting address of x.
func (p *Program) Addr(x Object) core.Address {
return core.Address(x)
Expand Down

0 comments on commit e4301ca

Please sign in to comment.