MCPcopy Create free account
hub / github.com/beefytech/Beef / ObjectDeleteRequested

Method ObjectDeleteRequested

BeefRT/dbg/gc.cpp:956–997  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

954}
955
956void BFGC::ObjectDeleteRequested(bf::System::Object* obj)
957{
958 const PageID p = reinterpret_cast<uintptr_t>(obj) >> kPageShift;
959 size_t cl = Static::pageheap()->GetSizeClassIfCached(p);
960 intptr allocSize = 0;
961 if (cl == 0)
962 {
963 auto span = Static::pageheap()->GetDescriptor(p);
964 if (span != NULL)
965 {
966 cl = span->sizeclass;
967 if (cl == 0)
968 {
969 allocSize = span->length << kPageShift;
970 }
971 }
972 }
973 if (cl != 0)
974 allocSize = Static::sizemap()->class_to_size(cl);
975
976 int sizeOffset = *(uint16*)((uint8*)obj + allocSize - 2);
977 int requestedSize = allocSize - sizeOffset;
978 if ((sizeOffset < 4) || (sizeOffset >= allocSize) || (sizeOffset >= kPageSize + 4) ||
979 (*(uint16*)((uint8*)obj + requestedSize) != 0xBFBF))
980 {
981 Beefy::String err = Beefy::StrFormat("Memory deallocation detected write-past-end error in %d-byte object allocation at 0x%@", requestedSize, obj);
982 BF_FATAL(err);
983 return;
984 }
985
986 if (mFreeTrigger >= 0)
987 {
988 int objSize = BFGetObjectSize(obj);
989 if (BfpSystem_InterlockedExchangeAdd32((uint32*)&mFreeSinceLastGC, (uint32)objSize) + objSize >= mFreeTrigger)
990 {
991 mFreeSinceLastGC = 0;
992 Collect(true);
993 }
994
995 BFLOG1(GCLog::EVENT_DELETE, (intptr)obj);
996 }
997}
998
999bool BFGC::HandlePendingGCData()
1000{

Callers 1

Dbg_MarkObjectDeletedMethod · 0.80

Calls 4

BFGetObjectSizeFunction · 0.85
GetDescriptorMethod · 0.80
class_to_sizeMethod · 0.45

Tested by

no test coverage detected