Skip to content

Commit

Permalink
Reordering some conditionals so commonly not taken branch is first
Browse files Browse the repository at this point in the history
  • Loading branch information
blairmcg committed Nov 23, 2017
1 parent 7779924 commit 5f271e8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 38 deletions.
32 changes: 16 additions & 16 deletions GC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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++;
}
}
}

Expand Down
8 changes: 5 additions & 3 deletions bytecde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,11 @@ BlockOTE* __fastcall Interpreter::blockCopy(DWORD ext)

HARDASSERT(ObjectMemoryIsIntegerObject(*reinterpret_cast<Oop*>(&pBlock->m_info)));

if (extension.needsOuter)
if (!extension.needsOuter)
{
pBlock->m_outer = Pointers.Nil;
}
else
{
OTE* outerPointer = reinterpret_cast<OTE*>(frame->m_environment);
// If this assertion fires its a clean block, which we don't expect at present
Expand All @@ -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)
Expand Down
23 changes: 8 additions & 15 deletions objmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ class ObjectMemory

static FixedSizePool& spacePoolForSize(MWORD objectSize);

static void decRefs(OTE* ote);
static void decRefs(Oop);

#ifdef _DEBUG
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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<BYTE*>(&objectPointer);
OTE* ote = reinterpret_cast<OTE*>(objectPointer);
return reinterpret_cast<BYTE*>(ote->m_location);
}
else
{
OTE* ote = reinterpret_cast<OTE*>(objectPointer);
return reinterpret_cast<BYTE*>(ote->m_location);
return reinterpret_cast<BYTE*>(&objectPointer);
}
}

Expand All @@ -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<BYTE*>(&objectPointer);
BytesOTE* oteBytes = reinterpret_cast<BytesOTE*>(objectPointer);
return oteBytes->m_location->m_fields;
}
else
{
BytesOTE* oteBytes = reinterpret_cast<BytesOTE*>(objectPointer);
return oteBytes->m_location->m_fields;
return reinterpret_cast<BYTE*>(&objectPointer);
}
}

Expand Down
12 changes: 8 additions & 4 deletions ote.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,29 @@ template <class T> class TOTE

__forceinline MWORD getIndex() const { return this - reinterpret_cast<const TOTE<T>*>(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);
}

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<int>(m_size) < 0; }
__forceinline void beImmutable() { m_size |= ImmutabilityBit; }
__forceinline void beMutable() { m_size &= SizeMask; }
Expand Down

0 comments on commit 5f271e8

Please sign in to comment.