mirror of https://github.com/golang/go.git
runtime: change heapObjectsCanMove to a func
A var is problematic because the zero value is already false, so if it goes away, it will appear to be false. I'm also not sure about go:linkname on vars, so switch to func for both reasons. Also add a test. Change-Id: I2318a5390d98577aec025152e65543491489defb Reviewed-on: https://go-review.googlesource.com/c/go/+/498261 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
parent
82d5ebce96
commit
789701e93a
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright 2023 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package runtime_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
//go:linkname heapObjectsCanMove runtime.heapObjectsCanMove
|
||||
func heapObjectsCanMove() bool
|
||||
|
||||
func TestHeapObjectsCanMove(t *testing.T) {
|
||||
if heapObjectsCanMove() {
|
||||
// If this happens (or this test stops building),
|
||||
// it will break go4.org/unsafe/assume-no-moving-gc.
|
||||
t.Fatalf("heap objects can move!")
|
||||
}
|
||||
}
|
||||
|
|
@ -149,7 +149,7 @@ const (
|
|||
sweepMinHeapDistance = 1024 * 1024
|
||||
)
|
||||
|
||||
// heapObjectsCanMove is always false in the current garbage collector.
|
||||
// heapObjectsCanMove always returns 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,
|
||||
|
|
@ -165,7 +165,11 @@ const (
|
|||
//
|
||||
// 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
|
||||
//
|
||||
//go:linkname heapObjectsCanMove
|
||||
func heapObjectsCanMove() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func gcinit() {
|
||||
if unsafe.Sizeof(workbuf{}) != _WorkbufSize {
|
||||
|
|
|
|||
Loading…
Reference in New Issue