mirror of
https://github.com/VSadov/Satori.git
synced 2025-06-10 18:11:04 +09:00
Conservative GC
This commit is contained in:
parent
f743383ad8
commit
1e11c3053e
4 changed files with 72 additions and 15 deletions
|
@ -219,6 +219,7 @@ SatoriPage* SatoriHeap::AddLargePage(size_t minSize)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
//TODO: VS unused?
|
||||
SatoriObject* SatoriHeap::ObjectForAddress(size_t address)
|
||||
{
|
||||
return PageForAddress(address)->RegionForAddress(address)->FindObject(address);
|
||||
|
@ -229,7 +230,11 @@ SatoriObject* SatoriHeap::ObjectForAddressChecked(size_t address)
|
|||
SatoriPage* page = PageForAddressChecked(address);
|
||||
if (page)
|
||||
{
|
||||
return page->RegionForAddress(address)->FindObject(address);
|
||||
SatoriRegion* region = page->RegionForAddress(address);
|
||||
if (region)
|
||||
{
|
||||
return region->FindObject(address);
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
|
|
@ -89,16 +89,21 @@ void SatoriPage::RegionDestroyed(SatoriRegion* region)
|
|||
}
|
||||
}
|
||||
|
||||
//TODO: VS should this be "Checked" ?
|
||||
SatoriRegion* SatoriPage::RegionForAddress(size_t address)
|
||||
{
|
||||
_ASSERTE(address >= Start() && address < End());
|
||||
size_t mapIndex = (address - Start()) >> Satori::REGION_BITS;
|
||||
while (RegionMap()[mapIndex] > 1)
|
||||
if (RegionMap()[mapIndex])
|
||||
{
|
||||
mapIndex -= ((size_t)1 << (RegionMap()[mapIndex] - 2));
|
||||
while (RegionMap()[mapIndex] > 1)
|
||||
{
|
||||
mapIndex -= ((size_t)1 << (RegionMap()[mapIndex] - 2));
|
||||
}
|
||||
return (SatoriRegion*)((mapIndex << Satori::REGION_BITS) + Start());
|
||||
}
|
||||
|
||||
return (SatoriRegion*)((mapIndex << Satori::REGION_BITS) + Start());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SatoriRegion* SatoriPage::NextInPage(SatoriRegion* region)
|
||||
|
|
|
@ -351,6 +351,13 @@ void SatoriRecycler::MarkFn(PTR_PTR_Object ppObject, ScanContext* sc, uint32_t f
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef FEATURE_CONSERVATIVE_GC
|
||||
if (GCConfig::GetConservativeGC() && o->IsFree())
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// TODO: VS when concurrent should not go into gen 0
|
||||
|
@ -1060,6 +1067,13 @@ void SatoriRecycler::UpdateFn(PTR_PTR_Object ppObject, ScanContext* sc, uint32_t
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef FEATURE_CONSERVATIVE_GC
|
||||
if (GCConfig::GetConservativeGC() && o->IsFree())
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// TODO: VS not sure we need to check the region.
|
||||
|
|
|
@ -459,9 +459,37 @@ inline int LocationToIndex(size_t location)
|
|||
return (location >> Satori::INDEX_GRANULARITY_BITS) % Satori::INDEX_LENGTH;
|
||||
}
|
||||
|
||||
// Finds an object that contains given location.
|
||||
//
|
||||
// Assumptions that caller must arrange or handle:
|
||||
// - we may return a Free object here.
|
||||
// - locations before the first object and after the last object match to the First/Last objects
|
||||
// - location must not be inside unparseable unconsumed budget when actively allocating.
|
||||
//
|
||||
// Typical usees:
|
||||
// - precise root marking.
|
||||
// not in allocating mode
|
||||
// always provides real refs into real objects.
|
||||
// - conservative root marking
|
||||
// not in allocating mode
|
||||
// can give refs outside of First/Last objects or pointing to Free
|
||||
// - escape checks for array copying.
|
||||
// always provides refs into real objects
|
||||
// may be in allocation mode, but uses the region owned by current thread, thus no allocations could happen concurrently.
|
||||
// - iterating over card table -
|
||||
// not in allocating mode
|
||||
// can give refs outside of First/Last objects or pointing to Free. (because of card granularity)
|
||||
SatoriObject* SatoriRegion::FindObject(size_t location)
|
||||
{
|
||||
_ASSERTE(location >= Start() && location <= End());
|
||||
_ASSERTE(location >= Start() && location < End());
|
||||
location = min(location, Start() + Satori::REGION_SIZE_GRANULARITY);
|
||||
|
||||
#ifdef FEATURE_CONSERVATIVE_GC
|
||||
if (GCConfig::GetConservativeGC() && m_generation < 0)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
// start search from the first object or after unparseable alloc gap
|
||||
SatoriObject* obj = (IsAllocating() && (location >= m_allocEnd)) ?
|
||||
|
@ -515,7 +543,7 @@ void SatoriRegion::MarkFn(PTR_PTR_Object ppObject, ScanContext* sc, uint32_t fla
|
|||
|
||||
// ignore objects outside of the current region.
|
||||
// this also rejects nulls and byrefs pointing to stack.
|
||||
if (location < (size_t)region->FirstObject() || location > region->End())
|
||||
if (location < (size_t)region->FirstObject() || location >= region->End())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -524,6 +552,13 @@ void SatoriRegion::MarkFn(PTR_PTR_Object ppObject, ScanContext* sc, uint32_t fla
|
|||
if (flags & GC_CALL_INTERIOR)
|
||||
{
|
||||
o = region->FindObject(location);
|
||||
|
||||
#ifdef FEATURE_CONSERVATIVE_GC
|
||||
if (GCConfig::GetConservativeGC() && o->IsFree())
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!o->IsMarked())
|
||||
|
@ -974,25 +1009,23 @@ void SatoriRegion::UpdateFn(PTR_PTR_Object ppObject, ScanContext* sc, uint32_t f
|
|||
size_t location = (size_t)*ppObject;
|
||||
|
||||
// ignore objects otside of the current region.
|
||||
// this also rejects nulls.
|
||||
if (location < (size_t)region->FirstObject() || location > region->End())
|
||||
// this also rejects nulls and byrefs pointing to stack.
|
||||
if (location < (size_t)region->FirstObject() || location >= region->End())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SatoriObject* o;
|
||||
SatoriObject* o = SatoriObject::At(location);
|
||||
if (flags & GC_CALL_INTERIOR)
|
||||
{
|
||||
o = region->FindObject(location);
|
||||
if (o == nullptr)
|
||||
|
||||
#ifdef FEATURE_CONSERVATIVE_GC
|
||||
if (GCConfig::GetConservativeGC() && o->IsFree())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
o = SatoriObject::At(location);
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t reloc = o->GetReloc();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue