Skip to content

Commit

Permalink
Move object deallocation functions to zct module
Browse files Browse the repository at this point in the history
Locality of reference
  • Loading branch information
blairmcg committed Nov 23, 2017
1 parent 0ba393e commit 7779924
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 52 deletions.
50 changes: 0 additions & 50 deletions dealloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,56 +132,6 @@ void ObjectMemory::deallocate(OTE* ote)
// Return to default setting
//#pragma auto_inline(on)


// Count down and deallocate an Object - only performed when reconciling
// the Zct.
//
void ObjectMemory::recursiveCountDown(OTE* ote)
{
if (ote->decRefs())
recursiveFree(ote);
}

OTE* __fastcall ObjectMemory::recursiveFree(OTE* rootOTE)
{
HARDASSERT(!isIntegerObject(rootOTE));
HARDASSERT(!isPermanent(rootOTE));
HARDASSERT(!rootOTE->isFree());
HARDASSERT(rootOTE->m_count == 0);

if (rootOTE->isFinalizable())
{
finalize(rootOTE);
rootOTE->beUnfinalizable();
}
else
{
// Deal with the class first, as this is now held in the OTE
recursiveCountDown(reinterpret_cast<POTE>(rootOTE->m_oteClass));

if (rootOTE->isPointers())
{
// Recurse through referenced objects as necessary
const MWORD lastPointer = rootOTE->getWordSize();
Oop* pFields = reinterpret_cast<Oop*>(rootOTE->m_location);
// Start after the header (only includes size now, which is not an Oop)
for (MWORD i = ObjectHeaderSize; i < lastPointer; i++)
{
Oop fieldPointer = pFields[i];
if (!isIntegerObject(fieldPointer))
{
OTE* fieldOTE = reinterpret_cast<OTE*>(fieldPointer);
recursiveCountDown(fieldOTE);
}
}
}

deallocate(rootOTE);
}

return rootOTE; // Important for some assembler routines - will be non-zero, so can act as TRUE
}

#pragma code_seg(GC_SEG)

// Free up a pool of objects maintained by the interpreter on request
Expand Down
54 changes: 52 additions & 2 deletions zct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,56 @@ void ObjectMemory::EmptyZct(Oop* const sp)
// CHECKREFSNOFIX
}


// Count down and deallocate an Object - only performed when reconciling
// the Zct.
//
void ObjectMemory::recursiveCountDown(OTE* ote)
{
if (ote->decRefs())
recursiveFree(ote);
}

OTE* __fastcall ObjectMemory::recursiveFree(OTE* rootOTE)
{
HARDASSERT(!isIntegerObject(rootOTE));
HARDASSERT(!isPermanent(rootOTE));
HARDASSERT(!rootOTE->isFree());
HARDASSERT(rootOTE->m_count == 0);

if (!rootOTE->isFinalizable())
{
// Deal with the class first, as this is now held in the OTE
recursiveCountDown(reinterpret_cast<POTE>(rootOTE->m_oteClass));

if (rootOTE->isPointers())
{
// Recurse through referenced objects as necessary
const MWORD lastPointer = rootOTE->getWordSize();
Oop* pFields = reinterpret_cast<Oop*>(rootOTE->m_location);
// Start after the header (only includes size now, which is not an Oop)
for (MWORD i = ObjectHeaderSize; i < lastPointer; i++)
{
Oop fieldPointer = pFields[i];
if (!isIntegerObject(fieldPointer))
{
OTE* fieldOTE = reinterpret_cast<OTE*>(fieldPointer);
recursiveCountDown(fieldOTE);
}
}
}

deallocate(rootOTE);
}
else
{
finalize(rootOTE);
rootOTE->beUnfinalizable();
}

return rootOTE; // Important for some assembler routines - will be non-zero, so can act as TRUE
}

void Interpreter::IncStackRefs(Oop* const sp)
{
Process* pProcess = actualActiveProcess();
Expand Down Expand Up @@ -229,12 +279,12 @@ void ObjectMemory::PopulateZct(Oop* const sp)
//CHECKREFSNOFIX
#endif

if (m_nZctEntries > (m_nZctHighWater - m_nZctHighWater / 4))
if (m_nZctEntries > (m_nZctHighWater - (m_nZctHighWater >> 2)))
{
// More than 75% full, then grow it
GrowZct();
}
else if ((m_nZctHighWater > (int)ZctMinSize) && (m_nZctEntries < m_nZctHighWater / 4))
else if ((m_nZctHighWater > (int)ZctMinSize) && (m_nZctEntries < (m_nZctHighWater >> 2)))
{
// Less than 25% full, so shrink it
ShrinkZct();
Expand Down

0 comments on commit 7779924

Please sign in to comment.