Source File
trace2region.go
Belonging Package
runtime
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build goexperiment.exectracer2
// Simple not-in-heap bump-pointer traceRegion allocator.
package runtime
import (
)
// traceRegionAlloc is a non-thread-safe region allocator.
// It holds a linked list of traceRegionAllocBlock.
type traceRegionAlloc struct {
head *traceRegionAllocBlock
off uintptr
}
// traceRegionAllocBlock is a block in traceRegionAlloc.
//
// traceRegionAllocBlock is allocated from non-GC'd memory, so it must not
// contain heap pointers. Writes to pointers to traceRegionAllocBlocks do
// not need write barriers.
type traceRegionAllocBlock struct {
_ sys.NotInHeap
next *traceRegionAllocBlock
data [64<<10 - goarch.PtrSize]byte
}
// alloc allocates n-byte block.
func ( *traceRegionAlloc) ( uintptr) *notInHeap {
= alignUp(, goarch.PtrSize)
if .head == nil || .off+ > uintptr(len(.head.data)) {
if > uintptr(len(.head.data)) {
throw("traceRegion: alloc too large")
}
:= (*traceRegionAllocBlock)(sysAlloc(unsafe.Sizeof(traceRegionAllocBlock{}), &memstats.other_sys))
if == nil {
throw("traceRegion: out of memory")
}
.next = .head
.head =
.off = 0
}
:= &.head.data[.off]
.off +=
return (*notInHeap)(unsafe.Pointer())
}
// drop frees all previously allocated memory and resets the allocator.
func ( *traceRegionAlloc) () {
for .head != nil {
:= .head
.head = .next
sysFree(unsafe.Pointer(), unsafe.Sizeof(traceRegionAllocBlock{}), &memstats.other_sys)
}
}
The pages are generated with Golds v0.6.9-preview. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |