core.internal.gc.impl.conservative.gc
Contains the garbage collector implementation.
Copyright
D Language Foundation 2001 - 2021.
var baseOffsetBits binbase binsize bytesAllocated extendTime freeTime lockTime mallocTime markTime maxCollectionTime maxPauseTime maxPoolMemory numCollections numExtends numFrees numMallocs numOthers numReallocs otherTime pauseTime prepTime reallocTime sweepTime
enum Bins
class ConservativeGC
fn _d_register_conservative_gc _d_register_precise_gc adjustAttrs baseOffset calcBinBase gc_conservative_ctor gc_precise_ctor initialize initialize_precise invalidate onInvalidMemoryOperationError onOutOfMemoryError rt_finalizeFromGC rt_hasFinalizerInSegment set setupMetadata undefinedRead undefinedWrite
Types 10
aliascurrTime = MonoTime.currTime
Debugging
aliasgc_t = GC
classConservativeGC : GC
Fields
size_t linechar * fileGcx *gcx gcxshared(AlignedSpinLock)(SpinLock.Contention.brief) gcLockbool _inFinalizerbool isPreciseMethods
void enable()Enables the GC if disable() was previously called. Must be called for each time disable was called in order to enable the GC again.void disable()Disable the GC. The GC may still run if it deems necessary.auto runLocked(alias func, Args...)(auto ref Args args)Run a function inside a lock/unlock set.auto runLocked(alias func, alias time, alias count, Args...)(auto ref Args args)Run a function in an lock/unlock set that keeps track of how much time was spend inside this function (in ticks) and how many times this fuction was called.uint getAttr(void * p) nothrowReturns a bit field representing all block attributes set for the memory referenced by p.void *malloc malloc(size_t size, uint bits = 0, const TypeInfo ti = null) nothrowRequests an aligned block of managed memory from the garbage collector.private
void *mallocNoSync mallocNoSync(size_t size, uint bits, ref size_t alloc_size, const TypeInfo ti = null) nothrowvoid *calloc calloc(size_t size, uint bits = 0, const TypeInfo ti = null) nothrowRequests an aligned block of managed memory from the garbage collector, which is initialized with all bits set to zero.void *realloc realloc(void * p, size_t size, uint bits = 0, const TypeInfo ti = null) nothrowRequest that the GC reallocate a block of memory, attempting to adjust the size in place if possible. If size is 0, the memory will be freed.private
void *reallocNoSync reallocNoSync(void * p, size_t size, ref uint bits, ref size_t alloc_size, const TypeInfo ti = null) nothrowprivate
size_t extendNoSync(void * p, size_t minsize, size_t maxsize, const TypeInfo ti = null) nothrowsize_t reserve(size_t size) nothrowRequests that at least size bytes of memory be obtained from the operating system and marked as free.void * addrOf(void * p) nothrowDetermine the base address of the block containing p. If p is not a gc allocated pointer, return null.size_t sizeOf(void * p) nothrowDetermine the allocated size of pointer p. If p is an interior pointer or not a gc allocated pointer, return 0.BlkInfo query(void * p) nothrowDetermine the base address of the block containing p. If p is not a gc allocated pointer, return null.BlkInfo queryNoSync(void * p) nothrowvoid check(void * p) nothrowPerforms certain checks on a pointer. These checks will cause asserts to fail unless the following conditions are met: 1) The poiinter belongs to this memory pool. 2) The pointer points to the star...void addRoot(void * p) nothrow @nogcAdd p to list of roots. If p is null, no operation is performed.void removeRoot(void * p) nothrow @nogcRemove p from list of roots. If p is null or is not a value previously passed to addRoot() then no operation is performed.RootIterator rootIter() @property @nogcReturns an iterator allowing roots to be traversed via a foreach loop.void addRange(void * p, size_t sz, const TypeInfo ti = null) nothrow @nogcAdd range to scan for roots. If p is null or sz is 0, no operation is performed.void removeRange(void * p) nothrow @nogcRemove range from list of ranges. If p is null or does not represent a value previously passed to addRange() then no operation is performed.RangeIterator rangeIter() @property @nogcReturns an iterator allowing ranges to be traversed via a foreach loop.void collect() nothrowulong allocatedInCurrentThread() nothrowvoid[] getArrayUsed(void * ptr, bool atomic = false) nothrowbool shrinkArrayUsed(void[] slice, size_t existingUsed, bool atomic = false) nothrowConstructors
this()Destructors
enumBins : ubyte
B_16
B_32
B_48
B_64
B_96
B_128
B_176
B_256
B_368
B_512
B_816
B_1024
B_1360
B_2048
B_NUMSMALL
B_PAGE = B_NUMSMALL
B_PAGEPLUS
B_FREE
B_MAX
aliasPageBits = GCBits.wordtype[PAGESIZE / 16 / GCBits.BITS_PER_WORD]
structGcx
Fields
shared(AlignedSpinLock)(SpinLock.Contention.brief) rootsLockshared(AlignedSpinLock)(SpinLock.Contention.brief) rangesLockbool minimizeAfterNextCollectionuint disabledList *[Bins.B_NUMSMALL] bucketfloat smallCollectThresholduint usedSmallPagesuint mappedPagesSmallObjectPool *[Bins.B_NUMSMALL] recoverPoolBins[2049] binTableuint numScanThreadsScanThreadData * scanThreadDataEvent evStackFilledEvent evDoneuint busyThreadsuint stoppedThreadsbool stopGCshared(AlignedSpinLock)(SpinLock.Contention.brief) stackLockMethods
void initialize()void Dtor()void Invariant() constint rootsApply(scope int delegate(ref Root) nothrow dg) nothrowint rangesApply(scope int delegate(ref Range) nothrow dg) nothrowvoid runFinalizers(const scope void[] segment) nothrowvoid * findBase(void * p) nothrow @nogcFind base address of block containing pointer p. Returns null if not a gc'd pointersize_t reserve(size_t size) nothrowAllocate a new pool of at least size bytes. Sort it into pooltable[]. Mark all memory in the pool as B_FREE. Return the actual number of bytes reserved or 0 on error.void * smallAlloc(size_t size, ref size_t alloc_size, uint bits, const TypeInfo ti) nothrowvoid * bigAlloc(size_t size, ref size_t alloc_size, uint bits, const TypeInfo ti = null) nothrowAllocate a chunk of memory that is larger than a page. Return null if out of memory.Pool *newPool newPool(size_t npages, bool isLargeObject) nothrowAllocate a new pool with at least npages in it. Sort it into pooltable[]. Return null if failed.List * allocPage(Bins bin) nothrowAllocate a page of bin's. Returns: head of a single linked list of new entriesprivate
void mark(bool precise, bool parallel, bool shared_mem)(ScanRange!precise rng) scope nothrowSearch a range of memory values and mark any pointers into the GC pool.void prepare() nothrowvoid markAll(alias markFn)() nothrowsize_t sweep() nothrowbool recoverPage(SmallObjectPool * pool, size_t pn, Bins bin) nothrowbool recoverNextPage(Bins bin) nothrowsize_t fullcollect(bool block = false, bool isFinal = false) nothrowReturn number of full pages free'd. The collection is done concurrently only if block and isFinal are false.void *clearBlkCacheData clearBlkCacheData(void * data) scope nothrowClear the block cache data if it exists, given the data which is the block info cache.void markParallel() nothrowint maxParallelThreads() nothrowvoid startScanThreads() nothrowvoid stopScanThreads() nothrowvoid scanBackground() nothrowbool pullFromScanStack() nothrowbool pullFromScanStackImpl(bool precise)() nothrowvoid scanStackPushLocked(bool precise)(ScanRange!precise[] ranges)bool scanStackPopLocked(bool precise)(ref ScanRange!precise rng)Nested Templates
ScanRangeToScanStackscanStack(bool precise)ScanThreadDatastructPool
Fields
void * baseAddrvoid * topAddrsize_t ptIndexGCBits markGCBits freebitsGCBits finalsGCBits structFinalsGCBits noscanGCBits appendableGCBits nointeriorGCBits is_pointersize_t npagessize_t freepagesBins * pagetablebool isLargeObjectShiftBy shiftByuint * bPageOffsetsuint.max PageRecovereduint[Bins.B_NUMSMALL] recoverPageFirstimmutable(size_t) * * rtinfosize_t searchStartsize_t largestFreeMethods
void initialize(size_t npages, bool isLargeObject) nothrowvoid Dtor() nothrowuint getBits(size_t biti) nothrowvoid setBits(size_t biti, uint mask) nothrowvoid freePageBits(size_t pagenum, const scope ref PageBits toFree) nothrowvoid freeAllPageBits(size_t pagenum) nothrowsize_t numPages(size_t size) nothrow @nogcReturn number of pages necessary for an allocation of the given sizevoid Invariant() constvoid setPointerBitmapSmall(void * p, size_t s, size_t allocSize, uint attr, const TypeInfo ti) nothrowvoid setPointerBitmap(void * p, size_t s, size_t allocSize, const TypeInfo ti, uint attr) nothrowNested Templates
ShiftBystructLargeObjectPool
Fields
Pool baseMethods
void setFreePageOffsets(size_t page, size_t num) nothrow @nogcSet the first and the last entry of a B_FREE block to the sizevoid runFinalizers(const scope void[] segment) nothrowstructSmallObjectPool
Functions 18
fn
int rt_hasFinalizerInSegment(void * p, size_t size, const(TypeInfo) typeInfo, const scope void[] segment) nothrow;fn
noreturn onInvalidMemoryOperationError(void * pretend_sideffect = null, string file = __FILE__, size_t line = __LINE__) @trusted pure nothrow @nogcfn
noreturn onOutOfMemoryError(void * pretend_sideffect = null, string file = __FILE__, size_t line = __LINE__) @trusted pure nothrow @nogcfn
void _d_register_conservative_gc()fn
void _d_register_precise_gc()fn
short[PAGESIZE / 16][Bins.B_NUMSMALL + 1] calcBinBase()fn
void invalidate(void[] mem, ubyte pattern, bool writable) nothrow @nogcMark the specified memory region as uninitialized - reading from this region is an error. If writable is false, writing to it is also an error.fn
T undefinedRead(T)(ref T var) nothrowRead memory that should otherwise be marked as unreadable (e.g. free lists overlapped with unallocated heap objects).fn
void undefinedWrite(T)(ref T var, T value) nothrowWrite memory that should otherwise be marked as unwritable.private fn
void[] setupMetadata(void[] block, uint bits, size_t padding, size_t used, const TypeInfo ti) nothrowVariables 23
var
Duration prepTimevar
Duration markTimevar
Duration sweepTimevar
Duration pauseTimevar
Duration maxPauseTimevar
Duration maxCollectionTimevar
size_t numCollectionsvar
size_t maxPoolMemoryvar
long numMallocsvar
long numFreesvar
long numReallocsvar
long numExtendsvar
long numOthersvar
long mallocTimevar
long freeTimevar
long reallocTimevar
long extendTimevar
long otherTimevar
long lockTimevar
ulong bytesAllocatedvar
short[Bins.B_NUMSMALL + 1] binsizevar
short[PAGESIZE / 16][Bins.B_NUMSMALL + 1] binbasevar
PageBits[Bins.B_NUMSMALL] baseOffsetBits