Skip to content

Commit

Permalink
CogVM source as per VMMaker.oscog-eem.3256
Browse files Browse the repository at this point in the history
The long-running primitive monitoring code in the JIT is broken; it will find
false positives (thanks Ronie).  Fix it by zeroing longRunningPrimitiveStopUsecs
whenever an external primitive is run (at the same time newMethod is assigned).
  • Loading branch information
eliotmiranda committed Oct 22, 2022
1 parent 51e3490 commit 30dd4fe
Show file tree
Hide file tree
Showing 51 changed files with 1,117 additions and 372 deletions.
2 changes: 1 addition & 1 deletion src/spur32.cog.lowcode/cogit.h
@@ -1,5 +1,5 @@
/* Automatically generated by
CCodeGenerator VMMaker.oscog-eem.3254 uuid: 3b74b441-2801-46f6-ae88-40b662719aed
CCodeGenerator VMMaker.oscog-eem.3256 uuid: 85febed5-d156-4c33-8b7f-3b0d1835665d
*/


Expand Down
38 changes: 29 additions & 9 deletions src/spur32.cog.lowcode/cogitARMv5.c
@@ -1,9 +1,9 @@
/* Automatically generated by
CCodeGenerator VMMaker.oscog-eem.3254 uuid: 3b74b441-2801-46f6-ae88-40b662719aed
CCodeGenerator VMMaker.oscog-eem.3256 uuid: 85febed5-d156-4c33-8b7f-3b0d1835665d
from
StackToRegisterMappingCogit VMMaker.oscog-eem.3254 uuid: 3b74b441-2801-46f6-ae88-40b662719aed
StackToRegisterMappingCogit VMMaker.oscog-eem.3256 uuid: 85febed5-d156-4c33-8b7f-3b0d1835665d
*/
static char __buildInfo[] = "StackToRegisterMappingCogit VMMaker.oscog-eem.3254 uuid: 3b74b441-2801-46f6-ae88-40b662719aed " __DATE__ ;
static char __buildInfo[] = "StackToRegisterMappingCogit VMMaker.oscog-eem.3256 uuid: 85febed5-d156-4c33-8b7f-3b0d1835665d " __DATE__ ;
char *__cogitBuildInfo = __buildInfo;


Expand Down Expand Up @@ -29182,22 +29182,42 @@ genFastPrimTraceUsingand(sqInt r1, sqInt r2)
static void
genLoadNewMethod(void)
{
sqInt address;
sqInt address1;
sqInt address2;
sqInt address3;
AbstractInstruction *anInstruction;
AbstractInstruction *anInstruction1;
sqInt offset;

addDependent(methodLabel, annotateAbsolutePCRef(gMoveCwR(((sqInt)methodLabel), ClassReg)));
/* begin MoveMw:r:R: */
offset = offsetof(CogMethod, methodObject);
/* begin checkQuickConstant:forInstruction: */
anInstruction = genoperandoperandoperand(MoveMwrR, offset, ClassReg, TempReg);
if (usesOutOfLineLiteral(anInstruction)) {
(anInstruction->dependent = locateLiteral(offset));
anInstruction1 = genoperandoperandoperand(MoveMwrR, offset, ClassReg, TempReg);
if (usesOutOfLineLiteral(anInstruction1)) {
(anInstruction1->dependent = locateLiteral(offset));
}
/* begin MoveR:Aw: */
address = newMethodAddress();
address3 = newMethodAddress();
/* begin gen:operand:literal: */
checkLiteralforInstruction(address, genoperandoperand(MoveRAw, TempReg, address));
checkLiteralforInstruction(address3, genoperandoperand(MoveRAw, TempReg, address3));
# if LRPCheck
if (checkingLongRunningPrimitives()) {
/* begin checkQuickConstant:forInstruction: */
anInstruction = genoperandoperand(MoveCqR, 0, TempReg);
if (usesOutOfLineLiteral(anInstruction)) {
(anInstruction->dependent = locateLiteral(0));
}
/* begin MoveR:Aw: */
address1 = longRunningPrimitiveStopUsecsAddress();
/* begin gen:operand:literal: */
checkLiteralforInstruction(address1, genoperandoperand(MoveRAw, TempReg, address1));
/* begin MoveR:Aw: */
address2 = (longRunningPrimitiveStopUsecsAddress()) + 4;
/* begin gen:operand:literal: */
checkLiteralforInstruction(address2, genoperandoperand(MoveRAw, TempReg, address2));
}
# endif // LRPCheck
}

/* SimpleStackBasedCogit>>#genLongJumpIfFalse */
Expand Down
29 changes: 23 additions & 6 deletions src/spur32.cog.lowcode/cogitIA32.c
@@ -1,9 +1,9 @@
/* Automatically generated by
CCodeGenerator VMMaker.oscog-eem.3254 uuid: 3b74b441-2801-46f6-ae88-40b662719aed
CCodeGenerator VMMaker.oscog-eem.3256 uuid: 85febed5-d156-4c33-8b7f-3b0d1835665d
from
StackToRegisterMappingCogit VMMaker.oscog-eem.3254 uuid: 3b74b441-2801-46f6-ae88-40b662719aed
StackToRegisterMappingCogit VMMaker.oscog-eem.3256 uuid: 85febed5-d156-4c33-8b7f-3b0d1835665d
*/
static char __buildInfo[] = "StackToRegisterMappingCogit VMMaker.oscog-eem.3254 uuid: 3b74b441-2801-46f6-ae88-40b662719aed " __DATE__ ;
static char __buildInfo[] = "StackToRegisterMappingCogit VMMaker.oscog-eem.3256 uuid: 85febed5-d156-4c33-8b7f-3b0d1835665d " __DATE__ ;
char *__cogitBuildInfo = __buildInfo;


Expand Down Expand Up @@ -26681,18 +26681,35 @@ genFastPrimTraceUsingand(sqInt r1, sqInt r2)
static void
genLoadNewMethod(void)
{
AbstractInstruction *anInstruction;
sqInt address;
AbstractInstruction *anInstruction1;
AbstractInstruction *anInstruction2;
AbstractInstruction *anInstruction3;
AbstractInstruction *anInstruction4;
AbstractInstruction *anInstruction5;
sqInt offset;

addDependent(methodLabel, annotateAbsolutePCRef(checkLiteralforInstruction(((sqInt)methodLabel), genoperandoperand(MoveCwR, ((sqInt)methodLabel), ClassReg))));
/* begin MoveMw:r:R: */
offset = offsetof(CogMethod, methodObject);
/* begin checkQuickConstant:forInstruction: */
anInstruction = genoperandoperandoperand(MoveMwrR, offset, ClassReg, TempReg);
anInstruction4 = genoperandoperandoperand(MoveMwrR, offset, ClassReg, TempReg);
/* begin checkLiteral:forInstruction: */
newMethodAddress();
anInstruction1 = genoperandoperand(MoveRAw, TempReg, newMethodAddress());
anInstruction5 = genoperandoperand(MoveRAw, TempReg, newMethodAddress());
# if LRPCheck
if (checkingLongRunningPrimitives()) {
/* begin checkQuickConstant:forInstruction: */
anInstruction3 = genoperandoperand(MoveCqR, 0, TempReg);
/* begin checkLiteral:forInstruction: */
longRunningPrimitiveStopUsecsAddress();
anInstruction1 = genoperandoperand(MoveRAw, TempReg, longRunningPrimitiveStopUsecsAddress());
/* begin MoveR:Aw: */
address = (longRunningPrimitiveStopUsecsAddress()) + 4;
/* begin checkLiteral:forInstruction: */
anInstruction2 = genoperandoperand(MoveRAw, TempReg, address);
}
# endif // LRPCheck
}

/* SimpleStackBasedCogit>>#genLongJumpIfFalse */
Expand Down
62 changes: 43 additions & 19 deletions src/spur32.cog.lowcode/cointerp.c
@@ -1,9 +1,9 @@
/* Automatically generated by
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.3254 uuid: 3b74b441-2801-46f6-ae88-40b662719aed
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.3256 uuid: 85febed5-d156-4c33-8b7f-3b0d1835665d
from
CoInterpreter VMMaker.oscog-eem.3254 uuid: 3b74b441-2801-46f6-ae88-40b662719aed
CoInterpreter VMMaker.oscog-eem.3256 uuid: 85febed5-d156-4c33-8b7f-3b0d1835665d
*/
static char __buildInfo[] = "CoInterpreter VMMaker.oscog-eem.3254 uuid: 3b74b441-2801-46f6-ae88-40b662719aed " __DATE__ ;
static char __buildInfo[] = "CoInterpreter VMMaker.oscog-eem.3256 uuid: 85febed5-d156-4c33-8b7f-3b0d1835665d " __DATE__ ;
char *__interpBuildInfo = __buildInfo;


Expand Down Expand Up @@ -455,6 +455,9 @@ extern void checkAssertsEnabledInCoInterpreter(void);
static sqInt NoDbgRegParms checkCodeIntegrity(sqInt gcModes);
extern sqInt checkForAndFollowForwardedPrimitiveState(void);
extern sqInt checkIfCFramePointerInUse(void);
#if LRPCheck
extern sqInt checkingLongRunningPrimitives(void);
#endif /* LRPCheck */
static sqInt checkLogIntegrity(void);
static sqInt NoDbgRegParms checkOkayFields(sqInt oop);
static sqInt checkStackIntegrity(void);
Expand Down Expand Up @@ -514,6 +517,9 @@ static sqInt NoDbgRegParms isExternalMethodInPlugin(sqInt methodObj);
static sqInt NoDbgRegParms isMachineCodeFrameForExternalPrimitiveMethod(char *theFP);
static sqInt NoDbgRegParms isMachineCodeFrameWithCogMethod(char *theFP);
static sqInt NoDbgRegParms isMachineCodeFrame(char *theFP);
#if LRPCheck
extern usqInt longRunningPrimitiveStopUsecsAddress(void);
#endif /* LRPCheck */
extern sqInt lookupMNUreceiver(sqInt selector, sqInt rcvr);
extern sqInt lookupOrdinaryreceiver(sqInt selector, sqInt rcvr);
static StackPage * NoDbgRegParms makeBaseFrameFor(sqInt aContext);
Expand Down Expand Up @@ -1812,10 +1818,10 @@ _iss usqInt lastMobileObject;
_iss sqInt numClassTablePages;
_iss sqInt profileProcess;
_iss sqInt futureSurvivorStart;
_iss sqInt lkupClass;
#if LRPCheck
_iss sqInt longRunningPrimitiveCheckSemaphore;
#endif
_iss sqInt lkupClass;
_iss sqInt mournQueue;
_iss sqInt numRememberedEphemerons;
_iss sqInt profileMethod;
Expand Down Expand Up @@ -1931,14 +1937,14 @@ _iss sqInt *extraRoots[ExtraRootsSize + 1 /* 65 */];
_iss sqInt preferredPinningSegment;
_iss sqInt statCoalesces;
_iss sqInt theUnknownShort;
#if LRPCheck
_iss usqLong longRunningPrimitiveStopUsecs;
#endif
_iss usqLong nextWakeupUsecs;
_iss usqLong statGCEndUsecs;
#if LRPCheck
_iss usqLong longRunningPrimitiveStartUsecs;
#endif
#if LRPCheck
_iss usqLong longRunningPrimitiveStopUsecs;
#endif
_iss usqLong statCheckForEvents;
_iss usqLong gcStartUsecs;
_iss sqLong oldSpaceUsePriorToScavenge;
Expand Down Expand Up @@ -2010,7 +2016,7 @@ static signed short primitiveMetadataTable[MaxPrimitiveIndex + 2 /* 584 */] = {
/*78*/ 0, 0,
/*80*/ -256,-256,-256, 4, 4, 0, 0x100, 0, 0x200,-256,-256, 0, 0, 0, 0x100,-256,-256,
/*97*/ -256, 0, 0,
/*100*/ 260, 0x200, 0x100, 0x200,-256, 513,-256,-256,-256,-256, 0, 0x100, 0, 0,-256,
/*100*/ 260, 0x200, 0x200, 0x200,-256, 513,-256,-256,-256,-256, 0, 0x100, 0, 0,-256,
/*115*/ 0x100, 0, 12, 260, 0,
/*120*/ 524, 0x100,-256,-256, 1, 0, 0, 0, 0,-255,-256,-256, 0, 0, 0,-256, 0,-256,-256,
/*139*/ 0,
Expand Down Expand Up @@ -2684,7 +2690,7 @@ sqInt debugCallbackInvokes;
sqInt debugCallbackReturns;
sqInt cannotDeferDisplayUpdates;
sqInt checkedPluginName;
const char *interpreterVersion = "Open Smalltalk Cog[Spur] VM [CoInterpreterPrimitives VMMaker.oscog-eem.3254]";
const char *interpreterVersion = "Open Smalltalk Cog[Spur] VM [CoInterpreterPrimitives VMMaker.oscog-eem.3256]";
sqInt minBackwardJumpCountForCompile = MinBackwardJumpCountForCompile /* 40 */;
char expensiveAsserts = 0;
int (*showSurfaceFn)(sqIntptr_t, int, int, int, int);
Expand Down Expand Up @@ -35377,6 +35383,15 @@ checkIfCFramePointerInUse(void)
return isCFramePointerInUse((&GIV(CFramePointer)), (&GIV(CStackPointer)));
}

/* CoInterpreter>>#checkingLongRunningPrimitives */
#if LRPCheck
sqInt
checkingLongRunningPrimitives(void)
{ DECL_MAYBE_SQ_GLOBAL_STRUCT
return GIV(longRunningPrimitiveCheckSemaphore) != null;
}
#endif /* LRPCheck */


/* Check the log for leaks. The trace log is a circular buffer of pairs of
entries. If there is an entry at traceLogIndex - 3 \\ TraceBufferSize it
Expand Down Expand Up @@ -37942,6 +37957,15 @@ isMachineCodeFrame(char *theFP)
return (((usqInt)(longAt(theFP + FoxMethod)))) < (startOfMemory());
}

/* CoInterpreter>>#longRunningPrimitiveStopUsecsAddress */
#if LRPCheck
usqInt
longRunningPrimitiveStopUsecsAddress(void)
{ DECL_MAYBE_SQ_GLOBAL_STRUCT
return ((usqInt)((&GIV(longRunningPrimitiveStopUsecs))));
}
#endif /* LRPCheck */


/* Lookup selector in rcvr, without doing MNU processing, and answer either a
method or an error code if the message was not understood. Used to
Expand Down Expand Up @@ -38985,7 +39009,7 @@ mnuMethodOrNilFor(sqInt rcvr)
{ DECL_MAYBE_SQ_GLOBAL_STRUCT
sqInt currentClass;
sqInt dictionary;
usqInt index;
sqInt index;
usqInt length;
sqInt mask;
sqInt methodArray;
Expand Down Expand Up @@ -39034,7 +39058,7 @@ mnuMethodOrNilFor(sqInt rcvr)
wrapAround = 0;
while (1) {
/* begin fetchPointer:ofObject: */
nextSelector = longAt((dictionary + BaseHeaderSize) + (index << (shiftForWord())));
nextSelector = longAt((dictionary + BaseHeaderSize) + (((sqInt)((usqInt)(index) << (shiftForWord())))));
if (nextSelector == GIV(nilObj)) {
mnuMethod = null;
goto l11;
Expand All @@ -39052,7 +39076,7 @@ mnuMethodOrNilFor(sqInt rcvr)
}
methodArray = objOop;
/* begin followField:ofObject: */
objOop1 = longAt((methodArray + BaseHeaderSize) + ((index - SelectorStart) << (shiftForWord())));
objOop1 = longAt((methodArray + BaseHeaderSize) + (((sqInt)((usqInt)((index - SelectorStart)) << (shiftForWord())))));
if (((!(objOop1 & (tagMask()))))
&& ((!((longAt(objOop1)) & ((classIndexMask()) - (isForwardedObjectClassIndexPun())))))) {
objOop1 = fixFollowedFieldofObjectwithInitialValue(index - SelectorStart, methodArray, objOop1);
Expand Down Expand Up @@ -80663,7 +80687,7 @@ updatePointersInsavedFirstFieldPointer(sqInt obj, sqInt firstFieldPtr)
assert((ReceiverIndex + ((sp >> 1))) < (lengthOf(obj)));
contextSize = (sp >> 1);
l6: /* end fetchStackPointerOf: */;
numPointerSlots = CtxtTempFrameStart + contextSize;
numPointerSlots = ((usqInt) (CtxtTempFrameStart + contextSize));
goto l10;
}
/* begin numSlotsOf: */
Expand Down Expand Up @@ -80693,7 +80717,7 @@ updatePointersInsavedFirstFieldPointer(sqInt obj, sqInt firstFieldPtr)
/* begin literalCountOfMethodHeader: */
assert((header & 1));
numLiterals = ((header >> 1)) & AlternateHeaderNumLiteralsMask;
numPointerSlots = numLiterals + LiteralStart;
numPointerSlots = ((usqInt) (numLiterals + LiteralStart));
l10: /* end numPointerSlotsWhileCompactingOf:withFormat:savedFirstFieldPointer: */;
if ((fmt <= 5 /* lastPointerFormat */)
&& (numPointerSlots > 0)) {
Expand Down Expand Up @@ -85053,8 +85077,8 @@ static sqInt
getErrorObjectFromPrimFailCode(void)
{ DECL_MAYBE_SQ_GLOBAL_STRUCT
sqInt classIndex;
usqInt clone;
usqInt errObj;
sqInt clone;
sqInt errObj;
sqInt fieldIndex;
sqInt i;
usqInt newObj;
Expand Down Expand Up @@ -87253,7 +87277,7 @@ lookupSelectorinClass(sqInt selector, sqInt class)
{ DECL_MAYBE_SQ_GLOBAL_STRUCT
sqInt currentClass;
sqInt dictionary;
usqInt index;
sqInt index;
usqInt length;
sqInt mask;
sqInt meth;
Expand Down Expand Up @@ -87297,7 +87321,7 @@ lookupSelectorinClass(sqInt selector, sqInt class)
wrapAround = 0;
while (1) {
/* begin fetchPointer:ofObject: */
nextSelector = longAt((dictionary + BaseHeaderSize) + (index << (shiftForWord())));
nextSelector = longAt((dictionary + BaseHeaderSize) + (((sqInt)((usqInt)(index) << (shiftForWord())))));
if (nextSelector == GIV(nilObj)) {
meth = null;
goto l8;
Expand All @@ -87315,7 +87339,7 @@ lookupSelectorinClass(sqInt selector, sqInt class)
}
methodArray = objOop2;
/* begin followField:ofObject: */
objOop1 = longAt((methodArray + BaseHeaderSize) + ((index - SelectorStart) << (shiftForWord())));
objOop1 = longAt((methodArray + BaseHeaderSize) + (((sqInt)((usqInt)((index - SelectorStart)) << (shiftForWord())))));
if (((!(objOop1 & (tagMask()))))
&& ((!((longAt(objOop1)) & ((classIndexMask()) - (isForwardedObjectClassIndexPun())))))) {
objOop1 = fixFollowedFieldofObjectwithInitialValue(index - SelectorStart, methodArray, objOop1);
Expand Down
8 changes: 7 additions & 1 deletion src/spur32.cog.lowcode/cointerp.h
@@ -1,5 +1,5 @@
/* Automatically generated by
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.3254 uuid: 3b74b441-2801-46f6-ae88-40b662719aed
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.3256 uuid: 85febed5-d156-4c33-8b7f-3b0d1835665d
*/


Expand Down Expand Up @@ -56,6 +56,9 @@ extern usqInt cFramePointerAddress(void);
extern void checkAssertsEnabledInCoInterpreter(void);
extern sqInt checkForAndFollowForwardedPrimitiveState(void);
extern sqInt checkIfCFramePointerInUse(void);
#if LRPCheck
extern sqInt checkingLongRunningPrimitives(void);
#endif /* LRPCheck */
extern void clearTraceLog(void);
extern CogMethod * cogMethodOf(sqInt aMethodOop);
extern void compilationBreakpointFor(sqInt selectorOop);
Expand All @@ -72,6 +75,9 @@ extern usqInt instructionPointerAddress(void);
extern sqInt interpret(void);
extern usqInt interpretAddress(void);
extern sqInt isCogMethodReference(sqInt methodHeader);
#if LRPCheck
extern usqInt longRunningPrimitiveStopUsecsAddress(void);
#endif /* LRPCheck */
extern sqInt lookupMNUreceiver(sqInt selector, sqInt rcvr);
extern sqInt lookupOrdinaryreceiver(sqInt selector, sqInt rcvr);
extern void markActiveMethodsAndReferents(void);
Expand Down

0 comments on commit 30dd4fe

Please sign in to comment.