MCPcopy Create free account
hub / github.com/WheretIB/nullc / MarkUsedBlocks

Function MarkUsedBlocks

NULLC/translation/runtime.cpp:1010–1047  ·  view source on GitHub ↗

Main function for marking all pointers in a program

Source from the content-addressed store, hash-verified

1008
1009// Main function for marking all pointers in a program
1010void MarkUsedBlocks()
1011{
1012 GC_DEBUG_PRINT("Unmanageable range: %p-%p\r\n", GC::unmanageableBase, GC::unmanageableTop);
1013
1014 // Mark global variables
1015 for(unsigned int i = 0; i < rootSet.size(); i++)
1016 {
1017 GC_DEBUG_PRINT("Global %s (at %p)\r\n", __nullcTypeList[rootSet[i].typeID].name, rootSet[i].ptr);
1018 GC::CheckVariable((char*)rootSet[i].ptr, __nullcTypeList[rootSet[i].typeID]);
1019 }
1020 // Check that temporary stack range is correct
1021 assert(GC::unmanageableTop >= GC::unmanageableBase, "ERROR: GC - incorrect stack range", 0);
1022 char* tempStackBase = GC::unmanageableBase;
1023 // Check temporary stack for pointers
1024 while(tempStackBase < GC::unmanageableTop)
1025 {
1026 char *ptr = *(char**)(tempStackBase);
1027 // Check for unmanageable ranges. Range of 0x00000000-0x00010000 is unmanageable by default due to upvalues with offsets inside closures.
1028 if(ptr > (char*)0x00010000 && (ptr < GC::unmanageableBase || ptr > GC::unmanageableTop))
1029 {
1030 // Get pointer base
1031 unsigned int *basePtr = (unsigned int*)NULLC::GetBasePointer(ptr);
1032 // If there is no base, this pointer points to memory that is not GCs memory
1033 if(basePtr)
1034 {
1035 unsigned int *marker = (unsigned int*)(basePtr)-1;
1036 // If block is unmarked, mark it as used
1037 if((*marker & 0xff) == 0)
1038 {
1039 *marker |= 1;
1040 GC_DEBUG_PRINT("Found %s type %d on stack at %p\n", __nullcTypeList[*marker >> 8].name, *marker >> 8, ptr);
1041 GC::CheckVariable(ptr, __nullcTypeList[*marker >> 8]);
1042 }
1043 }
1044 }
1045 tempStackBase += 4;
1046 }
1047}
1048
1049void __nullcRegisterGlobal(void* ptr, unsigned typeID)
1050{

Callers 1

CollectMemoryMethod · 0.70

Calls 3

assertFunction · 0.85
CheckVariableFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected