From 77799244e7dc96cc5f88b679510d14451930ca73 Mon Sep 17 00:00:00 2001 From: Blair McGlashan Date: Thu, 23 Nov 2017 17:56:30 +0000 Subject: [PATCH] Move object deallocation functions to zct module Locality of reference --- dealloc.cpp | 50 ------------------------------------------------- zct.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/dealloc.cpp b/dealloc.cpp index 49af3f6..a2fd13b 100644 --- a/dealloc.cpp +++ b/dealloc.cpp @@ -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(rootOTE->m_oteClass)); - - if (rootOTE->isPointers()) - { - // Recurse through referenced objects as necessary - const MWORD lastPointer = rootOTE->getWordSize(); - Oop* pFields = reinterpret_cast(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(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 diff --git a/zct.cpp b/zct.cpp index 3284a3a..fec7c9b 100644 --- a/zct.cpp +++ b/zct.cpp @@ -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(rootOTE->m_oteClass)); + + if (rootOTE->isPointers()) + { + // Recurse through referenced objects as necessary + const MWORD lastPointer = rootOTE->getWordSize(); + Oop* pFields = reinterpret_cast(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(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(); @@ -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();