runtime (gc_blocks.go): simplify scanning logic

Loop over valid pointer locations in heap objects instead of checking if each location is valid.
The conservative scanning code is now shared between markRoots and the heap scan.

This also removes the ending alignment requirement from markRoots, since the new scan* functions do not require an aligned length.
This requirement was occasionally violated by the linux global marking code.

This saves some code space and has negligible impact on performance.
This commit is contained in:
Nia Waldvogel
2025-11-30 12:21:55 -05:00
committed by Ron Evans
parent c9aa88b8ef
commit 26ac03a3f6
4 changed files with 104 additions and 152 deletions
+6 -17
View File
@@ -8,34 +8,23 @@ package runtime
import "unsafe"
// gcLayout tracks pointer locations in a heap object.
// The conservative GC treats all locations as potential pointers, so this doesn't need to store anything.
type gcLayout struct {
}
// parseGCLayout stores the layout information passed to alloc into a gcLayout value.
// The conservative GC discards this information.
func parseGCLayout(layout unsafe.Pointer) gcLayout {
return gcLayout{}
}
// scanner creates a gcObjectScanner with this layout.
func (l gcLayout) scanner() gcObjectScanner {
return gcObjectScanner{}
// gcLayout tracks pointer locations in a heap object.
// The conservative GC treats all locations as potential pointers, so this doesn't need to store anything.
type gcLayout struct {
}
type gcObjectScanner struct {
}
func (scanner *gcObjectScanner) pointerFree() bool {
func (l gcLayout) pointerFree() bool {
// We don't know whether this object contains pointers, so conservatively
// return false.
return false
}
// nextIsPointer returns whether this could be a pointer. Because the GC is
// conservative, we can't do much more than check whether the object lies
// somewhere in the heap.
func (scanner gcObjectScanner) nextIsPointer(ptr, parent, addrOfWord uintptr) bool {
return isOnHeap(ptr)
func (l gcLayout) scan(start, len uintptr) {
scanConservative(start, len)
}