memclrNoHeapPointers(x, size)
}
if goexperiment.AllocHeaders && hasHeader {
- header = (**_type)(x)
- x = add(x, mallocHeaderSize)
+ header = (**_type)(unsafe.Pointer(uintptr(v) + size - mallocHeaderSize))
size -= mallocHeaderSize
}
}
// is zeroed, so the GC just observes nil pointers.
// Note that this "tiled" bitmap isn't stored anywhere; it is generated on-the-fly.
//
-// For objects without their own span, the type metadata is stored in the first
-// word before the object at the beginning of the allocation slot. For objects
-// with their own span, the type metadata is stored in the mspan.
+// For objects without their own span, the type metadata is stored in the last
+// word of the allocation slot. For objects with their own span, the type metadata
+// is stored in the mspan.
//
// The bitmap for small unallocated objects in scannable spans is not maintained
// (can be junk).
// All of these objects have a header.
var typ *_type
if spc.sizeclass() != 0 {
- // Pull the allocation header from the first word of the object.
- typ = *(**_type)(unsafe.Pointer(addr))
- addr += mallocHeaderSize
+ // Pull the allocation header from the last word of the object.
+ typ = *(**_type)(unsafe.Pointer(addr + span.elemsize - mallocHeaderSize))
} else {
typ = span.largeType
}
import (
"internal/abi"
"internal/goarch"
- "internal/goexperiment"
"runtime/internal/atomic"
"runtime/internal/sys"
"unsafe"
}
// find the containing object
- base, span, _ := findObject(uintptr(e.data), 0, 0)
+ base, _, _ := findObject(uintptr(e.data), 0, 0)
if base == 0 {
if isGoPointerWithoutSpan(e.data) {
throw("runtime.SetFinalizer: pointer not in allocated block")
}
- // Move base forward if we've got an allocation header.
- if goexperiment.AllocHeaders && !span.spanclass.noscan() && !heapBitsInSpan(span.elemsize) && span.spanclass.sizeclass() != 0 {
- base += mallocHeaderSize
- }
-
if uintptr(e.data) != base {
// As an implementation detail we allow to set finalizers for an inner byte
// of an object if it could come from tiny alloc (see mallocgc for details).