diff options
| author | Michael Anthony Knyszek <mknyszek@google.com> | 2025-05-09 18:53:06 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-05-20 11:15:12 -0700 |
| commit | c58f58b9f8df0bde53bb5bc20b5ea97d34b1531d (patch) | |
| tree | 3d032baae8584ef335920ebc8febebffdfaa5927 /src/runtime/malloc.go | |
| parent | 913c069819b77c0cfda78806654696508baf7f32 (diff) | |
| download | go-c58f58b9f8df0bde53bb5bc20b5ea97d34b1531d.tar.xz | |
runtime: mark and identify tiny blocks in checkfinalizers mode
This change adds support for identifying cleanups and finalizers
attached to tiny blocks to checkfinalizers mode. It also notes a subtle
pitfall, which is that the cleanup arg, if tiny-allocated, could end up
co-located with the object with the cleanup attached! Oops...
For #72949.
Change-Id: Icbe0112f7dcfc63f35c66cf713216796a70121ce
Reviewed-on: https://go-review.googlesource.com/c/go/+/662037
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Diffstat (limited to 'src/runtime/malloc.go')
| -rw-r--r-- | src/runtime/malloc.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index 46200037e2..25caf0625b 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -1670,6 +1670,12 @@ func postMallocgcDebug(x unsafe.Pointer, elemsize uintptr, typ *_type) { traceRelease(trace) } } + + // N.B. elemsize == 0 indicates a tiny allocation, since no new slot was + // allocated to fulfill this call to mallocgc. + if debug.checkfinalizers != 0 && elemsize == 0 { + setTinyBlockContext(unsafe.Pointer(alignDown(uintptr(x), maxTinySize))) + } } // deductAssistCredit reduces the current G's assist credit |
