diff --git a/Core/DolphinVM/CrashDump.cpp b/Core/DolphinVM/CrashDump.cpp index 8ea5ba3e3e..e9c86214de 100755 --- a/Core/DolphinVM/CrashDump.cpp +++ b/Core/DolphinVM/CrashDump.cpp @@ -13,9 +13,9 @@ #include "VMExcept.h" #include "RegKey.h" -static const size_t DefaultStackDepth = 300; -static const size_t DefaultWalkbackDepth = static_cast(-1); -static const int MAXDUMPPARMCHARS = 40; +constexpr size_t DefaultStackDepth = 300; +constexpr size_t DefaultWalkbackDepth = static_cast(-1); +constexpr int MAXDUMPPARMCHARS = 40; extern wchar_t achImagePath[]; // Warning about SEH and destructable objects @@ -58,17 +58,17 @@ void CrashDump(EXCEPTION_POINTERS *pExceptionInfo, wostream* pStream, size_t nSt pStream = &TRACESTREAM; *pStream << std::endl; - for (int i=0;i<80;i++) + for (auto i=0;i<80;i++) *pStream << L'*'; EXCEPTION_RECORD* pExRec = pExceptionInfo->ExceptionRecord; DWORD exceptionCode = pExRec->ExceptionCode; *pStream << std::endl; - for (int i=0;i<26;i++) + for (auto i=0;i<26;i++) *pStream << L'*'; *pStream<< L" Dolphin Crash Dump Report "; - for (int i=0;i<27;i++) + for (auto i=0;i<27;i++) *pStream << L'*'; wchar_t szModule[_MAX_PATH+1]; @@ -101,7 +101,7 @@ void CrashDump(EXCEPTION_POINTERS *pExceptionInfo, wostream* pStream, size_t nSt wostream::char_type cFill = pStream->fill(L'0'); pStream->setf(ios::uppercase); *pStream << std::hex; - for (unsigned i=0;iExceptionInformation[i]; *pStream << setw(sizeof(uintptr_t)<<1) << parm<< L" "; @@ -228,7 +228,7 @@ void CrashDump(EXCEPTION_POINTERS *pExceptionInfo, const wchar_t* achImagePath) { wchar_t achLogPath[_MAX_PATH+1]; achLogPath[0] = 0; - unsigned long size = _MAX_PATH; + ULONG size = _MAX_PATH; rkDump.QueryStringValue(L"", achLogPath, &size); pStream = OpenLogStream(achLogPath, achImagePath, fStream); @@ -266,10 +266,10 @@ void __stdcall Dump2(const wchar_t* szMsg, wostream* pStream, int nStackDepth, i pStream = &TRACESTREAM; *pStream << std::endl; - for (int i=0;i<26;i++) + for (auto i=0;i<26;i++) *pStream << L'*'; *pStream<< L" Dolphin Virtual Machine Dump Report "; - for (int i=0;i<27;i++) + for (auto i=0;i<27;i++) *pStream << L'*'; // Dump the time and message diff --git a/Core/DolphinVM/ExternalBuf.cpp b/Core/DolphinVM/ExternalBuf.cpp index b2028207f9..daf63d3118 100644 --- a/Core/DolphinVM/ExternalBuf.cpp +++ b/Core/DolphinVM/ExternalBuf.cpp @@ -23,7 +23,7 @@ Oop * __fastcall Interpreter::primitiveAddressOf(Oop * const sp, primargcount_t Oop * __fastcall Interpreter::primitiveBytesIsNull(Oop * const sp, primargcount_t argCount) { AddressOTE* oteBytes = reinterpret_cast(*sp); - MWORD size = oteBytes->bytesSize(); + size_t size = oteBytes->bytesSize(); if (size == sizeof(uintptr_t)) { *sp = reinterpret_cast(oteBytes->m_location->m_pointer == nullptr ? Pointers.True : Pointers.False); @@ -87,9 +87,9 @@ Oop * __fastcall Interpreter::primitiveUint32AtPut(Oop * const sp, primargcount_ if (ObjectMemoryIsIntegerObject(oopOffset)) { - const int size = oteReceiver->bytesSizeForUpdate(); + const ptrdiff_t size = oteReceiver->bytesSizeForUpdate(); SmallInteger offset = ObjectMemoryIntegerValueOf(oopOffset); - if (offset >= 0 && static_cast(offset + sizeof(uint32_t)) <= size) + if (offset >= 0 && static_cast(offset + sizeof(uint32_t)) <= size) { // Store into byte object Oop oopValue = *sp; @@ -109,7 +109,7 @@ Oop * __fastcall Interpreter::primitiveUint32AtPut(Oop * const sp, primargcount_ uint32_t* valueFields = oteValue->m_location->m_fields; if (oteValue->isBytes()) { - MWORD argSize = oteValue->bytesSize(); + size_t argSize = oteValue->bytesSize(); // The primitive has traditionally been lenient and accepts any 4 byte object, or any 8 byte object // where the top 32-bits are zero. This is to allow positive argeIntegers in the interval [0x7FFFFFFF, 0xFFFFFFFF] @@ -167,7 +167,7 @@ Oop * __fastcall Interpreter::primitiveIndirectUint32AtPut(Oop * const sp, prima uint32_t* valueFields = oteValue->m_location->m_fields; if (oteValue->isBytes()) { - MWORD argSize = oteValue->bytesSize(); + size_t argSize = oteValue->bytesSize(); // The primitive has traditionally been lenient and accepts any 4 byte object, or any 8 byte object // where the top 32-bits are zero. This is to allow positive argeIntegers in the interval [0x7FFFFFFF, 0xFFFFFFFF] @@ -197,9 +197,9 @@ Oop * __fastcall Interpreter::primitiveInt32AtPut(Oop * const sp, primargcount_t if (ObjectMemoryIsIntegerObject(oopOffset)) { - const int size = oteReceiver->bytesSizeForUpdate(); + const ptrdiff_t size = oteReceiver->bytesSizeForUpdate(); SmallInteger offset = ObjectMemoryIntegerValueOf(oopOffset); - if (offset >= 0 && static_cast(offset + sizeof(int32_t)) <= size) + if (offset >= 0 && static_cast(offset + sizeof(int32_t)) <= size) { // Store into byte object Oop oopValue = *sp; @@ -219,7 +219,7 @@ Oop * __fastcall Interpreter::primitiveInt32AtPut(Oop * const sp, primargcount_t int32_t* pValue = reinterpret_cast(oteValue->m_location->m_fields); if (oteValue->isBytes()) { - MWORD argSize = oteValue->bytesSize(); + size_t argSize = oteValue->bytesSize(); // The primitive has traditionally been lenient and accepts any 4 byte object if (argSize == sizeof(int32_t)) @@ -275,7 +275,7 @@ Oop * __fastcall Interpreter::primitiveIndirectInt32AtPut(Oop * const sp, primar int32_t* pValue = reinterpret_cast(oteValue->m_location->m_fields); if (oteValue->isBytes()) { - MWORD argSize = oteValue->bytesSize(); + size_t argSize = oteValue->bytesSize(); // The primitive has traditionally been lenient and accepts any 4 byte object if (argSize == sizeof(int32_t)) diff --git a/Core/DolphinVM/ExternalBuf.h b/Core/DolphinVM/ExternalBuf.h index 0816ccbcfd..da0cef72ba 100644 --- a/Core/DolphinVM/ExternalBuf.h +++ b/Core/DolphinVM/ExternalBuf.h @@ -98,9 +98,9 @@ template Oop* __fastcall Interpreter::primitiveInte SmallInteger offset = ObjectMemoryIntegerValueOf(oopOffset); BytesOTE* oteReceiver = reinterpret_cast(*(sp - 1)); - const int size = oteReceiver->bytesSize(); + const size_t size = oteReceiver->bytesSize(); - if (offset >= 0 && static_cast(offset + sizeof(T)) <= size) + if (offset >= 0 && static_cast(offset) + sizeof(T) <= size) { T value = *reinterpret_cast(oteReceiver->m_location->m_fields + offset); Store()(sp - 1, value); @@ -125,9 +125,9 @@ template Oop* __fastcall if (ObjectMemoryIsIntegerObject(oopOffset)) { - const int size = oteReceiver->bytesSizeForUpdate(); + const ptrdiff_t size = oteReceiver->bytesSizeForUpdate(); SmallInteger offset = ObjectMemoryIntegerValueOf(oopOffset); - if (offset >= 0 && static_cast(offset + sizeof(T)) <= size) + if (offset >= 0 && offset + static_cast(sizeof(T)) <= size) { // Store into byte object Oop oopValue = *sp; @@ -172,7 +172,7 @@ template Oop* __fastcall if (ObjectMemoryIsIntegerObject(oopOffset)) { - const int size = oteReceiver->bytesSizeForUpdate(); + const ptrdiff_t size = oteReceiver->bytesSizeForUpdate(); SmallInteger offset = ObjectMemoryIntegerValueOf(oopOffset); // Store into byte object Oop oopValue = *sp; @@ -240,7 +240,7 @@ template Oop* __fastcall Interpreter::primitiveFloatAtOffsetPut(Oop fValue = oteValue->m_location->m_fValue; } - SmallUinteger offset = ObjectMemoryIntegerValueOf(integerPointer); + SmallInteger offset = ObjectMemoryIntegerValueOf(integerPointer); OTE* receiver = reinterpret_cast(*(sp - 2)); ASSERT(!ObjectMemoryIsIntegerObject(receiver)); @@ -261,8 +261,8 @@ template Oop* __fastcall Interpreter::primitiveFloatAtOffsetPut(Oop BytesOTE* oteBytes = reinterpret_cast(receiver); // We can check that the offset is in bounds - int size = oteBytes->bytesSizeForUpdate(); - if (static_cast(offset) >= 0 && static_cast(offset + sizeof(T)) <= size) + ptrdiff_t size = oteBytes->bytesSizeForUpdate(); + if (offset >= 0 && offset + static_cast(sizeof(T)) <= size) { T* pBuf = reinterpret_cast(oteBytes->m_location->m_fields + offset); *pBuf = static_cast(fValue); @@ -303,7 +303,7 @@ template Oop* __fastcall Interpreter::primitiveFloatAtOffset(Oop* c BytesOTE* oteBytes = reinterpret_cast(receiver); // We can check that the offset is in bounds - if (offset >= 0 && offset + sizeof(T) <= oteBytes->bytesSize()) + if (offset >= 0 && static_cast(offset) + sizeof(T) <= oteBytes->bytesSize()) { pValue = reinterpret_cast(oteBytes->m_location->m_fields + offset); } diff --git a/Core/DolphinVM/ExternalCall.asm b/Core/DolphinVM/ExternalCall.asm index c773eb76b1..4d6a9dd8d8 100644 --- a/Core/DolphinVM/ExternalCall.asm +++ b/Core/DolphinVM/ExternalCall.asm @@ -48,7 +48,7 @@ extern NewUnsigned64:near32 REQUESTCOMPLETION EQU ?OnCallReturned@OverlappedCall@@AAEXXZ extern REQUESTCOMPLETION:near32 -CharacterGetCodePoint EQU ?getCodePoint@Character@ST@@QBEIXZ +CharacterGetCodePoint EQU ?getCodePoint@Character@ST@@QBE_UXZ extern CharacterGetCodePoint:near32 ; We need to test the structure type specially diff --git a/Core/DolphinVM/FloatPrim.h b/Core/DolphinVM/FloatPrim.h index 24c8037fdf..cc0f0e8a8c 100644 --- a/Core/DolphinVM/FloatPrim.h +++ b/Core/DolphinVM/FloatPrim.h @@ -24,7 +24,7 @@ template static Oop* __fastcall Interpreter::primitiveFloatTruncat } else { - int intVal = static_cast(fValue); + auto intVal = static_cast(fValue); *sp = ObjectMemoryIntegerObjectOf(intVal); return sp; } diff --git a/Core/DolphinVM/GC.cpp b/Core/DolphinVM/GC.cpp index af879acf83..e3f6156a70 100755 --- a/Core/DolphinVM/GC.cpp +++ b/Core/DolphinVM/GC.cpp @@ -82,9 +82,9 @@ void ObjectMemory::markObjectsAccessibleFrom(OTE* ote) if ((oteClass->m_ubFlags ^ curMark) & OTEFlags::MarkMask) // Already accessible from roots of world? markObjectsAccessibleFrom(reinterpret_cast(oteClass)); - const MWORD lastPointer = lastStrongPointerOf(ote); + const size_t lastPointer = lastStrongPointerOf(ote); Oop* pFields = reinterpret_cast(ote->m_location); - for (MWORD i = ObjectHeaderSize; i < lastPointer; i++) + for (auto i = ObjectHeaderSize; i < lastPointer; i++) { // This will get nicely optimised by the Compiler Oop fieldPointer = pFields[i]; @@ -107,7 +107,7 @@ OTEFlags ObjectMemory::nextMark() OTEFlags oldMark = m_spaceOTEBits[OTEFlags::NormalSpace]; // Toggle the "visited" mark - all objects will then have previous mark BOOL newMark = oldMark.m_mark ? FALSE : TRUE; - for (unsigned i=0;i(ote); - const MWORD size = otePointers->pointersSize(); + const size_t size = otePointers->pointersSize(); VariantObject* weakObj = otePointers->m_location; const Behavior* weakObjClass = ote->m_oteClass->m_location; - const MWORD fixedFields = weakObjClass->fixedFields(); - for (MWORD j = fixedFields; j < size; j++) + const auto fixedFields = weakObjClass->fixedFields(); + for (size_t j = fixedFields; j < size; j++) { Oop fieldPointer = weakObj->m_fields[j]; if (!ObjectMemoryIsIntegerObject(fieldPointer)) @@ -290,10 +290,10 @@ void ObjectMemory::reclaimInaccessibleObjects(uintptr_t gcFlags) // Now sweep through the unmarked objects, and finalize/deallocate any objects which are STILL // unmarked - unsigned deletions=0; - unsigned queuedForFinalize=0; - const size_t loopEnd = nUnmarked; - for (size_t i=0;im_ubFlags; @@ -340,9 +340,9 @@ void ObjectMemory::reclaimInaccessibleObjects(uintptr_t gcFlags) if (ote->isPointers()) { PointersOTE* otePointers = reinterpret_cast(ote); - const MWORD lastPointer = otePointers->pointersSize(); + const size_t lastPointer = otePointers->pointersSize(); VariantObject* varObj = otePointers->m_location; - for (unsigned f = 0; f < lastPointer; f++) + for (auto f = 0u; f < lastPointer; f++) { Oop fieldPointer = varObj->m_fields[f]; if (!isIntegerObject(fieldPointer)) @@ -422,8 +422,8 @@ void ObjectMemory::addVMRefs() // Deliberately max out ref. counts of VM ref'd objects so that ref. counting ops // not needed Array* globalPointers = (Array*)&_Pointers; - const unsigned loopEnd = NumPointers; - for (unsigned i=0;im_elements[i]; if (!isIntegerObject(obj)) @@ -444,7 +444,7 @@ void ObjectMemory::addVMRefs() OTEFlags::Spaces space = ote.heapSpace(); if (space == OTEFlags::PoolSpace) { - unsigned size = ote.sizeOf(); + size_t size = ote.sizeOf(); if (size > MaxSizeOfPoolObject) { if (size <= MaxSmallObjectSize) @@ -463,14 +463,14 @@ void ObjectMemory::addVMRefs() } } } - for (int j=0;jm_stack;pOop <= sp;pOop++) { @@ -538,7 +538,7 @@ void ObjectMemory::addVMRefs() Interpreter::IncStackRefs(sp); } - int errors=0; + auto errors=0; uint8_t* currentRefs = new uint8_t[m_nOTSize]; { const size_t loopEnd = m_nOTSize; @@ -564,7 +564,7 @@ void ObjectMemory::addVMRefs() // Recalc the references const OTE* pEnd = m_pOT+m_nOTSize; - int nFree = 0; + size_t nFree = 0; for (OTE* ote=m_pOT; ote < pEnd; ote++) { if (!ote->isFree()) @@ -574,7 +574,7 @@ void ObjectMemory::addVMRefs() } POTE poteFree = m_pFreePointerList; - int cFreeList = 0; + size_t cFreeList = 0; while (poteFree < pEnd) { ++cFreeList; @@ -585,7 +585,7 @@ void ObjectMemory::addVMRefs() Interpreter::ReincrementVMReferences(); - int refCountTooSmall = 0; + auto refCountTooSmall = 0; const size_t loopEnd = m_nOTSize; for (size_t i=OTBase; i < loopEnd; i++) { @@ -617,7 +617,7 @@ void ObjectMemory::addVMRefs() TRACESTREAM<< L" Referenced From:" << std::endl; ArrayOTE* oteRefs = ObjectMemory::referencesTo(reinterpret_cast(ote), true); Array* refs = oteRefs->m_location; - for (unsigned i=0;ipointersSize();i++) + for (auto i=0u;ipointersSize();i++) TRACESTREAM<< L" " << reinterpret_cast(refs->m_elements[i]) << std::endl; deallocate(reinterpret_cast(oteRefs)); } @@ -653,8 +653,8 @@ void ObjectMemory::addVMRefs() if (ote->isPointers()) { VariantObject* obj = reinterpret_cast(ote)->m_location; - int size = ote->pointersSize(); - for (int i = 0; i < size; i++) + size_t size = ote->pointersSize(); + for (size_t i = 0; i < size; i++) { HARDASSERT(isValidOop(obj->m_fields[i])); } @@ -697,8 +697,8 @@ void ObjectMemory::addVMRefs() { PointersOTE* otePointers = reinterpret_cast(ote); VariantObject* varObj = otePointers->m_location; - const MWORD lastPointer = otePointers->pointersSize(); - for (MWORD i = 0; i < lastPointer; i++) + const size_t lastPointer = otePointers->pointersSize(); + for (size_t i = 0; i < lastPointer; i++) { Oop fieldPointer = varObj->m_fields[i]; // The reason we don't use an ASSERT here is that, ASSERT throws diff --git a/Core/DolphinVM/GCPrim.cpp b/Core/DolphinVM/GCPrim.cpp index 7dbeb4be7b..625b966d35 100644 --- a/Core/DolphinVM/GCPrim.cpp +++ b/Core/DolphinVM/GCPrim.cpp @@ -77,7 +77,7 @@ void Interpreter::asyncGC(uintptr_t gcFlags) #ifdef _DEBUG if (Interpreter::executionTrace != 0) { - for (unsigned i=0;i(ote->m_location); @@ -141,7 +141,7 @@ void Interpreter::freePools() { OTE* ote = m_otePools[BLOCKPOOL].m_pFreeList; - const MWORD sizeOfPoolBlock = SizeOfPointers(BlockClosure::FixedSize+BlockClosure::MaxCopiedValues); + const size_t sizeOfPoolBlock = SizeOfPointers(BlockClosure::FixedSize+BlockClosure::MaxCopiedValues); while (ote) { VariantObject* obj = static_cast(ote->m_location); @@ -154,7 +154,7 @@ void Interpreter::freePools() //DumpOTEPoolStats(); #endif - for (unsigned i=0;i(codePoint)); + return (POTE)Character::NewUnicode(static_cast(codePoint)); } STDMETHODIMP_(POTE) CDolphinSmalltalk::NewArray( diff --git a/Core/DolphinVM/InProcStub/InProcPlugHole.cpp b/Core/DolphinVM/InProcStub/InProcPlugHole.cpp index 62e5f62e14..e3eafcb56f 100755 --- a/Core/DolphinVM/InProcStub/InProcPlugHole.cpp +++ b/Core/DolphinVM/InProcStub/InProcPlugHole.cpp @@ -40,7 +40,7 @@ void CInProcPlugHole::WaitForPeerToStart() const // Wait until either the peer is available or the Dolphin thread terminates HANDLE aHandles[] = {m_hPeerAvailable, m_hDolphinThread}; - const int numHandles = sizeof(aHandles)/sizeof(HANDLE); + const ULONG numHandles = sizeof(aHandles)/sizeof(HANDLE); // New Win2000 CoWaitForMultipleHandles is ideal here... diff --git a/Core/DolphinVM/IntPrim.cpp b/Core/DolphinVM/IntPrim.cpp index 15137098b6..afed049bc6 100644 --- a/Core/DolphinVM/IntPrim.cpp +++ b/Core/DolphinVM/IntPrim.cpp @@ -87,7 +87,7 @@ Oop* __fastcall Interpreter::primitiveAnyMask(Oop* const sp, primargcount_t) { if (r < 0) { - for (MWORD i = oteArg->getWordSize()-1; i > 0; i--) + for (size_t i = oteArg->getWordSize()-1; i > 0; i--) { if (digits[i] != 0) { diff --git a/Core/DolphinVM/InterpRegisters.h b/Core/DolphinVM/InterpRegisters.h index e2157a6c86..9066507ba6 100644 --- a/Core/DolphinVM/InterpRegisters.h +++ b/Core/DolphinVM/InterpRegisters.h @@ -52,8 +52,8 @@ struct InterpreterRegisters inline void InterpreterRegisters::ResizeProcess() { HARDASSERT(m_pActiveProcess != NULL); - MWORD words = m_stackPointer - reinterpret_cast(m_pActiveProcess) + 1; - m_oteActiveProcess->setSize(words*sizeof(MWORD)); + size_t words = m_stackPointer - reinterpret_cast(m_pActiveProcess) + 1; + m_oteActiveProcess->setSize(words*sizeof(Oop)); } typedef __declspec(align(16)) struct InterpreterRegisters InterpreterRegisters16; diff --git a/Core/DolphinVM/Interprt.h b/Core/DolphinVM/Interprt.h index 4b4c16d629..334454e314 100644 --- a/Core/DolphinVM/Interprt.h +++ b/Core/DolphinVM/Interprt.h @@ -70,12 +70,15 @@ typedef volatile LONG SHAREDLONG; enum class TRACEFLAG { TraceInherit, TraceOff, TraceForce }; #endif +typedef uintptr_t argcount_t; + class Interpreter { friend class ObjectMemory; friend class BootLoader; public: + static HRESULT initialize(const wchar_t* szFileName, LPVOID imageData, size_t imageSize, bool isDevSys); // Fire off the startup message @@ -111,8 +114,8 @@ class Interpreter static BOOL isCallbackFrame(Oop framePointer); #endif - static void StackTraceOn(std::wostream& dc, StackFrame* pFrame=NULL, unsigned depth=10); - static void DumpStack(std::wostream&, unsigned); + static void StackTraceOn(std::wostream& dc, StackFrame* pFrame=NULL, size_t depth=10); + static void DumpStack(std::wostream&, size_t); static void DumpContext(EXCEPTION_POINTERS *pExceptionInfo, std::wostream& logStream); static void DumpContext(std::wostream& logStream); static std::wstring PrintString(Oop); @@ -137,7 +140,7 @@ class Interpreter // for callback unwinds, and do the appropriate thing. If not caught at every callback // point, then must be caught at some major entry point from Smalltalk to prevent it // unwinding other callbacks (esp. window procedure entry points). - static Oop __stdcall callback(SymbolOTE* selector, unsigned argCount TRACEPARM) + static Oop __stdcall callback(SymbolOTE* selector, argcount_t argCount TRACEPARM) /* throws SE_VMCALLBACKUNWIND */; static LRESULT lResultFromOop(Oop objectPointer, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -173,7 +176,7 @@ class Interpreter #if defined(_DEBUG) static const wchar_t* activeMethod(); static void decodeMethod(CompiledMethod*, std::wostream* pstream=NULL); - static void decodeMethodAt(CompiledMethod*, unsigned ip, std::wostream&); + static void decodeMethodAt(CompiledMethod*, size_t ip, std::wostream&); #endif // Contexts @@ -236,11 +239,11 @@ class Interpreter intptr_t primAddress; }; - static MethodCacheEntry* __fastcall findNewMethodInClass(BehaviorOTE* classPointer, const unsigned argCount); - static MethodCacheEntry* __stdcall findNewMethodInClassNoCache(BehaviorOTE* classPointer, const unsigned argCount); + static MethodCacheEntry* __fastcall findNewMethodInClass(BehaviorOTE* classPointer, const argcount_t argCount); + static MethodCacheEntry* __stdcall findNewMethodInClassNoCache(BehaviorOTE* classPointer, const argcount_t argCount); static MethodOTE* __fastcall lookupMethod(BehaviorOTE* aClass, SymbolOTE* selector); - static MethodCacheEntry* __fastcall messageNotUnderstood(BehaviorOTE* aClass, const unsigned argCount); - static void __fastcall createActualMessage(const unsigned argCount); + static MethodCacheEntry* __fastcall messageNotUnderstood(BehaviorOTE* aClass, const argcount_t argCount); + static void __fastcall createActualMessage(const argcount_t argCount); //Misc @@ -280,7 +283,7 @@ class Interpreter }; #ifdef _DEBUG - static const char* InterruptNames[static_cast(VMI_CRTFAULT) + 1]; + static const char* InterruptNames[static_cast(VMI_CRTFAULT) + 1]; #endif static bool __fastcall disableInterrupts(bool bDisable); @@ -339,10 +342,10 @@ class Interpreter static bool saveContextAfterFault(LPEXCEPTION_POINTERS info); static void wakePendingCallbacks(); - static unsigned countPendingCallbacks(); + static size_t countPendingCallbacks(); - static void sendSelectorArgumentCount(SymbolOTE* selector, unsigned count); - static void sendSelectorToClass(BehaviorOTE* classPointer, unsigned argCount); + 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); @@ -351,7 +354,7 @@ class Interpreter static BOOL sampleInput(); static bool __stdcall IsUserBreakRequested(); - static void __fastcall executeNewMethod(MethodOTE* methodOTE, unsigned argCount); + static void __fastcall executeNewMethod(MethodOTE* methodOTE, argcount_t argCount); static void __fastcall returnValueTo(Oop resultPointer, Oop contextPointer); static void __fastcall returnValueToCaller(Oop resultPointer, Oop contextPointer); static void __fastcall nonLocalReturnValueTo(Oop resultPointer, Oop contextPointer); @@ -361,10 +364,10 @@ class Interpreter public: static void basicQueueForFinalization(OTE* ote); - static void queueForFinalization(OTE* ote, int); + static void queueForFinalization(OTE* ote, SmallUinteger); static void queueForBereavementOf(OTE* ote, Oop argPointer); // Number of entries in the bereavement queue per object (one for the object, the other the loss count) - enum { OopsPerBereavementQEntry = 2 }; + 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); @@ -485,7 +488,7 @@ class Interpreter static bool isInPrimitive(LPEXCEPTION_POINTERS pExInfo); public: - typedef size_t primargcount_t; + typedef argcount_t primargcount_t; typedef Oop* (__fastcall *PrimitiveFp)(Oop* const sp, primargcount_t argCount); @@ -526,22 +529,22 @@ class Interpreter static Oop* __fastcall primitiveSmallIntegerPrintString(Oop* const sp, primargcount_t argCount); // LargeInteger Arithmetic - mostly templated - template static Oop * __fastcall primitiveLargeIntegerOpZ(Oop * const sp, unsigned); - template static Oop * __fastcall primitiveLargeIntegerOpR(Oop * const sp, unsigned); + template static Oop * __fastcall primitiveLargeIntegerOpZ(Oop * const sp, primargcount_t); + template static Oop * __fastcall primitiveLargeIntegerOpR(Oop * const sp, primargcount_t); static Oop* __fastcall primitiveLargeIntegerDivide(Oop* const sp, primargcount_t argCount); static Oop* __fastcall primitiveLargeIntegerQuo(Oop* const sp, primargcount_t argCount); // LargeInteger relational ops - mostly templated - template static Oop * __fastcall primitiveLargeIntegerCmp(Oop * const sp, unsigned); + template static Oop * __fastcall primitiveLargeIntegerCmp(Oop * const sp, primargcount_t); static Oop* __fastcall primitiveLargeIntegerEqual(Oop* const sp, primargcount_t argCount); // LargeInteger bit manipulation static Oop* __fastcall primitiveLargeIntegerBitInvert(Oop* const sp, primargcount_t argCount); static Oop* __fastcall primitiveLargeIntegerBitShift(Oop* const sp, primargcount_t argCount); - static Oop * __fastcall primitiveLargeIntegerHighBit(Oop * const sp, unsigned); + static Oop * __fastcall primitiveLargeIntegerHighBit(Oop * const sp, primargcount_t); // LargeInteger miscellaneous - template static Oop * __fastcall primitiveLargeIntegerUnaryOp(Oop * const sp, unsigned); + template static Oop * __fastcall primitiveLargeIntegerUnaryOp(Oop * const sp, primargcount_t); static Oop* __fastcall primitiveLargeIntegerAsFloat(Oop* const sp, primargcount_t argCount); // Float primitives @@ -571,10 +574,10 @@ class Interpreter static Oop* __fastcall primitiveStructureIsNull(Oop* const sp, primargcount_t argCount); static Oop* __fastcall primitiveBytesIsNull(Oop* const sp, primargcount_t argCount); - template static Oop * __fastcall primitiveIndirectIntegerAtOffset(Oop * const sp, unsigned); - template static Oop * __fastcall primitiveIntegerAtOffset(Oop * const sp, unsigned); - template static Oop * __fastcall primitiveAtOffsetPutInteger(Oop * const sp, unsigned); - template static Oop * __fastcall primitiveIndirectAtOffsetPutInteger(Oop * const sp, unsigned); + template static Oop * __fastcall primitiveIndirectIntegerAtOffset(Oop * const sp, primargcount_t); + template static Oop * __fastcall primitiveIntegerAtOffset(Oop * const sp, primargcount_t); + template static Oop * __fastcall primitiveAtOffsetPutInteger(Oop * const sp, primargcount_t); + template static Oop * __fastcall primitiveIndirectAtOffsetPutInteger(Oop * const sp, primargcount_t); // These have specialised implementations as they accept other than just SmallInteger values to 'put' static Oop* __fastcall primitiveUint32AtPut(Oop* const sp, primargcount_t argCount); @@ -583,17 +586,17 @@ class Interpreter static Oop* __fastcall primitiveIndirectInt32AtPut(Oop* const sp, primargcount_t argCount); // Floating point number accessors - template static Oop * __fastcall primitiveFloatAtOffset(Oop * const sp, unsigned); - template static Oop * __fastcall primitiveFloatAtOffsetPut(Oop * const sp, unsigned); + template static Oop * __fastcall primitiveFloatAtOffset(Oop * const sp, primargcount_t); + template static Oop * __fastcall primitiveFloatAtOffsetPut(Oop * const sp, primargcount_t); static Oop* __fastcall primitiveLongDoubleAt(Oop* const sp, primargcount_t argCount); // Get address of contents of a byte object static Oop* __fastcall primitiveAddressOf(Oop* const sp, primargcount_t argCount); - static void PushCharacter(Oop* const sp, MWORD codePoint); + static void PushCharacter(Oop* const sp, char32_t codePoint); - static Oop* primitiveNewCharacter(Oop * const sp, unsigned); + static Oop* primitiveNewCharacter(Oop * const sp, primargcount_t); /////////////////////////////////////////////////////////////////////////// // String Class Primitives @@ -613,7 +616,7 @@ class Interpreter static Oop* __fastcall primitiveStringNextIndexOfFromTo(Oop* const sp, primargcount_t argCount); // String comparisons - mostly templated - template static Oop * __fastcall primitiveStringComparison(Oop * const sp, unsigned); + template static Oop * __fastcall primitiveStringComparison(Oop * const sp, primargcount_t); static Oop* __fastcall primitiveStringEqual(Oop* const sp, primargcount_t argCount); static Oop* __fastcall primitiveBytesEqual(Oop* const sp, primargcount_t argCount); @@ -748,11 +751,11 @@ class Interpreter private: - static BOOL __stdcall callExternalFunction(FARPROC pProc, unsigned argCount, DolphinX::CallDescriptor* argTypes, BOOL isVirtual); + static BOOL __stdcall callExternalFunction(FARPROC pProc, argcount_t argCount, DolphinX::CallDescriptor* argTypes, BOOL isVirtual); // Pushs object on stack instantiated from address, and returns size of object pushed - static void pushArgsAt(CallbackDescriptor* descriptor, unsigned argCount, uint8_t* lpParms); - static unsigned pushArgsAt(const ExternalDescriptor* descriptor, uint8_t* lpParms); + static void pushArgsAt(CallbackDescriptor* descriptor, argcount_t argCount, uint8_t* lpParms); + static argcount_t pushArgsAt(const ExternalDescriptor* descriptor, uint8_t* lpParms); static int __cdecl IEEEFPHandler(_FPIEEE_RECORD *pIEEEFPException); @@ -777,7 +780,7 @@ class Interpreter 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 int MethodCacheSize = 1024; + constexpr static size_t MethodCacheSize = 1024; static MethodCacheEntry methodCache[MethodCacheSize]; static void flushCaches(); @@ -842,8 +845,8 @@ class Interpreter static bool m_bAsyncGCDisabled; static bool m_bShutDown; // Is the interpreter shutting down? - static unsigned m_nCallbacksPending; // Number of failed callback exits pending - static unsigned m_nOTOverflows; + static size_t m_nCallbacksPending; // Number of failed callback exits pending + static size_t m_nOTOverflows; // Circular queues to hold the semaphores and interrupts, etc static OopQueue m_qAsyncSignals; @@ -869,8 +872,8 @@ class Interpreter // List of VM referenced objects (generic mechanism for avoiding GC problems with // objects ref'd only from the VM) static Oop* m_pVMRefs; - static int m_nFreeVMRef; - static int m_nMaxVMRefs; // Current size of VM References array + static SmallInteger m_nFreeVMRef; + static SmallInteger m_nMaxVMRefs; // Current size of VM References array enum { VMREFSINITIAL = 16 }; enum { VMREFSGROWTH = 64 }; diff --git a/Core/DolphinVM/Interprt.inl b/Core/DolphinVM/Interprt.inl index a16d4e7e20..656adb8023 100644 --- a/Core/DolphinVM/Interprt.inl +++ b/Core/DolphinVM/Interprt.inl @@ -155,7 +155,7 @@ struct StoreUnsigned32 #ifndef _M_IX86 // Intel version in assembler (see primitiv.cpp) - inline int __fastcall smalltalkMod(int numerator, int denominator) + inline SmallInteger __fastcall smalltalkMod(SmallInteger numerator, SmallInteger denominator) { SmallInteger quotient = numerator/denominator; quotient = quotient - (quotient < 0 && quotient*denominator!=numerator); @@ -163,7 +163,7 @@ struct StoreUnsigned32 } #else // See primasm.asm - extern int __fastcall smalltalkMod(int numerator, int denominator); + extern SmallInteger __fastcall smalltalkMod(SmallInteger numerator, SmallInteger denominator); #endif inline bool Interpreter::IsShuttingDown() @@ -200,13 +200,13 @@ inline BOOL Interpreter::isAFloat(Oop objectPointer) #define STOPPROFILING() #endif -inline void Interpreter::sendSelectorArgumentCount(SymbolOTE* selector, unsigned argCount) +inline void Interpreter::sendSelectorArgumentCount(SymbolOTE* selector, argcount_t argCount) { m_oopMessageSelector = selector; sendSelectorToClass(ObjectMemory::fetchClassOf(*(m_registers.m_stackPointer - argCount)), argCount); } -inline void Interpreter::sendSelectorToClass(BehaviorOTE* classPointer, unsigned argCount) +inline void Interpreter::sendSelectorToClass(BehaviorOTE* classPointer, argcount_t argCount) { MethodCacheEntry* pEntry = findNewMethodInClass(classPointer, argCount); executeNewMethod(pEntry->method, argCount); @@ -231,14 +231,14 @@ inline void Interpreter::basicQueueForFinalization(OTE* ote) m_qForFinalize.Push(ote); } -inline void Interpreter::queueForFinalization(OTE* ote, int highWater) +inline void Interpreter::queueForFinalization(OTE* ote, SmallUinteger highWater) { basicQueueForFinalization(ote); asynchronousSignal(Pointers.FinalizeSemaphore); - unsigned count = m_qForFinalize.Count(); + size_t count = m_qForFinalize.Count(); // Only raise interrupt when high water mark is hit! - if (count == static_cast(highWater)) + if (count == highWater) queueInterrupt(VMI_HOSPICECRISIS, ObjectMemoryIntegerObjectOf(count)); } diff --git a/Core/DolphinVM/InterprtInit.cpp b/Core/DolphinVM/InterprtInit.cpp index e8c0d09a1f..bad3c101d1 100755 --- a/Core/DolphinVM/InterprtInit.cpp +++ b/Core/DolphinVM/InterprtInit.cpp @@ -42,8 +42,8 @@ void Interpreter::initializeVMReferences() ASSERT(m_nMaxVMRefs >= VMREFSINITIAL); // Now set up the free list - const int loopEnd = m_nMaxVMRefs; - for (int i=0;im_method->m_location); // Convert address to an offset - int offsetFromBeginningOfByteCodesObject = m_instructionPointer - ObjectMemory::ByteAddressOfObject(m_pMethod->m_byteCodes); + ptrdiff_t offsetFromBeginningOfByteCodesObject = m_instructionPointer - ObjectMemory::ByteAddressOfObject(m_pMethod->m_byteCodes); m_pActiveFrame->setInstructionPointer(offsetFromBeginningOfByteCodesObject); } inline void InterpreterRegisters::LoadIPFromFrame() { - int offsetFromBeginningOfByteCodesObject = ObjectMemoryIntegerValueOf(m_pActiveFrame->m_ip); + SmallInteger offsetFromBeginningOfByteCodesObject = ObjectMemoryIntegerValueOf(m_pActiveFrame->m_ip); //ASSERT(offsetFromBeginningOfByteCodesObject >= 0 && offsetFromBeginningOfByteCodesObject < 1024); m_instructionPointer = ObjectMemory::ByteAddressOfObject(m_pMethod->m_byteCodes) + offsetFromBeginningOfByteCodesObject; } diff --git a/Core/DolphinVM/LargeIntPrim.h b/Core/DolphinVM/LargeIntPrim.h index 7c35fabfc7..0d730eaece 100644 --- a/Core/DolphinVM/LargeIntPrim.h +++ b/Core/DolphinVM/LargeIntPrim.h @@ -105,12 +105,12 @@ template static bool liCmp(const LargeIntegerOTE* oteA, const // Same sign - const MWORD ai = oteA->getWordSize(); - const MWORD bi = oteB->getWordSize(); + const auto ai = oteA->getWordSize(); + const auto bi = oteB->getWordSize(); if (ai == bi) { - int i = ai - 1; + ptrdiff_t i = ai - 1; // Same sign and size: Compare words (same sign, so comparison can be unsigned) do { @@ -177,9 +177,9 @@ namespace Li Oop operator()(const LargeIntegerOTE* oteOuter, const LargeIntegerOTE* oteInner) const { const LargeInteger* liOuter = oteOuter->m_location; - MWORD outerSize = oteOuter->getWordSize(); + size_t outerSize = oteOuter->getWordSize(); const LargeInteger* liInner = oteInner->m_location; - MWORD innerSize = oteInner->getWordSize(); + size_t innerSize = oteInner->getWordSize(); // The algorithm is substantially faster if the outer loop is shorter return outerSize > innerSize ? LargeInteger::Mul(liInner, innerSize, liOuter, outerSize) : diff --git a/Core/DolphinVM/Launcher/dull.cpp b/Core/DolphinVM/Launcher/dull.cpp index 9cea88bb40..b0e2d4ab94 100644 --- a/Core/DolphinVM/Launcher/dull.cpp +++ b/Core/DolphinVM/Launcher/dull.cpp @@ -33,7 +33,7 @@ static const wchar_t* FindImageNameArg() LPCWSTR szImage = L"DPRO.img7"; static wchar_t achImageName[_MAX_PATH]; - for (int i=1;i<__argc;i++) + for (auto i=1;i<__argc;i++) { const wchar_t* arg = __wargv[i]; wchar_t ch = *arg; diff --git a/Core/DolphinVM/LoadImage.cpp b/Core/DolphinVM/LoadImage.cpp index db36275598..65ff20204d 100755 --- a/Core/DolphinVM/LoadImage.cpp +++ b/Core/DolphinVM/LoadImage.cpp @@ -127,9 +127,9 @@ HRESULT ObjectMemory::LoadImage(ibinstream& imageFile, ImageHeader* pHeader) // and a bit extra for working space - can grow to at least the maximum size in m_nOTMax ASSERT(sizeof(OTE) == 16); // If not change the page size multiple #ifdef NO_GPF_TRAP - const int otSlop = 500; + constexpr int otSlop = 500; #else - const int otSlop = 3; + constexpr int otSlop = 3; #endif HRESULT hr = allocateOT(pHeader->nMaxTableSize, pHeader->nTableSize + (dwPageSize*otSlop / sizeof(OTE))); if (FAILED(hr)) @@ -164,7 +164,7 @@ HRESULT ObjectMemory::LoadImage(ibinstream& imageFile, ImageHeader* pHeader) return S_OK; } -template HRESULT ObjectMemory::LoadPointersAndObjects(ibinstream& imageFile, const ImageHeader* pHeader, size_t& cbRead) +template HRESULT ObjectMemory::LoadPointersAndObjects(ibinstream& imageFile, const ImageHeader* pHeader, size_t& cbRead) { HRESULT hr = LoadPointers(imageFile, pHeader, cbRead); if (FAILED(hr)) @@ -172,7 +172,7 @@ template HRESULT ObjectMemory::LoadPointersAndObjects(ibi return LoadObjects(imageFile, pHeader, cbRead); } -template HRESULT ObjectMemory::LoadPointers(ibinstream& imageFile, const ImageHeader* pHeader, size_t& cbRead) +template HRESULT ObjectMemory::LoadPointers(ibinstream& imageFile, const ImageHeader* pHeader, size_t& cbRead) { ASSERT(pHeader->nGlobalPointers == NumPointers); @@ -180,17 +180,17 @@ template HRESULT ObjectMemory::LoadPointers(ibinstream& i size_t cbPerm = 0; uint8_t* pNextConst = reinterpret_cast(m_pConstObjs); - int i; + size_t i; for (i = 0; i < NumPermanent; i++) { VariantObject* pConstObj = reinterpret_cast(pNextConst); OTE* ote = m_pOT + i; - MWORD bytesToRead; - MWORD allocSize; + size_t bytesToRead; + size_t allocSize; if (ote->isNullTerminated()) { - MWORD byteSize = ote->getSize(); + size_t byteSize = ote->getSize(); allocSize = byteSize + NULLTERMSIZE; bytesToRead = byteSize + ImageNullTerms; } @@ -243,7 +243,7 @@ HRESULT ObjectMemory::LoadObjectTable(ibinstream& imageFile, const ImageHeader* // Load objects and repair the free list -template HRESULT ObjectMemory::LoadObjects(ibinstream & imageFile, const ImageHeader * pHeader, size_t & cbRead) +template HRESULT ObjectMemory::LoadObjects(ibinstream & imageFile, const ImageHeader * pHeader, size_t & cbRead) { // Other free OTEs will be threaded in front of the first OTE off the end // of the currently committed table space. We set the free list pointer @@ -254,7 +254,7 @@ template HRESULT ObjectMemory::LoadObjects(ibinstream & i m_pFreePointerList = reinterpret_cast(pEnd); #ifdef _DEBUG - unsigned numObjects = NumPermanent; // Allow for VM registry, etc! + auto numObjects = NumPermanent; // Allow for VM registry, etc! m_nFreeOTEs = m_nOTSize - pHeader->nTableSize; #endif @@ -263,21 +263,21 @@ template HRESULT ObjectMemory::LoadObjects(ibinstream & i { if (!ote->isFree()) { - MWORD byteSize = ote->getSize(); + size_t byteSize = ote->getSize(); - MWORD* oldLocation = reinterpret_cast(ote->m_location); + uintptr_t* oldLocation = reinterpret_cast(ote->m_location); Object* pBody; // Allocate space for the object, and copy into that space if (ote->heapSpace() == OTEFlags::VirtualSpace) { - MWORD dwMaxAlloc; - if (!imageFile.read(&dwMaxAlloc, sizeof(MWORD))) + size_t maxAlloc; + if (!imageFile.read(&maxAlloc, sizeof(maxAlloc))) return ImageReadError(imageFile); - cbRead += sizeof(MWORD); + cbRead += sizeof(maxAlloc); - pBody = reinterpret_cast(AllocateVirtualSpace(dwMaxAlloc, byteSize)); + pBody = reinterpret_cast(AllocateVirtualSpace(maxAlloc, byteSize)); ote->m_location = pBody; } else @@ -336,7 +336,7 @@ template HRESULT ObjectMemory::LoadObjects(ibinstream & i return S_OK; } -ST::Object* ObjectMemory::AllocObj(OTE * ote, MWORD allocSize) +ST::Object* ObjectMemory::AllocObj(OTE * ote, size_t allocSize) { ST::Object* pObj; if (allocSize <= MaxSmallObjectSize) @@ -356,7 +356,7 @@ ST::Object* ObjectMemory::AllocObj(OTE * ote, MWORD allocSize) return pObj; } -void ObjectMemory::FixupObject(OTE* ote, MWORD* oldLocation, const ImageHeader* pHeader) +void ObjectMemory::FixupObject(OTE* ote, uintptr_t* oldLocation, const ImageHeader* pHeader) { // Convert the class now separately BehaviorOTE* classPointer = reinterpret_cast(FixupPointer(reinterpret_cast(ote->m_oteClass), static_cast(pHeader->BasePointer))); @@ -450,7 +450,7 @@ void Process::PostLoadFix(ProcessOTE* oteThis) // Wind down the stack adjusting references to self as we go // Start with the suspended context - const int delta = m_callbackDepth - 1; + const SmallInteger delta = m_callbackDepth - 1; while (isIntegerObject(framePointer) && framePointer != ZeroPointer) { framePointer += delta; @@ -560,7 +560,7 @@ void ObjectMemory::PostLoadFix() { // Dump out the pointers TRACESTREAM << NumPointers<< L" VM Pointers..." << std::endl; - for (int i = 0; i < NumPointers; i++) + for (auto i = 0; i < NumPointers; i++) { VariantObject* obj = static_cast(m_pConstObjs); POTE pote = POTE(obj->m_fields[i]); diff --git a/Core/DolphinVM/ObjMemInit.cpp b/Core/DolphinVM/ObjMemInit.cpp index 63983cdc50..7ebe24a0e4 100755 --- a/Core/DolphinVM/ObjMemInit.cpp +++ b/Core/DolphinVM/ObjMemInit.cpp @@ -59,19 +59,19 @@ void ObjectMemory::FixedSizePool::Initialize() HRESULT ObjectMemory::Initialize() { // Assembler will need to be modified if these are not the case - ASSERT(sizeof(MWORD) == sizeof(uint32_t)); - ASSERT(sizeof(InstanceSpecification) == sizeof(MWORD)); + ASSERT(sizeof(Oop) == sizeof(uint32_t)); + ASSERT(sizeof(InstanceSpecification) == sizeof(Oop)); ASSERT(sizeof(OTE) == 16); ASSERT(sizeof(OTEFlags) == 1); ASSERT(sizeof(count_t) == 1); ASSERT(sizeof(hash_t) == 2); - ASSERT(sizeof(STMethodHeader) == sizeof(MWORD)); + ASSERT(sizeof(STMethodHeader) == sizeof(Oop)); ASSERT(OTEFlags::NumSpaces <= 8); ASSERT(Context::FixedSize == 2); ASSERT(BlockClosure::FixedSize == 5); ASSERT(sizeof(BlockCopyExtension) == sizeof(uint32_t)); - ASSERT(PoolGranularity >= sizeof(MWORD)); - ASSERT(_ROUND2(PoolGranularity,sizeof(MWORD)) == PoolGranularity); + ASSERT(PoolGranularity >= sizeof(Oop)); + ASSERT(_ROUND2(PoolGranularity,sizeof(Oop)) == PoolGranularity); //ASSERT(sizeof(Object) == ObjectHeaderSize*sizeof(MWORD)); ASSERT(sizeof(VMPointers) == (150*sizeof(Oop)+ObjectByteSize)); // Check that the const objects segment is still exactly one page @@ -116,7 +116,7 @@ HRESULT ObjectMemory::Initialize() // N.B. By default the blank flags of NormalSpace is set up for pointer objects // as these are more frequently allocated - for (unsigned i=0;i= 0 && NumPools <= MaxPools); //} - for (int j=0;j(::HeapAlloc(m_hHeap, HEAP_NO_SERIALIZE, chunkSize)); @@ -31,7 +31,7 @@ inline POBJECT ObjectMemory::allocChunk(MWORD chunkSize) extern "C" ST::Object emptyObj; -inline POBJECT ObjectMemory::allocSmallChunk(MWORD chunkSize) +inline POBJECT ObjectMemory::allocSmallChunk(size_t chunkSize) { #ifdef MEMSTATS ++m_nSmallAllocated; @@ -46,7 +46,7 @@ inline POBJECT ObjectMemory::allocSmallChunk(MWORD chunkSize) spacePoolForSize(chunkSize).allocate(); } -inline void ObjectMemory::freeSmallChunk(POBJECT pBlock, MWORD size) +inline void ObjectMemory::freeSmallChunk(POBJECT pBlock, size_t size) { #ifdef MEMSTATS ++m_nSmallFreed; diff --git a/Core/DolphinVM/PerformPrim.cpp b/Core/DolphinVM/PerformPrim.cpp index d38b731225..f3b1b42a5c 100644 --- a/Core/DolphinVM/PerformPrim.cpp +++ b/Core/DolphinVM/PerformPrim.cpp @@ -23,19 +23,19 @@ #include "STBlockClosure.h" // Value with args takes an array of arguments -Oop* __fastcall Interpreter::primitiveValueWithArgs(Oop* const bp, unsigned) +Oop* __fastcall Interpreter::primitiveValueWithArgs(Oop* const bp, primargcount_t) { ArrayOTE* argumentArray = reinterpret_cast(*(bp)); BlockOTE* oteBlock = reinterpret_cast(*(bp-1)); - ASSERT(ObjectMemory::fetchClassOf(Oop(oteBlock)) == Pointers.ClassBlockClosure); + ASSERT(ObjectMemory::fetchClassOf(reinterpret_cast(oteBlock)) == Pointers.ClassBlockClosure); BlockClosure* block = oteBlock->m_location; - const MWORD blockArgumentCount = block->m_info.argumentCount; + const auto blockArgumentCount = block->m_info.argumentCount; - BehaviorOTE* arrayClass = ObjectMemory::fetchClassOf(Oop(argumentArray)); + BehaviorOTE* arrayClass = ObjectMemory::fetchClassOf(reinterpret_cast(argumentArray)); if (arrayClass != Pointers.ClassArray) return primitiveFailure(_PrimitiveFailureCode::InvalidParameter1); - const MWORD arrayArgumentCount = argumentArray->pointersSize(); + const size_t arrayArgumentCount = argumentArray->pointersSize(); if (arrayArgumentCount != blockArgumentCount) return primitiveFailure(_PrimitiveFailureCode::WrongNumberOfArgs); @@ -55,7 +55,7 @@ Oop* __fastcall Interpreter::primitiveValueWithArgs(Oop* const bp, unsigned) // Push the args from the array { - for (unsigned i=0;im_elements[i]; *sp++ = pushee; @@ -63,9 +63,9 @@ Oop* __fastcall Interpreter::primitiveValueWithArgs(Oop* const bp, unsigned) } } - const unsigned copiedValues = block->copiedValuesCount(oteBlock); + const auto copiedValues = block->copiedValuesCount(oteBlock); { - for (unsigned i=0;im_copiedValues[i]; *sp++ = oopCopied; @@ -74,10 +74,10 @@ Oop* __fastcall Interpreter::primitiveValueWithArgs(Oop* const bp, unsigned) } // Nil out any extra stack temp slots we need - const unsigned extraTemps = block->stackTempsCount(); + const auto extraTemps = block->stackTempsCount(); { const Oop nilPointer = Oop(Pointers.Nil); - for (unsigned i=0;ienvTempsCount(); + const auto envTemps = block->envTempsCount(); if (envTemps > 0) { ContextOTE* oteContext = Context::New(envTemps, reinterpret_cast(block->m_outer)); @@ -156,7 +156,7 @@ Oop* __fastcall Interpreter::primitivePerform(Oop* const sp, primargcount_t argC MethodCacheEntry* pEntry = findNewMethodInClass(ObjectMemory::fetchClassOf(newReceiver), (argCount - 1)); MethodOTE* methodPointer = pEntry->method; CompiledMethod* method = methodPointer->m_location; - const unsigned methodArgCount = method->m_header.argumentCount; + const auto methodArgCount = method->m_header.argumentCount; if (methodArgCount == (argCount-1) || m_oopMessageSelector == Pointers.DoesNotUnderstandSelector) { // Shuffle arguments down over the selector (use argumentCount of @@ -168,7 +168,7 @@ Oop* __fastcall Interpreter::primitivePerform(Oop* const sp, primargcount_t argC // Not worth overhead of calling memmove here since argumentCount // normally small - for (unsigned i=0;ipointersSize(); + const auto argCount = argumentArray->pointersSize(); // Save old message selector in case of prim failure (need to reinstate) SymbolOTE* performSelector = m_oopMessageSelector; @@ -219,7 +219,7 @@ Oop* __fastcall Interpreter::primitivePerformWithArgs(Oop* const sp, primargcoun // the method then the lookup routines copy the arguments off the stack // into a Message object Array* args = argumentArray->m_location; - for (MWORD i=0; im_elements[i]; // Note no need to inc the ref. count when pushing on the stack @@ -241,7 +241,7 @@ Oop* __fastcall Interpreter::primitivePerformWithArgs(Oop* const sp, primargcoun MethodCacheEntry* pEntry = findNewMethodInClass(ObjectMemory::fetchClassOf(newReceiver), argCount); MethodOTE* methodPointer = pEntry->method; CompiledMethod& method = *methodPointer->m_location; - const unsigned methodArgCount = method.m_header.argumentCount; + const auto methodArgCount = method.m_header.argumentCount; if (methodArgCount == argCount || m_oopMessageSelector == Pointers.DoesNotUnderstandSelector) { @@ -277,22 +277,22 @@ Oop* __fastcall Interpreter::primitivePerformMethod(Oop* const sp, primargcount_ if (!ObjectMemory::isKindOf(receiverPointer, method->m_methodClass)) return primitiveFailure(_PrimitiveFailureCode::InvalidParameter1); // Wrong class of receiver - const unsigned argCount = oteArg->pointersSize(); - const unsigned methodArgCount = method->m_header.argumentCount; + const size_t argCount = oteArg->pointersSize(); + const auto methodArgCount = method->m_header.argumentCount; if (methodArgCount != argCount) return primitiveFailure(_PrimitiveFailureCode::WrongNumberOfArgs); // Wrong number of arguments // Push receiver and arguments on stack (over the top of array and receiver) bp[0] = receiverPointer; // Write receiver over the top of the method - for (MWORD i = 0; i < argCount; i++) + for (auto i = 0; i < methodArgCount; i++) { Oop pushee = arguments->m_elements[i]; // Don't count up because we are adding a stack ref. bp[i+1] = pushee; } - m_registers.m_stackPointer = bp+argCount; + m_registers.m_stackPointer = bp+ methodArgCount; // Don't count down any args - executeNewMethod(oteMethod, argCount); + executeNewMethod(oteMethod, methodArgCount); return primitiveSuccess(0); } diff --git a/Core/DolphinVM/STArray.h b/Core/DolphinVM/STArray.h index 3f52018f6b..fc2c92ca7b 100644 --- a/Core/DolphinVM/STArray.h +++ b/Core/DolphinVM/STArray.h @@ -21,7 +21,7 @@ namespace ST { class Array; } class ArrayOTE : public TOTE { public: - __forceinline int sizeForUpdate() const { return static_cast(m_size) / static_cast(sizeof(MWORD)); } + __forceinline ptrdiff_t sizeForUpdate() const { return static_cast(m_size) / static_cast(sizeof(Oop)); } }; namespace ST @@ -31,8 +31,8 @@ namespace ST public: Oop m_elements[]; // Variable length array of data - static ArrayOTE* New(unsigned size); - static ArrayOTE* NewUninitialized(unsigned size); + static ArrayOTE* New(size_t size); + static ArrayOTE* NewUninitialized(size_t size); }; } diff --git a/Core/DolphinVM/STBehavior.h b/Core/DolphinVM/STBehavior.h index 8a905c6d61..052ec7e360 100644 --- a/Core/DolphinVM/STBehavior.h +++ b/Core/DolphinVM/STBehavior.h @@ -33,7 +33,7 @@ union InstanceSpecification uint16_t m_extraSpec; // High word for class specific purposes (e.g. structure byte size) }; - MWORD m_value; + SmallUinteger m_value; enum { @@ -59,6 +59,8 @@ typedef TOTE MethodDictOTE; namespace ST { + typedef uint8_t instvarcount_t; + class Behavior //: public Object { public: @@ -68,7 +70,7 @@ namespace ST ArrayOTE* m_subclasses; public: - unsigned fixedFields() const { return (m_instanceSpec.m_value >> 1) & 0xFF; } + instvarcount_t fixedFields() const { return (m_instanceSpec.m_value >> 1) & UINT8_MAX; } BOOL isPointers() const { return m_instanceSpec.m_pointers; } BOOL isBytes() const { return !m_instanceSpec.m_pointers; } BOOL isIndexable() const { return m_instanceSpec.m_indexable; } diff --git a/Core/DolphinVM/STBlockClosure.h b/Core/DolphinVM/STBlockClosure.h index bf90456dee..7a54237621 100644 --- a/Core/DolphinVM/STBlockClosure.h +++ b/Core/DolphinVM/STBlockClosure.h @@ -40,34 +40,34 @@ namespace ST public: // The pool must contain fixed size objects, so choose a suitable maximum number of // copied values permissible; very uncommonly exceed 2 (see Util class>>blockStats) - enum { MaxCopiedValues = 4 }; + static constexpr size_t MaxCopiedValues = 4; enum { OuterIndex = ObjectFixedSize, MethodIndex, InitialIPIndex, InfoIndex, ReceiverIndex, FixedSize }; - enum { TempFrameStart = FixedSize }; + static constexpr size_t TempFrameStart = FixedSize; - static BlockOTE* __fastcall New(unsigned copiedValuesCount); + static BlockOTE* __fastcall New(size_t copiedValuesCount); - unsigned initialIP() const + SmallUinteger initialIP() const { return integerValueOf(m_initialIP); } - unsigned copiedValuesCount(BlockOTE* myOTE) const + size_t copiedValuesCount(BlockOTE* myOTE) const { return myOTE->pointersSize() - FixedSize; } - unsigned stackTempsCount() const + stacktempcount_t stackTempsCount() const { return m_info.stackTempsCount; } - unsigned envTempsCount() const + envtempcount_t envTempsCount() const { return m_info.envTempsCount; } - unsigned argumentCount() const + methodargcount_t argumentCount() const { return m_info.argumentCount; } diff --git a/Core/DolphinVM/STBlockInfo.h b/Core/DolphinVM/STBlockInfo.h index 9ace458d94..ea3d4935e6 100644 --- a/Core/DolphinVM/STBlockInfo.h +++ b/Core/DolphinVM/STBlockInfo.h @@ -10,7 +10,7 @@ typedef struct BlockInfo { // Bottom bit of flags must be 1 uint8_t isInteger; - uint8_t argumentCount; // Number of arguments expected - uint8_t stackTempsCount; // Number of extra temp slots to allocate in the stack when activated - uint8_t envTempsCount; // Number of shared temps slots to allocate in heap context when activated + methodargcount_t argumentCount; // Number of arguments expected + stacktempcount_t stackTempsCount; // Number of extra temp slots to allocate in the stack when activated + envtempcount_t envTempsCount; // Number of shared temps slots to allocate in heap context when activated } BlockInfo; \ No newline at end of file diff --git a/Core/DolphinVM/STByteArray.h b/Core/DolphinVM/STByteArray.h index 7cfade7a61..37b9a2f338 100644 --- a/Core/DolphinVM/STByteArray.h +++ b/Core/DolphinVM/STByteArray.h @@ -22,7 +22,7 @@ namespace ST { class ByteArray; } class ByteArrayOTE : public TOTE { public: - __forceinline int sizeForUpdate() const { return static_cast(m_size); } + __forceinline ptrdiff_t sizeForUpdate() const { return static_cast(m_size); } }; namespace ST @@ -32,22 +32,22 @@ namespace ST public: uint8_t m_elements[]; - static ByteArrayOTE* New(MWORD size); - static ByteArrayOTE* New(MWORD size, const void* pBytes); - static ByteArrayOTE* NewWithRef(MWORD size, const void* pBytes); + static ByteArrayOTE* New(size_t size); + static ByteArrayOTE* New(size_t size, const void* pBytes); + static ByteArrayOTE* NewWithRef(size_t size, const void* pBytes); }; - inline ByteArrayOTE* ByteArray::New(MWORD size) + inline ByteArrayOTE* ByteArray::New(size_t size) { return reinterpret_cast(ObjectMemory::newByteObject(Pointers.ClassByteArray, size)); } - inline ByteArrayOTE* ByteArray::New(MWORD size, const void* pBytes) + inline ByteArrayOTE* ByteArray::New(size_t size, const void* pBytes) { return reinterpret_cast(ObjectMemory::newByteObject(Pointers.ClassByteArray, size, pBytes)); } - inline ByteArrayOTE* ByteArray::NewWithRef(MWORD size, const void* pBytes) + inline ByteArrayOTE* ByteArray::NewWithRef(size_t size, const void* pBytes) { ByteArrayOTE* byteArray = New(size, pBytes); byteArray->m_count = 1; diff --git a/Core/DolphinVM/STCharacter.h b/Core/DolphinVM/STCharacter.h index a1c93e2627..154173da37 100644 --- a/Core/DolphinVM/STCharacter.h +++ b/Core/DolphinVM/STCharacter.h @@ -14,6 +14,7 @@ #pragma once #include "STMagnitude.h" +#include "ote.h" namespace ST { class Character; } typedef TOTE CharOTE; @@ -23,20 +24,20 @@ namespace ST class Character : public Magnitude { public: - Oop m_code; // Small integer value. + SmallInteger m_code; // Small integer value. enum { CharacterValueIndex = Magnitude::FixedSize, FixedSize }; static CharOTE* NewAnsi(unsigned char value); - static CharOTE* NewUnicode(MWORD value); + static CharOTE* NewUnicode(char32_t value); __declspec(property(get = getEncoding)) StringEncoding Encoding; StringEncoding getEncoding() const { return static_cast((m_code >> 25) & 0x3); } - __declspec(property(get = getCodeUnit)) MWORD CodeUnit; - MWORD getCodeUnit() const { return ObjectMemoryIntegerValueOf(m_code) & 0xffffff; } + __declspec(property(get = getCodeUnit)) char32_t CodeUnit; + char32_t getCodeUnit() const { return ObjectMemoryIntegerValueOf(m_code) & 0xffffff; } - __declspec(property(get = getCodePoint)) uint32_t CodePoint; - uint32_t getCodePoint() const; + __declspec(property(get = getCodePoint)) char32_t CodePoint; + char32_t getCodePoint() const; }; } diff --git a/Core/DolphinVM/STContext.h b/Core/DolphinVM/STContext.h index 67d72d8447..081de712e2 100644 --- a/Core/DolphinVM/STContext.h +++ b/Core/DolphinVM/STContext.h @@ -46,12 +46,12 @@ namespace ST // The environment pool must contain fixed size objects, so choose a suitable maximum number of // temps permissible; very uncommonly exceed even 1 environment (shared) temporaries // In fact quite often there are none since the Context is required just to support a ^-return - enum { MaxEnvironmentTemps = 1 }; + static constexpr size_t MaxEnvironmentTemps = 1; enum { OuterIndex = ObjectFixedSize, BlockIndex, FixedSize }; - enum { TempFrameStart = FixedSize }; + static constexpr size_t TempFrameStart = FixedSize; - static ContextOTE* __fastcall New(unsigned tempCount, Oop oopOuter); + static ContextOTE* __fastcall New(size_t tempCount, Oop oopOuter); }; /////////////////////////////////////////////////////////////////////////////// diff --git a/Core/DolphinVM/STExternal.h b/Core/DolphinVM/STExternal.h index 5e35437d69..6df42ab58e 100644 --- a/Core/DolphinVM/STExternal.h +++ b/Core/DolphinVM/STExternal.h @@ -94,7 +94,7 @@ namespace ST uint8_t m_returnClass; uint8_t m_args[]; - static unsigned argsLen(DescriptorOTE* ote) { return ote->getSize() - offsetof(DescriptorBytes, m_args); } + static size_t argsLen(DescriptorOTE* ote) { return ote->getSize() - offsetof(DescriptorBytes, m_args); } }; class ExternalDescriptor : public Object diff --git a/Core/DolphinVM/STInteger.h b/Core/DolphinVM/STInteger.h index a702b91c6f..756f88aecd 100644 --- a/Core/DolphinVM/STInteger.h +++ b/Core/DolphinVM/STInteger.h @@ -54,7 +54,7 @@ namespace ST int32_t sign(const LargeIntegerOTE* oteLI) const { return 1 | (signDigit(oteLI) >> 31); } int32_t signBit(const LargeIntegerOTE* oteLI) const { return signDigit(oteLI) >> 31; } - static LargeIntegerOTE* NewWithLimbs(MWORD limbs); + static LargeIntegerOTE* NewWithLimbs(size_t limbs); // Answer a signed 32 or 64-bit LargeInteger from the unsigned 32-bit argument static LargeIntegerOTE* __fastcall liNewUnsigned(uint32_t value); @@ -78,7 +78,7 @@ namespace ST static liDiv_t Divide(const LargeIntegerOTE* oteOp1, SmallInteger op2); static Oop Mul(const LargeIntegerOTE * oteInner, SmallInteger outerDigit); - static Oop Mul(const LargeInteger* liOuter, const MWORD outerSize, const LargeInteger* liInner, const MWORD innerSize); + static Oop Mul(const LargeInteger* liOuter, const size_t outerSize, const LargeInteger* liInner, const size_t innerSize); static Oop BitAnd(const LargeIntegerOTE * oteA, const LargeIntegerOTE * oteB); static Oop BitAnd(const LargeIntegerOTE * oteA, SmallInteger mask); diff --git a/Core/DolphinVM/STMethodHeader.h b/Core/DolphinVM/STMethodHeader.h index 6e89e85b9d..e8e1bc5099 100644 --- a/Core/DolphinVM/STMethodHeader.h +++ b/Core/DolphinVM/STMethodHeader.h @@ -26,12 +26,16 @@ typedef enum { PRIMITIVE_MAX = 255 } STPrimitives; +typedef uint8_t envtempcount_t; +typedef uint8_t stacktempcount_t; +typedef uint8_t methodargcount_t; + typedef struct STMethodHeader { - uint8_t isInt : 1; // MUST be 1 (to avoid treatment as object) - uint8_t isPrivate : 1; - uint8_t envTempCount : 6; // Note that this is actually count+1 - uint8_t stackTempCount; - uint8_t argumentCount; + uint8_t isInt : 1; // MUST be 1 (to avoid treatment as object) + uint8_t isPrivate : 1; + envtempcount_t envTempCount : 6; // Note that this is actually count+1 + stacktempcount_t stackTempCount; + methodargcount_t argumentCount; uint8_t primitiveIndex; } STMethodHeader; diff --git a/Core/DolphinVM/STObject.h b/Core/DolphinVM/STObject.h index 9de2a51e8a..f0ce8d8bf5 100644 --- a/Core/DolphinVM/STObject.h +++ b/Core/DolphinVM/STObject.h @@ -11,9 +11,9 @@ ******************************************************************************/ #pragma once -enum { ObjectFixedSize = 0 }; -enum { ObjectHeaderSize = 0 }; -enum { ObjectByteSize = ObjectHeaderSize*sizeof(MWORD) }; +constexpr size_t ObjectFixedSize = 0u; +constexpr size_t ObjectHeaderSize = 0u; +constexpr size_t ObjectByteSize = ObjectHeaderSize*sizeof(Oop); // Turn off warning about zero length arrays #pragma warning ( disable : 4200) diff --git a/Core/DolphinVM/STProcess.h b/Core/DolphinVM/STProcess.h index 5bf7976b23..12b330fa35 100644 --- a/Core/DolphinVM/STProcess.h +++ b/Core/DolphinVM/STProcess.h @@ -70,7 +70,7 @@ namespace ST SmallUinteger stackSize(ProcessOTE* oteMe) { - return (oteMe->getSize() - offsetof(Process, m_stack[0])) / sizeof(MWORD); + return (oteMe->getSize() - offsetof(Process, m_stack[0])) / sizeof(Oop); } SmallUinteger indexOfSP(Oop* sp) @@ -212,7 +212,7 @@ namespace ST DWORD Wait(SemaphoreOTE* oteThis, ProcessOTE* oteProcess, int nTimeout); - static SemaphoreOTE* New(int sigs = 0); + static SemaphoreOTE* New(SmallInteger sigs = 0); }; #ifdef _DEBUG @@ -246,8 +246,8 @@ namespace ST // when accessing the active frame using the 'thisContext' pseudo variable. inline void Process::sizeToSP(ProcessOTE* oteMe, Oop* sp) const { - MWORD words = sp - reinterpret_cast(this) + 1; - oteMe->setSize(words*sizeof(MWORD)); + size_t words = sp - reinterpret_cast(this) + 1; + oteMe->setSize(words*sizeof(Oop)); } #ifdef _DEBUG diff --git a/Core/DolphinVM/STStackFrame.h b/Core/DolphinVM/STStackFrame.h index dac38e5209..a851ebed6f 100644 --- a/Core/DolphinVM/STStackFrame.h +++ b/Core/DolphinVM/STStackFrame.h @@ -26,7 +26,7 @@ namespace ST Oop* stackPointer() const { return reinterpret_cast(m_sp - 1); } void setStackPointer(Oop* value); - void setInstructionPointer(int nOffset); + void setInstructionPointer(SmallInteger nOffset); Oop* basePointer() const; BOOL isBlockFrame() const; Oop receiver() const; @@ -47,7 +47,7 @@ namespace ST m_sp = Oop(value) + 1; } - inline void StackFrame::setInstructionPointer(int nOffset) + inline void StackFrame::setInstructionPointer(SmallInteger nOffset) { m_ip = integerObjectOf(nOffset); } diff --git a/Core/DolphinVM/STString.h b/Core/DolphinVM/STString.h index 8400ec9aec..ba68ca0e76 100644 --- a/Core/DolphinVM/STString.h +++ b/Core/DolphinVM/STString.h @@ -32,25 +32,25 @@ typedef TOTE SymbolOTE; class AnsiStringOTE : public TOTE { public: - __forceinline int sizeForUpdate() const { return static_cast(m_size); } + __forceinline ptrdiff_t sizeForUpdate() const { return static_cast(m_size); } }; class Utf8StringOTE : public TOTE { public: - __forceinline int sizeForUpdate() const { return static_cast(m_size); } + __forceinline ptrdiff_t sizeForUpdate() const { return static_cast(m_size); } }; class Utf16StringOTE : public TOTE { public: - __forceinline int sizeForUpdate() const { return static_cast(m_size) / static_cast(sizeof(char16_t)); } + __forceinline ptrdiff_t sizeForUpdate() const { return static_cast(m_size) / static_cast(sizeof(char16_t)); } }; class Utf32StringOTE : public TOTE { public: - __forceinline int sizeForUpdate() const { return static_cast(m_size) / static_cast(sizeof(char32_t)); } + __forceinline ptrdiff_t sizeForUpdate() const { return static_cast(m_size) / static_cast(sizeof(char32_t)); } }; typedef UINT codepage_t; diff --git a/Core/DolphinVM/STVirtualObject.h b/Core/DolphinVM/STVirtualObject.h index 1933b1b82d..ff457bb941 100644 --- a/Core/DolphinVM/STVirtualObject.h +++ b/Core/DolphinVM/STVirtualObject.h @@ -20,18 +20,18 @@ namespace ST { class VirtualObjectHeader { - uintptr_t m_maxAlloc; + size_t m_maxAlloc; uintptr_t m_reserved1; uintptr_t m_reserved2; BOOL m_bFxSaved; uint8_t m_fxSaveArea[512]; public: - void setCurrentAllocation(uintptr_t size) { ASSERT(size == getCurrentAllocation()); size; } - uintptr_t getCurrentAllocation(); + void setCurrentAllocation(size_t size) { ASSERT(size == getCurrentAllocation()); size; } + size_t getCurrentAllocation(); - uintptr_t getMaxAllocation() { return m_maxAlloc; } - void setMaxAllocation(MWORD dwSize) { m_maxAlloc = dwSize; } + size_t getMaxAllocation() { return m_maxAlloc; } + void setMaxAllocation(size_t maxAlloc) { m_maxAlloc = maxAlloc; } void fxSave() { @@ -51,7 +51,7 @@ namespace ST } }; - inline uintptr_t VirtualObjectHeader::getCurrentAllocation() + inline size_t VirtualObjectHeader::getCurrentAllocation() { MEMORY_BASIC_INFORMATION mbi; VERIFY(::VirtualQuery(this, &mbi, sizeof(mbi)) == sizeof(mbi)); diff --git a/Core/DolphinVM/SaveImage.cpp b/Core/DolphinVM/SaveImage.cpp index 1520690e9f..3f8116ab92 100644 --- a/Core/DolphinVM/SaveImage.cpp +++ b/Core/DolphinVM/SaveImage.cpp @@ -39,7 +39,7 @@ ////////////////////////////////////////////////////////////////////////////// // Image Save Methods -_PrimitiveFailureCode __stdcall ObjectMemory::SaveImageFile(const wchar_t* szFileName, bool bBackup, int nCompressionLevel, unsigned nMaxObjects) +_PrimitiveFailureCode __stdcall ObjectMemory::SaveImageFile(const wchar_t* szFileName, bool bBackup, int nCompressionLevel, size_t nMaxObjects) { // Answer: // NULL = success @@ -127,7 +127,7 @@ _PrimitiveFailureCode __stdcall ObjectMemory::SaveImageFile(const wchar_t* szFil header.nMaxTableSize = nMaxObjects; // Set the OT size - unsigned i = lastOTEntry(); + size_t i = lastOTEntry(); // Find the last used entry ASSERT(i > NumPermanent); header.nTableSize = i + 1; @@ -210,11 +210,11 @@ bool __stdcall ObjectMemory::SaveObjectTable(obinstream& imageFile, const ImageH return imageFile.write(m_pOT, sizeof(OTE)*pHeader->nTableSize); } -template bool __stdcall ObjectMemory::SaveObjects(obinstream& imageFile, const ImageHeader* pHeader) +template bool __stdcall ObjectMemory::SaveObjects(obinstream& imageFile, const ImageHeader* pHeader) { #ifdef _DEBUG - unsigned numObjects = 0; - unsigned nFree = 0; + size_t numObjects = 0; + size_t nFree = 0; #endif size_t dataSize = 0; @@ -235,11 +235,11 @@ template bool __stdcall ObjectMemory::SaveObjects(obinstr VirtualObjectHeader* pObjHeader = vObj->getHeader(); // We only write the max allocation size from the header. The rest of the info (fxstate) is not preserved across image saves. - imageFile.write(pObjHeader, sizeof(MWORD)); - dataSize += sizeof(MWORD); + imageFile.write(pObjHeader, sizeof(VirtualObjectHeader::m_maxAlloc)); + dataSize += sizeof(sizeof(VirtualObjectHeader::m_maxAlloc)); } - MWORD bytesToWrite = ote->getSize() + (ote->isNullTerminated() * ImageNullTerms); + size_t bytesToWrite = ote->getSize() + (ote->isNullTerminated() * ImageNullTerms); imageFile.write(obj, bytesToWrite); if (imageFile.good() == 0) @@ -263,7 +263,7 @@ template bool __stdcall ObjectMemory::SaveObjects(obinstr #endif // Append the amount of data written as a checksum. - return imageFile.write(&dataSize, sizeof(size_t)); + return imageFile.write(&dataSize, sizeof(dataSize)); } #endif diff --git a/Core/DolphinVM/SearchPrim.cpp b/Core/DolphinVM/SearchPrim.cpp index 01d66f05b9..3f3f985e28 100644 --- a/Core/DolphinVM/SearchPrim.cpp +++ b/Core/DolphinVM/SearchPrim.cpp @@ -50,7 +50,7 @@ Oop* __fastcall Interpreter::primitiveNextIndexOfFromTo(Oop* const sp, primargco if (ObjectMemoryIsIntegerObject(valuePointer))// Arg MUST be an Integer to be a member { - const MWORD byteValue = ObjectMemoryIntegerValueOf(valuePointer); + const SmallUinteger byteValue = ObjectMemoryIntegerValueOf(valuePointer); if (byteValue < 256) // Only worth looking for 0..255 { const SmallInteger length = oteBytes->bytesSize(); @@ -80,12 +80,12 @@ Oop* __fastcall Interpreter::primitiveNextIndexOfFromTo(Oop* const sp, primargco PointersOTE* oteReceiver = reinterpret_cast(receiverPointer); VariantObject* receiver = oteReceiver->m_location; Behavior* behavior = receiverPointer->m_oteClass->m_location; - const MWORD length = oteReceiver->pointersSize(); - const MWORD fixedFields = behavior->fixedFields(); + const auto length = oteReceiver->pointersSize(); + const auto fixedFields = behavior->fixedFields(); // Similar reasoning with to/from as for byte objects, but here we need to // take account of the fixed fields. - if (from < 1 || (to + fixedFields > length)) + if (from < 1 || (static_cast(to) + fixedFields > length)) return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); // Out of bounds Oop* indexedFields = receiver->m_fields + fixedFields; @@ -109,9 +109,9 @@ Oop* __fastcall Interpreter::primitiveNextIndexOfFromTo(Oop* const sp, primargco // Initialize the Boyer-Moorer skip array inline void __stdcall bmInitSkip(const uint8_t* p, const int M, int* skip) { - for (int j=0;j<256;j++) + for (auto j=0;j<256;j++) skip[j] = M; - for (int j=0;j < M;j++) + for (auto j=0;j < M;j++) skip[p[j]] = M-j-1; } @@ -192,7 +192,7 @@ Oop* __fastcall Interpreter::primitiveStringSearch(Oop* const sp, primargcount_t // Check 'startingAt' is in range if (startingAt > 0) { - int nOffset = M == 0 || ((startingAt + M) - 1 > N) + SmallInteger nOffset = M == 0 || ((startingAt + M) - 1 > N) ? -1 : stringSearch(bytesReceiver->m_fields, N, bytesPattern->m_fields, M, startingAt - 1); diff --git a/Core/DolphinVM/SnapshotPrim.cpp b/Core/DolphinVM/SnapshotPrim.cpp index c7ab9949d6..6094b68c25 100644 --- a/Core/DolphinVM/SnapshotPrim.cpp +++ b/Core/DolphinVM/SnapshotPrim.cpp @@ -106,7 +106,7 @@ Oop* __fastcall Interpreter::primitiveSnapshot(Oop* const sp, primargcount_t) #elif defined(TO_GO) -Oop* __fastcall Interpreter::primitiveSnapshot(Oop* const, unsigned) +Oop* __fastcall Interpreter::primitiveSnapshot(Oop* const, primargcount_t) { return primitiveFailure(_PrimitiveFailureCode::NotSupported); } diff --git a/Core/DolphinVM/StreamPrim.cpp b/Core/DolphinVM/StreamPrim.cpp index 7e334859bd..54ff4668b0 100644 --- a/Core/DolphinVM/StreamPrim.cpp +++ b/Core/DolphinVM/StreamPrim.cpp @@ -59,10 +59,10 @@ Oop* __fastcall Interpreter::primitiveNext(Oop* const sp, primargcount_t) { case StringEncoding::Ansi: { - if (MWORD(index) < oteBuf->bytesSize()) + if (static_cast(index) < oteBuf->bytesSize()) { auto ansiCodeUnit = static_cast(reinterpret_cast(oteBuf)->m_location->m_characters[index]); - PushCharacter(sp, static_cast(m_ansiToUnicodeCharMap[ansiCodeUnit])); + PushCharacter(sp, static_cast(m_ansiToUnicodeCharMap[ansiCodeUnit])); // When incrementing the index we must allow for it overflowing a SmallInteger, even though // this is extremely unlikely in practice readStream->m_index = Integer::NewSigned32WithRef(index + 1); @@ -73,8 +73,8 @@ Oop* __fastcall Interpreter::primitiveNext(Oop* const sp, primargcount_t) case StringEncoding::Utf8: { - MWORD size = oteBuf->bytesSize(); - if (MWORD(index) < size) + size_t size = oteBuf->bytesSize(); + if (static_cast(index) < size) { const Utf8String::CU* psz = reinterpret_cast(oteBuf)->m_location->m_characters; @@ -101,8 +101,8 @@ Oop* __fastcall Interpreter::primitiveNext(Oop* const sp, primargcount_t) { Utf16StringOTE* oteString = reinterpret_cast(oteBuf); - MWORD size = oteString->bytesSize(); - if (MWORD(index) < size / sizeof(Utf16String::CU)) + size_t size = oteString->bytesSize(); + if (static_cast(index) < size / sizeof(Utf16String::CU)) { const Utf16String::CU* pwsz = oteString->m_location->m_characters; SmallInteger codePoint; @@ -127,8 +127,8 @@ Oop* __fastcall Interpreter::primitiveNext(Oop* const sp, primargcount_t) { Utf32StringOTE* oteString = reinterpret_cast(oteBuf); - MWORD size = oteString->bytesSize(); - if (MWORD(index) < size / sizeof(Utf32String::CU)) + size_t size = oteString->bytesSize(); + if (static_cast(index) < size / sizeof(Utf32String::CU)) { Utf32String::CU codePoint = oteString->m_location->m_characters[index]; @@ -156,7 +156,7 @@ Oop* __fastcall Interpreter::primitiveNext(Oop* const sp, primargcount_t) else if (bufClass == Pointers.ClassByteArray) { ByteArrayOTE* oteBytes = reinterpret_cast(oteBuf); - if (MWORD(index) < oteBytes->bytesSize()) + if (static_cast(index) < oteBytes->bytesSize()) { *sp = ObjectMemoryIntegerObjectOf(oteBytes->m_location->m_elements[index]); readStream->m_index = Integer::NewSigned32WithRef(index + 1); @@ -168,7 +168,7 @@ Oop* __fastcall Interpreter::primitiveNext(Oop* const sp, primargcount_t) else if (bufClass == Pointers.ClassArray) { ArrayOTE* oteArray = reinterpret_cast(oteBuf); - if (MWORD(index) < oteArray->pointersSize()) + if (static_cast(index) < oteArray->pointersSize()) { *sp = oteArray->m_location->m_elements[index]; readStream->m_index = Integer::NewSigned32WithRef(index + 1); @@ -214,7 +214,7 @@ Oop* __fastcall Interpreter::primitiveNextPut(Oop* const sp, primargcount_t) if (ObjectMemory::fetchClassOf(value) == Pointers.ClassCharacter) { Character* character = reinterpret_cast(value)->m_location; - MWORD codeUnit = character->CodeUnit; + auto codeUnit = character->CodeUnit; switch (reinterpret_cast(oteBuf->m_oteClass->m_location)->Encoding) { @@ -230,7 +230,7 @@ Oop* __fastcall Interpreter::primitiveNextPut(Oop* const sp, primargcount_t) switch (character->Encoding) { case StringEncoding::Ansi: - oteStringBuf->m_location->m_characters[index] = codeUnit; + oteStringBuf->m_location->m_characters[index] = codeUnit & 0xff; writeStream->m_index = Integer::NewSigned32WithRef(index + 1); // Increment the stream index *newSp = value; return newSp; @@ -276,7 +276,7 @@ Oop* __fastcall Interpreter::primitiveNextPut(Oop* const sp, primargcount_t) // Write into a Utf8String - could possibly write more than one byte, so have to check bounds for each Character encoding Utf8StringOTE* oteStringBuf = reinterpret_cast(oteBuf); - MWORD codeUnit = character->CodeUnit; + auto codeUnit = character->CodeUnit; char32_t codePoint = MAX_UCSCHAR+1; switch (character->Encoding) @@ -539,7 +539,7 @@ Oop* __fastcall Interpreter::primitiveNextPut(Oop* const sp, primargcount_t) { if (ObjectMemoryIsIntegerObject(value)) { - MWORD intValue = ObjectMemoryIntegerValueOf(value); + SmallUinteger intValue = ObjectMemoryIntegerValueOf(value); if (intValue <= 255) { ByteArrayOTE* oteByteArray = reinterpret_cast(oteBuf); @@ -621,7 +621,7 @@ Oop* __fastcall Interpreter::primitiveBasicNext(Oop* const sp, primargcount_t) switch (ObjectMemory::GetBytesElementSize(reinterpret_cast(oteBuf))) { case 1: - if (MWORD(index) < oteBuf->bytesSize()) + if (static_cast(index) < oteBuf->bytesSize()) { uint8_t value = reinterpret_cast(oteBuf)->m_location->m_fields[index]; *sp = integerObjectOf(value); @@ -633,7 +633,7 @@ Oop* __fastcall Interpreter::primitiveBasicNext(Oop* const sp, primargcount_t) return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); case 2: - if (MWORD(index) < (oteBuf->bytesSize() / 2)) + if (static_cast(index) < (oteBuf->bytesSize() / 2)) { uint16_t value = reinterpret_cast(oteBuf)->m_location->m_fields[index]; *sp = integerObjectOf(value); @@ -645,7 +645,7 @@ Oop* __fastcall Interpreter::primitiveBasicNext(Oop* const sp, primargcount_t) return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); case 4: - if (MWORD(index) < (oteBuf->bytesSize() / 4)) + if (static_cast(index) < (oteBuf->bytesSize() / 4)) { uint32_t value = reinterpret_cast(oteBuf)->m_location->m_fields[index]; StoreUnsigned32()(sp, value); @@ -665,7 +665,7 @@ Oop* __fastcall Interpreter::primitiveBasicNext(Oop* const sp, primargcount_t) else if (bufClass == Pointers.ClassArray) { ArrayOTE* oteArray = reinterpret_cast(oteBuf); - if (MWORD(index) < oteArray->pointersSize()) + if (static_cast(index) < oteArray->pointersSize()) { *sp = oteArray->m_location->m_elements[index]; readStream->m_index = Integer::NewSigned32WithRef(index + 1); @@ -686,7 +686,7 @@ Oop* __fastcall Interpreter::primitiveBasicNext(Oop* const sp, primargcount_t) // Like primitiveNextPut, but always writes an integer element. For a ByteArray, this will be a byte. For a string, it will be a code unit. Oop* __fastcall Interpreter::primitiveBasicNextPut(Oop* const sp, primargcount_t) { - MWORD value = *sp; + uintptr_t value = *sp; if (ObjectMemoryIsIntegerObject(value)) { Oop* newSp = sp - 1; @@ -803,7 +803,7 @@ Oop* __fastcall Interpreter::primitiveNextPutAll(Oop* const sp, primargcount_t) auto oteBuf = writeStream->m_array; auto bufClass = oteBuf->m_oteClass; - MWORD newIndex; + size_t newIndex; if (oteBuf->isBytes()) { @@ -821,13 +821,13 @@ Oop* __fastcall Interpreter::primitiveNextPutAll(Oop* const sp, primargcount_t) auto oteAnsiString = reinterpret_cast(value); auto str = oteAnsiString->m_location; - MWORD valueSize = oteAnsiString->bytesSize(); - newIndex = MWORD(index) + valueSize; + size_t valueSize = oteAnsiString->bytesSize(); + newIndex = static_cast(index) + valueSize; - if (newIndex > static_cast(limit)) // Beyond write limit + if (newIndex > static_cast(limit)) // Beyond write limit return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); - if (static_cast(newIndex) > oteStringBuf->sizeForUpdate()) + if (static_cast(newIndex) > oteStringBuf->sizeForUpdate()) return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); // Attempt to write off end of buffer memcpy(oteStringBuf->m_location->m_characters + index, str->m_characters, valueSize); @@ -840,13 +840,13 @@ Oop* __fastcall Interpreter::primitiveNextPutAll(Oop* const sp, primargcount_t) auto oteUtf8String = reinterpret_cast(oteStringArg); auto str = oteUtf8String->m_location; - MWORD valueSize = oteUtf8String->bytesSize(); - newIndex = MWORD(index) + valueSize; + size_t valueSize = oteUtf8String->bytesSize(); + newIndex = static_cast(index) + valueSize; - if (newIndex > static_cast(limit)) // Beyond write limit + if (newIndex > static_cast(limit)) // Beyond write limit return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); - if (static_cast(newIndex) > oteStringBuf->sizeForUpdate()) + if (static_cast(newIndex) > oteStringBuf->sizeForUpdate()) return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); // Attempt to write off end of buffer memcpy(oteStringBuf->m_location->m_characters + index, str->m_characters, valueSize); @@ -869,14 +869,14 @@ Oop* __fastcall Interpreter::primitiveNextPutAll(Oop* const sp, primargcount_t) // TODO: Implement a direct ANSI to UTF-8 translation auto oteStringBuf = reinterpret_cast(oteBuf); Utf16StringBuf utf16(m_ansiCodePage, reinterpret_cast(oteStringArg)->m_location->m_characters, oteStringArg->getSize()); - MWORD valueSize = utf16.ToUtf8(); + size_t valueSize = utf16.ToUtf8(); - newIndex = MWORD(index) + valueSize; + newIndex = static_cast(index) + valueSize; - if (newIndex > static_cast(limit)) // Beyond write limit + if (newIndex > static_cast(limit)) // Beyond write limit return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); - if (static_cast(newIndex) > oteStringBuf->sizeForUpdate()) + if (static_cast(newIndex) > oteStringBuf->sizeForUpdate()) return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); // Attempt to write off end of buffer utf16.ToUtf8(oteStringBuf->m_location->m_characters + index, valueSize); @@ -889,17 +889,17 @@ Oop* __fastcall Interpreter::primitiveNextPutAll(Oop* const sp, primargcount_t) // UTF-8, Utf16 => UTF-8 auto oteStringBuf = reinterpret_cast(oteBuf); const Utf16String::CU* pArgChars = reinterpret_cast(oteStringArg)->m_location->m_characters; - MWORD cwchArg = oteStringArg->getSize() / sizeof(Utf16String::CU); + size_t cwchArg = oteStringArg->getSize() / sizeof(Utf16String::CU); int cbArg = ::WideCharToMultiByte(CP_UTF8, 0, (LPCWCH)pArgChars, cwchArg, nullptr, 0, nullptr, nullptr); ASSERT(cbArg >= 0); - MWORD valueSize = cbArg; + size_t valueSize = cbArg; - newIndex = MWORD(index) + valueSize; + newIndex = static_cast(index) + valueSize; - if (newIndex > static_cast(limit)) // Beyond write limit + if (newIndex > static_cast(limit)) // Beyond write limit return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); - if (static_cast(newIndex) > oteStringBuf->sizeForUpdate()) + if (static_cast(newIndex) > oteStringBuf->sizeForUpdate()) return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); // Attempt to write off end of buffer (or immutable) auto pchDest = oteStringBuf->m_location->m_characters; @@ -911,16 +911,16 @@ Oop* __fastcall Interpreter::primitiveNextPutAll(Oop* const sp, primargcount_t) { auto oteStringBuf = reinterpret_cast(oteBuf); auto pszArg = reinterpret_cast(oteStringArg)->m_location->m_characters; - MWORD cchArg = oteStringArg->getSize(); + size_t cchArg = oteStringArg->getSize(); int cwchArg = ::MultiByteToWideChar(m_ansiCodePage, 0, pszArg, cchArg, nullptr, 0); ASSERT(cwchArg >= 0); - MWORD valueSize = cwchArg; - newIndex = MWORD(index) + valueSize; + size_t valueSize = cwchArg; + newIndex = static_cast(index) + valueSize; - if (newIndex > static_cast(limit)) // Beyond write limit + if (newIndex > static_cast(limit)) // Beyond write limit return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); - if (static_cast(newIndex) > oteStringBuf->sizeForUpdate()) + if (static_cast(newIndex) > oteStringBuf->sizeForUpdate()) return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); // Attempt to write off end of buffer (or immutable) auto pwsz = oteStringBuf->m_location->m_characters; @@ -932,16 +932,16 @@ Oop* __fastcall Interpreter::primitiveNextPutAll(Oop* const sp, primargcount_t) { auto oteStringBuf = reinterpret_cast(oteBuf); auto pszArg = reinterpret_cast(oteStringArg)->m_location->m_characters; - MWORD cchArg = oteStringArg->getSize(); + size_t cchArg = oteStringArg->getSize(); int cwchArg = ::MultiByteToWideChar(CP_UTF8, 0, (LPCCH)pszArg, cchArg, nullptr, 0); ASSERT(cwchArg >= 0); - MWORD valueSize = cwchArg; - newIndex = MWORD(index) + valueSize; + size_t valueSize = cwchArg; + newIndex = static_cast(index) + valueSize; - if (newIndex > static_cast(limit)) // Beyond write limit + if (newIndex > static_cast(limit)) // Beyond write limit return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); - if (static_cast(newIndex) > oteStringBuf->sizeForUpdate()) + if (static_cast(newIndex) > oteStringBuf->sizeForUpdate()) return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); // Attempt to write off end of buffer (or immutable) auto pwsz = oteStringBuf->m_location->m_characters; @@ -955,13 +955,13 @@ Oop* __fastcall Interpreter::primitiveNextPutAll(Oop* const sp, primargcount_t) auto oteUtf16String = reinterpret_cast(oteStringArg); auto str = oteUtf16String->m_location; - MWORD valueSize = oteUtf16String->bytesSize()/sizeof(Utf16String::CU); - newIndex = MWORD(index) + valueSize; + size_t valueSize = oteUtf16String->bytesSize()/sizeof(Utf16String::CU); + newIndex = static_cast(index) + valueSize; - if (newIndex > static_cast(limit)) // Beyond write limit + if (newIndex > static_cast(limit)) // Beyond write limit return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); - if (static_cast(newIndex) > oteStringBuf->sizeForUpdate()) + if (static_cast(newIndex) > oteStringBuf->sizeForUpdate()) return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); // Attempt to write off end of buffer (or immutable) auto pwsz = oteStringBuf->m_location->m_characters; @@ -982,13 +982,13 @@ Oop* __fastcall Interpreter::primitiveNextPutAll(Oop* const sp, primargcount_t) auto oteBytes = reinterpret_cast(value); auto bytes = oteBytes->m_location; - MWORD valueSize = oteBytes->bytesSize(); - newIndex = MWORD(index) + valueSize; + size_t valueSize = oteBytes->bytesSize(); + newIndex = static_cast(index) + valueSize; - if (newIndex > (MWORD)limit) // Beyond write limit + if (newIndex > static_cast(limit)) // Beyond write limit return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); - if (static_cast(newIndex) > oteBytesBuf->sizeForUpdate()) + if (static_cast(newIndex) > oteBytesBuf->sizeForUpdate()) return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); // Attempt to write off end of buffer (or immutable) auto pb = oteBytesBuf->m_location->m_elements; @@ -1004,18 +1004,18 @@ Oop* __fastcall Interpreter::primitiveNextPutAll(Oop* const sp, primargcount_t) auto oteArray = reinterpret_cast(value); auto array = oteArray->m_location; - MWORD valueSize = oteArray->pointersSize(); - newIndex = MWORD(index) + valueSize; + size_t valueSize = oteArray->pointersSize(); + newIndex = static_cast(index) + valueSize; - if (newIndex > (MWORD)limit) // Beyond write limit + if (newIndex > static_cast(limit)) // Beyond write limit return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); - if (static_cast(newIndex) > oteArrayBuf->sizeForUpdate()) + if (static_cast(newIndex) > oteArrayBuf->sizeForUpdate()) return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); // Attempt to write off end of buffer (or immutable) auto pTarget = oteArrayBuf->m_location->m_elements; - for (MWORD i = 0; i < valueSize; i++) + for (auto i = 0u; i < valueSize; i++) { ObjectMemory::storePointerWithValue(pTarget[index + i], array->m_elements[i]); } @@ -1053,13 +1053,13 @@ Oop* __fastcall Interpreter::primitiveAtEnd(Oop* const sp, primargcount_t) if (oteBuf->isNullTerminated() || bufClass == Pointers.ClassByteArray) { - *sp = reinterpret_cast(index >= readLimit || (MWORD(ObjectMemoryIntegerValueOf(index)) >= readStream->m_array->bytesSize()) + *sp = reinterpret_cast(index >= readLimit || (static_cast(ObjectMemoryIntegerValueOf(index)) >= readStream->m_array->bytesSize()) ? Pointers.True : Pointers.False); return sp; } else if (bufClass == Pointers.ClassArray) { - *sp = reinterpret_cast(index >= readLimit || (MWORD(ObjectMemoryIntegerValueOf(index)) >= readStream->m_array->pointersSize()) + *sp = reinterpret_cast(index >= readLimit || (static_cast(ObjectMemoryIntegerValueOf(index)) >= readStream->m_array->pointersSize()) ? Pointers.True : Pointers.False); return sp; } @@ -1100,12 +1100,12 @@ Oop* __fastcall Interpreter::primitiveNextInt32(Oop* const sp, primargcount_t) ByteArrayOTE* oteBytes = reinterpret_cast(oteBuf); - const int newIndex = index + sizeof(int32_t); - if (MWORD(newIndex) > oteBytes->bytesSize()) + const auto newIndex = index + sizeof(int32_t); + if (static_cast(newIndex) > oteBytes->bytesSize()) return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); const Oop oopNewIndex = ObjectMemoryIntegerObjectOf(newIndex); - if (int(oopNewIndex) < 0) + if (static_cast(oopNewIndex) < 0) return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); // index overflowed SmallInteger range // When incrementing the index we must allow for it overflowing a SmallInteger, even though diff --git a/Core/DolphinVM/alloc.cpp b/Core/DolphinVM/alloc.cpp index c0224f709d..a1fa56757f 100755 --- a/Core/DolphinVM/alloc.cpp +++ b/Core/DolphinVM/alloc.cpp @@ -23,8 +23,8 @@ #endif #ifdef MEMSTATS - extern unsigned m_nLargeAllocated; - extern unsigned m_nSmallAllocated; + extern size_t m_nLargeAllocated; + extern size_t m_nSmallAllocated; #endif // Smalltalk classes @@ -34,8 +34,6 @@ // No auto-inlining in this module please #pragma auto_inline(off) -//MWORD ObjectMemory::MaxSizeOfPoolObject; -//int ObjectMemory::NumPools; ObjectMemory::FixedSizePool ObjectMemory::m_pools[MaxPools]; ObjectMemory::FixedSizePool::Link* ObjectMemory::FixedSizePool::m_pFreePages; void** ObjectMemory::FixedSizePool::m_pAllocations; @@ -45,7 +43,7 @@ size_t ObjectMemory::FixedSizePool::m_nAllocations; // Public object allocation routines // Rarely used, so don't inline it -POBJECT ObjectMemory::allocLargeObject(MWORD objectSize, OTE*& ote) +POBJECT ObjectMemory::allocLargeObject(size_t objectSize, OTE*& ote) { #ifdef MEMSTATS ++m_nLargeAllocated; @@ -60,7 +58,7 @@ POBJECT ObjectMemory::allocLargeObject(MWORD objectSize, OTE*& ote) return pObj; } -inline POBJECT ObjectMemory::allocObject(MWORD objectSize, OTE*& ote) +inline POBJECT ObjectMemory::allocObject(size_t objectSize, OTE*& ote) { // Callers are expected to round requests to Oop granularity if (objectSize > MaxSmallObjectSize) @@ -94,23 +92,22 @@ PointersOTE* __fastcall ObjectMemory::shallowCopy(PointersOTE* ote) BehaviorOTE* classPointer = ote->m_oteClass; PointersOTE* copyPointer; - MWORD size; + size_t size; if (ote->heapSpace() == OTEFlags::VirtualSpace) { Interpreter::resizeActiveProcess(); - //size = obj->PointerSize(); size = ote->pointersSize(); VirtualObject* pVObj = reinterpret_cast(obj); VirtualObjectHeader* pBase = pVObj->getHeader(); - unsigned maxByteSize = pBase->getMaxAllocation(); - unsigned currentTotalByteSize = pBase->getCurrentAllocation(); + size_t maxByteSize = pBase->getMaxAllocation(); + size_t currentTotalByteSize = pBase->getCurrentAllocation(); VirtualOTE* virtualCopy = ObjectMemory::newVirtualObject(classPointer, - currentTotalByteSize / sizeof(MWORD), - maxByteSize / sizeof(MWORD)); + currentTotalByteSize / sizeof(Oop), + maxByteSize / sizeof(Oop)); if (!virtualCopy) return nullptr; @@ -124,7 +121,6 @@ PointersOTE* __fastcall ObjectMemory::shallowCopy(PointersOTE* ote) } else { - //size = obj->PointerSize(); size = ote->pointersSize(); copyPointer = newPointerObject(classPointer, size); } @@ -132,7 +128,7 @@ PointersOTE* __fastcall ObjectMemory::shallowCopy(PointersOTE* ote) // Now copy over all the fields VariantObject* copy = copyPointer->m_location; ASSERT(copyPointer->pointersSize() == size); - for (unsigned i = 0; im_fields[i] = obj->m_fields[i]; countUp(obj->m_fields[i]); @@ -157,10 +153,10 @@ Oop* __fastcall Interpreter::primitiveShallowCopy(Oop* const sp, primargcount_t) // Public object Instantiation (see also Objmem.h) // // These methods return Oops rather than OTE*'s because we want the type to be -// opaque to external users, and to be interchangeable with MWORDs. +// opaque to external users, and to be interchangeable with uinptr_ts. // -Oop* __fastcall Interpreter::primitiveNewFromStack(Oop* const stackPointer, unsigned) +Oop* __fastcall Interpreter::primitiveNewFromStack(Oop* const stackPointer, primargcount_t) { BehaviorOTE* oteClass = reinterpret_cast(*(stackPointer - 1)); @@ -312,15 +308,15 @@ PointersOTE* __fastcall ObjectMemory::newPointerObject(BehaviorOTE* classPointer return newPointerObject(classPointer, classPointer->m_location->fixedFields()); } -PointersOTE* __fastcall ObjectMemory::newPointerObject(BehaviorOTE* classPointer, MWORD oops) +PointersOTE* __fastcall ObjectMemory::newPointerObject(BehaviorOTE* classPointer, size_t oops) { PointersOTE* ote = newUninitializedPointerObject(classPointer, oops); // Initialise the fields to nils const Oop nil = Oop(Pointers.Nil); // Loop invariant (otherwise compiler reloads each time) VariantObject* pLocation = ote->m_location; - const MWORD loopEnd = oops; - for (MWORD i = 0; im_fields[i] = nil; ASSERT(ote->isPointers()); @@ -328,10 +324,10 @@ PointersOTE* __fastcall ObjectMemory::newPointerObject(BehaviorOTE* classPointer return reinterpret_cast(ote); } -PointersOTE* __fastcall ObjectMemory::newUninitializedPointerObject(BehaviorOTE* classPointer, MWORD oops) +PointersOTE* __fastcall ObjectMemory::newUninitializedPointerObject(BehaviorOTE* classPointer, size_t oops) { // Don't worry, compiler will not really use multiply instruction here - MWORD objectSize = SizeOfPointers(oops); + size_t objectSize = SizeOfPointers(oops); OTE* ote; allocObject(objectSize, ote); ASSERT((objectSize > MaxSizeOfPoolObject && ote->heapSpace() == OTEFlags::NormalSpace) @@ -349,7 +345,7 @@ PointersOTE* __fastcall ObjectMemory::newUninitializedPointerObject(BehaviorOTE* return reinterpret_cast(ote); } -template BytesOTE* ObjectMemory::newByteObject(BehaviorOTE* classPointer, MWORD elementCount) +template BytesOTE* ObjectMemory::newByteObject(BehaviorOTE* classPointer, size_t elementCount) { Behavior& byteClass = *classPointer->m_location; OTE* ote; @@ -379,7 +375,7 @@ template BytesOTE* ObjectMemory::newByteObject(B { ASSERT(classPointer->m_location->m_instanceSpec.m_nullTerminated); - MWORD objectSize; + size_t objectSize; switch (reinterpret_cast(byteClass).Encoding) { @@ -429,10 +425,10 @@ template BytesOTE* ObjectMemory::newByteObject(B } // Explicit instantiations -template BytesOTE* ObjectMemory::newByteObject(BehaviorOTE*, MWORD); -template BytesOTE* ObjectMemory::newByteObject(BehaviorOTE*, MWORD); -template BytesOTE* ObjectMemory::newByteObject(BehaviorOTE*, MWORD); -template BytesOTE* ObjectMemory::newByteObject(BehaviorOTE*, MWORD); +template BytesOTE* ObjectMemory::newByteObject(BehaviorOTE*, size_t); +template BytesOTE* ObjectMemory::newByteObject(BehaviorOTE*, size_t); +template BytesOTE* ObjectMemory::newByteObject(BehaviorOTE*, size_t); +template BytesOTE* ObjectMemory::newByteObject(BehaviorOTE*, size_t); Oop* __fastcall Interpreter::primitiveNewPinned(Oop* const sp, primargcount_t) { @@ -462,7 +458,7 @@ Oop* __fastcall Interpreter::primitiveNewPinned(Oop* const sp, primargcount_t) return primitiveFailure(_PrimitiveFailureCode::InvalidParameter1); // Size must be positive SmallInteger } -OTE* ObjectMemory::CopyElements(OTE* oteObj, MWORD startingAt, MWORD count) +OTE* ObjectMemory::CopyElements(OTE* oteObj, size_t startingAt, size_t count) { // Note that startingAt is expected to be a zero-based index ASSERT(startingAt >= 0); @@ -475,7 +471,7 @@ OTE* ObjectMemory::CopyElements(OTE* oteObj, MWORD startingAt, MWORD count) if (count == 0 || ((startingAt + count) * elementSize <= oteBytes->bytesSize())) { - MWORD objectSize = elementSize * count; + size_t objectSize = elementSize * count; if (oteBytes->m_flags.m_weakOrZ) { @@ -511,12 +507,12 @@ OTE* ObjectMemory::CopyElements(OTE* oteObj, MWORD startingAt, MWORD count) if (count == 0 || (startingAt + count) <= otePointers->pointersSize()) { - MWORD objectSize = SizeOfPointers(count); + size_t objectSize = SizeOfPointers(count); auto pSlice = static_cast(allocObject(objectSize, oteSlice)); // When copying pointers, the slice is always an Array oteSlice->m_oteClass = Pointers.ClassArray; VariantObject* pSrc = otePointers->m_location; - for (MWORD i = 0; i < count; i++) + for (size_t i = 0; i < count; i++) { countUp(pSlice->m_fields[i] = pSrc->m_fields[startingAt + i]); } @@ -578,7 +574,7 @@ BytesOTE* __fastcall ObjectMemory::shallowCopy(BytesOTE* ote) // Copying byte objects is simple and fast VariantByteObject& bytes = *ote->m_location; BehaviorOTE* classPointer = ote->m_oteClass; - MWORD objectSize = ote->sizeOf(); + size_t objectSize = ote->sizeOf(); OTE* copyPointer; // Allocate an uninitialized object ... @@ -621,7 +617,7 @@ Oop* __fastcall Interpreter::primitiveNewVirtual(Oop* const sp, primargcount_t) InstanceSpecification instSpec = receiverClass->m_location->m_instanceSpec; if (instSpec.m_indexable && !instSpec.m_nonInstantiable) { - unsigned fixedFields = instSpec.m_fixedFields; + auto fixedFields = instSpec.m_fixedFields; VirtualOTE* newObject = ObjectMemory::newVirtualObject(receiverClass, initialSize + fixedFields, maxSize); if (newObject) { @@ -657,9 +653,9 @@ Oop* __fastcall Interpreter::primitiveNewVirtual(Oop* const sp, primargcount_t) virtual allocation overhead). Should the allocation request fail, then a memory exception is generated. */ -MWORD* __stdcall AllocateVirtualSpace(MWORD maxBytes, MWORD initialBytes) +Oop* __stdcall AllocateVirtualSpace(size_t maxBytes, size_t initialBytes) { - unsigned reserveBytes = _ROUND2(maxBytes + dwPageSize, dwAllocationGranularity); + size_t reserveBytes = _ROUND2(maxBytes + dwPageSize, dwAllocationGranularity); ASSERT(reserveBytes % dwAllocationGranularity == 0); void* pReservation = ::VirtualAlloc(NULL, reserveBytes, MEM_RESERVE, PAGE_NOACCESS); if (pReservation) @@ -702,7 +698,7 @@ MWORD* __stdcall AllocateVirtualSpace(MWORD maxBytes, MWORD initialBytes) // Use first slot to hold the maximum size for the object pLocation->setMaxAllocation(maxBytes); - return reinterpret_cast(pLocation + 1); + return reinterpret_cast(pLocation + 1); } } @@ -713,7 +709,7 @@ MWORD* __stdcall AllocateVirtualSpace(MWORD maxBytes, MWORD initialBytes) // objects in virtual space (used for allocating Processes, for example), does not adjust // the ref. count of the class, because this is often unecessary, and does not adjust the // sizes to allow for fixed fields - callers must do this -VirtualOTE* ObjectMemory::newVirtualObject(BehaviorOTE* classPointer, MWORD initialSize, MWORD maxSize) +VirtualOTE* ObjectMemory::newVirtualObject(BehaviorOTE* classPointer, size_t initialSize, size_t maxSize) { #ifdef _DEBUG { @@ -736,10 +732,10 @@ VirtualOTE* ObjectMemory::newVirtualObject(BehaviorOTE* classPointer, MWORD init // We have to allow for the virtual allocation overhead. The allocation function will add in // space for this. The maximum size should include this, the initial size should not - initialSize -= sizeof(VirtualObjectHeader)/sizeof(MWORD); + initialSize -= sizeof(VirtualObjectHeader)/sizeof(Oop); - unsigned byteSize = initialSize*sizeof(MWORD); - VariantObject* pLocation = reinterpret_cast(AllocateVirtualSpace(maxSize * sizeof(MWORD), byteSize)); + size_t byteSize = initialSize*sizeof(Oop); + VariantObject* pLocation = reinterpret_cast(AllocateVirtualSpace(maxSize * sizeof(Oop), byteSize)); if (pLocation) { // No need to alter ref. count of process class, as it is sticky @@ -768,7 +764,7 @@ VirtualOTE* ObjectMemory::newVirtualObject(BehaviorOTE* classPointer, MWORD init // void ObjectMemory::FixedSizePool::morePages() { - const int nPages = dwAllocationGranularity / dwPageSize; + const size_t nPages = dwAllocationGranularity / dwPageSize; UNREFERENCED_PARAMETER(nPages); ASSERT(dwPageSize*nPages == dwAllocationGranularity); @@ -830,9 +826,9 @@ inline uint8_t* ObjectMemory::FixedSizePool::allocatePage() // Allocate another page for a fixed size pool void ObjectMemory::FixedSizePool::moreChunks() { - const int nOverhead = 0;//12; - const int nBlockSize = dwPageSize - nOverhead; - const int nChunks = nBlockSize / m_nChunkSize; + const size_t nOverhead = 0;//12; + const size_t nBlockSize = dwPageSize - nOverhead; + const size_t nChunks = nBlockSize / m_nChunkSize; uint8_t* pStart = allocatePage(); @@ -873,7 +869,7 @@ void ObjectMemory::FixedSizePool::moreChunks() #endif } -void ObjectMemory::FixedSizePool::setSize(unsigned nChunkSize) +void ObjectMemory::FixedSizePool::setSize(size_t nChunkSize) { m_nChunkSize = nChunkSize; // Must be on 4 byte boundaries @@ -882,7 +878,7 @@ void ObjectMemory::FixedSizePool::setSize(unsigned nChunkSize) // m_dwPageUsed = (dwPageSize / m_nChunkSize) * m_nChunkSize; } -inline ObjectMemory::FixedSizePool::FixedSizePool(unsigned nChunkSize) : m_pFreeChunks(0) +inline ObjectMemory::FixedSizePool::FixedSizePool(size_t nChunkSize) : m_pFreeChunks(0) #ifdef _DEBUG , m_pages(0), m_nPages(0) #endif @@ -894,7 +890,7 @@ inline ObjectMemory::FixedSizePool::FixedSizePool(unsigned nChunkSize) : m_pFree // #pragma auto_inline(on) //#endif -inline POBJECT ObjectMemory::reallocChunk(POBJECT pChunk, MWORD newChunkSize) +inline POBJECT ObjectMemory::reallocChunk(POBJECT pChunk, size_t newChunkSize) { #ifdef PRIVATE_HEAP return static_cast(::HeapReAlloc(m_hHeap, HEAP_NO_SERIALIZE, pChunk, newChunkSize)); @@ -938,20 +934,20 @@ inline POBJECT ObjectMemory::reallocChunk(POBJECT pChunk, MWORD newChunkSize) << m_pools[NumPools-1].getSize()<< L" by: " << PoolGranularity << L')' << std::endl << std::endl; - int pageWaste=0; - int totalPages=0; - int totalFreeBytes=0; - int totalChunks=0; - int totalFreeChunks=0; - for (int i=0;iheapSpace() == OTEFlags::PoolSpace) { - int size = ote->sizeOf(); - int chunkSize = _ROUND2(size, PoolGranularity); + size_t size = ote->sizeOf(); + size_t chunkSize = _ROUND2(size, PoolGranularity); objectWaste += chunkSize - size; } } } - int wastePercentage = (totalChunks - totalFreeChunks) == 0 + size_t wastePercentage = (totalChunks - totalFreeChunks) == 0 ? 0 - : int(double(objectWaste)/ + : size_t(double(objectWaste)/ double(totalChunks-totalFreeChunks)*100.0); TRACESTREAM<< L"===============================================" << std::endl; @@ -1013,10 +1009,10 @@ inline POBJECT ObjectMemory::reallocChunk(POBJECT pChunk, MWORD newChunkSize) _CrtMemCheckpoint(&CRTMemState); } - int ObjectMemory::FixedSizePool::getFree() + size_t ObjectMemory::FixedSizePool::getFree() { Link* pChunk = m_pFreeChunks; - int tally = 0; + size_t tally = 0; while (pChunk) { tally++; diff --git a/Core/DolphinVM/bytecde.cpp b/Core/DolphinVM/bytecde.cpp index 88bc85b814..c9387b5fc0 100755 --- a/Core/DolphinVM/bytecde.cpp +++ b/Core/DolphinVM/bytecde.cpp @@ -139,25 +139,24 @@ Oop* __fastcall Interpreter::primitiveReturnStaticZero(Oop* const sp, primargcou // performance of the system (as we've discovered). #pragma auto_inline(off) -extern "C" void __fastcall callPrimitiveValue(unsigned, unsigned numArgs); +extern "C" void __fastcall callPrimitiveValue(unsigned, argcount_t numArgs); #ifdef PROFILING - unsigned contextsCopied = 0; - unsigned blocksInstantiated = 0; - unsigned contextReturns = 0; - unsigned methodsActivated = 0; - unsigned contextsSuspended = 0; - unsigned methodsCPPActivated = 0; - unsigned contextCPPReturns = 0; - unsigned contextsCPPSuspended = 0; - unsigned byteCodeCount = 0; - //unsigned contextDepth = 0; + size_t contextsCopied = 0; + size_t blocksInstantiated = 0; + size_t contextReturns = 0; + size_t methodsActivated = 0; + size_t contextsSuspended = 0; + size_t methodsCPPActivated = 0; + size_t contextCPPReturns = 0; + size_t contextsCPPSuspended = 0; + size_t byteCodeCount = 0; #endif #ifdef _DEBUG #define MAXCACHEMISSES 100000 - uintptr_t cacheHits = 0; - static uintptr_t cacheMisses = 0; + size_t cacheHits = 0; + static size_t cacheMisses = 0; #endif @@ -166,7 +165,7 @@ extern "C" void __fastcall callPrimitiveValue(unsigned, unsigned numArgs); //============= /* -inline unsigned __fastcall Interpreter::cacheHash(Oop classPointer, Oop messageSelector) +inline size_t __fastcall Interpreter::cacheHash(Oop classPointer, Oop messageSelector) { // Bits of History paper on method cache recommends latter, but // the former is quicker in IST because of the use of real pointers @@ -246,7 +245,7 @@ bool Interpreter::IsUserBreakRequested() // so we don't want to early out just because one of the required keys has not // been pressed. - int hotkey = integerValueOf(Pointers.InterruptHotKey); + SmallInteger hotkey = integerValueOf(Pointers.InterruptHotKey); int vk = hotkey & 0x1FF; bool interrupt = (::GetAsyncKeyState(vk) & 0x8001) != 0; int modifiers = (hotkey >> 9); @@ -302,7 +301,7 @@ BOOL __stdcall Interpreter::MsgSendPoll() #pragma code_seg(INTERP_SEG) -Interpreter::MethodCacheEntry* __fastcall Interpreter::findNewMethodInClass(BehaviorOTE* classPointer, const unsigned argCount) +Interpreter::MethodCacheEntry* __fastcall Interpreter::findNewMethodInClass(BehaviorOTE* classPointer, const argcount_t argCount) { ASSERT(ObjectMemory::isBehavior(Oop(classPointer))); @@ -335,7 +334,7 @@ Interpreter::MethodCacheEntry* __fastcall Interpreter::findNewMethodInClass(Beha #pragma code_seg(INTERP_SEG) -Interpreter::MethodCacheEntry* __stdcall Interpreter::findNewMethodInClassNoCache(BehaviorOTE* classPointer, const unsigned argCount) +Interpreter::MethodCacheEntry* __stdcall Interpreter::findNewMethodInClassNoCache(BehaviorOTE* classPointer, const argcount_t argCount) { HARDASSERT(argCount < 256); @@ -421,7 +420,7 @@ Interpreter::MethodCacheEntry* __stdcall Interpreter::findNewMethodInClassNoCach #pragma code_seg(INTERP_SEG) // Translate args on stack to a message containing an array of arguments -void __fastcall Interpreter::createActualMessage(const unsigned argCount) +void __fastcall Interpreter::createActualMessage(const argcount_t argCount) { MessageOTE* messagePointer = Message::NewUninitialized(); Message* message = messagePointer->m_location; @@ -434,8 +433,8 @@ void __fastcall Interpreter::createActualMessage(const unsigned argCount) Oop* const sp = m_registers.m_stackPointer - argCount + 1; // Transfer the arguments off the stack to the array - const unsigned loopEnd = argCount; - for (unsigned i=0;im_block = reinterpret_cast(Pointers.Nil); // Nil out the old frame up to the required number of temps - const unsigned loopEnd = tempCount; - for (unsigned i=0;im_tempFrame[i] = nil; newContext->setSize(SizeOfPointers(FixedSize+tempCount)); @@ -533,7 +532,7 @@ ContextOTE* __fastcall Context::New(unsigned tempCount, Oop oopOuter) return newContext; } -BlockOTE* __fastcall BlockClosure::New(unsigned copiedValuesCount) +BlockOTE* __fastcall BlockClosure::New(size_t copiedValuesCount) { BlockOTE* newBlock; @@ -761,11 +760,11 @@ BlockOTE* __fastcall Interpreter::blockCopy(uint32_t ext) outerPointer->countUp(); } - const unsigned nValuesToCopy = extension.copiedValuesCount; + const auto nValuesToCopy = extension.copiedValuesCount; if (nValuesToCopy > 0) { Oop* sp = m_registers.m_stackPointer; - unsigned i=0; + auto i=0u; do { Oop copiedValue = *(sp--); @@ -803,7 +802,7 @@ MethodOTE* __fastcall Interpreter::lookupMethod(BehaviorOTE* classPointer, Symbo { ASSERT(ObjectMemory::isBehavior(Oop(classPointer))); - unsigned hashForCache = cacheHash(classPointer, targetSelector); + size_t hashForCache = cacheHash(classPointer, targetSelector); if (methodCache[hashForCache].classPointer == classPointer) { @@ -886,8 +885,8 @@ Oop* __fastcall Interpreter::primitiveLookupMethod(Oop* const sp, primargcount_t // If not then VM hash lookup logic won't work ASSERT(MethodDictionary::FixedSize == 2); - int used = 0; - for (int i=0;i 0); - unsigned i = m_nOTSize-1; + size_t i = m_nOTSize-1; const OTE* pOT = m_pOT; while (pOT[i].isFree()) { @@ -54,8 +54,8 @@ void ObjectMemory::compactObject(OTE* ote) if (ote->isPointers()) { VariantObject* varObj = static_cast(ote->m_location); - const MWORD lastPointer = ote->pointersSize(); - for (MWORD i = 0; i < lastPointer; i++) + const size_t lastPointer = ote->pointersSize(); + for (size_t i = 0; i < lastPointer; i++) { // This will get nicely optimised by the Compiler Oop fieldPointer = varObj->m_fields[i]; diff --git a/Core/DolphinVM/dealloc.cpp b/Core/DolphinVM/dealloc.cpp index 6835a6af50..6056614884 100644 --- a/Core/DolphinVM/dealloc.cpp +++ b/Core/DolphinVM/dealloc.cpp @@ -18,7 +18,7 @@ #include "STVirtualObject.h" #ifdef MEMSTATS - extern unsigned m_nLargeFreed; + extern size_t m_nLargeFreed; #endif #pragma code_seg(MEM_SEG) @@ -116,7 +116,7 @@ void ObjectMemory::deallocate(OTE* ote) case OTEFlags::PoolSpace: { - MWORD size = ote->sizeOf(); + size_t size = ote->sizeOf(); HARDASSERT(size <= MaxSmallObjectSize); freeSmallChunk(ote->m_location, size); releasePointer(ote); diff --git a/Core/DolphinVM/decode.cpp b/Core/DolphinVM/decode.cpp index dd146924b4..50c5b64806 100755 --- a/Core/DolphinVM/decode.cpp +++ b/Core/DolphinVM/decode.cpp @@ -46,7 +46,7 @@ static void printChars(wostream& stream, const char16_t* pwsz, size_t len) size_t end = min(len, 80); for (size_t i = 0; i < end; i++) { - char16_t ch = pwsz[i]; + wchar_t ch = pwsz[i]; if (!iswprint(ch)) { stream << L"\\x" << std::hex << (unsigned)ch; @@ -561,7 +561,7 @@ void DumpStackEntry(Oop* sp, Process* pProc, wostream& stream) // Formatted output void HexDump(tracestream out, LPCTSTR lpszLine, uint8_t* pby, - int nBytes, int nWidth) + size_t nBytes, size_t nWidth) // do a simple hex-dump (8 per line) to a tracestream // the "lpszLine" is a string to print at the start of each line // (%lx should be used to expand the current address) @@ -726,7 +726,7 @@ wostream& operator<<(wostream& stream, StackFrame *pFrame) CompiledMethod* method = oteMethod->m_location; SmallInteger ip = ObjectMemoryIntegerValueOf(pFrame->m_ip); if (ip != 0) - ip += isIntegerObject(method->m_byteCodes) ? 1 : -(int(ObjectByteSize) - 1); + ip += isIntegerObject(method->m_byteCodes) ? 1 : -(static_cast(ObjectByteSize) - 1); stream << L'{' << LPVOID(pFrame) // otherwise would be recursive! << L": cf " << LPVOID(pFrame->m_caller) @@ -748,8 +748,8 @@ wostream& operator<<(wostream& stream, StackFrame *pFrame) ctx = NULL; } - unsigned argc; - unsigned stackTempCount; + methodargcount_t argc; + stacktempcount_t stackTempCount; if (ctx != NULL && ctx->isBlockContext()) { stream << L"[] in "; @@ -789,16 +789,15 @@ wostream& operator<<(wostream& stream, StackFrame *pFrame) << '}' << std::endl; stream << L" receiver: " << reinterpret_cast(receiver) << std::endl; - unsigned i = 0; - for (i = 0; i < argc; i++) + for (auto i = 0u; i < argc; i++) stream << L" arg[" << std::dec << i << L"]: " << reinterpret_cast(*(bp + i)) << std::endl; - for (i = 0; i < stackTempCount; i++) + for (auto i = 0u; i < stackTempCount; i++) stream << L" stack temp[" << std::dec << i << L"]: " << reinterpret_cast(*(bp + i + argc)) << std::endl; if (ctx != NULL) { - const size_t envTempCount = oteContext->pointersSize() - Context::FixedSize; - for (i = 0; i < envTempCount; i++) + const auto envTempCount = oteContext->pointersSize() - Context::FixedSize; + for (auto i = 0u; i < envTempCount; i++) stream << L" env temp[" << std::dec << i << L"]: " << reinterpret_cast(ctx->m_tempFrame[i]) << std::endl; } @@ -891,7 +890,7 @@ void Interpreter::DumpContext(wostream& logStream) ///////////////////////////////////////////////////////////////////////////// -void Interpreter::DumpStack(wostream& logStream, unsigned nStackDepth) +void Interpreter::DumpStack(wostream& logStream, size_t nStackDepth) { if (nStackDepth == 0) return; @@ -907,7 +906,7 @@ void Interpreter::DumpStack(wostream& logStream, unsigned nStackDepth) } } -void Interpreter::StackTraceOn(wostream& dc, StackFrame* pFrame, unsigned depth) +void Interpreter::StackTraceOn(wostream& dc, StackFrame* pFrame, size_t depth) { if (!pFrame) pFrame = m_registers.m_pActiveFrame; @@ -1090,11 +1089,11 @@ void Interpreter::decodeMethod(CompiledMethod* method, wostream* pstream) STMethodHeader hdr = method->m_header; stream << L"Method " << method; if (hdr.primitiveIndex > 7) - stream << L", primitive=" << std::dec << int(hdr.primitiveIndex); + stream << L", primitive=" << std::dec << static_cast(hdr.primitiveIndex); if (hdr.argumentCount > 0) - stream << L"; args=" << std::dec << int(hdr.argumentCount); + stream << L"; args=" << std::dec << static_cast(hdr.argumentCount); if (hdr.stackTempCount > 0) - stream << L"; stack temps=" << std::dec << int(hdr.stackTempCount); + stream << L"; stack temps=" << std::dec << static_cast(hdr.stackTempCount); int envTemps = hdr.envTempCount; if (envTemps > 0) { @@ -1118,10 +1117,10 @@ void Interpreter::decodeMethod(CompiledMethod* method, wostream* pstream) } } -void Interpreter::decodeMethodAt(CompiledMethod* method, unsigned ip, wostream& stream) +void Interpreter::decodeMethodAt(CompiledMethod* method, size_t ip, wostream& stream) { DisassemblyContext info(method); - BytecodeDisassembler disassembler(info); + BytecodeDisassembler disassembler(info); disassembler.DisassembleAt(ip, stream); stream.flush(); } @@ -1147,7 +1146,7 @@ void DumpObject(const POTE pote) // interpreter void Interpreter::checkStack(Oop* sp) { - /* for (unsigned i=1;i<=50;i++) + /* for (auto i=1;i<=50;i++) { Oop objectPointer = sp[i]; if (!ObjectMemoryIsIntegerObject(objectPointer) && @@ -1186,9 +1185,6 @@ void __fastcall Interpreter::debugMethodActivated(Oop* sp) void __fastcall Interpreter::debugExecTrace(uint8_t* ip, Oop* sp) { - //for (unsigned i=0;im_byteCodes)); + ptrdiff_t ipIndex = ip - ObjectMemory::ByteAddressOfObjectContents(method->m_byteCodes); HARDASSERT(ipIndex >= 0 && ipIndex < 1024); - //for (i=0;i(oteMethod->m_location)); } -extern "C" unsigned byteCodeCounters[]; -extern "C" unsigned byteCodePairs[]; +extern "C" size_t byteCodeCounters[]; +extern "C" size_t byteCodePairs[]; void DumpBytecodeCounts(bool bClear) { TRACESTREAM << std::endl << L"Bytecode invocation counts" << std::endl << L"-----------------------------" << std::endl; - for (int i = 0; i < 256; i++) + for (auto i = 0; i < 256; i++) { TRACESTREAM << std::dec << i << L": " << byteCodeCounters[i] << std::endl; if (bClear) byteCodeCounters[i] = 0; @@ -1266,9 +1260,9 @@ void DumpBytecodeCounts(bool bClear) TRACESTREAM << L"-----------------------------" << std::endl << std::endl; TRACESTREAM << std::endl << L"Bytecode pair counts" << std::endl << L"-----------------------------" << std::endl; - for (int i = 0; i < 256; i++) + for (auto i = 0; i < 256; i++) { - for (int j = 0; j < 256; j++) + for (auto j = 0; j < 256; j++) { TRACESTREAM << byteCodePairs[i * 256 + j] << L' '; if (bClear) byteCodePairs[i * 256 + j] = 0; @@ -1279,12 +1273,12 @@ void DumpBytecodeCounts(bool bClear) } -extern "C" unsigned primitiveCounters[]; +extern "C" size_t primitiveCounters[]; void DumpPrimitiveCounts(bool bClear) { TRACESTREAM << std::endl << L"Primitive invocation counts" << std::endl << L"-----------------------------" << std::endl; - for (int i = 0; i <= PRIMITIVE_MAX; i++) + for (auto i = 0; i <= PRIMITIVE_MAX; i++) { TRACESTREAM << std::dec << i << L": " << primitiveCounters[i] << std::endl; if (bClear) primitiveCounters[i] = 0; diff --git a/Core/DolphinVM/environ.h b/Core/DolphinVM/environ.h index d123a436e4..2aeebee8a4 100644 --- a/Core/DolphinVM/environ.h +++ b/Core/DolphinVM/environ.h @@ -120,8 +120,8 @@ #define HARDASSERT(e) ((void)0) #endif - enum { dwPageSize = 0x1000 }; // 4Kb - enum { dwAllocationGranularity = 0x10000 }; // 64Kb + constexpr size_t dwPageSize = 0x1000; // 4Kb + constexpr size_t dwAllocationGranularity = 0x10000; // 64Kb #else #error "Not implemented for other platforms yet" diff --git a/Core/DolphinVM/extcall.cpp b/Core/DolphinVM/extcall.cpp index ccea6e8d12..f0e41fcfaf 100644 --- a/Core/DolphinVM/extcall.cpp +++ b/Core/DolphinVM/extcall.cpp @@ -36,7 +36,7 @@ using namespace DolphinX; #include "STBlockClosure.h" static AnsiStringOTE* (__fastcall *ForceNonInlineNewByteStringFromUtf16)(LPCWSTR) = &AnsiString::New; -static AnsiStringOTE* (__fastcall *ForceNonInlineNewByteStringWithLen)(const char * __restrict, MWORD) = &AnsiString::New; +static AnsiStringOTE* (__fastcall *ForceNonInlineNewByteStringWithLen)(const char * __restrict, size_t) = &AnsiString::New; /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// @@ -76,7 +76,7 @@ OTE* __fastcall ExternalStructure::NewPointer(BehaviorOTE* classPointer, void* p } else { - int nSize = behavior.extraSpec(); + size_t nSize = behavior.extraSpec(); BytesOTE* oteBytes = ObjectMemory::newByteObject(classPointer, nSize, ptr); resultPointer = reinterpret_cast(oteBytes); } @@ -95,7 +95,7 @@ OTE* __fastcall ExternalStructure::New(BehaviorOTE* classPointer, void* ptr) OTE* resultPointer; Behavior& behavior = *classPointer->m_location; BytesOTE* bytesPointer; - unsigned size = behavior.extraSpec(); + auto size = behavior.extraSpec(); if (behavior.isPointers()) { StructureOTE* otePointers = reinterpret_cast(ObjectMemory::newPointerObject(classPointer)); @@ -217,12 +217,12 @@ BytesOTE* __fastcall NewGUID(GUID* rguid) /////////////////////////////////////////////////////////////////////////////// // -unsigned Interpreter::pushArgsAt(const ExternalDescriptor* descriptor, uint8_t* lpParms) +argcount_t Interpreter::pushArgsAt(const ExternalDescriptor* descriptor, uint8_t* lpParms) { DescriptorOTE* oteTypes = descriptor->m_descriptor; const DescriptorBytes* types = oteTypes->m_location; - const unsigned argsLen = types->argsLen(oteTypes); - unsigned i=0; + const auto argsLen = types->argsLen(oteTypes); + auto i=0u; while (im_args[i++]; @@ -232,7 +232,7 @@ unsigned Interpreter::pushArgsAt(const ExternalDescriptor* descriptor, uint8_t* case ExtCallArgType::Void: // Not a valid argument HARDASSERT(FALSE); pushNil(); - lpParms += sizeof(MWORD); + lpParms += sizeof(uintptr_t); break; case ExtCallArgType::LPVoid: @@ -241,50 +241,50 @@ unsigned Interpreter::pushArgsAt(const ExternalDescriptor* descriptor, uint8_t* break; case ExtCallArgType::Char: - pushObject((OTE*)Character::NewUnicode(*reinterpret_cast(lpParms))); - lpParms += sizeof(MWORD); + pushObject((OTE*)Character::NewUnicode(*reinterpret_cast(lpParms))); + lpParms += sizeof(uintptr_t); break; case ExtCallArgType::UInt8: pushSmallInteger(*lpParms); - lpParms += sizeof(MWORD); + lpParms += sizeof(uintptr_t); break; case ExtCallArgType::Int8: pushSmallInteger(*reinterpret_cast(lpParms)); - lpParms += sizeof(MWORD); + lpParms += sizeof(uintptr_t); break; case ExtCallArgType::UInt16: pushSmallInteger(*reinterpret_cast(lpParms)); - lpParms += sizeof(MWORD); + lpParms += sizeof(uintptr_t); break; case ExtCallArgType::Int16: pushSmallInteger(*reinterpret_cast(lpParms)); - lpParms += sizeof(MWORD); + lpParms += sizeof(uintptr_t); break; case ExtCallArgType::UInt32: pushUint32(*reinterpret_cast(lpParms)); - lpParms += sizeof(uint32_t); + lpParms += sizeof(uintptr_t); break; case ExtCallArgType::Int32: case ExtCallArgType::HResult: case ExtCallArgType::NTStatus: pushInt32(*reinterpret_cast(lpParms)); - lpParms += sizeof(int32_t); + lpParms += sizeof(uintptr_t); break; case ExtCallArgType::Bool: pushBool(*reinterpret_cast(lpParms)); - lpParms += sizeof(MWORD); + lpParms += sizeof(uintptr_t); break; case ExtCallArgType::Handle: pushHandle(*reinterpret_cast(lpParms)); - lpParms += sizeof(HANDLE); + lpParms += sizeof(uintptr_t); break; case ExtCallArgType::Double: @@ -295,19 +295,19 @@ unsigned Interpreter::pushArgsAt(const ExternalDescriptor* descriptor, uint8_t* case ExtCallArgType::LPStr: push(*reinterpret_cast(lpParms)); - lpParms += sizeof(LPCSTR); + lpParms += sizeof(uintptr_t); break; case ExtCallArgType::Oop: case ExtCallArgType::Ote: push(*reinterpret_cast(lpParms)); - lpParms += sizeof(Oop); + lpParms += sizeof(uintptr_t); break; case ExtCallArgType::Float: push(static_cast(*reinterpret_cast(lpParms))); - // Yup, even doubles passed on main stack - lpParms += sizeof(FLOAT); + // Yup, even floats passed on main stack + lpParms += sizeof(uintptr_t); break; case ExtCallArgType::LPPVoid: @@ -348,7 +348,7 @@ unsigned Interpreter::pushArgsAt(const ExternalDescriptor* descriptor, uint8_t* case ExtCallArgType::VarBool: pushBool(*reinterpret_cast(lpParms)); - lpParms += sizeof(MWORD); // Note passes as 32-bit + lpParms += sizeof(uintptr_t); break; case ExtCallArgType::Guid: @@ -380,7 +380,7 @@ unsigned Interpreter::pushArgsAt(const ExternalDescriptor* descriptor, uint8_t* arg = types->m_args[i++]; BehaviorOTE* behaviorPointer = reinterpret_cast(descriptor->m_literals[arg]); pushNewObject(ExternalStructure::New(behaviorPointer, lpParms)); - lpParms += 4; + lpParms += sizeof(uintptr_t); } break; @@ -468,7 +468,7 @@ Oop* __fastcall Interpreter::primitivePerformWithArgsAt(Oop* const sp, primargco // Pop the descriptor and address and the selector m_registers.m_stackPointer = sp - 3; - unsigned argCount; + argcount_t argCount; // NEW FORMAT ExternalDescriptor* descriptor = static_cast(descriptorPointer->m_location); argCount = pushArgsAt(descriptor, lpParms); @@ -506,11 +506,11 @@ Oop* __fastcall Interpreter::primitiveValueWithArgsAt(Oop* const sp, primargcoun BlockOTE* oteBlock = reinterpret_cast(*(sp-2)); HARDASSERT(ObjectMemory::fetchClassOf(Oop(oteBlock)) == Pointers.ClassBlockClosure); BlockClosure* block = oteBlock->m_location; - const MWORD blockArgumentCount = block->m_info.argumentCount; + const auto blockArgumentCount = block->m_info.argumentCount; const ExternalDescriptor* descriptor = static_cast(descriptorPointer->m_location); const DescriptorBytes* types = static_cast(descriptor->m_descriptor->m_location); - const unsigned argCount = types->m_argumentCount; + const auto argCount = types->m_argumentCount; if (argCount != blockArgumentCount) return primitiveFailure(_PrimitiveFailureCode::WrongNumberOfArgs); @@ -531,19 +531,19 @@ Oop* __fastcall Interpreter::primitiveValueWithArgsAt(Oop* const sp, primargcoun Oop* localSp = m_registers.m_stackPointer + 1; - const unsigned copiedValues = block->copiedValuesCount(oteBlock); + const auto copiedValues = block->copiedValuesCount(oteBlock); { - for (unsigned i=0;im_copiedValues[i]; *localSp++ = oopCopied; } } - const unsigned extraTemps = block->stackTempsCount(); + const auto extraTemps = block->stackTempsCount(); { const Oop nilPointer = Oop(Pointers.Nil); - for (unsigned i=0;im_method = block->m_method; // Note that ref. count remains the same due to overwritten receiver slot - const unsigned envTemps = block->envTempsCount(); + const auto envTemps = block->envTempsCount(); if (envTemps > 0) { ContextOTE* oteContext = Context::New(envTemps, reinterpret_cast(block->m_outer)); @@ -664,7 +664,7 @@ void doBlah() /////////////////////////////////////////////////////////////////////////////// #ifndef _M_IX86 - extern "C" BOOL __stdcall callExternalFunction(FARPROC pProc, unsigned argCount, uint8_t* argTypes, BOOL isVirtual); + extern "C" BOOL __stdcall callExternalFunction(FARPROC pProc, argcount_t argCount, uint8_t* argTypes, BOOL isVirtual); BOOL __fastcall Interpreter::primitiveVirtualCall(Oop* const sp, primargcount_t argCount) { @@ -752,10 +752,10 @@ void doBlah() FARPROC pLibProc = *reinterpret_cast(argTypes.m_elements); if (!pLibProc) { - unsigned procNameOffset = argCount+ExtCallArgStart; + size_t procNameOffset = argCount+ExtCallArgStart; #ifdef _DEBUG // Compiler should have ensured number of arg types = argumentCount - unsigned argsLength = ObjectMemory::fetchByteLengthOf(arrayPointer); + size_t argsLength = ObjectMemory::fetchByteLengthOf(arrayPointer); ASSERT(argsLength > procNameOffset); // Compiler allocates space for a null terminator ASSERT(argTypes.m_elements[argsLength-1] == 0); @@ -787,7 +787,7 @@ void doBlah() } // Returns true/false for success/failure. Also sets the failure code. - BOOL __stdcall Interpreter::callExternalFunction(FARPROC pProc, unsigned argCount, uint8_t* argTypes, BOOL isVirtual) + BOOL __stdcall Interpreter::callExternalFunction(FARPROC pProc, argcount_t argCount, uint8_t* argTypes, BOOL isVirtual) { Oop arg; uintptr_t retValue; @@ -798,17 +798,17 @@ void doBlah() // Compiler optimises out unless we pretend its volatile StackFrame volatile* pCallingFrame = (StackFrame volatile*)m_pActiveFrame; - unsigned savedSP; + uintptr_t savedSP; _asm { mov eax, esp mov DWORD PTR[savedSP], eax } - int pushCount = argCount + isVirtual - 1; + size_t pushCount = argCount + isVirtual - 1; Oop* stackPointer = m_stackPointer - pushCount; // Push args from Smalltalk stack onto machine stack - for (int i = pushCount;i >= 0;i--) + for (auto i = pushCount;i >= 0;i--) { arg = stackPointer[i]; switch (argTypes[ExtCallArgStart+i]) @@ -1147,10 +1147,10 @@ void doBlah() if (stackPointer != m_stackPointer) { TRACE("primitiveDLL32Call WARNING: before call SP %p, after call SP %p\n\r", stackPointer, m_stackPointer); - const int extra = m_stackPointer - stackPointer; + const ptrdiff_t extra = m_stackPointer - stackPointer; if (extra > 0) { - for (int i=0;im_hospiceHighWater)); + Interpreter::queueForFinalization(ote, (SmallUinteger)integerValueOf(memMan->m_hospiceHighWater)); } void Interpreter::scheduleFinalization() @@ -80,9 +80,9 @@ void Interpreter::scheduleFinalization() } MemoryManager* memMan = ObjectMemory::memoryManager(); - unsigned count = m_qForFinalize.Count(); + size_t count = m_qForFinalize.Count(); // Raise interrupt when at or above high water mark - if (count >= (unsigned)integerValueOf(memMan->m_hospiceHighWater)) + if (count >= (SmallUinteger)integerValueOf(memMan->m_hospiceHighWater)) queueInterrupt(VMI_HOSPICECRISIS, integerObjectOf(count)); } @@ -102,7 +102,7 @@ OTE* Interpreter::dequeueBereaved(VariantObject* out) answer = Pointers.False; else { - for (unsigned i = 0; i < OopsPerBereavementQEntry; i++) + for (auto i = 0u; i < OopsPerBereavementQEntry; i++) { ObjectMemory::countDown(out->m_fields[i]); out->m_fields[i] = m_qBereavements.Pop(); diff --git a/Core/DolphinVM/flotprim.cpp b/Core/DolphinVM/flotprim.cpp index 8315982708..289825c6ed 100644 --- a/Core/DolphinVM/flotprim.cpp +++ b/Core/DolphinVM/flotprim.cpp @@ -118,7 +118,7 @@ Oop* __fastcall Interpreter::primitiveLongDoubleAt(Oop* const sp, primargcount_t return primitiveFailure(_PrimitiveFailureCode::InvalidParameter1); // Index not an integer } - SmallUinteger offset = ObjectMemoryIntegerValueOf(integerPointer); + SmallInteger offset = ObjectMemoryIntegerValueOf(integerPointer); OTE* receiver = reinterpret_cast(*(sp-1)); ASSERT(!ObjectMemoryIsIntegerObject(receiver)); @@ -138,7 +138,7 @@ Oop* __fastcall Interpreter::primitiveLongDoubleAt(Oop* const sp, primargcount_t BytesOTE* oteBytes = reinterpret_cast(receiver); // We can check that the offset is in bounds - if (static_cast(offset) < 0 || offset+sizeof(double) > oteBytes->bytesSize()) + if (offset < 0 || static_cast(offset)+sizeof(double) > oteBytes->bytesSize()) return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); // Out of bounds VariantByteObject* bytes = oteBytes->m_location; diff --git a/Core/DolphinVM/interfac.cpp b/Core/DolphinVM/interfac.cpp index 2bb7e6674a..c182102f6d 100644 --- a/Core/DolphinVM/interfac.cpp +++ b/Core/DolphinVM/interfac.cpp @@ -37,8 +37,6 @@ static Oop currentCallbackContext = ZeroPointer; #define NUMVTBLENTRIES 1024 -typedef int (__stdcall *FP)(); - #pragma pack(push, 1) struct VTblThunk @@ -71,7 +69,7 @@ inline void __fastcall Interpreter::returnValueTo(Oop resultPointer, Oop context } // Private - common part of perform callback routines -Oop __stdcall Interpreter::callback(SymbolOTE* selector, unsigned argCount TRACEPARM) /* throws SE_VMCALLBACKUNWIND */ +Oop __stdcall Interpreter::callback(SymbolOTE* selector, argcount_t argCount TRACEPARM) /* throws SE_VMCALLBACKUNWIND */ { //CHECKREFERENCES @@ -92,7 +90,7 @@ Oop __stdcall Interpreter::callback(SymbolOTE* selector, unsigned argCount TRACE savedContext.m_stackPointer = m_registers.m_stackPointer-argCount; int lastTrace=executionTrace; - if (traceFlag==TRACEFLAG::TraceOff && unsigned(executionTrace) < 2) + if (traceFlag==TRACEFLAG::TraceOff && static_cast(executionTrace) < 2) executionTrace=0; #endif @@ -277,13 +275,13 @@ inline Semaphore* Interpreter::pendingCallbacks() return pendingCallbacksPointer()->m_location; } -unsigned Interpreter::countPendingCallbacks() +size_t Interpreter::countPendingCallbacks() { const Semaphore* pendingReturns = pendingCallbacks(); const ProcessOTE* nil = reinterpret_cast(Pointers.Nil); const ProcessOTE* oteLink = pendingReturns->m_firstLink; - unsigned count = 0; + size_t count = 0; while (oteLink != nil) { @@ -424,7 +422,7 @@ SymbolOTE* __stdcall Interpreter::NewSymbol(const char* name) /* throws SE_VMCAL void Interpreter::MarkRoots() { - unsigned i=0; + size_t i=0; while (m_roots[i]) { ObjectMemory::MarkObjectsAccessibleFromRoot(*m_roots[i]); @@ -444,7 +442,7 @@ void Interpreter::OnCompact() m_qAsyncSignals.onCompact(); m_qInterrupts.onCompact(); - unsigned i=0; + size_t i=0; while (m_roots[i]) { ObjectMemory::compactOop(*m_roots[i]); @@ -845,7 +843,7 @@ uintptr_t __fastcall Interpreter::VirtualCallbackMain(SmallInteger offset, COMTh #ifndef _M_X64 -__declspec(naked) int __stdcall _commonVfnEntryPoint() +__declspec(naked) intptr_t __stdcall _commonVfnEntryPoint() { _asm { @@ -878,7 +876,7 @@ void InitializeVtbl() return; } - for (unsigned i=0;i(i); CPINFOEX cpInfo; @@ -263,7 +262,7 @@ HRESULT Interpreter::initializeCharMaps() return E_OUTOFMEMORY; } - unsigned i = 0; + auto i = 0u; for (; i < 0xd800; i++) wideChars[i] = static_cast(i); for (; i <= 0xdfff; i++) @@ -332,10 +331,10 @@ inline void Interpreter::initializeCaches() #ifdef _DEBUG #pragma code_seg(DEBUG_SEG) -static MWORD ResizeProcInContext(InterpreterRegisters& reg) +static size_t ResizeProcInContext(InterpreterRegisters& reg) { ProcessOTE* oteProc = reg.m_oteActiveProcess; - MWORD size = oteProc->getSize(); + size_t size = oteProc->getSize(); reg.ResizeProcess(); if (size != oteProc->getSize() && Interpreter::executionTrace) { @@ -357,11 +356,11 @@ void Interpreter::checkReferences(Oop* const sp) void Interpreter::checkReferences(InterpreterRegisters& reg) { HARDASSERT(ObjectMemory::isKindOf(m_registers.m_oteActiveProcess, Pointers.ClassProcess)); - MWORD oldProcSize = ResizeProcInContext(reg); + size_t oldProcSize = ResizeProcInContext(reg); if (reg.m_pActiveProcess != m_registers.m_pActiveProcess) { // Resize active process as well as the one in the context passed - MWORD oldActiveProcSize = ResizeProcInContext(m_registers); + size_t oldActiveProcSize = ResizeProcInContext(m_registers); ObjectMemory::checkReferences(); m_registers.m_oteActiveProcess->setSize(oldActiveProcSize); } @@ -446,8 +445,8 @@ bool Interpreter::saveContextAfterFault(LPEXCEPTION_POINTERS info) uint8_t* ip = reinterpret_cast(info->ContextRecord->Edi); Oop byteCodes = m_registers.m_pMethod->m_byteCodes; uint8_t* pBytes = ObjectMemory::ByteAddressOfObjectContents(byteCodes); - int numByteCodes = ObjectMemoryIsIntegerObject(byteCodes) ? - sizeof(MWORD) : reinterpret_cast(byteCodes)->bytesSize(); + size_t numByteCodes = ObjectMemoryIsIntegerObject(byteCodes) ? + sizeof(Oop) : reinterpret_cast(byteCodes)->bytesSize(); if (ip >= pBytes && ip < pBytes + numByteCodes) { m_registers.m_instructionPointer = ip; @@ -463,7 +462,7 @@ bool Interpreter::saveContextAfterFault(LPEXCEPTION_POINTERS info) { VirtualObject* pVObj = reinterpret_cast(pProc); VirtualObjectHeader* pBase = pVObj->getHeader(); - unsigned cbCurrent = pBase->getCurrentAllocation(); + size_t cbCurrent = pBase->getCurrentAllocation(); if (sp < reinterpret_cast(reinterpret_cast(pBase) + cbCurrent)) m_registers.m_stackPointer = sp; } diff --git a/Core/DolphinVM/ist.h b/Core/DolphinVM/ist.h index 02e5797387..c7c140e75d 100755 --- a/Core/DolphinVM/ist.h +++ b/Core/DolphinVM/ist.h @@ -82,17 +82,9 @@ typedef _Return_type_success_(return >= 0) int32_t NTSTATUS; #include "Environ.h" // The basic word size of the machine -typedef uintptr_t MWORD; typedef intptr_t SmallInteger; // Optimized SmallInteger; same size as machine word. Known to be representable as a Smalltalk SmallInteger (i.e. 31-bits 2's complement) typedef uintptr_t SmallUinteger; // Unsigned optimized SmallInteger; same size as machine word -typedef MWORD Oop; - -typedef _Return_type_success_(return >= 0) int32_t NTSTATUS; - -// Define this is using a 16-bit word -// as it conditionally compiles in MethodHeaderExtension which -// can otherwise be held in the MethodHeader itself -#define MWORDBITS (sizeof(uintptr_t)*8) // Number of bits in a machine word +typedef uintptr_t Oop; class ObjectMemory; class Interpreter; diff --git a/Core/DolphinVM/largeintprim.cpp b/Core/DolphinVM/largeintprim.cpp index 47bdbae59b..72711094a8 100644 --- a/Core/DolphinVM/largeintprim.cpp +++ b/Core/DolphinVM/largeintprim.cpp @@ -83,7 +83,7 @@ LargeIntegerOTE* __fastcall LargeInteger::liNewSigned32(int32_t value) return oteR; } -inline LargeIntegerOTE* LargeInteger::NewWithLimbs(MWORD limbs) +inline LargeIntegerOTE* LargeInteger::NewWithLimbs(size_t limbs) { return reinterpret_cast(ObjectMemory::newByteObject(Pointers.ClassLargeInteger, limbs*sizeof(uint32_t))); } @@ -122,7 +122,7 @@ Oop __stdcall Integer::NewUnsigned64(uint64_t ullValue) // Need up to 96 bits to represent full range of 64-bit positive numbers as // 2's complement - const unsigned nDigits = static_cast(highPart) < 0 ? 3 : 2; + const auto nDigits = static_cast(highPart) < 0 ? 3 : 2; LargeIntegerOTE* oteLarge = LargeInteger::NewWithLimbs(nDigits); LargeInteger* large = oteLarge->m_location; large->m_digits[0] = lowPart; @@ -181,8 +181,8 @@ Oop __fastcall LargeInteger::Normalize(LargeIntegerOTE* oteLI) { LargeInteger* li = oteLI->m_location; - MWORD size = oteLI->getWordSize(); - MWORD last = size - 1; + size_t size = oteLI->getWordSize(); + size_t last = size - 1; int32_t highPart = static_cast(li->m_digits[last]); if (last) // If more than one digit, attempt to remove any which are redundant { @@ -259,14 +259,14 @@ LargeIntegerOTE* __stdcall liLeftShift(LargeIntegerOTE* oteLI, unsigned shift) // Assume there'll be a carry out of the high digit (or that it won't // be the same sign if we don't add a digit). Could do this // in a more sophisticated way and avoid the shrink - int size = oteLI->getWordSize(); - const int resultSize = size + words + 1; + const size_t size = oteLI->getWordSize(); + const auto resultSize = size + words + 1; LargeIntegerOTE* oteResult = LargeInteger::NewWithLimbs(resultSize); LargeInteger* liResult = oteResult->m_location; int32_t carry = 0; // Initial carry is 0 - for (int i=0;im_digits[i]; int64_t accum = (digit << bits) | carry; @@ -302,9 +302,9 @@ Oop __stdcall liRightShift(LargeIntegerOTE* oteLI, unsigned shift) LargeInteger* li = oteLI->m_location; - const int size = oteLI->getWordSize(); + const size_t size = oteLI->getWordSize(); ASSERT(size > 0); - const int resultSize = size - words; + const ptrdiff_t resultSize = static_cast(size) - words; if (resultSize <= 0) // All bits lost. As this is an arithmetic (signed) shift, answer the sign "bit" return ObjectMemoryIntegerObjectOf(signBitOf(static_cast(li->m_digits[size - 1]))); @@ -332,10 +332,10 @@ Oop __stdcall liRightShift(LargeIntegerOTE* oteLI, unsigned shift) liResult->m_digits[resultSize-1] = static_cast(digit) >> bits; // The carry will be at most 31 bits uint32_t carry; - for (int i=resultSize-2;i>=0;i--) + for (auto i=resultSize-2;i>=0;i--) { carry = digit << carryShift; - const int j = i+words; + const auto j = i+words; ASSERT(j >= 0 && j < size); digit = li->m_digits[j]; liResult->m_digits[i] = (digit >> bits) | carry; @@ -358,10 +358,10 @@ static LargeIntegerOTE* __stdcall liNegatePriv(const LargeIntegerOTE* oteLI) { uint32_t* digits = oteLI->m_location->m_digits; - const MWORD size = oteLI->getWordSize(); + const size_t size = oteLI->getWordSize(); int32_t highDigit = static_cast(digits[size-1]); - MWORD negatedSize = size; + size_t negatedSize = size; // Handle boundary conditions to avoid the need to allocate extra digits and/or // normalize the result. Because the range of positive/negative 2's complement @@ -376,7 +376,7 @@ static LargeIntegerOTE* __stdcall liNegatePriv(const LargeIntegerOTE* oteLI) uint32_t* negated = oteNegated->m_location->m_digits; uint8_t carry = 1; - for (MWORD i=0;im_location; - const int size = oteLI->getWordSize(); + const auto size = oteLI->getWordSize(); if (size == 1 && static_cast(li->m_digits[0]) == 0x40000000) { // Can reduce this large positive integer to negative SmallInteger (boundary case) @@ -430,7 +430,7 @@ LargeIntegerOTE* LargeInteger::Add(const LargeIntegerOTE* oteLI, const SmallInte ASSERT(operand != 0); const uint32_t* const digits = oteLI->m_location->m_digits; - const MWORD numLimbs = oteLI->getWordSize(); + const size_t numLimbs = oteLI->getWordSize(); ASSERT(numLimbs > 0); LargeIntegerOTE* const oteSum = LargeInteger::NewWithLimbs(numLimbs); @@ -438,7 +438,7 @@ LargeIntegerOTE* LargeInteger::Add(const LargeIntegerOTE* oteLI, const SmallInte uint8_t carry = _addcarry_u32(0, digits[0], operand, sumDigits); const int32_t operandSign = operand >> 31; - for (MWORD i = 1; i < numLimbs; i++) + for (size_t i = 1; i < numLimbs; i++) { carry = _addcarry_u32(carry, digits[i], operandSign, sumDigits + i); } @@ -467,8 +467,8 @@ LargeIntegerOTE* LargeInteger::Add(const LargeIntegerOTE* oteLI, const SmallInte LargeIntegerOTE* LargeInteger::Add(const LargeIntegerOTE* oteOp1, const LargeIntegerOTE* oteOp2) { - MWORD size1 = oteOp1->getWordSize(); - MWORD size2 = oteOp2->getWordSize(); + size_t size1 = oteOp1->getWordSize(); + size_t size2 = oteOp2->getWordSize(); const uint32_t *digits1; const uint32_t *digits2; @@ -493,7 +493,7 @@ LargeIntegerOTE* LargeInteger::Add(const LargeIntegerOTE* oteOp1, const LargeInt uint32_t* sumDigits = oteSum->m_location->m_digits; uint8_t carry = _addcarry_u32(0, digits1[0], digits2[0], sumDigits); - MWORD i; + size_t i; // add up the least significant limbs up to the most-significant limb of the addend (the receiver is at least as large) for (i = 1; i < size2; i++) { @@ -533,16 +533,16 @@ LargeIntegerOTE* LargeInteger::Add(const LargeIntegerOTE* oteOp1, const LargeInt LargeIntegerOTE* LargeInteger::Sub(const LargeIntegerOTE* oteLI, SmallInteger operand) { const uint32_t* const digits = oteLI->m_location->m_digits; - const MWORD differenceSize = oteLI->getWordSize(); + const size_t differenceSize = oteLI->getWordSize(); LargeIntegerOTE* oteDifference = LargeInteger::NewWithLimbs(differenceSize); uint32_t* difference = oteDifference->m_location->m_digits; - const MWORD last = differenceSize - 1; + const size_t last = differenceSize - 1; // The initial "borrow" is the argument int32_t carry = operand * -1; - for (MWORD i = 0; i < last; i++) + for (size_t i = 0; i < last; i++) { // Must cast at least one operand to 64-bits so that 64-bit subtraction performed int64_t accum = static_cast(digits[i]) + carry; @@ -576,10 +576,10 @@ LargeIntegerOTE* LargeInteger::Sub(const LargeIntegerOTE* oteLI, const LargeInte const uint32_t* digits1 = oteLI->m_location->m_digits; const uint32_t* digits2 = oteOperand->m_location->m_digits; - const MWORD size = oteLI->getWordSize(); - const MWORD operandSize = oteOperand->getWordSize(); + const size_t size = oteLI->getWordSize(); + const size_t operandSize = oteOperand->getWordSize(); - MWORD differenceSize; + size_t differenceSize; if (size > operandSize) { differenceSize = size; @@ -594,7 +594,7 @@ LargeIntegerOTE* LargeInteger::Sub(const LargeIntegerOTE* oteLI, const LargeInte int32_t carry = 0; - for (MWORD i = 0; i < differenceSize; i++) + for (size_t i = 0; i < differenceSize; i++) { TODO("Unroll this loop to avoid conditionals in loop") // Compiler unable to optimize size() calls out @@ -636,17 +636,17 @@ Oop LargeInteger::Mul(const LargeIntegerOTE* oteInner, SmallInteger outerDigit) ASSERT(outerDigit != 0); const uint32_t* inner = oteInner->m_location->m_digits; - MWORD innerSize = oteInner->getWordSize(); + size_t innerSize = oteInner->getWordSize(); // Can optimize case where multiplying by zero ASSERT(innerSize > 0 || inner[0] != 0); - const MWORD productSize = innerSize + 1; + const size_t productSize = innerSize + 1; LargeIntegerOTE* oteProduct = LargeInteger::NewWithLimbs(productSize); uint32_t* product = oteProduct->m_location->m_digits; int32_t carry = 0; - for (MWORD i = 0; i < innerSize - 1; i++) + for (size_t i = 0; i < innerSize - 1; i++) { // This operations requires a 64-bit multiply because positive 32-bit int // might need 64-bit 2's complement bits to represent it @@ -668,19 +668,19 @@ Oop LargeInteger::Mul(const LargeIntegerOTE* oteInner, SmallInteger outerDigit) // LargeInteger::Mul - Multiply one LargeInteger by another // Private - Answer the result of multiplying the receiver by the argument, anInteger // -Oop LargeInteger::Mul(const LargeInteger* liOuter, const MWORD outerSize, const LargeInteger* liInner, const MWORD innerSize) +Oop LargeInteger::Mul(const LargeInteger* liOuter, const size_t outerSize, const LargeInteger* liInner, const size_t innerSize) { // Can optimize case where multiplying by zero ASSERT(innerSize > 0 || liInner->m_digits[0] != 0); - const MWORD productSize = innerSize + outerSize; + const size_t productSize = innerSize + outerSize; LargeIntegerOTE* productPointer = LargeInteger::NewWithLimbs(productSize); LargeInteger* product = productPointer->m_location; uint8_t* prodBytes = reinterpret_cast(product->m_digits); - const MWORD innerByteSize = innerSize << 2; - const MWORD outerByteSize = outerSize << 2; - const MWORD productByteSize = productSize << 2; + const size_t innerByteSize = innerSize << 2; + const size_t outerByteSize = outerSize << 2; + const size_t productByteSize = productSize << 2; ASSERT(outerByteSize > 3); ASSERT(innerByteSize > 3); @@ -688,15 +688,15 @@ Oop LargeInteger::Mul(const LargeInteger* liOuter, const MWORD outerSize, const const uint8_t* innerBytes = reinterpret_cast(liInner->m_digits); int32_t accum; - MWORD k = 0; - for (MWORD i = 0; i < outerByteSize; i++) + size_t k = 0; + for (size_t i = 0; i < outerByteSize; i++) { int32_t outerDigit = i == outerByteSize - 1 ? static_cast(static_cast(outerBytes[i])) : outerBytes[i]; if (outerDigit) { k = i; int32_t carry = 0; - for (MWORD j = 0; j < innerByteSize; j++) + for (size_t j = 0; j < innerByteSize; j++) { int32_t innerDigit = j == innerByteSize - 1 ? static_cast(static_cast(innerBytes[j])) : innerBytes[j]; ASSERT(k < productSize << 2); @@ -824,14 +824,14 @@ liDiv_t __stdcall liDivSingleUnsigned(const LargeIntegerOTE* oteLI, SmallUintege // v could be 1 greater than MaxSmallInteger as may be negated MinSmallInteger _ASSERTE(v <= 0x40000000); - const MWORD qSize = oteLI->getWordSize(); + const size_t qSize = oteLI->getWordSize(); uint32_t* u = oteLI->m_location->m_digits; LargeIntegerOTE* oteQ = LargeInteger::NewWithLimbs(qSize); uint32_t* q = oteQ->m_location->m_digits; uint32_t rem = 0; - for (int i=qSize-1;i>=0;i--) + for (ptrdiff_t i=static_cast(qSize)-1;i>=0;i--) { uint64_t ui = u[i] + (static_cast(rem) << 32); @@ -865,7 +865,7 @@ liDiv_t LargeInteger::Divide(const LargeIntegerOTE* oteU, SmallInteger v) } LargeInteger* liU = oteU->m_location; - const MWORD qSize = oteU->getWordSize(); + const size_t qSize = oteU->getWordSize(); if (qSize == 1) { @@ -1024,20 +1024,20 @@ liDiv_t __stdcall liDivUnsigned(LargeIntegerOTE* oteEwe, LargeIntegerOTE* oteVee "\nby " << oteVee<< L"\n\n"; #endif - int eweSize = oteEwe->getWordSize(); + ptrdiff_t eweSize = oteEwe->getWordSize(); // As this is an unsigned op., we don't need leading zero // digit to distinguish positives while (liEwe->m_digits[eweSize-1] == 0) eweSize--; - int veeSize = oteVee->getWordSize(); + ptrdiff_t veeSize = oteVee->getWordSize(); while (liVee->m_digits[veeSize-1] == 0) veeSize--; ASSERT(veeSize > 0); - const int n = veeSize; - const int m = eweSize - n + 1; + const ptrdiff_t n = veeSize; + const ptrdiff_t m = eweSize - n + 1; TRACE(L"n=%d, eweSize= %d, m=%d\n", n, eweSize, m); @@ -1098,9 +1098,9 @@ liDiv_t __stdcall liDivUnsigned(LargeIntegerOTE* oteEwe, LargeIntegerOTE* oteVee TRACE(L"d=%d, v1=%X, v2=%X, entering loop 1...\n", d, v1, v2); - for (int k=1;k<=m;k++) + for (ptrdiff_t k=1;k<=m;k++) { - const int j = eweSize + 1 - k; + const ptrdiff_t j = eweSize + 1 - k; // Since m = uSize-n+1, and uSize and n are at least 1, j should be at least 1 ASSERT(j >= 1 && j <= eweSize); @@ -1167,14 +1167,14 @@ liDiv_t __stdcall liDivUnsigned(LargeIntegerOTE* oteEwe, LargeIntegerOTE* oteVee */ // Our digits are in reverse order to Knuth - int l = j - n; + ptrdiff_t l = j - n; TRACE(L" Final qHat %X\n Entering inner loop with l=%d\n", qHat, l); LARGE_INTEGER carry; carry.QuadPart = 0; // For each digit, including the extra one introduced by the shift... - for (int i=0;i<=n;i++) + for (ptrdiff_t i=0;i<=n;i++) { ASSERT(l >= 0 && l < int(oteU->getWordSize())); uint32_t uij = liU->m_digits[l]; @@ -1251,7 +1251,7 @@ liDiv_t __stdcall liDivUnsigned(LargeIntegerOTE* oteEwe, LargeIntegerOTE* oteVee l = j - n; LARGE_INTEGER accum; accum.HighPart = 0; - for (int i=0;i<=n;i++) + for (ptrdiff_t i=0;i<=n;i++) { ASSERT(l >= 0 && l < int(oteU->getWordSize())); accum.QuadPart = static_cast(accum.HighPart) + liU->m_digits[l] + liV->m_digits[i]; @@ -1265,7 +1265,7 @@ liDiv_t __stdcall liDivUnsigned(LargeIntegerOTE* oteEwe, LargeIntegerOTE* oteVee ASSERT(carry.QuadPart < 2); } - int qi = m - k; + ptrdiff_t qi = m - k; ASSERT(qi >= 0 && qi < m); liQuo->m_digits[qi] = qHat; #ifdef _DEBUG @@ -1390,12 +1390,12 @@ Oop* __fastcall Interpreter::primitiveLargeIntegerBitInvert(Oop* const sp, prima LargeInteger* li = oteLI->m_location; - MWORD size = oteLI->getWordSize(); - MWORD invertedSize = size; + size_t size = oteLI->getWordSize(); + size_t invertedSize = size; LargeIntegerOTE* oteInverted = LargeInteger::NewWithLimbs(invertedSize); LargeInteger* liInverted = oteInverted->m_location; - for (unsigned i = 0; i < size; i++) + for (auto i = 0u; i < size; i++) liInverted->m_digits[i] = ~li->m_digits[i]; oteInverted->beImmutable(); @@ -1569,7 +1569,7 @@ Oop* __fastcall Interpreter::primitiveLargeIntegerEqual(Oop* const sp, primargco { if (oteArg->m_oteClass == Pointers.ClassLargeInteger) { - const MWORD receiverSize = oteReceiver->getSize(); + const size_t receiverSize = oteReceiver->getSize(); if (receiverSize != oteArg->getSize()) { // Different sizes, cannot be equal if both normalized @@ -1584,8 +1584,8 @@ Oop* __fastcall Interpreter::primitiveLargeIntegerEqual(Oop* const sp, primargco const uint32_t* receiver = oteReceiver->m_location->m_digits; const uint32_t* arg = oteArg->m_location->m_digits; - const int words = receiverSize / sizeof(uint32_t); - for (int i = 0; i < words; i++) + const auto words = receiverSize / sizeof(uint32_t); + for (auto i = 0u; i < words; i++) { if (receiver[i] != arg[i]) { @@ -1622,8 +1622,8 @@ Oop* __fastcall Interpreter::primitiveLargeIntegerEqual(Oop* const sp, primargco Oop LargeInteger::BitAnd(const LargeIntegerOTE* oteA, const LargeIntegerOTE* oteB) { - MWORD aSize = oteA->getWordSize(); - MWORD bSize = oteB->getWordSize(); + size_t aSize = oteA->getWordSize(); + size_t bSize = oteB->getWordSize(); const uint32_t *digitsA, *digitsB; @@ -1649,7 +1649,7 @@ Oop LargeInteger::BitAnd(const LargeIntegerOTE* oteA, const LargeIntegerOTE* ote // The answer must have the correct sign oteR = LargeInteger::NewWithLimbs(aSize); digitsR = oteR->m_location->m_digits; - for (unsigned i = bSize; i < aSize; i++) + for (auto i = bSize; i < aSize; i++) digitsR[i] = digitsA[i]; } else @@ -1663,7 +1663,7 @@ Oop LargeInteger::BitAnd(const LargeIntegerOTE* oteA, const LargeIntegerOTE* ote digitsR = oteR->m_location->m_digits; } - for (unsigned i = 0; i < bSize; i++) + for (auto i = 0u; i < bSize; i++) digitsR[i] = digitsA[i] & digitsB[i]; // The result MUST have the correct sign, because if both negative then @@ -1702,14 +1702,14 @@ Oop LargeInteger::BitAnd(const LargeIntegerOTE* oteA, SmallInteger mask) { // bitAnd with negative SmallInteger // Copy across all words except the least significant - const MWORD aSize = oteA->getWordSize(); + const size_t aSize = oteA->getWordSize(); ASSERT(aSize >= 1); const uint32_t* digitsA = oteA->m_location->m_digits; LargeIntegerOTE* oteR = LargeInteger::NewWithLimbs(aSize); uint32_t *digitsR = oteR->m_location->m_digits; digitsR[0] = digitsA[0] & static_cast(mask); - for (unsigned i = 1; i < aSize; i++) + for (auto i = 1u; i < aSize; i++) digitsR[i] = digitsA[i]; // The result MUST have the correct sign, because if both negative then @@ -1739,8 +1739,8 @@ Oop LargeInteger::BitAnd(const LargeIntegerOTE* oteA, SmallInteger mask) // LargeIntegerOTE* LargeInteger::BitOr(const LargeIntegerOTE* oteA, const LargeIntegerOTE* oteB) { - MWORD aSize = oteA->getWordSize(); - MWORD bSize = oteB->getWordSize(); + size_t aSize = oteA->getWordSize(); + size_t bSize = oteB->getWordSize(); const uint32_t *digitsA, *digitsB; @@ -1769,18 +1769,18 @@ LargeIntegerOTE* LargeInteger::BitOr(const LargeIntegerOTE* oteA, const LargeInt // The answer must be negative // All the digits above the size of B will be -1 // (anything bitOr'd with 2's complement -1 is -1). - for (unsigned i = bSize; i < aSize; i++) + for (auto i = bSize; i < aSize; i++) digitsR[i] = static_cast(-1); } else { // bitOr with shorter positive number // Just copy across the digits from A - for (unsigned i = bSize; i < aSize; i++) + for (auto i = bSize; i < aSize; i++) digitsR[i] = digitsA[i]; } - for (unsigned i = 0; i < bSize; i++) + for (auto i = 0u; i < bSize; i++) digitsR[i] = digitsA[i] | digitsB[i]; // Debug check the result has the correct sign @@ -1803,7 +1803,7 @@ LargeIntegerOTE* LargeInteger::BitOr(const LargeIntegerOTE* oteA, const LargeInt LargeIntegerOTE* LargeInteger::BitOr(const LargeIntegerOTE* oteA, SmallInteger mask) { const uint32_t* digitsA = oteA->m_location->m_digits; - const MWORD aSize = oteA->getWordSize(); + const size_t aSize = oteA->getWordSize(); ASSERT(aSize >= 1); LargeIntegerOTE* oteR = LargeInteger::NewWithLimbs(aSize); @@ -1813,14 +1813,14 @@ LargeIntegerOTE* LargeInteger::BitOr(const LargeIntegerOTE* oteA, SmallInteger m // bitOr with single-precision negative number // All high digits must be -1 (anything bitOr'd // with -1 is -1). - for (unsigned i = 1; i < aSize; i++) + for (auto i = 1u; i < aSize; i++) digitsR[i] = static_cast(-1); } else { // bitOr with single-precision positive number // Copy across digits other than the first from A - for (unsigned i = 1; i < aSize; i++) + for (auto i = 1u; i < aSize; i++) digitsR[i] = digitsA[i]; } @@ -1847,8 +1847,8 @@ LargeIntegerOTE* LargeInteger::BitOr(const LargeIntegerOTE* oteA, SmallInteger m LargeIntegerOTE* LargeInteger::BitXor(const LargeIntegerOTE* oteA, const LargeIntegerOTE* oteB) { - MWORD aSize = oteA->getWordSize(); - MWORD bSize = oteB->getWordSize(); + size_t aSize = oteA->getWordSize(); + size_t bSize = oteB->getWordSize(); const uint32_t* digitsA, *digitsB; @@ -1875,18 +1875,18 @@ LargeIntegerOTE* LargeInteger::BitXor(const LargeIntegerOTE* oteA, const LargeIn if (static_cast(digitsB[bSize - 1]) < 0) { // bitXor with shorter negative number - for (unsigned i = bSize; i < aSize; i++) + for (auto i = bSize; i < aSize; i++) digitsR[i] = digitsA[i] ^ static_cast(-1); } else { // bitXor with shorter positive number // Just copy across the digits from A - for (unsigned i = bSize; i < aSize; i++) + for (auto i = bSize; i < aSize; i++) digitsR[i] = digitsA[i]; } - for (unsigned i = 0; i < bSize; i++) + for (auto i = 0u; i < bSize; i++) digitsR[i] = digitsA[i] ^ digitsB[i]; // Debug check the result has the correct sign @@ -1907,7 +1907,7 @@ LargeIntegerOTE* LargeInteger::BitXor(const LargeIntegerOTE* oteA, const LargeIn LargeIntegerOTE* LargeInteger::BitXor(const LargeIntegerOTE* oteA, SmallInteger mask) { const uint32_t* digitsA = oteA->m_location->m_digits; - const MWORD aSize = oteA->getWordSize(); + const size_t aSize = oteA->getWordSize(); ASSERT(aSize >= 1); LargeIntegerOTE* oteR = LargeInteger::NewWithLimbs(aSize); @@ -1915,14 +1915,14 @@ LargeIntegerOTE* LargeInteger::BitXor(const LargeIntegerOTE* oteA, SmallInteger if (mask < 0) { // bitXor with single-precision negative number - for (unsigned i = 1; i < aSize; i++) + for (auto i = 1u; i < aSize; i++) digitsR[i] = digitsA[i] ^ static_cast(-1); } else { // bitXor with single-precision positive number // Copy across digits other than the first from A - for (unsigned i = 1; i < aSize; i++) + for (auto i = 1u; i < aSize; i++) digitsR[i] = digitsA[i]; } @@ -1994,7 +1994,7 @@ Oop* __fastcall Interpreter::primitiveLargeIntegerHighBit(Oop* const sp, primarg // Also there can be at most one leading zero limb (e.g. for 2**63) LargeInteger* liReceiver = oteReceiver->m_location; - MWORD i = oteReceiver->getWordSize() - 1; + size_t i = oteReceiver->getWordSize() - 1; uint32_t digit = liReceiver->m_digits[i]; if (static_cast(digit) >= 0) { @@ -2021,7 +2021,7 @@ Oop* __fastcall Interpreter::primitiveLargeIntegerAsFloat(Oop* const sp, primarg { LargeIntegerOTE* oteReceiver = reinterpret_cast(*sp); LargeInteger* liReceiver = oteReceiver->m_location; - const MWORD size = oteReceiver->getWordSize(); + const size_t size = oteReceiver->getWordSize(); if (size <= 2) { FloatOTE* oteResult = Float::New(); diff --git a/Core/DolphinVM/objmem.cpp b/Core/DolphinVM/objmem.cpp index e025d44eaa..b0eccc9df6 100644 --- a/Core/DolphinVM/objmem.cpp +++ b/Core/DolphinVM/objmem.cpp @@ -22,14 +22,14 @@ HANDLE ObjectMemory::m_hHeap; extern "C" { HANDLE _crtheap; } #ifdef MEMSTATS - unsigned m_nLargeAllocated = 0; - unsigned m_nLargeFreed = 0; - unsigned m_nSmallAllocated = 0; - unsigned m_nSmallFreed = 0; + size_t m_nLargeAllocated = 0; + size_t m_nLargeFreed = 0; + size_t m_nSmallAllocated = 0; + size_t m_nSmallFreed = 0; #endif #ifdef _DEBUG - int ObjectMemory::m_nFreeOTEs = 0; + size_t ObjectMemory::m_nFreeOTEs = 0; #endif // Smalltalk classes @@ -60,7 +60,7 @@ uint32_t ObjectMemory::m_imageVersionMinor; // The number of OT pages to be allocated each time an OT overflow occurs // Higher numbers could waste more space, but will reduce the frequency of the overflows // It is important that the result be exactly divisible by the OTE size (hence 16, because 16*4096%16==0) -static const int OTPagesAllocatedPerOverflow = 16; // i.e. 64Kb per overflow, 4096 objects +constexpr int OTPagesAllocatedPerOverflow = 16; // i.e. 64Kb per overflow, 4096 objects #pragma code_seg(PROCESS_SEG) @@ -90,8 +90,8 @@ void __fastcall ObjectMemory::oneWayBecome(OTE* ote1, OTE* ote2) { VariantObject* obj = static_cast(ote->m_location); - const MWORD lastPointer = ote->pointersSize(); - for (MWORD j = 0; j < lastPointer; j++) + const size_t lastPointer = ote->pointersSize(); + for (size_t j = 0; j < lastPointer; j++) { Oop fieldPointer = obj->m_fields[j]; if (fieldPointer == oop1) @@ -152,12 +152,12 @@ ArrayOTE* __fastcall ObjectMemory::instancesOf(BehaviorOTE* classPointer) ASSERT(isBehavior(Oop(classPointer))); // Use the ref. count as an initial size - unsigned size = classPointer->m_count; + size_t size = classPointer->m_count; ArrayOTE* arrayPointer = Array::New(size); Array* pInstances = arrayPointer->m_location; - unsigned cnt = 0; + size_t cnt = 0; const OTE* pEnd = m_pOT+m_nOTSize; for (OTE* ote=m_pOT; ote < pEnd; ote++) { @@ -239,14 +239,14 @@ ArrayOTE* __fastcall ObjectMemory::subinstancesOf(BehaviorOTE* classPointer) ASSERT(isBehavior(Oop(classPointer))); // Use the ref. count as an initial size - unsigned size = classPointer->m_count; + size_t size = classPointer->m_count; if (size < 32) size = 32; ArrayOTE* arrayPointer = Array::New(size); Array* pInstances = arrayPointer->m_location; - unsigned cnt = 0; + size_t cnt = 0; const OTE* pEnd = m_pOT+m_nOTSize; for (OTE* ote=m_pOT; ote < pEnd; ote++) { @@ -290,11 +290,11 @@ template inline size_t hash_value(TOTE* ote) struct InstStats { - int count; - int bytes; + size_t count; + size_t bytes; InstStats() { count = bytes = 0; } - InstStats(int count, int bytes) { this->count = count; this->bytes = bytes; } + InstStats(size_t count, size_t bytes) { this->count = count; this->bytes = bytes; } }; template > ClassCountMap; -static int storageSize(OTE* ote) +static size_t storageSize(OTE* ote) { - int bodySize = ote->sizeOf(); + size_t bodySize = ote->sizeOf(); // The body is rounded to a multiple of 8 bytes return _ROUND2(bodySize, 8) + sizeof(OTE); } @@ -365,10 +365,10 @@ ArrayOTE* __fastcall ObjectMemory::instanceCounts(ArrayOTE* oteClasses) if (oteClasses->isNil()) { - int n = counts.size(); + auto n = counts.size(); oteClassStats = Array::NewUninitialized(n * 3); Array* classStats = oteClassStats->m_location; - int i = 0; + size_t i = 0; ClassCountMap::const_iterator end = counts.end(); for (ClassCountMap::const_iterator it = counts.begin();it != end; it++,i+=3) { @@ -384,17 +384,17 @@ ArrayOTE* __fastcall ObjectMemory::instanceCounts(ArrayOTE* oteClasses) } else { - int n = oteClasses->pointersSize(); + auto n = oteClasses->pointersSize(); oteClassStats = Array::NewUninitialized(n * 3); Array* classStats = oteClassStats->m_location; Array* array = oteClasses->m_location; - MWORD count = oteClasses->pointersSize(); + size_t count = oteClasses->pointersSize(); ClassCountMap::const_iterator end = counts.end(); - for (MWORD i=0;im_elements[i]; countUp(obj); - int j = i * 3; + size_t j = i * 3; classStats->m_elements[j] = obj; ClassCountMap::const_iterator it; if (isBehavior(obj) && (it = counts.find(reinterpret_cast(obj))) != end) @@ -443,8 +443,8 @@ Oop* __fastcall Interpreter::primitiveAllReferences(Oop* const sp, primargcount_ // Resize the active process to exclude the receiver and arg (if any) to the primitive ST::Process* pActiveProcess = m_registers.m_pActiveProcess; - MWORD words = sp - 1 - reinterpret_cast(pActiveProcess); - m_registers.m_oteActiveProcess->setSize(words * sizeof(MWORD)); + size_t words = sp - 1 - reinterpret_cast(pActiveProcess); + m_registers.m_oteActiveProcess->setSize(words * sizeof(Oop)); Oop receiver = *(sp - 1); ArrayOTE* refs = ObjectMemory::referencesTo(receiver, includeWeakRefs); @@ -460,7 +460,7 @@ ArrayOTE* __stdcall ObjectMemory::referencesTo(Oop referencedObjectPointer, bool { WeaknessMask = includeWeakRefs ? 0 : OTEFlags::WeakMask; - unsigned size = !isIntegerObject(referencedObjectPointer) ? max(reinterpret_cast(referencedObjectPointer)->m_count, 1) : 32; + size_t size = !isIntegerObject(referencedObjectPointer) ? max(reinterpret_cast(referencedObjectPointer)->m_count, 1) : 32; ArrayOTE* arrayPointer = Array::New(size); Array* pRefs = arrayPointer->m_location; @@ -469,7 +469,7 @@ ArrayOTE* __stdcall ObjectMemory::referencesTo(Oop referencedObjectPointer, bool // circular reference before the oop of the new array is considered arrayPointer->beFree(); - unsigned refCnt = 0; + size_t refCnt = 0; const OTE* pEnd = m_pOT + m_nOTSize; for (OTE* ote = m_pOT; ote < pEnd; ote++) { @@ -491,8 +491,8 @@ ArrayOTE* __stdcall ObjectMemory::referencesTo(Oop referencedObjectPointer, bool else { VariantObject* obj = static_cast(ote->m_location); - const MWORD lastPointer = lastStrongPointerOf(ote); - for (MWORD i = 0; i < lastPointer; i++) + const size_t lastPointer = lastStrongPointerOf(ote); + for (size_t i = 0; i < lastPointer; i++) { if (obj->m_fields[i] == referencedObjectPointer) { @@ -537,7 +537,7 @@ ArrayOTE* __stdcall ObjectMemory::referencesTo(Oop referencedObjectPointer, bool // These map directly onto C or Win32 heap #ifdef _DEBUG - MWORD ObjectMemory::chunkSize(void* pChunk) + size_t ObjectMemory::chunkSize(void* pChunk) { #ifdef PRIVATE_HEAP return ::HeapSize(m_hHeap, 0, pChunk); @@ -552,7 +552,7 @@ ArrayOTE* __stdcall ObjectMemory::referencesTo(Oop referencedObjectPointer, bool #pragma code_seg(GC_SEG) -HRESULT ObjectMemory::allocateOT(unsigned reserve, unsigned commit) +HRESULT ObjectMemory::allocateOT(size_t reserve, size_t commit) { //ASSERT(!m_pOT); // ASSERT(m_nInCritSection > 0); // Must obviously be performed exclusively as OT is globally shared @@ -649,7 +649,7 @@ void ObjectMemory::Terminate() if (m_pOT) { // Deallocate all objects that need deallocating to avoid leaking when loaded in-proc - for (unsigned i=NumPermanent; i < m_nOTSize; i++) + for (auto i=NumPermanent; i < m_nOTSize; i++) { OTE& ote = m_pOT[i]; if (!ote.isFree()) @@ -673,14 +673,14 @@ void ObjectMemory::Terminate() // Clean up the OTE pools before object table is deleted Interpreter::freePools(); - //for (int j=0;j(ote->m_location); } - for (unsigned i=0;i(index)) /////////////////////////////////////////////////////////////////////////////// // Class of Object Memory Managers @@ -62,8 +62,8 @@ class ObjectMemory static void Terminate(); // Object Pointer access - static Oop fetchPointerOfObject(MWORD fieldIndex, PointersOTE* ote); - static Oop storePointerOfObjectWithValue(MWORD fieldIndex, PointersOTE* ote, Oop valuePointer); + static Oop fetchPointerOfObject(size_t fieldIndex, PointersOTE* ote); + static Oop storePointerOfObjectWithValue(size_t fieldIndex, PointersOTE* ote, Oop valuePointer); static Oop storePointerWithValue(Oop& oopSlot, Oop oopValue); static OTE* storePointerWithValue(OTE*& oteSlot, OTE* oteValue); static Oop storePointerWithValue(Oop& oopSlot, OTE* oteValue); @@ -72,11 +72,11 @@ class ObjectMemory // Use these versions to store values which are not themselves ref. counted static Oop storePointerWithUnrefCntdValue(Oop&, Oop); - static void __fastcall storePointerOfObjectWithUnrefCntdValue(MWORD fieldIndex, PointersOTE* ote, Oop value); + static void __fastcall storePointerOfObjectWithUnrefCntdValue(size_t fieldIndex, PointersOTE* ote, Oop value); // Word Access - static MWORD fetchWordOfObject(MWORD fieldIndex, Oop objectPointer); - static MWORD storeWordOfObjectWithValue(MWORD fieldIndex, Oop objectPointer, MWORD valueWord); + static uintptr_t fetchWordOfObject(size_t fieldIndex, Oop objectPointer); + static uintptr_t storeWordOfObjectWithValue(size_t fieldIndex, Oop objectPointer, uintptr_t valueWord); // Formerly Private reference count management static void __fastcall countUp(Oop objectPointer); @@ -93,27 +93,27 @@ class ObjectMemory static size_t GetBytesElementSize(BytesOTE* ote); // Use CRT Small block heap OR pool if size <= this threshold - enum { MaxSmallObjectSize = 0x3f8 }; - enum { PoolObjectSizeLimit = 144 }; - enum { MinObjectSize = /*sizeof(Object)+*/PoolGranularity }; - enum { MaxPools = (PoolObjectSizeLimit - MinObjectSize) / PoolGranularity + 1 }; + static constexpr size_t MaxSmallObjectSize = 0x3f8; + static constexpr size_t PoolObjectSizeLimit = 144; + static constexpr size_t MinObjectSize = /*sizeof(Object)+*/PoolGranularity; + static constexpr size_t MaxPools = (PoolObjectSizeLimit - MinObjectSize) / PoolGranularity + 1; - static VirtualOTE* __fastcall newVirtualObject(BehaviorOTE* classPointer, MWORD initialSize, MWORD maxSize); + static VirtualOTE* __fastcall newVirtualObject(BehaviorOTE* classPointer, size_t initialSize, size_t maxSize); static PointersOTE* __fastcall newPointerObject(BehaviorOTE* classPointer); - static PointersOTE* __fastcall newPointerObject(BehaviorOTE* classPointer, MWORD instanceSize); - static PointersOTE* __fastcall newUninitializedPointerObject(BehaviorOTE* classPointer, MWORD instanceSize); - template static BytesOTE* newByteObject(BehaviorOTE* classPointer, MWORD instanceByteSize); - template static TOTE* newUninitializedNullTermObject(MWORD instanceByteSize); - static BytesOTE* __fastcall newByteObject(BehaviorOTE* classPointer, MWORD instanceByteSize, const void* pBytes); - static OTE* CopyElements(OTE* oteObj, MWORD startingAt, MWORD countfrom); + static PointersOTE* __fastcall newPointerObject(BehaviorOTE* classPointer, size_t instanceSize); + static PointersOTE* __fastcall newUninitializedPointerObject(BehaviorOTE* classPointer, size_t instanceSize); + template static BytesOTE* newByteObject(BehaviorOTE* classPointer, size_t instanceByteSize); + template static TOTE* newUninitializedNullTermObject(size_t instanceByteSize); + static BytesOTE* __fastcall newByteObject(BehaviorOTE* classPointer, size_t instanceByteSize, const void* pBytes); + static OTE* CopyElements(OTE* oteObj, size_t startingAt, size_t countfrom); // Resizing objects (RAW - assumes no. ref counting to be done) template static POBJECT basicResize(OTE* ote, size_t byteSize /*should include header*/); - static POBJECT resizeVirtual(OTE* ote, MWORD byteSize /*ditto*/); + static POBJECT resizeVirtual(OTE* ote, size_t byteSize /*ditto*/); // More useful (and safe) entry points from Interpreter - static VariantObject* resize(PointersOTE* objectPointer, MWORD newPointers, bool bRefCount); - static VariantByteObject* resize(BytesOTE* objectPointer, MWORD newBytes); + static VariantObject* resize(PointersOTE* objectPointer, size_t newPointers, bool bRefCount); + static VariantByteObject* resize(BytesOTE* objectPointer, size_t newBytes); static BytesOTE* __fastcall shallowCopy(BytesOTE* ote); static PointersOTE* __fastcall shallowCopy(PointersOTE* ote); @@ -123,8 +123,8 @@ class ObjectMemory // GC support static SmallInteger OopsLeft(); - static int __fastcall OopsUsed(); - static unsigned GetOTSize(); + static size_t __fastcall OopsUsed(); + static size_t GetOTSize(); static size_t compact(Oop* const sp); static void HeapCompact(); @@ -140,7 +140,7 @@ class ObjectMemory } } - static OTE* PointerFromIndex(int index) + static OTE* PointerFromIndex(size_t index) { return pointerFromIndex(index); } @@ -212,7 +212,7 @@ class ObjectMemory static void CheckPoint(); #endif - static _PrimitiveFailureCode __stdcall SaveImageFile(const wchar_t* fileName, bool bBackup, int nCompressionLevel, unsigned nMaxObjects); + static _PrimitiveFailureCode __stdcall SaveImageFile(const wchar_t* fileName, bool bBackup, int nCompressionLevel, size_t nMaxObjects); static HRESULT __stdcall LoadImage(const wchar_t* szImageName, LPVOID imageData, size_t imageSize, bool bIsDevSys); static int gpFaultExceptionFilter(LPEXCEPTION_POINTERS pExInfo); @@ -220,12 +220,10 @@ class ObjectMemory static MemoryManager* memoryManager(); public: - enum { - OTMinHeadroom = 16384, - OTDefaultSize = 65536, - OTDefaultMax = 24 * 1024 * 1024, - OTMaxLimit = 64 * 1024 * 1024 - }; + static constexpr size_t OTMinHeadroom = 16384; + static constexpr size_t OTDefaultSize = 65536; + static constexpr size_t OTDefaultMax = 24 * 1024 * 1024; + static constexpr size_t OTMaxLimit = 64 * 1024 * 1024; enum { registryIndex, FirstBuiltInIdx }; @@ -242,11 +240,9 @@ class ObjectMemory emptyArrayOOPIndex, FirstCharacterIdx }; - enum { - NumCharacters = 256, - NumPermanent = FirstCharacterIdx + NumCharacters - }; - enum { OTBase = NumPermanent }; + static constexpr size_t NumCharacters = 256; + static constexpr size_t NumPermanent = FirstCharacterIdx + NumCharacters; + static constexpr size_t OTBase = NumPermanent; class OTEPool { @@ -276,8 +272,8 @@ class ObjectMemory OTE* allocate(); void deallocate(OTE* ote); - BytesOTE* newByteObject(BehaviorOTE* classPointer, unsigned bytes, OTEFlags::Spaces space); - PointersOTE* newPointerObject(BehaviorOTE* classPointer, unsigned pointers, OTEFlags::Spaces space); + BytesOTE* newByteObject(BehaviorOTE* classPointer, size_t bytes, OTEFlags::Spaces space); + PointersOTE* newPointerObject(BehaviorOTE* classPointer, size_t pointers, OTEFlags::Spaces space); void terminate() { @@ -296,8 +292,8 @@ class ObjectMemory // newly allocated, or who's count has dropped to zero static OTE** m_pZct; - static int m_nZctEntries; // Current no. of Zct entries - static int m_nZctHighWater; // High water mark at which ZCT reconciled + static ptrdiff_t m_nZctEntries; // Current no. of Zct entries + static ptrdiff_t m_nZctHighWater; // High water mark at which ZCT reconciled static bool m_bIsReconcilingZct; static HRESULT InitializeZct(); @@ -330,12 +326,12 @@ class ObjectMemory __declspec(align(8)) class FixedSizePool { public: - FixedSizePool(unsigned nChunkSize=MinObjectSize); + FixedSizePool(size_t nChunkSize=MinObjectSize); POBJECT allocate(); void deallocate(POBJECT pChunk); - void setSize(unsigned nChunkSize); + void setSize(size_t nChunkSize); void terminate(); #ifdef _DEBUG @@ -344,13 +340,13 @@ class ObjectMemory #endif #ifdef MEMSTATS - int getPages() { return m_nPages; } - int getFree(); + size_t getPages() { return m_nPages; } + size_t getFree(); void** m_pages; size_t m_nPages; #endif - int getSize() { return m_nChunkSize; } + size_t getSize() { return m_nChunkSize; } private: void moreChunks(); @@ -378,7 +374,7 @@ class ObjectMemory static HRESULT __stdcall allocateOT(size_t reserve, size_t commit); // Answer the index of the last occuppied OT entry - static unsigned __stdcall lastOTEntry(); + static size_t __stdcall lastOTEntry(); static OTE* __fastcall allocateOop(POBJECT pLocation); public: @@ -386,18 +382,18 @@ class ObjectMemory private: // Memory allocators - these are very thin layers of C/Win32 heap static void freeChunk(POBJECT pChunk); - static void freeSmallChunk(POBJECT pObj, MWORD size); - static POBJECT reallocChunk(POBJECT pChunk, MWORD newChunkSize); + static void freeSmallChunk(POBJECT pObj, size_t size); + static POBJECT reallocChunk(POBJECT pChunk, size_t newChunkSize); #ifdef _DEBUG - static MWORD chunkSize(void* pChunk); + static size_t chunkSize(void* pChunk); #endif - static POBJECT allocSmallChunk(MWORD chunkSize); - static POBJECT allocChunk(MWORD chunkSize); - static POBJECT allocObject(MWORD objectSize, OTE*& ote); - static POBJECT allocLargeObject(MWORD objectSize, OTE*& ote); + static POBJECT allocSmallChunk(size_t chunkSize); + static POBJECT allocChunk(size_t chunkSize); + static POBJECT allocObject(size_t objectSize, OTE*& ote); + static POBJECT allocLargeObject(size_t objectSize, OTE*& ote); - static FixedSizePool& spacePoolForSize(MWORD objectSize); + static FixedSizePool& spacePoolForSize(size_t objectSize); static void decRefs(Oop); @@ -418,7 +414,7 @@ class ObjectMemory // Garbage collection/Ref count checking static uint8_t WeaknessMask; - static MWORD lastStrongPointerOf(OTE* ote); + static size_t lastStrongPointerOf(OTE* ote); static void reclaimInaccessibleObjects(uintptr_t flags); static void markObjectsAccessibleFrom(OTE* ote); static void ClearGCInfo(); @@ -443,20 +439,20 @@ class ObjectMemory static const char ISTHDRTYPE[4]; static bool __stdcall SaveObjectTable(obinstream& imageFile, const ImageHeader*); - template static bool __stdcall SaveObjects(obinstream& imageFile, const ImageHeader*); - static bool __stdcall SaveImage(obinstream& imageFile, const ImageHeader*, int); + template static bool __stdcall SaveObjects(obinstream& imageFile, const ImageHeader*); + static bool __stdcall SaveImage(obinstream& imageFile, const ImageHeader*, int nRet); static HRESULT __stdcall LoadImage(ibinstream& imageFile, ImageHeader*); static OTE* __fastcall FixupPointer(OTE* pSavedPointer, OTE* pSavedBase); static HRESULT __stdcall LoadObjectTable(ibinstream& imageFile, const ImageHeader*); - template static HRESULT LoadPointersAndObjects(ibinstream& imageFile, const ImageHeader* pHeader, size_t& cbRead); - template static HRESULT __stdcall LoadPointers(ibinstream& imageFile, const ImageHeader*, size_t&); - template static HRESULT __stdcall LoadObjects(ibinstream& imageFile, const ImageHeader*, size_t&); + template static HRESULT LoadPointersAndObjects(ibinstream& imageFile, const ImageHeader* pHeader, size_t& cbRead); + template static HRESULT __stdcall LoadPointers(ibinstream& imageFile, const ImageHeader*, size_t&); + template static HRESULT __stdcall LoadObjects(ibinstream& imageFile, const ImageHeader*, size_t&); - static ST::Object* AllocObj(OTE * ote, MWORD allocSize); + static ST::Object* AllocObj(OTE * ote, size_t allocSize); - static void __stdcall FixupObject(OTE* ote, MWORD* oldLocation, const ImageHeader*); + static void __stdcall FixupObject(OTE* ote, uintptr_t* oldLocation, const ImageHeader*); static void __stdcall PostLoadFix(); public: // Public Data @@ -475,19 +471,19 @@ class ObjectMemory static uint32_t m_nNextIdHash; // Next identity hash value to use // These are to be used for collecting statistics in future - static unsigned m_nObjectsAllocated; - static unsigned m_nObjectsFreed; - static unsigned m_nBytesAllocated; - static unsigned m_nBytesFreed; + static size_t m_nObjectsAllocated; + static size_t m_nObjectsFreed; + static size_t m_nBytesAllocated; + static size_t m_nBytesFreed; #ifdef _DEBUG - static int m_nFreeOTEs; - static int CountFreeOTEs(); + static size_t m_nFreeOTEs; + static size_t CountFreeOTEs(); #endif static OTEFlags m_spaceOTEBits[OTEFlags::NumSpaces]; - static unsigned m_nOTMax; - static unsigned m_nOTSize; // The size (in Oops, not bytes) of the object table + static size_t m_nOTMax; + static size_t m_nOTSize; // The size (in Oops, not bytes) of the object table public: static OTE* m_pOT; // The Object Table itself private: @@ -500,7 +496,7 @@ class ObjectMemory // Lower level object creation // Note that we deliberately do not make this a member fn, so that we are sure it is not // touching any of the static member vars -MWORD* __stdcall AllocateVirtualSpace(MWORD maxBytes, MWORD initialBytes); +Oop* __stdcall AllocateVirtualSpace(size_t maxBytes, size_t initialBytes); // Globally accessible pointers, but please don't write to them! @@ -538,7 +534,7 @@ inline bool ObjectMemory::isValidOop(Oop objectPointer) #define roundUpTo(n, to) ((((n)+(to)-1)/(to)) * (to)) // Macro to calculate the byte size of an object with N pointers -#define SizeOfPointers(N) (((N)+ObjectHeaderSize)*sizeof(MWORD)) +#define SizeOfPointers(N) ((static_cast(N)+ObjectHeaderSize)*sizeof(Oop)) inline void ObjectMemory::decRefs(Oop oop) { @@ -546,7 +542,7 @@ inline void ObjectMemory::decRefs(Oop oop) reinterpret_cast(oop)->decRefs(); } -inline unsigned ObjectMemory::GetOTSize() +inline size_t ObjectMemory::GetOTSize() { return m_nOTSize; } @@ -623,7 +619,7 @@ inline void __fastcall ObjectMemory::AddToZct(TOTE* ote) HARDASSERT(m_nZctEntries >= 0); // If we don't use a temp here, compiler generates code that needlessly reads the field from memory multiple times - int zctEntries = m_nZctEntries; + auto zctEntries = m_nZctEntries; m_pZct[zctEntries++] = reinterpret_cast(ote); m_nZctEntries = zctEntries; @@ -642,7 +638,7 @@ inline void __fastcall ObjectMemory::AddStackRefToZct(TOTE* ote) HARDASSERT(m_nZctEntries >= 0); // If we don't use a temp here, compiler generates code that needlessly reads the field from memory multiple times - int zctEntries = m_nZctEntries; + auto zctEntries = m_nZctEntries; m_pZct[zctEntries++] = reinterpret_cast(ote); m_nZctEntries = zctEntries; @@ -662,14 +658,14 @@ inline bool ObjectMemory::IsReconcilingZct() /////////////////////////////////////////////////////////////////////////////// // Machine Word Access -inline Oop ObjectMemory::fetchPointerOfObject(MWORD fieldIndex, PointersOTE* ote) +inline Oop ObjectMemory::fetchPointerOfObject(size_t fieldIndex, PointersOTE* ote) { ASSERT(fieldIndex < ote->pointersSize()); return ote->m_location->m_fields[fieldIndex]; } // SmallIntegers and some special objects are not ref. counted, so this saves a little time -inline void __fastcall ObjectMemory::storePointerOfObjectWithUnrefCntdValue(MWORD fieldIndex, PointersOTE* ote, Oop nonRefCountedPointer) +inline void __fastcall ObjectMemory::storePointerOfObjectWithUnrefCntdValue(size_t fieldIndex, PointersOTE* ote, Oop nonRefCountedPointer) { ASSERT(fieldIndex < ote->pointersSize()); VariantObject* obj = ote->m_location; @@ -677,7 +673,7 @@ inline void __fastcall ObjectMemory::storePointerOfObjectWithUnrefCntdValue(MWOR obj->m_fields[fieldIndex] = nonRefCountedPointer; } -inline Oop ObjectMemory::storePointerOfObjectWithValue(MWORD fieldIndex, PointersOTE* ote, Oop valuePointer) +inline Oop ObjectMemory::storePointerOfObjectWithValue(size_t fieldIndex, PointersOTE* ote, Oop valuePointer) { ASSERT(fieldIndex < ote->pointersSize()); countUp(valuePointer); @@ -742,14 +738,14 @@ inline void ObjectMemory::nilOutPointer(OTE*& ote) /////////////////////////////////////////////////////////////////////////////// // Machine Word Access -inline MWORD ObjectMemory::fetchWordOfObject(MWORD wordIndex, Oop objectPointer) +inline uintptr_t ObjectMemory::fetchWordOfObject(size_t wordIndex, Oop objectPointer) { PointersOTE* ote = reinterpret_cast(objectPointer); VariantObject* obj = ote->m_location; return obj->m_fields[wordIndex]; } -inline MWORD ObjectMemory::storeWordOfObjectWithValue(MWORD wordIndex, Oop objectPointer, MWORD valueWord) +inline uintptr_t ObjectMemory::storeWordOfObjectWithValue(size_t wordIndex, Oop objectPointer, uintptr_t valueWord) { PointersOTE* ote = reinterpret_cast(objectPointer); VariantObject* obj = ote->m_location; @@ -830,7 +826,7 @@ inline void ObjectMemory::markObject(OTE* ote) } // lastPointerOf includes the object header, sizeBitsOf()/mwordSizeOf() does NOT -inline MWORD ObjectMemory::lastStrongPointerOf(OTE* ote) +inline size_t ObjectMemory::lastStrongPointerOf(OTE* ote) { uint8_t flags = ote->m_ubFlags; return (flags & OTEFlags::PointerMask) @@ -844,9 +840,9 @@ inline MWORD ObjectMemory::lastStrongPointerOf(OTE* ote) /////////////////////////////////////////////////////////////////////////////// // Memory pool routines -inline ObjectMemory::FixedSizePool& ObjectMemory::spacePoolForSize(MWORD objectSize) +inline ObjectMemory::FixedSizePool& ObjectMemory::spacePoolForSize(size_t objectSize) { - int nPool = (_ROUND2(objectSize, PoolGranularity) - MinObjectSize) / PoolGranularity; + auto nPool = (_ROUND2(objectSize, PoolGranularity) - MinObjectSize) / PoolGranularity; ASSERT(nPool < MaxPools); ASSERT(nPool * PoolGranularity + (DWORD)MinObjectSize >= objectSize); return m_pools[nPool]; @@ -971,7 +967,7 @@ inline void ObjectMemory::OTEPool::deallocate(OTE* ote) } // Although this looks like a long routine to inline, in fact it is very few machine instructions -inline BytesOTE* ObjectMemory::OTEPool::newByteObject(BehaviorOTE* classPointer, unsigned bytes, OTEFlags::Spaces space) +inline BytesOTE* ObjectMemory::OTEPool::newByteObject(BehaviorOTE* classPointer, size_t bytes, OTEFlags::Spaces space) { BytesOTE* ote = reinterpret_cast(m_pFreeList); if (ote) @@ -1011,7 +1007,7 @@ inline BytesOTE* ObjectMemory::OTEPool::newByteObject(BehaviorOTE* classPointer, } // Although this looks like a long routine to inline, in fact it is very few machine instructions -inline PointersOTE* ObjectMemory::OTEPool::newPointerObject(BehaviorOTE* classPointer, unsigned pointers, OTEFlags::Spaces space) +inline PointersOTE* ObjectMemory::OTEPool::newPointerObject(BehaviorOTE* classPointer, size_t pointers, OTEFlags::Spaces space) { PointersOTE* ote = reinterpret_cast(m_pFreeList); if (ote) @@ -1050,7 +1046,7 @@ inline PointersOTE* ObjectMemory::OTEPool::newPointerObject(BehaviorOTE* classPo return ote; } -template TOTE* __fastcall ObjectMemory::newUninitializedNullTermObject(MWORD byteSize) +template TOTE* __fastcall ObjectMemory::newUninitializedNullTermObject(size_t byteSize) { OTE* ote; allocObject(byteSize + NULLTERMSIZE + SizeOfPointers(0), ote); @@ -1060,7 +1056,7 @@ template TOTE* __fastcall ObjectMemory::newUninitializedNullTermObj return reinterpret_cast*>(ote); } -inline BytesOTE* __fastcall ObjectMemory::newByteObject(BehaviorOTE* classPointer, MWORD cBytes, const void* pBytes) +inline BytesOTE* __fastcall ObjectMemory::newByteObject(BehaviorOTE* classPointer, size_t cBytes, const void* pBytes) { ASSERT((OTE*)classPointer != Pointers.Nil); ASSERT(!classPointer->m_location->m_instanceSpec.m_nullTerminated); @@ -1092,12 +1088,12 @@ inline hash_t ObjectMemory::nextIdentityHash() /////////////////////////////////////////////////////////////////////////////// // ST::Array allocators -inline ArrayOTE* ST::Array::New(unsigned size) +inline ArrayOTE* ST::Array::New(size_t size) { return reinterpret_cast(ObjectMemory::newPointerObject(Pointers.ClassArray, size)); } -inline ArrayOTE* ST::Array::NewUninitialized(unsigned size) +inline ArrayOTE* ST::Array::NewUninitialized(size_t size) { return reinterpret_cast(ObjectMemory::newUninitializedPointerObject(Pointers.ClassArray, size)); } diff --git a/Core/DolphinVM/oopq.h b/Core/DolphinVM/oopq.h index 6ae6e05cc4..7c6ef88698 100644 --- a/Core/DolphinVM/oopq.h +++ b/Core/DolphinVM/oopq.h @@ -22,13 +22,13 @@ template class OopQueue OopQueue() : m_bufferArray(0), m_pBuffer(0), m_nHead(0), m_nTail(0), m_nGrowthGranularity(0), m_nSize(0) {} - OopQueue(OTE* bufferArray, MWORD nGrowthGranularity) + OopQueue(OTE* bufferArray, size_t nGrowthGranularity) { UseBuffer(bufferArray, nGrowthGranularity); } // initialization - void UseBuffer(ArrayOTE* bufferArray, MWORD nGrowthGranularity, bool bShrink) + void UseBuffer(ArrayOTE* bufferArray, size_t nGrowthGranularity, bool bShrink) { m_bufferArray = bufferArray; m_nGrowthGranularity = nGrowthGranularity; @@ -98,20 +98,20 @@ template class OopQueue } // Return the number of elements in the queue - unsigned Count() + size_t Count() { // Remember the slot pointed at by m_hHead is empty return m_nTail < m_nHead ? m_nSize - m_nHead + m_nTail : m_nTail - m_nHead; } // testing - BOOL isFull() const + bool isFull() const { ASSERT(m_pBuffer); return m_nHead == (m_nTail+1) % m_nSize; } - BOOL isEmpty() const + bool isEmpty() const { ASSERT(m_pBuffer); return m_nHead == m_nTail; @@ -126,7 +126,7 @@ template class OopQueue // The queue overflowed, grow it to accomodate more elements void Overflow() { - MWORD oldSize = m_nSize; + size_t oldSize = m_nSize; m_nSize += m_nGrowthGranularity; m_pBuffer = reinterpret_cast(ObjectMemory::resize(reinterpret_cast(m_bufferArray), m_nSize, false)->m_fields); if (m_nTail == 0) @@ -137,9 +137,9 @@ template class OopQueue // The queue is split i.e. it has wrapped around, so we need to // move those elements between the front and the old size so that they // end at old size (this is quite likely to be an overlapping move). - const MWORD numToMove = oldSize - m_nHead; + const size_t numToMove = oldSize - m_nHead; const T nil = reinterpret_cast(Pointers.Nil); - for (unsigned i=1;i<=numToMove;i++) + for (size_t i=1;i<=numToMove;i++) { m_pBuffer[m_nSize-i] = m_pBuffer[oldSize-i]; m_pBuffer[oldSize-i] = nil; diff --git a/Core/DolphinVM/ote.h b/Core/DolphinVM/ote.h index 104c12a829..c785f7ae58 100644 --- a/Core/DolphinVM/ote.h +++ b/Core/DolphinVM/ote.h @@ -42,8 +42,8 @@ union OTEFlags uint8_t m_pointer : 1; // Pointer bit? uint8_t m_mark : 1; // Garbage collector mark uint8_t m_finalize : 1; // Should the object be finalized - uint8_t m_weakOrZ : 1; // weak references if pointers, null term if bytes - uint8_t m_space : SPACEBITS; // Memory space in which the object resides (used when deallocating) + uint8_t m_weakOrZ : 1; // weak references if pointers, null term if bytes + uint8_t m_space : SPACEBITS; // Memory space in which the object resides (used when deallocating) }; uint8_t m_value; @@ -69,25 +69,25 @@ template class TOTE enum { MAXCOUNT = ((2<<(COUNTBITS-1))-1) }; enum { SizeMask = 0x7FFFFFFF, ImmutabilityBit = 0x80000000 }; - __forceinline MWORD getSize() const { return m_size & SizeMask; } - __forceinline void setSize(MWORD size) { m_size = size; } + __forceinline size_t getSize() const { return m_size & SizeMask; } + __forceinline void setSize(size_t size) { m_size = size; } - __forceinline MWORD getWordSize() const { return getSize()/sizeof(MWORD); } - __forceinline MWORD pointersSize() const { ASSERT(isPointers()); return getSize()/sizeof(MWORD); } - __forceinline int pointersSizeForUpdate() const { ASSERT(isPointers()); return static_cast(m_size)/static_cast(sizeof(MWORD)); } - __forceinline MWORD bytesSize() const { ASSERT(isBytes()); return getSize(); } - __forceinline int bytesSizeForUpdate() const { ASSERT(isBytes()); return m_size; } + __forceinline size_t getWordSize() const { return getSize()/sizeof(Oop); } + __forceinline size_t pointersSize() const { ASSERT(isPointers()); return getSize()/sizeof(Oop); } + __forceinline ptrdiff_t pointersSizeForUpdate() const { ASSERT(isPointers()); return static_cast(m_size)/static_cast(sizeof(Oop)); } + __forceinline size_t bytesSize() const { ASSERT(isBytes()); return getSize(); } + __forceinline ptrdiff_t bytesSizeForUpdate() const { ASSERT(isBytes()); return m_size; } // The size of a byte object can be one more than it pretends because of the hidden null terminator! // Answers actual byte (heap) size of the object pointed at by this OTE - __forceinline int sizeOf() const + __forceinline size_t sizeOf() const { // If we use getSize() here, it does not get inlined return getSize() + (isNullTerminated() * NULLTERMSIZE); } // The required size for this variable pointer object to accommodate the specified number of indexable fields - __forceinline MWORD pointerSizeFor(MWORD pointersRequested) { ASSERT(isPointers()); return pointersRequested + m_oteClass->m_location->fixedFields(); } + __forceinline size_t pointerSizeFor(size_t pointersRequested) { ASSERT(isPointers()); return pointersRequested + m_oteClass->m_location->fixedFields(); } __forceinline BOOL isSticky() const { return m_count == MAXCOUNT; } __forceinline void beSticky() { m_count = MAXCOUNT; } @@ -95,7 +95,7 @@ template class TOTE // Answer whether the receiver has the current mark __forceinline void setMark(uint8_t mark) { m_flags.m_mark = mark; } - __forceinline MWORD getIndex() const { return this - reinterpret_cast*>(ObjectMemory::m_pOT); } + __forceinline size_t getIndex() const { return this - reinterpret_cast*>(ObjectMemory::m_pOT); } __forceinline void countUp() { @@ -125,7 +125,7 @@ template class TOTE } __forceinline bool decRefs() { return (m_count != MAXCOUNT) && (--m_count == 0); } - __forceinline bool isImmutable() const { return static_cast(m_size) < 0; } + __forceinline bool isImmutable() const { return static_cast(m_size) < 0; } __forceinline void beImmutable() { m_size |= ImmutabilityBit; } __forceinline void beMutable() { m_size &= SizeMask; } __forceinline BOOL isFree() const { return m_flagsWord & OTEFlags::FreeMask; /*m_flags.m_free;*/ } @@ -165,7 +165,7 @@ template class TOTE T* m_location; // Pointer to array of elements which is the object BehaviorOTE* m_oteClass; // Class Oop // Size is now in the OTE too, if zero then m_location should be NULL - MWORD m_size; // In practice max size is maximum positive SmallInteger, i.e. 16r3FFFFFFF, around 1Mb + size_t m_size; // In practice max size is maximum positive SmallInteger, i.e. 16r3FFFFFFF, around 1Mb union { @@ -179,7 +179,7 @@ template class TOTE count_t m_count; hash_t m_idHash; // identity hash value (16-bit) }; - MWORD m_flagsWord; + uintptr_t m_flagsWord; }; }; diff --git a/Core/DolphinVM/primitiv.cpp b/Core/DolphinVM/primitiv.cpp index 99da00c7de..9268e1f02a 100644 --- a/Core/DolphinVM/primitiv.cpp +++ b/Core/DolphinVM/primitiv.cpp @@ -22,19 +22,19 @@ #include "STAssoc.h" #ifdef PROFILING - extern unsigned blocksInstantiated; - extern unsigned freeBlocks = 0; - extern unsigned contextsSuspended; + extern size_t blocksInstantiated; + extern size_t freeBlocks = 0; + extern size_t contextsSuspended; #endif /////////////////////////////////////////////////////////////////////////////// // Primitive Helper routines -Oop* __fastcall Interpreter::unusedPrimitive(Oop* const, unsigned) +Oop* __fastcall Interpreter::unusedPrimitive(Oop* const, primargcount_t) { // Note that the failure code is not set. #ifdef _DEBUG - int primitiveIndex = m_registers.m_oopNewMethod->m_location->m_header.primitiveIndex; + auto primitiveIndex = m_registers.m_oopNewMethod->m_location->m_header.primitiveIndex; TRACESTREAM << L"Unused primitive " << primitiveIndex << " in " << m_registers.m_oopNewMethod << std::endl; #endif @@ -91,7 +91,7 @@ Oop* __fastcall Interpreter::primitiveSize(Oop* const sp, primargcount_t) { // The primitive assumes it is never called for SmallIntegers. OTE* oteReceiver = reinterpret_cast(*sp); - MWORD bytesSize = oteReceiver->getSize(); + size_t bytesSize = oteReceiver->getSize(); if (oteReceiver->m_flags.m_pointer) { InstanceSpecification instSpec = oteReceiver->m_oteClass->m_location->m_instanceSpec; @@ -180,10 +180,10 @@ Oop* __fastcall Interpreter::primitiveResize(Oop* const sp, primargcount_t) if (!behavior->isIndexable()) return primitiveFailure(_PrimitiveFailureCode::ObjectTypeMismatch); - MWORD newPointerSize = newSize + behavior->fixedFields(); + size_t newPointerSize = static_cast(newSize) + behavior->fixedFields(); - int currentPointerSize = oteReceiver->pointersSizeForUpdate(); - if (currentPointerSize == (int)newPointerSize) + ptrdiff_t currentPointerSize = oteReceiver->pointersSizeForUpdate(); + if (currentPointerSize == (ptrdiff_t)newPointerSize) { // No change, succeed return sp - 1; @@ -204,8 +204,8 @@ Oop* __fastcall Interpreter::primitiveResize(Oop* const sp, primargcount_t) } else { - int currentByteSize = oteReceiver->bytesSizeForUpdate(); - if (currentByteSize == (int)newSize) + ptrdiff_t currentByteSize = oteReceiver->bytesSizeForUpdate(); + if (currentByteSize == static_cast(newSize)) { // No change, succeed return sp - 1; @@ -262,7 +262,7 @@ Oop* __fastcall Interpreter::primitiveChangeBehavior(Oop* const sp, primargcount // We must check class shapes the same, so compare instance spec. of receivers class with that of new class by xor'ing together // and then checking if any of the important shape bits are different - MWORD diff = receiverClass->m_instanceSpec.m_value ^ argClass->m_instanceSpec.m_value; + SmallUinteger diff = receiverClass->m_instanceSpec.m_value ^ argClass->m_instanceSpec.m_value; if ((diff & ~InstanceSpecification::IndirectMask) == 0) { @@ -284,9 +284,9 @@ Oop* __fastcall Interpreter::primitiveChangeBehavior(Oop* const sp, primargcount // Do instances of the new class contain pointers, if so fail if (!argClass->m_instanceSpec.m_pointers) { - BytesOTE* oteBytes = ObjectMemory::newByteObject(oteClassArg, sizeof(MWORD)); + BytesOTE* oteBytes = ObjectMemory::newByteObject(oteClassArg, sizeof(SmallUinteger)); oteClassArg->countUp(); - *reinterpret_cast(oteBytes->m_location->m_fields) = ObjectMemoryIntegerValueOf(receiver); + *reinterpret_cast(oteBytes->m_location->m_fields) = ObjectMemoryIntegerValueOf(receiver); // We've created a new object, so must replace the receiver at stack top *(sp - 1) = reinterpret_cast(oteBytes); @@ -430,7 +430,7 @@ Oop* __fastcall Interpreter::primitiveStackAtPut(Oop* const sp, primargcount_t) ProcessOTE* oteReceiver = reinterpret_cast(*(sp-2)); Process* receiverProcess = static_cast(oteReceiver->m_location); - if (static_cast(index) > receiverProcess->stackSize(oteReceiver)) + if (static_cast(index) > receiverProcess->stackSize(oteReceiver)) return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); Oop argPointer = *sp; @@ -500,9 +500,9 @@ Oop* __fastcall Interpreter::primitiveReplacePointers(Oop* const sp, primargcoun // this is the convention adopted by most implementations. // We can test that we're not going to write off the end of the argument - int length = argPointer->pointersSizeForUpdate(); + auto length = argPointer->pointersSizeForUpdate(); - unsigned toOffset = argPointer->m_oteClass->m_location->fixedFields(); + auto toOffset = argPointer->m_oteClass->m_location->fixedFields(); // Adjust to zero-based indices into variable fields of target stop = stop - 1 + toOffset; @@ -516,13 +516,13 @@ Oop* __fastcall Interpreter::primitiveReplacePointers(Oop* const sp, primargcoun PointersOTE* receiverPointer = reinterpret_cast(*(sp-4)); - int fromSize = receiverPointer->pointersSize(); - unsigned fromOffset = receiverPointer->m_oteClass->m_location->fixedFields(); + size_t fromSize = receiverPointer->pointersSize(); + auto fromOffset = receiverPointer->m_oteClass->m_location->fixedFields(); // Adjust to zero based index into variable fields of source startAt = startAt - 1 + fromOffset; - int stopAt = startAt + stop - start; - if (stopAt >= fromSize) + auto stopAt = startAt + stop - start; + if (stopAt >= static_cast(fromSize)) return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); // Only works for pointer objects @@ -535,7 +535,7 @@ Oop* __fastcall Interpreter::primitiveReplacePointers(Oop* const sp, primargcoun if (argPointer == receiverPointer && startAt < start) { // Need to do backwards - for (int i = stop - start; i >= 0; i--) + for (auto i = stop - start; i >= 0; i--) { ObjectMemory::storePointerWithValue(pTo[start + i], pFrom[startAt + i]); } @@ -543,7 +543,7 @@ Oop* __fastcall Interpreter::primitiveReplacePointers(Oop* const sp, primargcoun else { // Do forwards - for (int i = 0; i <= stop - start; i++) + for (auto i = 0; i <= stop - start; i++) { ObjectMemory::storePointerWithValue(pTo[start + i], pFrom[startAt + i]); } @@ -566,11 +566,11 @@ Oop* __fastcall Interpreter::primitiveBasicAt(Oop* const sp, const primargcount_ SmallInteger index = ObjectMemoryIntegerValueOf(oopIndex) - 1; if (oteReceiver->m_flags.m_pointer) { - MWORD size = oteReceiver->pointersSize(); - MWORD fixedFields = oteReceiver->m_oteClass->m_location->fixedFields(); + size_t size = oteReceiver->pointersSize(); + const auto fixedFields = oteReceiver->m_oteClass->m_location->fixedFields(); VariantObject* pointerObj = reinterpret_cast(oteReceiver)->m_location; - if (index >= 0 && (index + fixedFields) < size) + if (index >= 0 && static_cast(index) + fixedFields < size) { Oop field = pointerObj->m_fields[index + fixedFields]; *newSp = field; @@ -587,7 +587,7 @@ Oop* __fastcall Interpreter::primitiveBasicAt(Oop* const sp, const primargcount_ switch (ObjectMemory::GetBytesElementSize(reinterpret_cast(oteReceiver))) { case 1: - if (static_cast(index) < oteReceiver->bytesSize()) + if (static_cast(index) < oteReceiver->bytesSize()) { uint8_t value = reinterpret_cast(oteReceiver)->m_location->m_fields[index]; *newSp = ObjectMemoryIntegerObjectOf(value); @@ -596,7 +596,7 @@ Oop* __fastcall Interpreter::primitiveBasicAt(Oop* const sp, const primargcount_ break; case 2: - if (static_cast(index) < (oteReceiver->bytesSize() / 2)) + if (static_cast(index) < (oteReceiver->bytesSize() / 2)) { uint16_t value = reinterpret_cast(oteReceiver)->m_location->m_fields[index]; *newSp = ObjectMemoryIntegerObjectOf(value); @@ -605,7 +605,7 @@ Oop* __fastcall Interpreter::primitiveBasicAt(Oop* const sp, const primargcount_ break; case 4: - if (static_cast(index) < (oteReceiver->bytesSize() / 4)) + if (static_cast(index) < (oteReceiver->bytesSize() / 4)) { uint32_t value = reinterpret_cast(oteReceiver)->m_location->m_fields[index]; *newSp = ObjectMemoryIntegerObjectOf(value); @@ -644,8 +644,8 @@ Oop* __fastcall Interpreter::primitiveBasicAtPut(Oop* const sp, primargcount_t) { // Store into pointer object - int size = oteReceiver->pointersSizeForUpdate(); - int fixedFields = static_cast(oteReceiver->m_oteClass->m_location->fixedFields()); + const auto size = oteReceiver->pointersSizeForUpdate(); + const auto fixedFields = oteReceiver->m_oteClass->m_location->fixedFields(); VariantObject* pointerObj = reinterpret_cast(oteReceiver)->m_location; if (index + fixedFields < size) @@ -675,13 +675,13 @@ Oop* __fastcall Interpreter::primitiveBasicAtPut(Oop* const sp, primargcount_t) Oop oopValue = *sp; if (ObjectMemoryIsIntegerObject(oopValue)) { - const MWORD newValue = ObjectMemoryIntegerValueOf(oopValue); - const int size = oteReceiver->bytesSizeForUpdate(); + const SmallUinteger newValue = ObjectMemoryIntegerValueOf(oopValue); + const auto size = oteReceiver->bytesSizeForUpdate(); switch (ObjectMemory::GetBytesElementSize(reinterpret_cast(oteReceiver))) { case 1: - if (newValue <= 0xFF) + if (newValue <= UINT8_MAX) { if (index < size) { @@ -698,7 +698,7 @@ Oop* __fastcall Interpreter::primitiveBasicAtPut(Oop* const sp, primargcount_t) return primitiveFailure(_PrimitiveFailureCode::IntegerOutOfRange); case 2: - if (newValue <= 0xFFFF) + if (newValue <= UINT16_MAX) { if (index < (size / 2)) { @@ -755,10 +755,10 @@ Oop* __fastcall Interpreter::primitiveInstVarAt(Oop* const sp, primargcount_t) SmallInteger index = ObjectMemoryIntegerValueOf(oopIndex) - 1; if (oteReceiver->m_flags.m_pointer) { - MWORD size = oteReceiver->pointersSize(); + size_t size = oteReceiver->pointersSize(); VariantObject* pointerObj = reinterpret_cast(oteReceiver)->m_location; - if (static_cast(index) < size) + if (static_cast(index) < size) { Oop field = pointerObj->m_fields[index]; *newSp = field; @@ -772,7 +772,7 @@ Oop* __fastcall Interpreter::primitiveInstVarAt(Oop* const sp, primargcount_t) switch (ObjectMemory::GetBytesElementSize(reinterpret_cast(oteReceiver))) { case 1: - if (static_cast(index) < oteReceiver->bytesSize()) + if (static_cast(index) < oteReceiver->bytesSize()) { uint8_t value = reinterpret_cast(oteReceiver)->m_location->m_fields[index]; *newSp = ObjectMemoryIntegerObjectOf(value); @@ -781,7 +781,7 @@ Oop* __fastcall Interpreter::primitiveInstVarAt(Oop* const sp, primargcount_t) break; case 2: - if (static_cast(index) < (oteReceiver->bytesSize() / 2)) + if (static_cast(index) < (oteReceiver->bytesSize() / 2)) { uint16_t value = reinterpret_cast(oteReceiver)->m_location->m_fields[index]; *newSp = ObjectMemoryIntegerObjectOf(value); @@ -790,7 +790,7 @@ Oop* __fastcall Interpreter::primitiveInstVarAt(Oop* const sp, primargcount_t) break; case 4: - if (static_cast(index) < (oteReceiver->bytesSize() / 4)) + if (static_cast(index) < (oteReceiver->bytesSize() / 4)) { uint32_t value = reinterpret_cast(oteReceiver)->m_location->m_fields[index]; *newSp = ObjectMemoryIntegerObjectOf(value); @@ -826,7 +826,7 @@ Oop* __fastcall Interpreter::primitiveInstVarAtPut(Oop* const sp, primargcount_t { // Store into pointer object - int size = oteReceiver->pointersSizeForUpdate(); + ptrdiff_t size = oteReceiver->pointersSizeForUpdate(); VariantObject* pointerObj = reinterpret_cast(oteReceiver)->m_location; if (index < size) @@ -852,13 +852,13 @@ Oop* __fastcall Interpreter::primitiveInstVarAtPut(Oop* const sp, primargcount_t Oop oopValue = *sp; if (ObjectMemoryIsIntegerObject(oopValue)) { - const MWORD newValue = ObjectMemoryIntegerValueOf(oopValue); - const int size = oteReceiver->bytesSizeForUpdate(); + const SmallUinteger newValue = ObjectMemoryIntegerValueOf(oopValue); + const ptrdiff_t size = oteReceiver->bytesSizeForUpdate(); switch (ObjectMemory::GetBytesElementSize(reinterpret_cast(oteReceiver))) { case 1: - if (newValue <= 0xFF) + if (newValue <= UINT8_MAX) { if (index < size) { @@ -875,7 +875,7 @@ Oop* __fastcall Interpreter::primitiveInstVarAtPut(Oop* const sp, primargcount_t return primitiveFailure(_PrimitiveFailureCode::IntegerOutOfRange); case 2: - if (newValue <= 0xFFFF) + if (newValue <= UINT16_MAX) { if (index < (size / 2)) { diff --git a/Core/DolphinVM/process.cpp b/Core/DolphinVM/process.cpp index fdb3e0553a..de807cfd2f 100644 --- a/Core/DolphinVM/process.cpp +++ b/Core/DolphinVM/process.cpp @@ -237,8 +237,9 @@ Oop* __fastcall Interpreter::primitiveEnableInterrupts(Oop* const sp, primargcou } /////////////////////////////////////////////////////////////////////////////// -// Signal a Semaphore without regard to the execution state. The Semaphore will be properly -SemaphoreOTE* Semaphore::New(int sigs) +// Answer a new Semaphore, with the specified number of initial signals + +SemaphoreOTE* Semaphore::New(SmallInteger sigs) { SemaphoreOTE* oteSem = reinterpret_cast(ObjectMemory::newPointerObject(Pointers.ClassSemaphore)); Semaphore* sem = oteSem->m_location; @@ -433,7 +434,7 @@ void Interpreter::Yield() // Yield to the Processes of the same or higher priority than the current active process // Answers whether a process switch occurred -Oop* __fastcall Interpreter::primitiveYield(Oop* const, unsigned) +Oop* __fastcall Interpreter::primitiveYield(Oop* const, primargcount_t) { Yield(); return m_registers.m_stackPointer; @@ -447,9 +448,9 @@ ProcessOTE* Interpreter::wakeHighestPriority() ProcessorScheduler* scheduler = (ProcessorScheduler*)Pointers.Scheduler->m_location; ArrayOTE* oteLists = scheduler->m_processLists; HARDASSERT(oteLists->m_oteClass == Pointers.ClassArray); - unsigned highestPriority = oteLists->pointersSize(); + size_t highestPriority = oteLists->pointersSize(); Array* processLists = oteLists->m_location; - unsigned index = highestPriority; + size_t index = highestPriority; LinkedList* pProcessList; do { @@ -892,8 +893,8 @@ int Interpreter::highestWaitingPriority() ArrayOTE* oteLists = scheduler->m_processLists; Array* processLists = oteLists->m_location; - unsigned highestPriority = oteLists->pointersSize(); - unsigned index = highestPriority; + size_t highestPriority = oteLists->pointersSize(); + size_t index = highestPriority; LinkedList* pProcessList; do { @@ -968,7 +969,7 @@ LinkedListOTE* Interpreter::ResuspendProcessOn(ProcessOTE* oteProcess, LinkedLis // to avoid incorrectly suspending the process Semaphore* sem = static_cast(oteList->m_location); HARDASSERT(ObjectMemoryIsIntegerObject(sem->m_excessSignals)); - int excessSignals = ObjectMemoryIntegerValueOf(sem->m_excessSignals); + auto excessSignals = ObjectMemoryIntegerValueOf(sem->m_excessSignals); if (excessSignals > 0) { @@ -999,7 +1000,7 @@ LinkedListOTE* Interpreter::ResuspendProcessOn(ProcessOTE* oteProcess, LinkedLis CHECKREFERENCES - return oteList; + return oteList; } BOOL __stdcall Interpreter::Reschedule() @@ -1350,19 +1351,6 @@ BOOL Interpreter::FastYield() return FALSE; } -/* -/////////////////////////////////////////////////////////////////////////////// -// Answer a new Semaphore, with the specified number of initial signals - -OTE* Semaphore::New(int initSignals) -{ - SemaphoreOTE* pAnswer = ObjectMemory::instantiateClassWithPointers(Pointers.ClassSemaphore); - Semaphore* sem = pAnswer->m_location; - sem->m_excessSignals = ObjectMemoryIntegerObjectOf(initSignals); - return pAnswer; -} -*/ - DWORD Semaphore::Wait(SemaphoreOTE* oteThis, ProcessOTE* oteProcess, int timeout) { if (!ObjectMemoryIsIntegerObject(m_excessSignals)) @@ -1631,7 +1619,7 @@ Oop* __fastcall Interpreter::primitiveTerminateProcess(Oop* const sp, primargcou return primitiveSuccess(0); } -Oop* __fastcall Interpreter::primitiveUnwindInterrupt(Oop* const, unsigned) +Oop* __fastcall Interpreter::primitiveUnwindInterrupt(Oop* const, primargcount_t) { // Terminate any overlapped call outstanding for the process, this may need to suspend the process // and so this may cause a context switch diff --git a/Core/DolphinVM/realloc.cpp b/Core/DolphinVM/realloc.cpp index ea52dcca7e..f74eab618f 100755 --- a/Core/DolphinVM/realloc.cpp +++ b/Core/DolphinVM/realloc.cpp @@ -26,7 +26,7 @@ // These map directly onto C or Win32 heap -inline POBJECT ObjectMemory::reallocChunk(POBJECT pChunk, MWORD newChunkSize) +inline POBJECT ObjectMemory::reallocChunk(POBJECT pChunk, size_t newChunkSize) { #if defined(_DEBUG) if (__sbh_find_block(pChunk) != NULL) @@ -34,8 +34,8 @@ inline POBJECT ObjectMemory::reallocChunk(POBJECT pChunk, MWORD newChunkSize) ASSERT(FALSE); else { - for (int i=0;i(pChunk))); + for (auto i=0;i(pChunk))); } #endif @@ -103,7 +103,7 @@ template POBJECT ObjectMemory::basicResize(POTE ote, size_t byteS pObject = allocSmallChunk(byteSize+Extra); POBJECT pOldObject = ote->m_location; - MWORD oldSize = ote->getSize(); + auto oldSize = ote->getSize(); memcpy(pObject, pOldObject, min(oldSize, byteSize)); freeSmallChunk(pOldObject, ote->sizeOf()); ote->m_location = pObject; @@ -130,17 +130,17 @@ template POBJECT ObjectMemory::basicResize(POTE ote, size_t byteS // Resize an object in VirtualSpace (commit/decommit some memory) // N.B. Assumes that there are no ref. counted object above shrinkTo (primarily intended for // Process stacks) -POBJECT ObjectMemory::resizeVirtual(OTE* ote, MWORD newByteSize) +POBJECT ObjectMemory::resizeVirtual(OTE* ote, size_t newByteSize) { ASSERT(ote->heapSpace() == OTEFlags::VirtualSpace); VariantObject* pObject = static_cast(ote->m_location); VirtualObject* pVObj = reinterpret_cast(pObject); VirtualObjectHeader* pBase = pVObj->getHeader(); - unsigned maxByteSize = pBase->getMaxAllocation(); maxByteSize; - unsigned currentTotalByteSize = pBase->getCurrentAllocation(); + size_t maxByteSize = pBase->getMaxAllocation(); maxByteSize; + size_t currentTotalByteSize = pBase->getCurrentAllocation(); ASSERT(_ROUND2(currentTotalByteSize, dwPageSize) == currentTotalByteSize); - unsigned newTotalByteSize = _ROUND2(newByteSize + sizeof(VirtualObjectHeader), dwPageSize); + auto newTotalByteSize = _ROUND2(newByteSize + sizeof(VirtualObjectHeader), dwPageSize); // Minimum virtual allocation is one page (4k normally) ASSERT(newTotalByteSize >= dwPageSize); @@ -148,7 +148,7 @@ POBJECT ObjectMemory::resizeVirtual(OTE* ote, MWORD newByteSize) { // The object is increasing in size - commit some more memory ASSERT(newByteSize <= maxByteSize); - unsigned allocSize = newTotalByteSize - currentTotalByteSize; + size_t allocSize = newTotalByteSize - currentTotalByteSize; ASSERT(_ROUND2(allocSize, dwPageSize) == allocSize); if (!::VirtualAlloc(reinterpret_cast(pBase) + currentTotalByteSize, allocSize, MEM_COMMIT, PAGE_READWRITE)) return 0; // Request to resize failed @@ -157,9 +157,9 @@ POBJECT ObjectMemory::resizeVirtual(OTE* ote, MWORD newByteSize) { const Behavior* behavior = ote->m_oteClass->m_location; behavior; // The object is shrinking - decommit some memory - ASSERT(newByteSize > (ObjectHeaderSize+behavior->fixedFields())*sizeof(MWORD)); + ASSERT(newByteSize > (ObjectHeaderSize+behavior->fixedFields())*sizeof(Oop)); - MWORD* pCeiling = reinterpret_cast(reinterpret_cast(pBase) + newTotalByteSize); + auto pCeiling = reinterpret_cast(reinterpret_cast(pBase) + newTotalByteSize); // Determine the size of the committed region above shrinkTo MEMORY_BASIC_INFORMATION mbi; @@ -186,14 +186,14 @@ POBJECT ObjectMemory::resizeVirtual(OTE* ote, MWORD newByteSize) /////////////////////////////////////////////////////////////////////////////// // Safe public resizing functions. -VariantByteObject* ObjectMemory::resize(BytesOTE* ote, MWORD newByteSize) +VariantByteObject* ObjectMemory::resize(BytesOTE* ote, size_t newByteSize) { ASSERT(!ObjectMemoryIsIntegerObject(ote) && ote->isBytes()); - MWORD totalByteSize = newByteSize + SizeOfPointers(0); // Add header size + auto totalByteSize = newByteSize + SizeOfPointers(0); // Add header size - VariantByteObject* pByteObj = ote->m_location; - MWORD oldByteSize = ote->getSize(); + auto pByteObj = ote->m_location; + auto oldByteSize = ote->getSize(); if (ote->isNullTerminated()) { @@ -214,18 +214,18 @@ VariantByteObject* ObjectMemory::resize(BytesOTE* ote, MWORD newByteSize) return pByteObj; } -VariantObject* ObjectMemory::resize(PointersOTE* ote, MWORD newPointers, bool bRefCount) +VariantObject* ObjectMemory::resize(PointersOTE* ote, size_t newPointers, bool bRefCount) { ASSERT(!ObjectMemoryIsIntegerObject(ote) && ote->isPointers()); VariantObject* pObj = ote->m_location; - const MWORD oldPointers = ote->pointersSize(); + const auto oldPointers = ote->pointersSize(); // If resizing the active process, then we don't do any ref. counting as refs from // the current stack are not counted (we used deferred ref. counting) if (bRefCount) { - for (MWORD i=newPointers;im_fields[i]); } @@ -239,7 +239,7 @@ VariantObject* ObjectMemory::resize(PointersOTE* ote, MWORD newPointers, bool bR // Initialize any new pointers to Nil (indices must fit in a SmallInteger) const Oop nil = Oop(Pointers.Nil); - for (MWORD i=oldPointers; im_fields[i] = nil; } diff --git a/Core/DolphinVM/strgprim.cpp b/Core/DolphinVM/strgprim.cpp index cace625765..4c47ac336d 100644 --- a/Core/DolphinVM/strgprim.cpp +++ b/Core/DolphinVM/strgprim.cpp @@ -31,7 +31,7 @@ CHAR Interpreter::m_unicodeToAnsiCharMap[65536]; #pragma comment(lib, "icuuc.lib") -CharOTE* Character::NewUnicode(uint32_t value) +CharOTE* Character::NewUnicode(char32_t value) { if (__isascii(value)) { @@ -47,7 +47,7 @@ CharOTE* Character::NewUnicode(uint32_t value) } CharOTE* character = reinterpret_cast(ObjectMemory::newPointerObject(Pointers.ClassCharacter)); - MWORD code = (static_cast(StringEncoding::Utf32) << 24) | value; + SmallInteger code = (static_cast(StringEncoding::Utf32) << 24) | (value & 0xffffff); character->m_location->m_code = ObjectMemoryIntegerObjectOf(code); character->beImmutable(); @@ -59,11 +59,11 @@ CharOTE* Character::NewUnicode(uint32_t value) CharOTE* Character::NewAnsi(unsigned char value) { CharOTE* character = reinterpret_cast(ObjectMemory::PointerFromIndex(ObjectMemory::FirstCharacterIdx + value)); - ASSERT(ObjectMemoryIntegerValueOf(character->m_location->m_code) == ((static_cast(StringEncoding::Ansi) << 24) | value)); + ASSERT(ObjectMemoryIntegerValueOf(character->m_location->m_code) == ((static_cast(StringEncoding::Ansi) << 24) | value)); return character; } -uint32_t Character::getCodePoint() const +char32_t Character::getCodePoint() const { // For UTF surrogates, this won't actually be a valid code point @@ -146,7 +146,7 @@ Oop* __fastcall Interpreter::primitiveReplaceBytes(Oop* const sp, primargcount_t else { // We can test that we're not going to write off the end of the argument - int length = argPointer->bytesSizeForUpdate(); + auto length = argPointer->bytesSizeForUpdate(); // We can only be in here if stop>=start, so => stop-start >= 0 // therefore if startAt >= 1 then => stopAt >= 1, for similar @@ -164,10 +164,10 @@ Oop* __fastcall Interpreter::primitiveReplaceBytes(Oop* const sp, primargcount_t // Now validate that the interval specified for copying from the receiver // is within the bounds of the receiver (we've already tested startAt) { - int length = receiverPointer->bytesSize(); + ptrdiff_t length = receiverPointer->bytesSize(); // We can only be in here if stop>=start, so if start>=1, then => stop >= 1 // furthermore if stop <= length then => start <= length - int stopAt = startAt+stop-start; + ptrdiff_t stopAt = startAt+stop-start; if (stopAt > length) return primitiveFailure(_PrimitiveFailureCode::OutOfBounds); } @@ -346,12 +346,12 @@ Oop* __fastcall Interpreter::primitiveStringAt(Oop* const sp, const primargcount SmallInteger oopIndex = *(newSp + 1); if (ObjectMemoryIsIntegerObject(oopIndex)) { - int index = ObjectMemoryIntegerValueOf(oopIndex) - 1; + SmallInteger index = ObjectMemoryIntegerValueOf(oopIndex) - 1; AnsiStringOTE* oteReceiver = reinterpret_cast(*newSp); switch (String::GetEncoding(oteReceiver)) { case StringEncoding::Ansi: - if (static_cast(index) < oteReceiver->bytesSize()) + if (static_cast(index) < oteReceiver->bytesSize()) { AnsiString::CU codeUnit = oteReceiver->m_location->m_characters[index]; *newSp = reinterpret_cast(Character::NewAnsi(codeUnit)); @@ -361,7 +361,7 @@ Oop* __fastcall Interpreter::primitiveStringAt(Oop* const sp, const primargcount case StringEncoding::Utf8: { - if (static_cast(index) < oteReceiver->bytesSize()) + if (static_cast(index) < oteReceiver->bytesSize()) { Utf8String::CU codeUnit = reinterpret_cast(oteReceiver->m_location)->m_characters[index]; @@ -376,7 +376,7 @@ Oop* __fastcall Interpreter::primitiveStringAt(Oop* const sp, const primargcount { // Otherwise return a UTF-8 surrogate Character CharOTE* character = reinterpret_cast(ObjectMemory::newPointerObject(Pointers.ClassCharacter)); - MWORD code = (static_cast(StringEncoding::Utf8) << 24) | codeUnit; + SmallInteger code = (static_cast(StringEncoding::Utf8) << 24) | codeUnit; character->m_location->m_code = ObjectMemoryIntegerObjectOf(code); character->beImmutable(); *newSp = reinterpret_cast(character); @@ -389,10 +389,10 @@ Oop* __fastcall Interpreter::primitiveStringAt(Oop* const sp, const primargcount case StringEncoding::Utf16: { - if (static_cast(index) < (oteReceiver->bytesSize() / sizeof(Utf16String::CU))) + if (static_cast(index) < (oteReceiver->bytesSize() / sizeof(Utf16String::CU))) { Utf16String::CU codeUnit = reinterpret_cast(oteReceiver->m_location)->m_characters[index]; - MWORD code; + SmallInteger code; // If not a surrogate, may have an ANSI character that can represent the code point if (!U_IS_SURROGATE(codeUnit)) @@ -406,12 +406,12 @@ Oop* __fastcall Interpreter::primitiveStringAt(Oop* const sp, const primargcount } // Non-ansi, non-surrogate, so return a full UTF-32 Character - code = (static_cast(StringEncoding::Utf32) << 24) | codeUnit; + code = (static_cast(StringEncoding::Utf32) << 24) | codeUnit; } else { // Return a UTF-16 Character for surrogates so it is possible to detect surrogates in the image - code = (static_cast(StringEncoding::Utf16) << 24) | codeUnit; + code = (static_cast(StringEncoding::Utf16) << 24) | codeUnit; } CharOTE* character = reinterpret_cast(ObjectMemory::newPointerObject(Pointers.ClassCharacter)); @@ -427,7 +427,7 @@ Oop* __fastcall Interpreter::primitiveStringAt(Oop* const sp, const primargcount case StringEncoding::Utf32: { - if (static_cast(index) < (oteReceiver->bytesSize() / sizeof(Utf32String::CU))) + if (static_cast(index) < (oteReceiver->bytesSize() / sizeof(Utf32String::CU))) { Utf32String::CU codePoint = reinterpret_cast(oteReceiver->m_location)->m_characters[index]; @@ -445,7 +445,7 @@ Oop* __fastcall Interpreter::primitiveStringAt(Oop* const sp, const primargcount // Otherwise return a full UTF-32 Character CharOTE* character = reinterpret_cast(ObjectMemory::newPointerObject(Pointers.ClassCharacter)); - MWORD code = (static_cast(StringEncoding::Utf32) << 24) | codePoint; + SmallInteger code = (static_cast(StringEncoding::Utf32) << 24) | codePoint; character->m_location->m_code = ObjectMemoryIntegerObjectOf(code); character->beImmutable(); *newSp = reinterpret_cast(character); @@ -484,8 +484,8 @@ Oop* __fastcall Interpreter::primitiveStringAtPut(Oop* const sp, primargcount_t) const Oop oopValue = *sp; if (!ObjectMemoryIsIntegerObject(oopValue) && reinterpret_cast(oopValue)->m_oteClass == Pointers.ClassCharacter) { - MWORD code = ObjectMemoryIntegerValueOf(reinterpret_cast(oopValue)->m_location->m_code); - MWORD codeUnit = code & 0x1fffff; + SmallInteger code = ObjectMemoryIntegerValueOf(reinterpret_cast(oopValue)->m_location->m_code); + char32_t codeUnit = code & 0x1fffff; switch (ST::String::GetEncoding(oteReceiver)) { @@ -549,7 +549,7 @@ Oop* __fastcall Interpreter::primitiveStringAtPut(Oop* const sp, primargcount_t) break; case StringEncoding::Utf8: - if (index < receiverSize / static_cast(sizeof(Utf8String::CU))) + if (index < receiverSize / static_cast(sizeof(Utf8String::CU))) { Utf8String::CU* psz = reinterpret_cast(oteReceiver)->m_location->m_characters; @@ -565,7 +565,7 @@ Oop* __fastcall Interpreter::primitiveStringAtPut(Oop* const sp, primargcount_t) break; case StringEncoding::Utf16: - if (index < receiverSize / static_cast(sizeof(Utf16String::CU))) + if (index < receiverSize / static_cast(sizeof(Utf16String::CU))) { Utf16String::CU* psz = reinterpret_cast(oteReceiver)->m_location->m_characters; @@ -619,7 +619,7 @@ Oop* __fastcall Interpreter::primitiveStringAtPut(Oop* const sp, primargcount_t) break; case StringEncoding::Utf32: - if (index < receiverSize / static_cast(sizeof(Utf32String::CU))) + if (index < receiverSize / static_cast(sizeof(Utf32String::CU))) { Utf32String::CU* const __restrict psz = reinterpret_cast(oteReceiver)->m_location->m_characters; @@ -693,7 +693,7 @@ Oop* __fastcall Interpreter::primitiveStringAtPut(Oop* const sp, primargcount_t) } } -void Interpreter::PushCharacter(Oop* const sp, MWORD codePoint) +void Interpreter::PushCharacter(Oop* const sp, char32_t codePoint) { ASSERT(U_IS_UNICODE_CHAR(codePoint)); @@ -717,7 +717,7 @@ void Interpreter::PushCharacter(Oop* const sp, MWORD codePoint) // Otherwise represent as new Character with a Utf32 encoding (i.e. as the Unicode code point) CharOTE* character = reinterpret_cast(ObjectMemory::newPointerObject(Pointers.ClassCharacter)); - MWORD code = (static_cast(StringEncoding::Utf32) << 24) | codePoint; + SmallInteger code = (static_cast(StringEncoding::Utf32) << 24) | codePoint; character->m_location->m_code = ObjectMemoryIntegerObjectOf(code); character->beImmutable(); *sp = reinterpret_cast(character); @@ -815,7 +815,7 @@ Oop* Interpreter::primitiveBytesEqual(Oop* const sp, primargcount_t) if (oteArg->m_oteClass == oteReceiver->m_oteClass) { ASSERT(oteArg->isBytes()); - MWORD argSize = oteArg->bytesSize(); + size_t argSize = oteArg->bytesSize(); Oop answer = reinterpret_cast(Pointers.False); if (argSize == oteReceiver->bytesSize()) { @@ -876,7 +876,7 @@ Oop* __fastcall Interpreter::primitiveHashBytes(Oop* const sp, primargcount_t) // Assume some kind of Ansi string Utf8StringOTE * utf8 = Utf8String::NewFromAnsi( reinterpret_cast(receiver)->m_location->m_characters, receiver->bytesSize()); - MWORD hash = hashBytes(utf8->m_location->m_characters, utf8->bytesSize()); + SmallInteger hash = hashBytes(utf8->m_location->m_characters, utf8->bytesSize()); *sp = ObjectMemoryIntegerObjectOf(hash); ObjectMemory::deallocateByteObject(reinterpret_cast(utf8)); return sp; @@ -884,7 +884,7 @@ Oop* __fastcall Interpreter::primitiveHashBytes(Oop* const sp, primargcount_t) case StringEncoding::Utf8: { - MWORD hash = hashBytes(reinterpret_cast(receiver)->m_location->m_characters, receiver->bytesSize()); + SmallInteger hash = hashBytes(reinterpret_cast(receiver)->m_location->m_characters, receiver->bytesSize()); *sp = ObjectMemoryIntegerObjectOf(hash); return sp; } @@ -893,7 +893,7 @@ Oop* __fastcall Interpreter::primitiveHashBytes(Oop* const sp, primargcount_t) { Utf8StringOTE* utf8 = Utf8String::New( reinterpret_cast(receiver)->m_location->m_characters, receiver->getSize() / sizeof(Utf16String::CU)); - MWORD hash = hashBytes(utf8->m_location->m_characters, utf8->bytesSize()); + SmallInteger hash = hashBytes(utf8->m_location->m_characters, utf8->bytesSize()); *sp = ObjectMemoryIntegerObjectOf(hash); ObjectMemory::deallocateByteObject(reinterpret_cast(utf8)); return sp; @@ -908,13 +908,13 @@ Oop* __fastcall Interpreter::primitiveHashBytes(Oop* const sp, primargcount_t) } else { - MWORD hash = hashBytes(receiver->m_location->m_fields, receiver->bytesSize()); + SmallInteger hash = hashBytes(receiver->m_location->m_fields, receiver->bytesSize()); *sp = ObjectMemoryIntegerObjectOf(hash); return sp; } } -extern "C" MWORD __cdecl HashBytes(const uint8_t* bytes, MWORD size) +extern "C" SmallInteger __cdecl HashBytes(const uint8_t* bytes, size_t size) { return bytes != nullptr ? hashBytes(bytes, size) : 0; } @@ -960,7 +960,7 @@ Utf16StringOTE * ST::Utf16String::New(size_t cwch) return reinterpret_cast(ObjectMemory::newUninitializedNullTermObject(cwch * sizeof(Utf16String::CU))); } -Oop * Interpreter::primitiveStringAsUtf8String(Oop * const sp, unsigned) +Oop * Interpreter::primitiveStringAsUtf8String(Oop * const sp, primargcount_t) { const OTE* receiver = reinterpret_cast(*sp); BehaviorOTE* oteClass = receiver->m_oteClass; @@ -1109,8 +1109,8 @@ Oop* Interpreter::primitiveStringConcatenate(Oop* const sp, primargcount_t) { case ENCODINGPAIR(StringEncoding::Ansi, StringEncoding::Ansi): { - MWORD cbPrefix = oteReceiver->getSize(); - MWORD cbSuffix = oteArg->getSize(); + size_t cbPrefix = oteReceiver->getSize(); + size_t cbSuffix = oteArg->getSize(); auto oteAnswer = AnsiString::New(cbPrefix + cbSuffix); LPSTR psz = reinterpret_cast(oteAnswer)->m_location->m_characters; memcpy(psz, reinterpret_cast(oteReceiver)->m_location->m_characters, cbPrefix); @@ -1122,8 +1122,8 @@ Oop* Interpreter::primitiveStringConcatenate(Oop* const sp, primargcount_t) case ENCODINGPAIR(StringEncoding::Utf8, StringEncoding::Utf8): { - MWORD cbPrefix = oteReceiver->getSize(); - MWORD cbSuffix = oteArg->getSize(); + size_t cbPrefix = oteReceiver->getSize(); + size_t cbSuffix = oteArg->getSize(); auto oteAnswer = Utf8String::New(cbPrefix + cbSuffix); auto psz = oteAnswer->m_location->m_characters; memcpy(psz, reinterpret_cast(oteReceiver)->m_location->m_characters, cbPrefix); @@ -1138,7 +1138,7 @@ Oop* Interpreter::primitiveStringConcatenate(Oop* const sp, primargcount_t) // Ansi, UTF-8 => UTF-8; but we have to translate to translate via UTF16 Utf16StringBuf utf16(m_ansiCodePage, reinterpret_cast(oteReceiver)->m_location->m_characters, oteReceiver->getSize()); size_t cbPrefix = utf16.ToUtf8(); - MWORD cbSuffix = oteArg->getSize(); + size_t cbSuffix = oteArg->getSize(); auto oteAnswer = Utf8String::New(cbPrefix + cbSuffix); auto psz = oteAnswer->m_location->m_characters; utf16.ToUtf8(psz, cbPrefix); @@ -1152,10 +1152,10 @@ Oop* Interpreter::primitiveStringConcatenate(Oop* const sp, primargcount_t) { // Ansi, UTF-16 => UTF-16 LPCSTR pszReceiver = reinterpret_cast(oteReceiver)->m_location->m_characters; - MWORD cchReceiver = oteReceiver->getSize(); + size_t cchReceiver = oteReceiver->getSize(); int cwchPrefix = ::MultiByteToWideChar(m_ansiCodePage, 0, pszReceiver, cchReceiver, nullptr, 0); - MWORD cbSuffix = oteArg->getSize(); - MWORD cwchSuffix = cbSuffix / sizeof(Utf16String::CU); + size_t cbSuffix = oteArg->getSize(); + size_t cwchSuffix = cbSuffix / sizeof(Utf16String::CU); auto oteAnswer = Utf16String::New(cwchPrefix + cwchSuffix); Utf16String::CU* pwszAnswer = oteAnswer->m_location->m_characters; ::MultiByteToWideChar(m_ansiCodePage, 0, pszReceiver, cchReceiver, (LPWSTR)pwszAnswer, cwchPrefix); @@ -1172,8 +1172,8 @@ Oop* Interpreter::primitiveStringConcatenate(Oop* const sp, primargcount_t) Utf16StringBuf utf16(m_ansiCodePage, reinterpret_cast(oteArg)->m_location->m_characters, oteArg->getSize()); size_t cbSuffix = utf16.ToUtf8(); - MWORD cbPrefix = oteReceiver->getSize(); - MWORD cbAnswer = cbPrefix + cbSuffix; + size_t cbPrefix = oteReceiver->getSize(); + size_t cbAnswer = cbPrefix + cbSuffix; auto oteAnswer = Utf8String::New(cbAnswer); Utf8String::CU* psz = oteAnswer->m_location->m_characters; memcpy(psz, reinterpret_cast(oteReceiver)->m_location->m_characters, cbPrefix); @@ -1189,10 +1189,10 @@ Oop* Interpreter::primitiveStringConcatenate(Oop* const sp, primargcount_t) // Since both encodings can represent any string, we return a result that is the same class as the receiver, i.e. // UTF-8, Utf16 => UTF-8 const Utf16String::CU* pArgChars = reinterpret_cast(oteArg)->m_location->m_characters; - MWORD cwchSuffix = oteArg->getSize() / sizeof(Utf16String::CU); + size_t cwchSuffix = oteArg->getSize() / sizeof(Utf16String::CU); int cbSuffix = ::WideCharToMultiByte(CP_UTF8, 0, (LPCWCH)pArgChars, cwchSuffix, nullptr, 0, nullptr, nullptr); ASSERT(cbSuffix >= 0); - MWORD cbPrefix = oteReceiver->getSize(); + size_t cbPrefix = oteReceiver->getSize(); auto oteAnswer = Utf8String::New(cbPrefix + cbSuffix); Utf8String::CU* psz = oteAnswer->m_location->m_characters; memcpy(psz, reinterpret_cast(oteReceiver)->m_location->m_characters, cbPrefix); @@ -1206,11 +1206,11 @@ Oop* Interpreter::primitiveStringConcatenate(Oop* const sp, primargcount_t) { // Ansi, UTF-16 => UTF-16 LPCSTR pszArg = reinterpret_cast(oteArg)->m_location->m_characters; - MWORD cchArg = oteArg->getSize(); + size_t cchArg = oteArg->getSize(); int cwchSuffix = ::MultiByteToWideChar(m_ansiCodePage, 0, pszArg, cchArg, nullptr, 0); ASSERT(cwchSuffix >= 0); - MWORD cbPrefix = oteReceiver->getSize(); - MWORD cwchPrefix = cbPrefix / sizeof(Utf16String::CU); + size_t cbPrefix = oteReceiver->getSize(); + size_t cwchPrefix = cbPrefix / sizeof(Utf16String::CU); auto oteAnswer = Utf16String::New(cwchPrefix + cwchSuffix); Utf16String::CU* pwsz = oteAnswer->m_location->m_characters; memcpy(pwsz, reinterpret_cast(oteReceiver)->m_location->m_characters, cbPrefix); @@ -1225,10 +1225,10 @@ Oop* Interpreter::primitiveStringConcatenate(Oop* const sp, primargcount_t) // Since both encodings can represent any string, we return a result that is the same class as the receiver, i.e. // UTF-16, Utf8 => UTF-16 auto pszArg = reinterpret_cast(oteArg)->m_location->m_characters; - MWORD cbArg = oteArg->getSize(); + size_t cbArg = oteArg->getSize(); int cwchSuffix = ::MultiByteToWideChar(CP_UTF8, 0, reinterpret_cast(pszArg), cbArg, nullptr, 0); - int cbPrefix = oteReceiver->getSize(); - int cwchPrefix = cbPrefix / sizeof(Utf16String::CU); + size_t cbPrefix = oteReceiver->getSize(); + size_t cwchPrefix = cbPrefix / sizeof(Utf16String::CU); auto oteAnswer = Utf16String::New(cwchPrefix + cwchSuffix); Utf16String::CU* pwszAnswer = oteAnswer->m_location->m_characters; const Utf16String::CU* pwszReceiver = reinterpret_cast(oteReceiver)->m_location->m_characters; @@ -1242,8 +1242,8 @@ Oop* Interpreter::primitiveStringConcatenate(Oop* const sp, primargcount_t) case ENCODINGPAIR(StringEncoding::Utf16, StringEncoding::Utf16): { // UTF-16, UTF-16 => UTF-16 - MWORD cbPrefix = oteReceiver->getSize(); - MWORD cbSuffix = oteArg->getSize(); + size_t cbPrefix = oteReceiver->getSize(); + size_t cbSuffix = oteArg->getSize(); Utf16StringOTE* oteAnswer = reinterpret_cast(ObjectMemory::newUninitializedNullTermObject(cbPrefix + cbSuffix)); auto pbAnswer = reinterpret_cast(oteAnswer->m_location->m_characters); memcpy(pbAnswer, reinterpret_cast(oteReceiver)->m_location->m_characters, cbPrefix); diff --git a/Core/DolphinVM/thrdcall.cpp b/Core/DolphinVM/thrdcall.cpp index 2dac71ee8e..385f3a2cba 100644 --- a/Core/DolphinVM/thrdcall.cpp +++ b/Core/DolphinVM/thrdcall.cpp @@ -413,7 +413,7 @@ OverlappedCall::States OverlappedCall::beTerminated() /////////////////////////////////////////////////////////////////////////////// // Thread loop -extern "C" Oop* __fastcall asyncDLL32Call(CompiledMethod* pMethod, unsigned argCount, OverlappedCall* pThis, InterpreterRegisters* pContext); +extern "C" Oop* __fastcall asyncDLL32Call(CompiledMethod* pMethod, size_t argCount, OverlappedCall* pThis, InterpreterRegisters* pContext); DWORD OverlappedCall::WaitForRequest() { @@ -539,7 +539,7 @@ bool OverlappedCall::PerformCall() return stayAlive; } -bool OverlappedCall::Initiate(CompiledMethod* pMethod, unsigned argCount) +bool OverlappedCall::Initiate(CompiledMethod* pMethod, argcount_t argCount) { HARDASSERT(::GetCurrentThreadId() == Interpreter::MainThreadId()); @@ -1049,7 +1049,7 @@ void OverlappedCall::OnCallReturned() /////////////////////////////////////////////////////////////////////////////// // Interpreter primitive helpers -OverlappedCallPtr OverlappedCall::Do(CompiledMethod* pMethod, unsigned argCount) +OverlappedCallPtr OverlappedCall::Do(CompiledMethod* pMethod, argcount_t argCount) { HARDASSERT(::GetCurrentThreadId() == Interpreter::MainThreadId()); OverlappedCallPtr pCall = GetActiveProcessOverlappedCall(); diff --git a/Core/DolphinVM/thrdcall.h b/Core/DolphinVM/thrdcall.h index af9fd6f19b..5036686492 100755 --- a/Core/DolphinVM/thrdcall.h +++ b/Core/DolphinVM/thrdcall.h @@ -223,7 +223,7 @@ class OverlappedCall : public DoubleLink void TerminateThread(); - bool Initiate(CompiledMethod* pMethod, unsigned nArgCount); + bool Initiate(CompiledMethod* pMethod, argcount_t nArgCount); DWORD WaitForRequest(); int ProcessRequests(); bool PerformCall(); @@ -259,7 +259,7 @@ class OverlappedCall : public DoubleLink static void Uninitialize(); static OverlappedCallPtr GetActiveProcessOverlappedCall(); - static OverlappedCallPtr Do(CompiledMethod* pMethod, unsigned argCount); + static OverlappedCallPtr Do(CompiledMethod* pMethod, argcount_t argCount); static Semaphore* pendingTerms(); @@ -319,7 +319,7 @@ class OverlappedCall : public DoubleLink // Method causing this overlapped call to start executing CompiledMethod* m_pMethod; - unsigned m_nArgCount; + argcount_t m_nArgCount; volatile States m_state; private: SHAREDLONG m_nSuspendCount; diff --git a/Core/DolphinVM/vmref.cpp b/Core/DolphinVM/vmref.cpp index 82dcb048a6..3569efc471 100755 --- a/Core/DolphinVM/vmref.cpp +++ b/Core/DolphinVM/vmref.cpp @@ -27,8 +27,8 @@ TODO("Replace with hash table implementation") #ifdef _DEBUG // JGFoster Oop* Interpreter::m_pVMRefs = 0; -int Interpreter::m_nMaxVMRefs = 0; -int Interpreter::m_nFreeVMRef = -1; +SmallInteger Interpreter::m_nMaxVMRefs = 0; +SmallInteger Interpreter::m_nFreeVMRef = -1; // Add a reference to an object in use by the VM by storing it in an array reserved // for the purpose, which is itself reference from the special VMPointers root object @@ -51,13 +51,13 @@ void Interpreter::AddVMReference(OTE* pOTE) m_nFreeVMRef = m_nMaxVMRefs; m_nMaxVMRefs += VMREFSGROWTH; m_pVMRefs = ((Array*)ObjectMemory::resize((PointersOTE*)Pointers.VMReferences, m_nMaxVMRefs, false))->m_elements; - for (int i=m_nFreeVMRef;icountUp(); } @@ -78,7 +78,7 @@ void Interpreter::RemoveVMReference(OTE* pOTE) { if (!ObjectMemory::isPermanent(pOTE)) { - for (int i=0;iisFree() && ote->m_count == 0) @@ -208,10 +206,10 @@ OTE* __fastcall ObjectMemory::recursiveFree(OTE* rootOTE) if (rootOTE->isPointers()) { // Recurse through referenced objects as necessary - const MWORD lastPointer = rootOTE->getWordSize(); + const auto 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++) + for (auto i = ObjectHeaderSize; i < lastPointer; i++) { Oop fieldPointer = pFields[i]; if (!isIntegerObject(fieldPointer)) @@ -284,7 +282,7 @@ void ObjectMemory::PopulateZct(Oop* const sp) // More than 75% full, then grow it GrowZct(); } - else if ((m_nZctHighWater > (int)ZctMinSize) && (m_nZctEntries < (m_nZctHighWater >> 2))) + else if ((m_nZctHighWater > (ptrdiff_t)ZctMinSize) && (m_nZctEntries < (m_nZctHighWater >> 2))) { // Less than 25% full, so shrink it ShrinkZct(); @@ -301,7 +299,7 @@ void ObjectMemory::DumpZct() TRACESTREAM<< L"ZCT @ " << std::hex << m_pZct<< L", size: " << std::dec << m_nZctEntries << std::endl; TRACESTREAM<< L"===========================================================" << std::endl; - for (int i = 0; i < m_nZctEntries; i++) + for (auto i = 0; i < m_nZctEntries; i++) TRACESTREAM << std::dec << i<< L": " << std::hex << (uintptr_t)m_pZct[i]<< L": " << m_pZct[i] << std::endl; TRACESTREAM<< L"===========================================================" << std::endl;