Skip to content

Commit

Permalink
Replace all unscoped enums in interprt.h with constexpr and enum class
Browse files Browse the repository at this point in the history
Modernisation contributing to #531
  • Loading branch information
blairmcg committed Mar 24, 2020
1 parent 8bb9ba0 commit e7e03b3
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 117 deletions.
14 changes: 7 additions & 7 deletions Core/DolphinVM/GCPrim.cpp
Expand Up @@ -37,7 +37,7 @@ bool Interpreter::disableAsyncGC(bool bDisable)
{
m_nOTOverflows = 0;
CHECKREFERENCES
queueInterrupt(VMI_OTOVERFLOW, ObjectMemoryIntegerObjectOf(ObjectMemory::GetOTSize()));
queueInterrupt(VMInterrupts::OtOverflow, ObjectMemoryIntegerObjectOf(ObjectMemory::GetOTSize()));
}
return true;
}
Expand All @@ -54,7 +54,7 @@ void Interpreter::NotifyOTOverflow()
else
{
CHECKREFERENCES
queueInterrupt(VMI_OTOVERFLOW, ObjectMemoryIntegerObjectOf(ObjectMemory::GetOTSize()));
queueInterrupt(VMInterrupts::OtOverflow, ObjectMemoryIntegerObjectOf(ObjectMemory::GetOTSize()));
}
}

Expand All @@ -77,7 +77,7 @@ void Interpreter::asyncGC(uintptr_t gcFlags)
#ifdef _DEBUG
if (Interpreter::executionTrace != 0)
{
for (auto i=0u;i<NUMOTEPOOLS;i++)
for (auto i=0u;i<NumOtePools;i++)
m_otePools[i].DumpStats();
}
#endif
Expand Down Expand Up @@ -112,7 +112,7 @@ Oop* __fastcall Interpreter::primitiveCoreLeft(Oop* const sp , primargcount_t ar
#ifdef _DEBUG
void Interpreter::DumpOTEPoolStats()
{
for (auto i=0u;i<NUMOTEPOOLS;i++)
for (auto i=0u;i<NumOtePools;i++)
m_otePools[i].DumpStats();
}
#endif
Expand All @@ -129,7 +129,7 @@ void Interpreter::freePools()
// Must first adjust context size back to normal for free
// in case from a pool (avoids freeing mem back to smaller pool)
{
OTE* ote = m_otePools[CONTEXTPOOL].m_pFreeList;
OTE* ote = m_otePools[static_cast<size_t>(Pools::Contexts)].m_pFreeList;
const size_t sizeOfPoolContext = SizeOfPointers(Context::FixedSize+Context::MaxEnvironmentTemps);
while (ote)
{
Expand All @@ -140,7 +140,7 @@ void Interpreter::freePools()
}

{
OTE* ote = m_otePools[BLOCKPOOL].m_pFreeList;
OTE* ote = m_otePools[static_cast<size_t>(Pools::Blocks)].m_pFreeList;
const size_t sizeOfPoolBlock = SizeOfPointers(BlockClosure::FixedSize+BlockClosure::MaxCopiedValues);
while (ote)
{
Expand All @@ -154,7 +154,7 @@ void Interpreter::freePools()
//DumpOTEPoolStats();
#endif

for (auto i=0u;i<NUMOTEPOOLS;i++)
for (auto i=0u;i<NumOtePools;i++)
m_otePools[i].clear();

#if defined(_DEBUG) && defined(VMDLL)
Expand Down
82 changes: 42 additions & 40 deletions Core/DolphinVM/Interprt.h
Expand Up @@ -258,32 +258,33 @@ class Interpreter

public:

enum VMInterrupts {
VMI_TERMINATE = ObjectMemoryIntegerObjectOf(1),
VMI_STACKOVERFLOW = ObjectMemoryIntegerObjectOf(2),
VMI_BREAKPOINT = ObjectMemoryIntegerObjectOf(3),
VMI_SINGLESTEP = ObjectMemoryIntegerObjectOf(4),
VMI_ACCESSVIOLATION = ObjectMemoryIntegerObjectOf(5),
VMI_IDLEPANIC = ObjectMemoryIntegerObjectOf(6),
VMI_GENERIC = ObjectMemoryIntegerObjectOf(7),
VMI_STARTED = ObjectMemoryIntegerObjectOf(8),
VMI_KILL = ObjectMemoryIntegerObjectOf(9),
VMI_FPFAULT = ObjectMemoryIntegerObjectOf(10),
VMI_USERINTERRUPT = ObjectMemoryIntegerObjectOf(11),
VMI_ZERODIVIDE = ObjectMemoryIntegerObjectOf(12),
VMI_OTOVERFLOW = ObjectMemoryIntegerObjectOf(13),
VMI_CONSTWRITE = ObjectMemoryIntegerObjectOf(14),
enum class VMInterrupts : SmallInteger {
Terminate = ObjectMemoryIntegerObjectOf(1),
StackOverflow = ObjectMemoryIntegerObjectOf(2),
Breakpoint = ObjectMemoryIntegerObjectOf(3),
SingleStep = ObjectMemoryIntegerObjectOf(4),
AccessViolation = ObjectMemoryIntegerObjectOf(5),
IdlePanic = ObjectMemoryIntegerObjectOf(6),
Generic = ObjectMemoryIntegerObjectOf(7),
Started = ObjectMemoryIntegerObjectOf(8),
Kill = ObjectMemoryIntegerObjectOf(9),
FpFault = ObjectMemoryIntegerObjectOf(10),
UserInterrupt = ObjectMemoryIntegerObjectOf(11),
ZeroDivide = ObjectMemoryIntegerObjectOf(12),
OtOverflow = ObjectMemoryIntegerObjectOf(13),
ConstWrite = ObjectMemoryIntegerObjectOf(14),
// Miscellaneous exceptions
VMI_EXCEPTION = ObjectMemoryIntegerObjectOf(15),
VMI_FPSTACK = ObjectMemoryIntegerObjectOf(16),
VMI_NOMEMORY = ObjectMemoryIntegerObjectOf(17),
VMI_HOSPICECRISIS = ObjectMemoryIntegerObjectOf(18),
VMI_BEREAVEDCRISIS = ObjectMemoryIntegerObjectOf(19),
VMI_CRTFAULT = ObjectMemoryIntegerObjectOf(20)
Exception = ObjectMemoryIntegerObjectOf(15),
FpStack = ObjectMemoryIntegerObjectOf(16),
NoMemory = ObjectMemoryIntegerObjectOf(17),
HospiceCrisis = ObjectMemoryIntegerObjectOf(18),
BereavedCrisis = ObjectMemoryIntegerObjectOf(19),
CrtFault = ObjectMemoryIntegerObjectOf(20)
};

#ifdef _DEBUG
static const char* InterruptNames[static_cast<size_t>(VMI_CRTFAULT) + 1];
static constexpr size_t NumInterrupts = static_cast<size_t>(VMInterrupts::CrtFault) + 1;
static const char* InterruptNames[NumInterrupts];
#endif

static bool __fastcall disableInterrupts(bool bDisable);
Expand Down Expand Up @@ -338,16 +339,16 @@ class Interpreter
static int callbackTerminationFilter(LPEXCEPTION_POINTERS info, Process* callbackProcess, Oop prevCallbackContext);

static void recoverFromFault(LPEXCEPTION_POINTERS pExRec);
static void sendExceptionInterrupt(Oop oopInterrupt, LPEXCEPTION_POINTERS pExRec);
static void sendExceptionInterrupt(VMInterrupts oopInterrupt, LPEXCEPTION_POINTERS pExRec);
static bool saveContextAfterFault(LPEXCEPTION_POINTERS info);

static void wakePendingCallbacks();
static size_t countPendingCallbacks();

static void sendSelectorArgumentCount(SymbolOTE* selector, argcount_t count);
static void sendSelectorToClass(BehaviorOTE* classPointer, argcount_t argCount);
static void sendVMInterrupt(ProcessOTE* processPointer, Oop nInterrupt, Oop argPointer);
static void __fastcall sendVMInterrupt(Oop nInterrupt, Oop argPointer);
static void sendVMInterrupt(ProcessOTE* processPointer, VMInterrupts nInterrupt, Oop argPointer);
static void __fastcall sendVMInterrupt(VMInterrupts nInterrupt, Oop argPointer);

static BOOL __stdcall MsgSendPoll();
static BOOL __stdcall BytecodePoll();
Expand All @@ -370,8 +371,8 @@ class Interpreter
static constexpr size_t OopsPerBereavementQEntry = 2;

// Queue a process interrupt to be executed at the earliest opportunity
static void __stdcall queueInterrupt(ProcessOTE* processPointer, Oop nInterrupt, Oop argPointer);
static void __stdcall queueInterrupt(Oop nInterrupt, Oop argPointer);
static void __stdcall queueInterrupt(ProcessOTE* processPointer, VMInterrupts nInterrupt, Oop argPointer);
static void __stdcall queueInterrupt(VMInterrupts nInterrupt, Oop argPointer);

// Queue up a semaphore signal to be performed in sync with byte code execution
// at the next possible opportunity. Used from interrupts and from external sources
Expand Down Expand Up @@ -775,33 +776,34 @@ class Interpreter

public:
// Special Selector Table
enum {NumSpecialSelectors = 32};
static constexpr size_t NumSpecialSelectors = 32;

private:
// Method cache is a hash table with overwrite on collision
// If changing method cache size, then must also modify METHODCACHEWORDS in ISTASM.INC!
constexpr static size_t MethodCacheSize = 1024;
static constexpr size_t MethodCacheSize = 1024;
static MethodCacheEntry methodCache[MethodCacheSize];

static void flushCaches();
static void initializeCaches();

enum { FIXEDVMREFERENCES };
enum { SIGNALQGROWTH=32, SIGNALQSIZE=64 };
enum { INTERRUPTQGROWTH=8, INTERRUPTQSIZE=16 };
enum { FINALIZEQSIZE = 128 };
enum { FINALIZEQGROWTH = 128 };
enum { BEREAVEMENTQSIZE = 64 };
enum { BEREAVEMENTQGROWTH=64 };
static constexpr size_t FixedVmReferences = 0;
static constexpr size_t SignalQueueGrowth=32, SignalQueueSize=64;
static constexpr size_t InterruptQueueGrowth=8, InterruptQueueSize=16;
static constexpr size_t FinalizeQueueSize = 128;
static constexpr size_t FinalizeQueueGrowth = 128;
static constexpr size_t BereavementQueueSize = 64;
static constexpr size_t BereavementQueueGrowth=64;

private:
// Critical section to protect the async queues
static CRITICAL_SECTION m_csAsyncProtect;

public:
// Pools
enum { DWORDPOOL, FLOATPOOL, CONTEXTPOOL, BLOCKPOOL, NUMOTEPOOLS };
static ObjectMemory::OTEPool m_otePools[NUMOTEPOOLS];
enum class Pools { Dwords, Floats, Contexts, Blocks };
static constexpr size_t NumOtePools = static_cast<size_t>(Pools::Blocks) + 1;
static ObjectMemory::OTEPool m_otePools[NumOtePools];
private:

// Process related registers
Expand Down Expand Up @@ -875,8 +877,8 @@ class Interpreter
static SmallInteger m_nFreeVMRef;
static SmallInteger m_nMaxVMRefs; // Current size of VM References array

enum { VMREFSINITIAL = 16 };
enum { VMREFSGROWTH = 64 };
static constexpr size_t VMREFSINITIAL = 16;
static constexpr size_t VMREFSGROWTH = 64;
#endif
};

Expand Down
2 changes: 1 addition & 1 deletion Core/DolphinVM/Interprt.inl
Expand Up @@ -239,7 +239,7 @@ inline void Interpreter::queueForFinalization(OTE* ote, SmallUinteger highWater)
size_t count = m_qForFinalize.Count();
// Only raise interrupt when high water mark is hit!
if (count == highWater)
queueInterrupt(VMI_HOSPICECRISIS, ObjectMemoryIntegerObjectOf(count));
queueInterrupt(VMInterrupts::HospiceCrisis, ObjectMemoryIntegerObjectOf(count));
}

inline void Interpreter::queueForBereavementOf(OTE* ote, Oop argPointer)
Expand Down
14 changes: 7 additions & 7 deletions Core/DolphinVM/InterprtInit.cpp
Expand Up @@ -67,22 +67,22 @@ void Interpreter::initializeVMReferences()

// Initialize the various VM circular queues
if (_Pointers.SignalQueue->isNil())
_Pointers.SignalQueue = Array::New(SIGNALQSIZE);
_Pointers.SignalQueue = Array::New(SignalQueueSize);
ASSERT(_Pointers.SignalQueue->m_oteClass == _Pointers.ClassArray);
m_qAsyncSignals.UseBuffer(_Pointers.SignalQueue, SIGNALQGROWTH, true);
m_qAsyncSignals.UseBuffer(_Pointers.SignalQueue, SignalQueueGrowth, true);

if (_Pointers.InterruptQueue->isNil())
_Pointers.InterruptQueue = Array::New(INTERRUPTQSIZE);
_Pointers.InterruptQueue = Array::New(InterruptQueueSize);
ASSERT(_Pointers.InterruptQueue->m_oteClass == _Pointers.ClassArray);
m_qInterrupts.UseBuffer(_Pointers.InterruptQueue, INTERRUPTQGROWTH, false);
m_qInterrupts.UseBuffer(_Pointers.InterruptQueue, InterruptQueueGrowth, false);

ArrayOTE* finalizeQueue = _Pointers.FinalizeQueue;
ASSERT(finalizeQueue->m_oteClass == Pointers.ClassArray);
m_qForFinalize.UseBuffer(finalizeQueue, FINALIZEQGROWTH, true);
m_qForFinalize.UseBuffer(finalizeQueue, FinalizeQueueGrowth, true);

ArrayOTE* bereavementQueue = _Pointers.BereavementQueue;
ASSERT(bereavementQueue->m_oteClass == Pointers.ClassArray);
m_qBereavements.UseBuffer(bereavementQueue, BEREAVEMENTQGROWTH, true);
m_qBereavements.UseBuffer(bereavementQueue, BereavementQueueGrowth, true);

ObjectMemory::InitializeMemoryManager();

Expand Down Expand Up @@ -116,5 +116,5 @@ void Interpreter::sendStartup(const wchar_t* szImagePath, uintptr_t arg)
// We no longer need to ref. count things we push on the stack, sendVMInterrupt will count
// down the argument after it has pushed it on the stack, possibly causing its addition to the Zct
oteArgs->m_count = 1;
sendVMInterrupt(VMI_STARTED, reinterpret_cast<Oop>(oteArgs));
sendVMInterrupt(VMInterrupts::Started, reinterpret_cast<Oop>(oteArgs));
}
2 changes: 1 addition & 1 deletion Core/DolphinVM/byteasm.asm
Expand Up @@ -92,7 +92,7 @@ ENDIF

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; C++ method imports
SENDVMINTERRUPT EQU ?sendVMInterrupt@Interpreter@@CIXII@Z
SENDVMINTERRUPT EQU ?sendVMInterrupt@Interpreter@@CIXW4VMInterrupts@1@I@Z
extern SENDVMINTERRUPT:near32

FINDNEWMETHODNOCACHE EQU ?findNewMethodInClassNoCache@Interpreter@@SGPAUMethodCacheEntry@1@PAV?$TOTE@VBehavior@ST@@@@I@Z ; STDCALL, OTE return and arg
Expand Down
6 changes: 3 additions & 3 deletions Core/DolphinVM/bytecde.cpp
Expand Up @@ -211,7 +211,7 @@ inline BOOL Interpreter::sampleInput()
#ifdef _DEBUG
WarningWithStackTrace(L"User Interrupt:");
#endif
queueInterrupt(VMI_USERINTERRUPT, Oop(Pointers.Nil));
queueInterrupt(VMInterrupts::UserInterrupt, Oop(Pointers.Nil));
}
// By setting a Win32 event we guarantee that the image will continue
// even if about to make a call to MsgWaitForMultipleObjects(), if we
Expand Down Expand Up @@ -505,7 +505,7 @@ ContextOTE* __fastcall Context::New(size_t tempCount, Oop oopOuter)
{
// Can allocate from pool of contexts

newContext = reinterpret_cast<ContextOTE*>(Interpreter::m_otePools[Interpreter::CONTEXTPOOL].newPointerObject(Pointers.ClassContext,
newContext = reinterpret_cast<ContextOTE*>(Interpreter::m_otePools[static_cast<size_t>(Interpreter::Pools::Contexts)].newPointerObject(Pointers.ClassContext,
FixedSize + MaxEnvironmentTemps, OTEFlags::ContextSpace));
pContext = newContext->m_location;

Expand Down Expand Up @@ -540,7 +540,7 @@ BlockOTE* __fastcall BlockClosure::New(size_t copiedValuesCount)
{
// Can allocate from pool of contexts

newBlock = reinterpret_cast<BlockOTE*>(Interpreter::m_otePools[Interpreter::BLOCKPOOL].newPointerObject(Pointers.ClassBlockClosure,
newBlock = reinterpret_cast<BlockOTE*>(Interpreter::m_otePools[static_cast<size_t>(Interpreter::Pools::Blocks)].newPointerObject(Pointers.ClassBlockClosure,
FixedSize + MaxCopiedValues, OTEFlags::BlockSpace));
BlockClosure* pClosure = newBlock->m_location;

Expand Down
8 changes: 4 additions & 4 deletions Core/DolphinVM/dealloc.cpp
Expand Up @@ -93,16 +93,16 @@ void ObjectMemory::deallocate(OTE* ote)
break;

case OTEFlags::BlockSpace:
Interpreter::m_otePools[Interpreter::BLOCKPOOL].deallocate(ote);
Interpreter::m_otePools[static_cast<size_t>(Interpreter::Pools::Blocks)].deallocate(ote);
break;

case OTEFlags::ContextSpace:
// Return it to the interpreter's free list of contexts
Interpreter::m_otePools[Interpreter::CONTEXTPOOL].deallocate(ote);
Interpreter::m_otePools[static_cast<size_t>(Interpreter::Pools::Contexts)].deallocate(ote);
break;

case OTEFlags::DWORDSpace:
Interpreter::m_otePools[Interpreter::DWORDPOOL].deallocate(ote);
Interpreter::m_otePools[static_cast<size_t>(Interpreter::Pools::Dwords)].deallocate(ote);
break;

case OTEFlags::HeapSpace:
Expand All @@ -111,7 +111,7 @@ void ObjectMemory::deallocate(OTE* ote)
break;

case OTEFlags::FloatSpace:
Interpreter::m_otePools[Interpreter::FLOATPOOL].deallocate(ote);
Interpreter::m_otePools[static_cast<size_t>(Interpreter::Pools::Floats)].deallocate(ote);
break;

case OTEFlags::PoolSpace:
Expand Down
2 changes: 1 addition & 1 deletion Core/DolphinVM/decode.cpp
Expand Up @@ -569,7 +569,7 @@ void HexDump(tracestream out, LPCTSTR lpszLine, uint8_t* pby,
ASSERT(nBytes > 0);
ASSERT(nWidth > 0);

int nRow = 0;
size_t nRow = 0;

tracestream::char_type oldFill = out.fill('0');
out << std::hex;
Expand Down
2 changes: 1 addition & 1 deletion Core/DolphinVM/finalize.cpp
Expand Up @@ -83,7 +83,7 @@ void Interpreter::scheduleFinalization()
size_t count = m_qForFinalize.Count();
// Raise interrupt when at or above high water mark
if (count >= (SmallUinteger)integerValueOf(memMan->m_hospiceHighWater))
queueInterrupt(VMI_HOSPICECRISIS, integerObjectOf(count));
queueInterrupt(VMInterrupts::HospiceCrisis, integerObjectOf(count));
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions Core/DolphinVM/flotprim.cpp
Expand Up @@ -34,7 +34,7 @@ inline FloatOTE* __stdcall Float::New()
{
ASSERT(sizeof(Float) == sizeof(double) + ObjectHeaderSize);

FloatOTE* newFloatPointer = reinterpret_cast<FloatOTE*>(Interpreter::m_otePools[Interpreter::FLOATPOOL].newByteObject(Pointers.ClassFloat, sizeof(double), OTEFlags::FloatSpace));
FloatOTE* newFloatPointer = reinterpret_cast<FloatOTE*>(Interpreter::m_otePools[static_cast<size_t>(Interpreter::Pools::Floats)].newByteObject(Pointers.ClassFloat, sizeof(double), OTEFlags::FloatSpace));
ASSERT(ObjectMemory::hasCurrentMark(newFloatPointer));
ASSERT(newFloatPointer->m_oteClass == Pointers.ClassFloat);
newFloatPointer->beImmutable();
Expand All @@ -47,7 +47,7 @@ inline FloatOTE* __stdcall Float::New(double fValue)
{
ASSERT(sizeof(Float) == sizeof(double) + ObjectHeaderSize);

FloatOTE* newFloatPointer = reinterpret_cast<FloatOTE*>(Interpreter::m_otePools[Interpreter::FLOATPOOL].newByteObject(Pointers.ClassFloat, sizeof(double), OTEFlags::FloatSpace));
FloatOTE* newFloatPointer = reinterpret_cast<FloatOTE*>(Interpreter::m_otePools[static_cast<size_t>(Interpreter::Pools::Floats)].newByteObject(Pointers.ClassFloat, sizeof(double), OTEFlags::FloatSpace));
ASSERT(ObjectMemory::hasCurrentMark(newFloatPointer));
ASSERT(newFloatPointer->m_oteClass == Pointers.ClassFloat);
newFloatPointer->beImmutable();
Expand Down
2 changes: 1 addition & 1 deletion Core/DolphinVM/interfac.cpp
Expand Up @@ -383,7 +383,7 @@ Oop __stdcall Interpreter::performWithArguments(Oop receiver, SymbolOTE* selecto
// Allocate a new four byte object of the specified (unref counted) class from the DWORD pool
BytesOTE* __fastcall Interpreter::NewUint32(uint32_t value, BehaviorOTE* classPointer)
{
BytesOTE* ote = m_otePools[DWORDPOOL].newByteObject(classPointer, sizeof(uint32_t), OTEFlags::DWORDSpace);
BytesOTE* ote = m_otePools[static_cast<size_t>(Pools::Dwords)].newByteObject(classPointer, sizeof(uint32_t), OTEFlags::DWORDSpace);
ASSERT(ObjectMemory::hasCurrentMark(ote));

// Assign class as this can differ in this particular pool, which is used for all manner of 32-bit objects
Expand Down

0 comments on commit e7e03b3

Please sign in to comment.