From 5f271e830159851c53f109fcdec6357946b716c3 Mon Sep 17 00:00:00 2001 From: Blair McGlashan Date: Thu, 23 Nov 2017 17:57:34 +0000 Subject: [PATCH] Reordering some conditionals so commonly not taken branch is first --- GC.cpp | 32 ++++++++++++++++---------------- bytecde.cpp | 8 +++++--- objmem.h | 23 ++++++++--------------- ote.h | 12 ++++++++---- 4 files changed, 37 insertions(+), 38 deletions(-) diff --git a/GC.cpp b/GC.cpp index 2259a88..253502f 100755 --- a/GC.cpp +++ b/GC.cpp @@ -249,7 +249,7 @@ void ObjectMemory::reclaimInaccessibleObjects(DWORD gcFlags) fieldOTE << "(" << (UINT)fieldOTE << "/" << indexOfObject(fieldOTE) << " refs " << int(ote->m_flags.m_count) << ")" << endl; #endif - decRefs(fieldOTE); + fieldOTE->decRefs(); weakObj->m_fields[j] = corpse; losses++; } @@ -300,21 +300,7 @@ void ObjectMemory::reclaimInaccessibleObjects(DWORD gcFlags) HARDASSERT(!ObjectMemory::hasCurrentMark(ote)); // We found a dying object, finalize it if necessary - if (oteFlags & OTE::FinalizeMask) - { - #if 0//def _DEBUG - TRACESTREAM << "Finalizing " << ote << endl; - #endif - - Interpreter::basicQueueForFinalization(ote); - // Prevent a second finalization - ote->beUnfinalizable(); - // We must ensure the object has the current mark so that it doesn't cock up the - // next GC in case it survives that long - markObject(ote); - queuedForFinalize++; - } - else + if (!(oteFlags & OTE::FinalizeMask)) { // It doesn't want finalizing, so we can free it // Countdown all refs from objects which are to be @@ -371,6 +357,20 @@ void ObjectMemory::reclaimInaccessibleObjects(DWORD gcFlags) deallocate(ote); deletions++; } + else + { +#if 0//def _DEBUG + TRACESTREAM << "Finalizing " << ote << endl; +#endif + + Interpreter::basicQueueForFinalization(ote); + // Prevent a second finalization + ote->beUnfinalizable(); + // We must ensure the object has the current mark so that it doesn't cock up the + // next GC in case it survives that long + markObject(ote); + queuedForFinalize++; + } } } diff --git a/bytecde.cpp b/bytecde.cpp index 490f2fa..71ace76 100755 --- a/bytecde.cpp +++ b/bytecde.cpp @@ -654,7 +654,11 @@ BlockOTE* __fastcall Interpreter::blockCopy(DWORD ext) HARDASSERT(ObjectMemoryIsIntegerObject(*reinterpret_cast(&pBlock->m_info))); - if (extension.needsOuter) + if (!extension.needsOuter) + { + pBlock->m_outer = Pointers.Nil; + } + else { OTE* outerPointer = reinterpret_cast(frame->m_environment); // If this assertion fires its a clean block, which we don't expect at present @@ -680,8 +684,6 @@ BlockOTE* __fastcall Interpreter::blockCopy(DWORD ext) // We've added a heap object to home context so we must count it outerPointer->countUp(); } - else - pBlock->m_outer = Pointers.Nil; const unsigned nValuesToCopy = extension.copiedValuesCount; if (nValuesToCopy > 0) diff --git a/objmem.h b/objmem.h index 12d7f94..d53ae40 100755 --- a/objmem.h +++ b/objmem.h @@ -392,7 +392,6 @@ class ObjectMemory static FixedSizePool& spacePoolForSize(MWORD objectSize); - static void decRefs(OTE* ote); static void decRefs(Oop); #ifdef _DEBUG @@ -531,12 +530,6 @@ inline bool ObjectMemory::isValidOop(Oop objectPointer) // Macro to calculate the byte size of an object with N pointers #define SizeOfPointers(N) (((N)+ObjectHeaderSize)*sizeof(MWORD)) -inline void ObjectMemory::decRefs(OTE* ote) -{ - ASSERT(!isIntegerObject(ote)); - ote->decRefs(); -} - inline void ObjectMemory::decRefs(Oop oop) { if (!isIntegerObject(oop)) @@ -774,14 +767,14 @@ inline bool ObjectMemory::isAContext(const OTE* ote) inline BYTE* ObjectMemory::ByteAddressOfObject(Oop& objectPointer) { - if (isIntegerObject(objectPointer)) + if (!isIntegerObject(objectPointer)) { - return reinterpret_cast(&objectPointer); + OTE* ote = reinterpret_cast(objectPointer); + return reinterpret_cast(ote->m_location); } else { - OTE* ote = reinterpret_cast(objectPointer); - return reinterpret_cast(ote->m_location); + return reinterpret_cast(&objectPointer); } } @@ -792,14 +785,14 @@ inline BYTE* ObjectMemory::ByteAddressOfObject(Oop& objectPointer) // byte after the header. inline BYTE* ObjectMemory::ByteAddressOfObjectContents(Oop& objectPointer) { - if (isIntegerObject(objectPointer)) + if (!isIntegerObject(objectPointer)) { - return reinterpret_cast(&objectPointer); + BytesOTE* oteBytes = reinterpret_cast(objectPointer); + return oteBytes->m_location->m_fields; } else { - BytesOTE* oteBytes = reinterpret_cast(objectPointer); - return oteBytes->m_location->m_fields; + return reinterpret_cast(&objectPointer); } } diff --git a/ote.h b/ote.h index 46d084d..8790edb 100644 --- a/ote.h +++ b/ote.h @@ -81,12 +81,16 @@ template class TOTE __forceinline MWORD getIndex() const { return this - reinterpret_cast*>(ObjectMemory::m_pOT); } - __forceinline void countUp() { if (m_count < MAXCOUNT) m_count++; } + __forceinline void countUp() + { + BYTE up = m_count + 1; + if (up != 0) m_count = up; + } __forceinline void countDown() { HARDASSERT(m_count > 0); - if (m_count < MAXCOUNT) + if (m_count != MAXCOUNT) if (--m_count == 0) ObjectMemory::AddToZct((OTE*)this); } @@ -94,12 +98,12 @@ template class TOTE void countDownStackRef() { HARDASSERT(m_count > 0); - if (m_count < MAXCOUNT) + if (m_count != MAXCOUNT) if (--m_count == 0) ObjectMemory::AddStackRefToZct((OTE*)this); } - __forceinline bool decRefs() { return (m_count < MAXCOUNT) && (--m_count == 0); } + __forceinline bool decRefs() { return (m_count != MAXCOUNT) && (--m_count == 0); } __forceinline bool isImmutable() const { return static_cast(m_size) < 0; } __forceinline void beImmutable() { m_size |= ImmutabilityBit; } __forceinline void beMutable() { m_size &= SizeMask; }