summaryrefslogtreecommitdiffstats
path: root/libgo
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2022-03-25 17:23:50 -0700
committerIan Lance Taylor <iant@golang.org>2022-04-15 14:27:05 -0700
commitd00dd52ea15f9026c327d2f591eb456d6f11df2c (patch)
tree278f15dc95ab9f1cebaa975bece1cbd395f127de /libgo
parentlibstdc++: Avoid double-deref of __first in ranges::minmax [PR104858] (diff)
downloadgcc-d00dd52ea15f9026c327d2f591eb456d6f11df2c.tar.gz
gcc-d00dd52ea15f9026c327d2f591eb456d6f11df2c.tar.bz2
gcc-d00dd52ea15f9026c327d2f591eb456d6f11df2c.tar.xz
compiler: revert `for package-scope "a = b; b = x" just set "a = x"`
Revert CL 245098. It caused incorrect initialization ordering. Adjust the runtime package to work even with the CL reverted. Original description of CL 245098: This avoids requiring an init function to initialize the variable. This can only be done if x is a static initializer. The go1.15rc1 runtime package relies on this optimization. The package has a variable "var maxSearchAddr = maxOffAddr". The maxSearchAddr variable is used by code that runs before package initialization is complete. For golang/go#51913 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/395994
Diffstat (limited to 'libgo')
-rw-r--r--libgo/go/runtime/mpagealloc.go12
-rw-r--r--libgo/go/runtime/mpagecache.go2
2 files changed, 8 insertions, 6 deletions
diff --git a/libgo/go/runtime/mpagealloc.go b/libgo/go/runtime/mpagealloc.go
index 2725e3b7c7b..5e40da45d17 100644
--- a/libgo/go/runtime/mpagealloc.go
+++ b/libgo/go/runtime/mpagealloc.go
@@ -87,7 +87,9 @@ const (
87// 87//
88// We alias maxOffAddr just to make it clear that this is the maximum address 88// We alias maxOffAddr just to make it clear that this is the maximum address
89// for the page allocator's search space. See maxOffAddr for details. 89// for the page allocator's search space. See maxOffAddr for details.
90var maxSearchAddr = maxOffAddr 90func maxSearchAddr() offAddr {
91 return maxOffAddr
92}
91 93
92// Global chunk index. 94// Global chunk index.
93// 95//
@@ -331,13 +333,13 @@ func (p *pageAlloc) init(mheapLock *mutex, sysStat *sysMemStat) {
331 p.sysInit() 333 p.sysInit()
332 334
333 // Start with the searchAddr in a state indicating there's no free memory. 335 // Start with the searchAddr in a state indicating there's no free memory.
334 p.searchAddr = maxSearchAddr 336 p.searchAddr = maxSearchAddr()
335 337
336 // Set the mheapLock. 338 // Set the mheapLock.
337 p.mheapLock = mheapLock 339 p.mheapLock = mheapLock
338 340
339 // Initialize scavenge tracking state. 341 // Initialize scavenge tracking state.
340 p.scav.scavLWM = maxSearchAddr 342 p.scav.scavLWM = maxSearchAddr()
341} 343}
342 344
343// tryChunkOf returns the bitmap data for the given chunk. 345// tryChunkOf returns the bitmap data for the given chunk.
@@ -760,7 +762,7 @@ nextLevel:
760 } 762 }
761 if l == 0 { 763 if l == 0 {
762 // We're at level zero, so that means we've exhausted our search. 764 // We're at level zero, so that means we've exhausted our search.
763 return 0, maxSearchAddr 765 return 0, maxSearchAddr()
764 } 766 }
765 767
766 // We're not at level zero, and we exhausted the level we were looking in. 768 // We're not at level zero, and we exhausted the level we were looking in.
@@ -854,7 +856,7 @@ func (p *pageAlloc) alloc(npages uintptr) (addr uintptr, scav uintptr) {
854 // exhausted. Otherwise, the heap still might have free 856 // exhausted. Otherwise, the heap still might have free
855 // space in it, just not enough contiguous space to 857 // space in it, just not enough contiguous space to
856 // accommodate npages. 858 // accommodate npages.
857 p.searchAddr = maxSearchAddr 859 p.searchAddr = maxSearchAddr()
858 } 860 }
859 return 0, 0 861 return 0, 0
860 } 862 }
diff --git a/libgo/go/runtime/mpagecache.go b/libgo/go/runtime/mpagecache.go
index 7206e2dbdb7..5bad4f789a1 100644
--- a/libgo/go/runtime/mpagecache.go
+++ b/libgo/go/runtime/mpagecache.go
@@ -143,7 +143,7 @@ func (p *pageAlloc) allocToCache() pageCache {
143 if addr == 0 { 143 if addr == 0 {
144 // We failed to find adequate free space, so mark the searchAddr as OoM 144 // We failed to find adequate free space, so mark the searchAddr as OoM
145 // and return an empty pageCache. 145 // and return an empty pageCache.
146 p.searchAddr = maxSearchAddr 146 p.searchAddr = maxSearchAddr()
147 return pageCache{} 147 return pageCache{}
148 } 148 }
149 ci := chunkIndex(addr) 149 ci := chunkIndex(addr)