Skip to content

Commit

Permalink
Port fix for SmallInteger>>testModulo locking up in test runs
Browse files Browse the repository at this point in the history
# Conflicts:
#	Interprt.h
#	decode.cpp
#	objmem.cpp
#	process.cpp
#	thrdcall.cpp
  • Loading branch information
blairmcg committed Sep 17, 2018
1 parent e18837b commit cd25fb5
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 91 deletions.
8 changes: 6 additions & 2 deletions ExternalCall.asm
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,13 @@ procAddressNotCached:
test eax, eax ; Returns null if not a valid proc name
jnz performCall

mov edx, callContext
ASSUME edx:PTR InterpRegisters
add esp, 16 ; Remove args pushed for aborted call
PrimitiveFailureCode 1

mov edx, [edx].m_pActiveProcess
xor eax, eax
mov (Process PTR[edx]).m_primitiveFailureCode, SMALLINTONE
ret
asyncDLL32Call ENDP

getProcAddress PROC
Expand Down
4 changes: 4 additions & 0 deletions GCPrim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ bool Interpreter::disableAsyncGC(bool bDisable)
if (m_nOTOverflows > 0)
{
m_nOTOverflows = 0;
CHECKREFERENCES
queueInterrupt(VMI_OTOVERFLOW, ObjectMemoryIntegerObjectOf(ObjectMemory::GetOTSize()));
}
return true;
Expand All @@ -52,6 +53,7 @@ void Interpreter::NotifyOTOverflow()
}
else
{
CHECKREFERENCES
queueInterrupt(VMI_OTOVERFLOW, ObjectMemoryIntegerObjectOf(ObjectMemory::GetOTSize()));
}
}
Expand Down Expand Up @@ -91,6 +93,8 @@ void Interpreter::asyncGC(DWORD gcFlags)
// This has been usurped for GC primitive
Oop* __fastcall Interpreter::primitiveCoreLeft(Oop* const sp , unsigned argCount)
{
CHECKREFERENCESSP(sp);

DWORD gcFlags = 0;
if (argCount)
{
Expand Down
8 changes: 6 additions & 2 deletions Interprt.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ using namespace ST;
#define TRACEARG(x) ,(x)
#define TRACEPARM ,TRACEFLAG traceFlag
#define TRACEDEFAULT TRACEPARM=TraceOff
#define CHECKREFERENCESSP(sp) Interpreter::checkReferences(sp)
#define CHECKREFERENCES Interpreter::checkReferences(Interpreter::GetRegisters());
#define CHECKREFSNOFIX \
{\
Expand All @@ -43,6 +44,8 @@ using namespace ST;
#define TRACEARG(x)
#define TRACEDEFAULT
#define CHECKREFERENCES
#define CHECKREFERENCESSP(sp)
#define CHECKREFERENCESIF(x)
#define CHECKREFSNOFIX
#endif

Expand Down Expand Up @@ -91,6 +94,7 @@ class Interpreter
static void RemoveVMReference(Oop);
static void RemoveVMReference(OTE*);

static void checkReferences(Oop* const sp);
static void checkReferences(InterpreterRegisters&);

// Only needed for non-Debug because of C++ walkback code
Expand Down Expand Up @@ -846,8 +850,8 @@ class Interpreter
static int m_nFreeVMRef;
static int m_nMaxVMRefs; // Current size of VM References array

enum { VMREFSINITIAL = 16 };
enum { VMREFSGROWTH = 16 };
enum { VMREFSINITIAL = 128 };
enum { VMREFSGROWTH = 64 };
#endif
};

Expand Down
2 changes: 1 addition & 1 deletion interfac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ Oop __stdcall Interpreter::callback(SymbolOTE* selector, unsigned argCount TRACE
//ASSERT(!memcmp(&savedContext, &m_registers, sizeof(InterpreterRegisters)));
#endif

// Must countUp to prevent it being GC'd since the stack no longer has ref. count
// Must countUp to prevent it being GC'd since it is no longer ref'd from the stack
VERIFY(retVal == popAndCountUp());
return retVal;
}
Expand Down
6 changes: 6 additions & 0 deletions interprt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ static MWORD ResizeProcInContext(InterpreterRegisters& reg)
return size;
}

void Interpreter::checkReferences(Oop* const sp)
{
m_registers.m_stackPointer = sp;
checkReferences(GetRegisters());
}

// Check references without upsetting the current active process size (otherwise
// this may mask bugs in the release version)
void Interpreter::checkReferences(InterpreterRegisters& reg)
Expand Down
45 changes: 25 additions & 20 deletions objmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class ObjectMemory
static Oop storePointerWithValue(Oop& oopSlot, Oop oopValue);
static OTE* storePointerWithValue(OTE*& oteSlot, OTE* oteValue);
static Oop storePointerWithValue(Oop& oopSlot, OTE* oteValue);
static Oop nilOutPointer(Oop& objectPointer);
static OTE* nilOutPointer(OTE*& ote);
static void nilOutPointer(Oop& objectPointer);
static void nilOutPointer(OTE*& ote);

// Use these versions to store values which are not themselves ref. counted
static Oop storePointerWithUnrefCntdValue(Oop&, Oop);
Expand Down Expand Up @@ -188,6 +188,7 @@ class ObjectMemory

#ifdef _DEBUG
// Recalc and consistency check
static void checkReferences(Oop* const sp);
static void checkReferences();
static void addRefsFrom(OTE* ote);
static void checkPools();
Expand Down Expand Up @@ -681,30 +682,30 @@ inline Oop ObjectMemory::storePointerOfObjectWithValue(MWORD fieldIndex, Pointer
// Useful for overwriting structure members
inline Oop ObjectMemory::storePointerWithValue(Oop& oopSlot, Oop oopValue)
{
// Sadly compiler refuses to inline the count up code, and macro seems to generate
// bad code(!) so inline by hand
countUp(oopValue); // Increase the reference count on stored object
countDown(oopSlot);
return oopSlot = oopValue;
Oop oldValue = oopSlot;
oopSlot = oopValue;
countDown(oldValue);
return oopValue;
}

// Useful for overwriting structure members
inline Oop ObjectMemory::storePointerWithUnrefCntdValue(Oop& oopSlot, Oop oopValue)
{
// Sadly compiler refuses to inline the count up code, and macro seems to generate
// bad code(!) so inline by hand
countDown(oopSlot);
return oopSlot = oopValue;
Oop oldValue = oopSlot;
oopSlot = oopValue;
countDown(oldValue);
return oopValue;
}

// Useful for overwriting structure members
inline OTE* ObjectMemory::storePointerWithValue(OTE*& oteSlot, OTE* oteValue)
{
// Sadly compiler refuses to inline the count up code, and macro seems to generate
// bad code(!) so inline by hand
oteValue->countUp(); // Increase the reference count on stored object
oteSlot->countDown();
return (oteSlot = oteValue);
OTE* oteOldValue = oteSlot;
oteSlot = oteValue;
oteOldValue->countDown();
return oteValue;
}

// Useful for overwriting structure members
Expand All @@ -713,20 +714,24 @@ inline Oop ObjectMemory::storePointerWithValue(Oop& oopSlot, OTE* oteValue)
// Sadly compiler refuses to inline the count up code, and macro seems to generate
// bad code(!) so inline by hand
oteValue->countUp(); // Increase the reference count on stored object
countDown(oopSlot);
return oopSlot = Oop(oteValue);
Oop oldValue = oopSlot;
oopSlot = reinterpret_cast<Oop>(oteValue);
countDown(oldValue);
return oopSlot;
}

inline Oop ObjectMemory::nilOutPointer(Oop& objectPointer)
inline void ObjectMemory::nilOutPointer(Oop& objectPointer)
{
Oop oldValue = objectPointer;
objectPointer = reinterpret_cast<Oop>(Pointers.Nil);
countDown(objectPointer);
return objectPointer = Oop(Pointers.Nil);
}

inline OTE* ObjectMemory::nilOutPointer(OTE*& ote)
inline void ObjectMemory::nilOutPointer(OTE*& ote)
{
OTE* oldValue = ote;
ote = const_cast<OTE*>(Pointers.Nil);
ote->countDown();
return ote = const_cast<OTE*>(Pointers.Nil);
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
18 changes: 12 additions & 6 deletions process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,12 @@ Oop* __fastcall Interpreter::primitiveUnwindInterrupt(Oop* const)
{
// Terminate any overlapped call outstanding for the process, this may need to suspend the process
// and so this may cause a context switch
TerminateOverlapped(actualActiveProcessPointer());
ProcessOTE* oteActive = actualActiveProcessPointer();
OverlappedCall* pOverlapped = oteActive->m_location->GetOverlappedCall();
if (pOverlapped != nullptr && pOverlapped->IsInCall())
{
TerminateOverlapped(oteActive);
}
return primitiveSuccess(0);
}

Expand Down Expand Up @@ -1765,6 +1770,9 @@ bool Interpreter::TerminateOverlapped(ProcessOTE* oteProc)

if (activeProcessPointer() == oteProc)
Reschedule();

// The process must wait for the associated overlapped call thread to terminate
return true;
}
else
{
Expand All @@ -1774,12 +1782,10 @@ bool Interpreter::TerminateOverlapped(ProcessOTE* oteProc)
HARDASSERT(FALSE); // Actually I don't think we can get here
}

// The process was in/is in an overlapped call
return true;
}
else
// The process is not in an overlapped call
return false;

// The process can be terminated immediately
return false;
}

inline bool Process::SuspendOverlappedCall()
Expand Down
Loading

0 comments on commit cd25fb5

Please sign in to comment.