core.internal.gc.impl.conservative.gc

Contains the garbage collector implementation.

Types 10

aliascurrTime = MonoTime.currTime

Debugging

aliasgc_t = GC
Fields
size_t line
char * file
Gcx *gcx gcx
shared(AlignedSpinLock)(SpinLock.Contention.brief) gcLock
bool _inFinalizer
bool isPrecise
Methods
void lockNR() @safe @nogc nothrow
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.
uint setAttr(void * p, uint mask) nothrowSets the specified bits for the memory references by p.
uint clrAttr(void * p, uint mask) nothrowClears the specified bits for the memory references 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) nothrow
BlkInfo qalloc( size_t size, uint bits, const scope TypeInfo ti) nothrow
void *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) nothrow
size_t extend(void * p, size_t minsize, size_t maxsize, const TypeInfo ti) nothrow
private size_t extendNoSync(void * p, size_t minsize, size_t maxsize, const TypeInfo ti = null) nothrow
size_t reserve(size_t size) nothrowRequests that at least size bytes of memory be obtained from the operating system and marked as free.
private size_t reserveNoSync(size_t size) nothrow
void free(void * p) nothrowDeallocates the memory referenced by p.
private bool freeNoSync(void * p) nothrow @nogc
void * addrOf(void * p) nothrowDetermine the base address of the block containing p. If p is not a gc allocated pointer, return null.
void * addrOfNoSync(void * p) nothrow @nogc
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.
private size_t sizeOfNoSync(void * p) nothrow @nogc
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) nothrow
void 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...
private void checkNoSync(void * p) nothrow
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 runFinalizers(const scope void[] segment) nothrowRun all finalizers in the code segment.
bool inFinalizer() nothrow @nogc
void collect() nothrow
size_t fullCollect() nothrowBegins a full collection, scanning all stack segments for roots.
void minimize() nothrowMinimize free space usage.
core.memory.GC.Stats stats() @safe nothrow @nogc
core.memory.GC.ProfileStats profileStats() nothrow @trusted
ulong allocatedInCurrentThread() nothrow
private void getStatsNoSync(out core.memory.GC.Stats stats) @trusted nothrow @nogc
void[] getArrayUsed(void * ptr, bool atomic = false) nothrow
bool expandArrayUsed(void[] slice, size_t newUsed, bool atomic = false) nothrow @trusted
bool shrinkArrayUsed(void[] slice, size_t existingUsed, bool atomic = false) nothrow
size_t reserveArrayCapacity(void[] slice, size_t request, bool atomic = false) nothrow @trusted
void initThread(ThreadBase t) nothrow @nogc
void cleanupThread(ThreadBase t) nothrow @nogc
Constructors
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
structList
Fields
List *next next
Pool *pool pool
aliasPageBits = GCBits.wordtype[PAGESIZE / 16 / GCBits.BITS_PER_WORD]
structGcx
Fields
shared(AlignedSpinLock)(SpinLock.Contention.brief) rootsLock
shared(AlignedSpinLock)(SpinLock.Contention.brief) rangesLock
Treap!Root roots
Treap!Range ranges
bool minimizeAfterNextCollection
uint disabled
PoolTable!Pool pooltable
List *[Bins.B_NUMSMALL] bucket
float smallCollectThreshold
uint usedSmallPages
uint mappedPages
SmallObjectPool *[Bins.B_NUMSMALL] recoverPool
Bins[2049] binTable
uint numScanThreads
ScanThreadData * scanThreadData
Event evStackFilled
Event evDone
uint busyThreads
uint stoppedThreads
bool stopGC
shared(AlignedSpinLock)(SpinLock.Contention.brief) stackLock
Methods
void initialize()
void Dtor()
void Invariant() const
bool collectInProgress() @property const nothrow
void addRoot(void * p) nothrow @nogc
void removeRoot(void * p) nothrow @nogc
int rootsApply(scope int delegate(ref Root) nothrow dg) nothrow
void addRange(void * pbot, void * ptop, const TypeInfo ti) nothrow @nogc
void removeRange(void * pbot) nothrow @nogc
int rangesApply(scope int delegate(ref Range) nothrow dg) nothrow
void runFinalizers(const scope void[] segment) nothrow
Pool * findPool(void * p) pure nothrow @nogc
void * findBase(void * p) nothrow @nogcFind base address of block containing pointer p. Returns null if not a gc'd pointer
size_t findSize(void * p) nothrow @nogcFind size of pointer p. Returns 0 if not a gc'd pointer
BlkInfo getInfo(void * p) nothrow
Bins[2049] ctfeBins() nothrowComputes the bin table using CTFE.
size_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 updateCollectThresholds() nothrowUpdate the thresholds for when to collect the next time
void minimize() nothrowMinimizes physical memory usage by returning free pools to the OS.
private bool lowMem() @property const nothrow
void * alloc(size_t size, ref size_t alloc_size, uint bits, const TypeInfo ti) nothrow
void * smallAlloc(size_t size, ref size_t alloc_size, uint bits, const TypeInfo ti) nothrow
void * 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 entries
private 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 markConservative(bool shared_mem)(void * pbot, void * ptop) scope nothrow
void markPrecise(bool shared_mem)(void * pbot, void * ptop) scope nothrow
void prepare() nothrow
void markAll(alias markFn)() nothrow
size_t sweep() nothrow
bool recoverPage(SmallObjectPool * pool, size_t pn, Bins bin) nothrow
bool recoverNextPage(Bins bin) nothrow
private SmallObjectPool * setNextRecoverPool(Bins bin, size_t poolIndex) nothrow
size_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.
IsMarked isMarked(void * addr) scope nothrowReturns true if the addr lies within a marked block.
void markParallel() nothrow
int maxParallelThreads() nothrow
void startScanThreads() nothrow
void stopScanThreads() nothrow
void scanBackground() nothrow
bool pullFromScanStack() nothrow
bool pullFromScanStackImpl(bool precise)() nothrow
void scanStackPushLocked(bool precise)(ScanRange!precise[] ranges)
bool scanStackPopLocked(bool precise)(ref ScanRange!precise rng)
Nested Templates
ScanRange
ToScanStack
scanStack(bool precise)
ScanThreadData
structPool
Fields
void * baseAddr
void * topAddr
size_t ptIndex
GCBits mark
GCBits freebits
GCBits finals
GCBits structFinals
GCBits noscan
GCBits appendable
GCBits nointerior
GCBits is_pointer
size_t npages
size_t freepages
Bins * pagetable
bool isLargeObject
ShiftBy shiftBy
uint * bPageOffsets
uint.max PageRecovered
uint[Bins.B_NUMSMALL] recoverPageFirst
immutable(size_t) * * rtinfo
size_t searchStart
size_t largestFree
Methods
void initialize(size_t npages, bool isLargeObject) nothrow
void Dtor() nothrow
uint getBits(size_t biti) nothrow
void clrBits(size_t biti, uint mask) nothrow @nogc
void setBits(size_t biti, uint mask) nothrow
void freePageBits(size_t pagenum, const scope ref PageBits toFree) nothrow
void freeAllPageBits(size_t pagenum) nothrow
size_t pagenumOf(void * p) const nothrow @nogcGiven a pointer p in the p, return the pagenum.
bool isFree() @property const scope @safe pure nothrow @nogc
size_t numPages(size_t size) nothrow @nogcReturn number of pages necessary for an allocation of the given size
void * findBase(void * p) nothrow @nogc
size_t slGetSize(void * p) nothrow @nogc
BlkInfo slGetInfo(void * p) nothrow
void Invariant() const
void setPointerBitmapSmall(void * p, size_t s, size_t allocSize, uint attr, const TypeInfo ti) nothrow
void setPointerBitmap(void * p, size_t s, size_t allocSize, const TypeInfo ti, uint attr) nothrow
Nested Templates
ShiftBy
Fields
Pool base
Methods
size_t allocPages(size_t n) nothrowAllocate n pages from Pool. Returns OPFAIL on failure.
void freePages(size_t pagenum, size_t npages) nothrow @nogcFree npages pages starting with pagenum.
void setFreePageOffsets(size_t page, size_t num) nothrow @nogcSet the first and the last entry of a B_FREE block to the size
void mergeFreePageOffsets(bool bwd, bool fwd)(size_t page, size_t num) nothrow @nogc
size_t getPages(void * p) const nothrow @nogcGet pages of allocation at pointer p in pool.
size_t getSize(size_t pn) const nothrow @nogcGet size of allocation at page pn in pool.
BlkInfo getInfo(void * p) nothrow
void runFinalizers(const scope void[] segment) nothrow
Fields
Pool base
Methods
size_t getSize(void * p) const nothrow @nogcGet size of pointer p in pool.
BlkInfo getInfo(void * p) nothrow
void runFinalizers(const scope void[] segment) nothrow
List * allocPage(Bins bin) nothrowAllocate a page of bin's. Returns: head of a single linked list of new entries

Functions 18

fnvoid rt_finalizeFromGC(void * p, size_t size, uint attr, const(TypeInfo) typeInfo) nothrow;
fnint rt_hasFinalizerInSegment(void * p, size_t size, const(TypeInfo) typeInfo, const scope void[] segment) nothrow;
fnnoreturn onInvalidMemoryOperationError(void * pretend_sideffect = null, string file = __FILE__, size_t line = __LINE__) @trusted pure nothrow @nogc
fnnoreturn onOutOfMemoryError(void * pretend_sideffect = null, string file = __FILE__, size_t line = __LINE__) @trusted pure nothrow @nogc
private fnvoid gc_conservative_ctor()
private fnvoid gc_precise_ctor()
private fnGC initialize()
fnshort[PAGESIZE / 16][Bins.B_NUMSMALL + 1] calcBinBase()
fnsize_t baseOffset(size_t offset, Bins bin) @nogc nothrow
private fnvoid set(ref PageBits bits, size_t i) @nogc pure nothrow
fnvoid 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.
fnT undefinedRead(T)(ref T var) nothrowRead memory that should otherwise be marked as unreadable (e.g. free lists overlapped with unallocated heap objects).
fnvoid undefinedWrite(T)(ref T var, T value) nothrowWrite memory that should otherwise be marked as unwritable.
private fnvoid adjustAttrs(ref uint attrs, const TypeInfo ti) nothrow
private fnvoid[] setupMetadata(void[] block, uint bits, size_t padding, size_t used, const TypeInfo ti) nothrow

Variables 23

varDuration prepTime
varDuration markTime
varDuration sweepTime
varDuration pauseTime
varDuration maxPauseTime
varDuration maxCollectionTime
varsize_t numCollections
varsize_t maxPoolMemory
varlong numMallocs
varlong numFrees
varlong numReallocs
varlong numExtends
varlong numOthers
varlong mallocTime
varlong freeTime
varlong reallocTime
varlong extendTime
varlong otherTime
varlong lockTime
varulong bytesAllocated
varshort[Bins.B_NUMSMALL + 1] binsize
varshort[PAGESIZE / 16][Bins.B_NUMSMALL + 1] binbase
varPageBits[Bins.B_NUMSMALL] baseOffsetBits