runtime: access modules via a slice

The introduction of -buildmode=plugin means modules can be added to a
Go program while it is running. This means there exists some time
while the program is running with the module is on the moduledata
linked list, but it has not been initialized to the satisfaction of
other parts of the runtime. Notably, the GC.

This CL adds a new way of access modules, an activeModules function.
It returns a slice of modules that is built in the background and
atomically swapped in. The parts of the runtime that need to wait on
module initialization can use this slice instead of the linked list.

Fixes #17455

Change-Id: I04790fd07e40c7295beb47cea202eb439206d33d
Reviewed-on: https://go-review.googlesource.com/32357
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
David Crawshaw 2016-10-30 20:30:38 -04:00
parent 807a7ebd51
commit 54ec7b072e
11 changed files with 74 additions and 31 deletions

View file

@ -471,9 +471,9 @@ func typelinksinit() {
}
typehash := make(map[uint32][]*_type, len(firstmoduledata.typelinks))
prev := &firstmoduledata
md := firstmoduledata.next
for md != nil {
modules := activeModules()
prev := modules[0]
for _, md := range modules[1:] {
// Collect types from the previous module into typehash.
collect:
for _, tl := range prev.typelinks {
@ -513,7 +513,6 @@ func typelinksinit() {
}
prev = md
md = md.next
}
}