const _DebugGC … const _FinBlockSize … const concurrentSweep … const debugScanConservative … const sweepMinHeapDistance … // heapObjectsCanMove always returns false in the current garbage collector. // It exists for go4.org/unsafe/assume-no-moving-gc, which is an // unfortunate idea that had an even more unfortunate implementation. // Every time a new Go release happened, the package stopped building, // and the authors had to add a new file with a new //go:build line, and // then the entire ecosystem of packages with that as a dependency had to // explicitly update to the new version. Many packages depend on // assume-no-moving-gc transitively, through paths like // inet.af/netaddr -> go4.org/intern -> assume-no-moving-gc. // This was causing a significant amount of friction around each new // release, so we added this bool for the package to //go:linkname // instead. The bool is still unfortunate, but it's not as bad as // breaking the ecosystem on every new release. // // If the Go garbage collector ever does move heap objects, we can set // this to true to break all the programs using assume-no-moving-gc. // //go:linkname heapObjectsCanMove func heapObjectsCanMove() bool { … } func gcinit() { … } // gcenable is called after the bulk of the runtime initialization, // just before we're about to start letting user code run. // It kicks off the background sweeper goroutine, the background // scavenger goroutine, and enables GC. func gcenable() { … } var gcphase … var writeBarrier … var gcBlackenEnabled … const _GCoff … const _GCmark … const _GCmarktermination … //go:nosplit func setGCPhase(x uint32) { … } type gcMarkWorkerMode … const gcMarkWorkerNotWorker … const gcMarkWorkerDedicatedMode … const gcMarkWorkerFractionalMode … const gcMarkWorkerIdleMode … var gcMarkWorkerModeStrings … // pollFractionalWorkerExit reports whether a fractional mark worker // should self-preempt. It assumes it is called from the fractional // worker. func pollFractionalWorkerExit() bool { … } var work … type workType … // GC runs a garbage collection and blocks the caller until the // garbage collection is complete. It may also block the entire // program. func GC() { … } // gcWaitOnMark blocks until GC finishes the Nth mark phase. If GC has // already completed this mark phase, it returns immediately. func gcWaitOnMark(n uint32) { … } type gcMode … const gcBackgroundMode … const gcForceMode … const gcForceBlockMode … type gcTrigger … type gcTriggerKind … const gcTriggerHeap … const gcTriggerTime … const gcTriggerCycle … // test reports whether the trigger condition is satisfied, meaning // that the exit condition for the _GCoff phase has been met. The exit // condition should be tested when allocating. func (t gcTrigger) test() bool { … } // gcStart starts the GC. It transitions from _GCoff to _GCmark (if // debug.gcstoptheworld == 0) or performs all of GC (if // debug.gcstoptheworld != 0). // // This may return without performing this transition in some cases, // such as when called on a system stack or with locks held. func gcStart(trigger gcTrigger) { … } var gcMarkDoneFlushed … // gcMarkDone transitions the GC from mark to mark termination if all // reachable objects have been marked (that is, there are no grey // objects and can be no more in the future). Otherwise, it flushes // all local work to the global queues where it can be discovered by // other workers. // // This should be called when all local mark work has been drained and // there are no remaining workers. Specifically, when // // work.nwait == work.nproc && !gcMarkWorkAvailable(p) // // The calling context must be preemptible. // // Flushing local work is important because idle Ps may have local // work queued. This is the only way to make that work visible and // drive GC to completion. // // It is explicitly okay to have write barriers in this function. If // it does transition to mark termination, then all reachable objects // have been marked, so the write barrier cannot shade any more // objects. func gcMarkDone() { … } // World must be stopped and mark assists and background workers must be // disabled. func gcMarkTermination(stw worldStop) { … } // gcBgMarkStartWorkers prepares background mark worker goroutines. These // goroutines will not run until the mark phase, but they must be started while // the work is not stopped and from a regular G stack. The caller must hold // worldsema. func gcBgMarkStartWorkers() { … } // gcBgMarkPrepare sets up state for background marking. // Mutator assists must not yet be enabled. func gcBgMarkPrepare() { … } type gcBgMarkWorkerNode … func gcBgMarkWorker(ready chan struct{ … } // gcMarkWorkAvailable reports whether executing a mark worker // on p is potentially useful. p may be nil, in which case it only // checks the global sources of work. func gcMarkWorkAvailable(p *p) bool { … } // gcMark runs the mark (or, for concurrent GC, mark termination) // All gcWork caches must be empty. // STW is in effect at this point. func gcMark(startTime int64) { … } // gcSweep must be called on the system stack because it acquires the heap // lock. See mheap for details. // // Returns true if the heap was fully swept by this function. // // The world must be stopped. // //go:systemstack func gcSweep(mode gcMode) bool { … } // gcResetMarkState resets global state prior to marking (concurrent // or STW) and resets the stack scan state of all Gs. // // This is safe to do without the world stopped because any Gs created // during or after this will start out in the reset state. // // gcResetMarkState must be called on the system stack because it acquires // the heap lock. See mheap for details. // //go:systemstack func gcResetMarkState() { … } var poolcleanup … var boringCaches … var uniqueMapCleanup … // sync_runtime_registerPoolCleanup should be an internal detail, // but widely used packages access it using linkname. // Notable members of the hall of shame include: // - github.com/bytedance/gopkg // - github.com/songzhibin97/gkit // // Do not remove or change the type signature. // See go.dev/issue/67401. // //go:linkname sync_runtime_registerPoolCleanup sync.runtime_registerPoolCleanup func sync_runtime_registerPoolCleanup(f func()) { … } //go:linkname boring_registerCache crypto/internal/boring/bcache.registerCache func boring_registerCache(p unsafe.Pointer) { … } //go:linkname unique_runtime_registerUniqueMapCleanup unique.runtime_registerUniqueMapCleanup func unique_runtime_registerUniqueMapCleanup(f func()) { … } func clearpools() { … } // itoaDiv formats val/(10**dec) into buf. func itoaDiv(buf []byte, val uint64, dec int) []byte { … } // fmtNSAsMS nicely formats ns nanoseconds as milliseconds. func fmtNSAsMS(buf []byte, ns uint64) []byte { … } // gcTestMoveStackOnNextCall causes the stack to be moved on a call // immediately following the call to this. It may not work correctly // if any other work appears after this call (such as returning). // Typically the following call should be marked go:noinline so it // performs a stack check. // // In rare cases this may not cause the stack to move, specifically if // there's a preemption between this call and the next. func gcTestMoveStackOnNextCall() { … } // gcTestIsReachable performs a GC and returns a bit set where bit i // is set if ptrs[i] is reachable. func gcTestIsReachable(ptrs ...unsafe.Pointer) (mask uint64) { … } // gcTestPointerClass returns the category of what p points to, one of: // "heap", "stack", "data", "bss", "other". This is useful for checking // that a test is doing what it's intended to do. // // This is nosplit simply to avoid extra pointer shuffling that may // complicate a test. // //go:nosplit func gcTestPointerClass(p unsafe.Pointer) string { … }