]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add heapObjectsCanMove
authorRuss Cox <rsc@golang.org>
Thu, 25 May 2023 04:21:13 +0000 (00:21 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 25 May 2023 13:00:06 +0000 (13:00 +0000)
heapObjectsCanMove is always false in the current garbage collector.
It exists for go4.org/unsafe/assume-no-moving-gc, which is an
unfortunate idea that had an even more unfortunate implementation.
Every time a new Go release happened, the package stopped building,
and the authors had to add a new file with a new //go:build line, and
then the entire ecosystem of packages with that as a dependency had to
explicitly update to the new version. Many packages depend on
assume-no-moving-gc transitively, through paths like
inet.af/netaddr -> go4.org/intern -> assume-no-moving-gc.
This was causing a significant amount of friction around each new
release, so we added this bool for the package to //go:linkname
instead. The bool is still unfortunate, but it's not as bad as
breaking the ecosystem on every new release.

If the Go garbage collector ever does move heap objects, we can set
this to true to break all the programs using assume-no-moving-gc.

Change-Id: I06c32bf6ccc4601c8eef741d7382b678aada3508
Reviewed-on: https://go-review.googlesource.com/c/go/+/498121
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/mgc.go

index c8e68807ee7e176af49a48999f12e900d39a8a4b..d3658df489bc156dec5b636ece5fb98d6b68a766 100644 (file)
@@ -149,6 +149,24 @@ const (
        sweepMinHeapDistance = 1024 * 1024
 )
 
+// heapObjectsCanMove is always false in the current garbage collector.
+// It exists for go4.org/unsafe/assume-no-moving-gc, which is an
+// unfortunate idea that had an even more unfortunate implementation.
+// Every time a new Go release happened, the package stopped building,
+// and the authors had to add a new file with a new //go:build line, and
+// then the entire ecosystem of packages with that as a dependency had to
+// explicitly update to the new version. Many packages depend on
+// assume-no-moving-gc transitively, through paths like
+// inet.af/netaddr -> go4.org/intern -> assume-no-moving-gc.
+// This was causing a significant amount of friction around each new
+// release, so we added this bool for the package to //go:linkname
+// instead. The bool is still unfortunate, but it's not as bad as
+// breaking the ecosystem on every new release.
+//
+// If the Go garbage collector ever does move heap objects, we can set
+// this to true to break all the programs using assume-no-moving-gc.
+var heapObjectsCanMove = false
+
 func gcinit() {
        if unsafe.Sizeof(workbuf{}) != _WorkbufSize {
                throw("size of Workbuf is suboptimal")