aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2025-05-20 20:56:46 +0000
committerGopher Robot <gobot@golang.org>2025-05-21 21:20:52 -0700
commit53b9eae3875122a65b387adf18c5cb7a67e824d7 (patch)
tree5523e395c2aed03ab1147c1ed6ca7de90a9cb523 /src/runtime
parent27ff0f249c33fdfa9c8e17a0367b46561236f36c (diff)
downloadgo-53b9eae3875122a65b387adf18c5cb7a67e824d7.tar.xz
runtime: use the immortal weak handle map for sbrk mode
Currently weak pointers break in sbrk mode. We can just use the immortal weak handle map for weak pointers in this case, since nothing is ever freed. Fixes #69729. Change-Id: Ie9fa7e203c22776dc9eb3601c6480107d9ad0c99 Reviewed-on: https://go-review.googlesource.com/c/go/+/674656 Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Michael Knyszek <mknyszek@google.com> TryBot-Bypass: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/mheap.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/runtime/mheap.go b/src/runtime/mheap.go
index 0729184e22..3612d71e66 100644
--- a/src/runtime/mheap.go
+++ b/src/runtime/mheap.go
@@ -2545,6 +2545,16 @@ func gcWakeAllStrongFromWeak() {
// Retrieves or creates a weak pointer handle for the object p.
func getOrAddWeakHandle(p unsafe.Pointer) *atomic.Uintptr {
+ if debug.sbrk != 0 {
+ // debug.sbrk never frees memory, so it'll never go nil. However, we do still
+ // need a weak handle that's specific to p. Use the immortal weak handle map.
+ // Keep p alive across the call to getOrAdd defensively, though it doesn't
+ // really matter in this particular case.
+ handle := mheap_.immortalWeakHandles.getOrAdd(uintptr(p))
+ KeepAlive(p)
+ return handle
+ }
+
// First try to retrieve without allocating.
if handle := getWeakHandle(p); handle != nil {
// Keep p alive for the duration of the function to ensure