github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/runtime/mbitmap_noallocheaders.go (about) 1 // Copyright 2023 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build !goexperiment.allocheaders 6 7 // Garbage collector: type and heap bitmaps. 8 // 9 // Stack, data, and bss bitmaps 10 // 11 // Stack frames and global variables in the data and bss sections are 12 // described by bitmaps with 1 bit per pointer-sized word. A "1" bit 13 // means the word is a live pointer to be visited by the GC (referred to 14 // as "pointer"). A "0" bit means the word should be ignored by GC 15 // (referred to as "scalar", though it could be a dead pointer value). 16 // 17 // Heap bitmap 18 // 19 // The heap bitmap comprises 1 bit for each pointer-sized word in the heap, 20 // recording whether a pointer is stored in that word or not. This bitmap 21 // is stored in the heapArena metadata backing each heap arena. 22 // That is, if ha is the heapArena for the arena starting at "start", 23 // then ha.bitmap[0] holds the 64 bits for the 64 words "start" 24 // through start+63*ptrSize, ha.bitmap[1] holds the entries for 25 // start+64*ptrSize through start+127*ptrSize, and so on. 26 // Bits correspond to words in little-endian order. ha.bitmap[0]&1 represents 27 // the word at "start", ha.bitmap[0]>>1&1 represents the word at start+8, etc. 28 // (For 32-bit platforms, s/64/32/.) 29 // 30 // We also keep a noMorePtrs bitmap which allows us to stop scanning 31 // the heap bitmap early in certain situations. If ha.noMorePtrs[i]>>j&1 32 // is 1, then the object containing the last word described by ha.bitmap[8*i+j] 33 // has no more pointers beyond those described by ha.bitmap[8*i+j]. 34 // If ha.noMorePtrs[i]>>j&1 is set, the entries in ha.bitmap[8*i+j+1] and 35 // beyond must all be zero until the start of the next object. 36 // 37 // The bitmap for noscan spans is set to all zero at span allocation time. 38 // 39 // The bitmap for unallocated objects in scannable spans is not maintained 40 // (can be junk). 41 42 package runtime