Content-Length: 287763 | pFad | http://github.com/golang/go/commit/53b9eae3875122a65b387adf18c5cb7a67e824d7

4B runtime: use the immortal weak handle map for sbrk mode · golang/go@53b9eae · GitHub
Skip to content

Commit 53b9eae

Browse files
mknyszekgopherbot
authored andcommitted
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>
1 parent 27ff0f2 commit 53b9eae

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/runtime/mheap.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,6 +2545,16 @@ func gcWakeAllStrongFromWeak() {
25452545

25462546
// Retrieves or creates a weak pointer handle for the object p.
25472547
func getOrAddWeakHandle(p unsafe.Pointer) *atomic.Uintptr {
2548+
if debug.sbrk != 0 {
2549+
// debug.sbrk never frees memory, so it'll never go nil. However, we do still
2550+
// need a weak handle that's specific to p. Use the immortal weak handle map.
2551+
// Keep p alive across the call to getOrAdd defensively, though it doesn't
2552+
// really matter in this particular case.
2553+
handle := mheap_.immortalWeakHandles.getOrAdd(uintptr(p))
2554+
KeepAlive(p)
2555+
return handle
2556+
}
2557+
25482558
// First try to retrieve without allocating.
25492559
if handle := getWeakHandle(p); handle != nil {
25502560
// Keep p alive for the duration of the function to ensure

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/golang/go/commit/53b9eae3875122a65b387adf18c5cb7a67e824d7

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy