Skip to content

Commit

Permalink
CogVM source as per VMMaker.oscog-eem.2347
Browse files Browse the repository at this point in the history
StackInterpreter:
Immutability:
Fix primitiveSlotAtPut (& InterpreterPrimitives>>primitiveInstVarAtPut) to fail
with PrimErrorNoModification for read-only objects.

Cogit:
Inline a few trivial methods.

StackToRegisterMappingCogit:
For simplicity, especially in the RegisterAllocatingCogit subclass, eliminate
simSelf and optStatus and include the receiver's simStackEntry as the 0'th
element of the simStack.  optStatus is therefore whether simSelf's liveRegister
is ReceiverResultReg.  Hence loops from 0 to: methodOrBlockNumTemps - 1 become
loops from 1 to: methodOrBlockNumTemps.  The simSelf variable is replaced by
self simSelf, which is short-hand for self simStackAt: 0.

Fix ancient bug in voidReceiverResultRegContainsSelf.  The computed index is the
right argument for ssFlushTo:; it shouldn't be subtracted from simStackPtr!

Replace the UnknownSimStackPtrFlag hack in a fixup's simStackPtr and replace it
by a proper flag.  Consequently make a fixup's simStackPtr unsigned char,
giving us a maximim of 255 stack slots (0 being for the receiver).

Get much stricter with simSpillBase for the benefit of RegisterAllocatingCogit.
updateSimSpillBase is now called after the new descriptor is pushed and either
counts up or counts down as required to guarantee it points one beyond the last
spilled entry.  The assertCorrectSimStackPtr asserts now insist on this.  With
this change we can start to replace all the simSpillBase max: 0 phrases with
simply simSpillBase.

Deal with the assert failures due to frameless methods with unused temporaries
by simply refusing to JIT them; see the new methodFoundInvalidPostScan hook.

Plugins:
All plugins should include config.h and it should always be the first include.

FilePlugin connect to file primitives primitiveConnectToFileDescriptor &
primitiveConnectToFile.  Many thanks to Holger Freyther for the original code.

Rewrite the primitives in MiscPrimitivePlugin using conventional Slang, avoiding
the translatedPrimitives ineffiicencies and dependence on methods in the image.
Volunteers are invited to do the same for the ADPCMCodecPlugin and
SoundGenerationPlugin.
  • Loading branch information
eliotmiranda committed Mar 7, 2018
1 parent 19a102b commit 4749358
Show file tree
Hide file tree
Showing 141 changed files with 21,026 additions and 12,277 deletions.
2 changes: 1 addition & 1 deletion nsspur64src/vm/cogit.h
@@ -1,5 +1,5 @@
/* Automatically generated by
CCodeGenerator VMMaker.oscog-eem.2324 uuid: 904abc56-e5a8-467e-a337-880211e33805
CCodeGenerator VMMaker.oscog-eem.2347 uuid: 062614a7-e3da-4b30-997a-9568911b9ff5
*/


Expand Down
737 changes: 518 additions & 219 deletions nsspur64src/vm/cogitX64SysV.c

Large diffs are not rendered by default.

747 changes: 523 additions & 224 deletions nsspur64src/vm/cogitX64WIN64.c

Large diffs are not rendered by default.

117 changes: 62 additions & 55 deletions nsspur64src/vm/cointerp.c
@@ -1,9 +1,9 @@
/* Automatically generated by
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.2320 uuid: e2692e35-5fc8-4623-95d0-b445b3329f75
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.2347 uuid: 062614a7-e3da-4b30-997a-9568911b9ff5
from
CoInterpreter VMMaker.oscog-eem.2320 uuid: e2692e35-5fc8-4623-95d0-b445b3329f75
CoInterpreter VMMaker.oscog-eem.2347 uuid: 062614a7-e3da-4b30-997a-9568911b9ff5
*/
static char __buildInfo[] = "CoInterpreter VMMaker.oscog-eem.2320 uuid: e2692e35-5fc8-4623-95d0-b445b3329f75 " __DATE__ ;
static char __buildInfo[] = "CoInterpreter VMMaker.oscog-eem.2347 uuid: 062614a7-e3da-4b30-997a-9568911b9ff5 " __DATE__ ;
char *__interpBuildInfo = __buildInfo;


Expand Down Expand Up @@ -536,7 +536,6 @@ static void followForwardedFieldsInCurrentMethod(void);
static void NoDbgRegParms followForwardingPointersInStackZone(sqInt theBecomeEffectsFlags);
extern void forceInterruptCheckFromHeartbeat(void);
static sqInt NoDbgRegParms frameCallerContext(char *theFP);
static sqInt NoDbgRegParms frameCallerContextput(char *theFP, sqInt aValue);
static sqInt NoDbgRegParms frameHasContext(char *theFP);
static sqInt NoDbgRegParms frameIsBlockActivation(char *theFP);
static sqInt NoDbgRegParms frameMethodObject(char *theFP);
Expand Down Expand Up @@ -1530,7 +1529,7 @@ static sqInt NoDbgRegParms marriedContextpointsTostackDeltaForCurrentFrame(sqInt
static void NoDbgRegParms marryContextInNewStackPageAndInitializeInterpreterRegisters(sqInt aContext);
static sqInt NoDbgRegParms marryFrameSP(char *theFP, char *theSP);
static sqInt NoDbgRegParms maybeLeakCheckExternalPrimCall(sqInt aMethodObj);
static sqInt NoDbgRegParms maybeSelectorOfMethod(sqInt methodObj);
extern sqInt maybeSelectorOfMethod(sqInt methodObj);
extern sqInt methodArgumentCount(void);
extern sqInt methodArg(sqInt index);
extern sqInt methodClassAssociationOf(sqInt methodPointer);
Expand Down Expand Up @@ -2587,7 +2586,7 @@ static signed char primitiveAccessorDepthTable[MaxPrimitiveIndex + 2 /* 577 */]
};
sqInt checkedPluginName;
char expensiveAsserts = 0;
const char *interpreterVersion = "Newspeak Virtual Machine CoInterpreterPrimitives_VMMaker.oscog-eem.2320";
const char *interpreterVersion = "Newspeak Virtual Machine CoInterpreterPrimitives_VMMaker.oscog-eem.2347";
sqInt minBackwardJumpCountForCompile = MinBackwardJumpCountForCompile /* 40 */;
volatile int sendTrace;

Expand Down Expand Up @@ -19963,24 +19962,6 @@ frameCallerContext(char *theFP)
return callerContextOrNil;
}


/* In the StackInterpreter the saved ip field of a base frame holds the
base frame's caller context. But in the Cog VM the first word on the
stack holds the base frame's caller context, which is immediately
above the stacked receiver. */

/* CoInterpreter>>#frameCallerContext:put: */
static sqInt NoDbgRegParms
frameCallerContextput(char *theFP, sqInt aValue)
{
assert(isBaseFrame(theFP));
assert(((theFP + (frameStackedReceiverOffset(theFP))) + (2 * BytesPerWord)) == (((stackPageFor(theFP))->baseAddress)));
assert((longAt((theFP + (frameStackedReceiverOffset(theFP))) + BytesPerWord)) == (frameContext(theFP)));
return longAtput((theFP + (frameStackedReceiverOffsetNumArgs(((((usqInt)(longAt(theFP + FoxMethod)))) < (startOfMemory())
? ((mframeCogMethod(theFP))->cmNumArgs)
: byteAt((theFP + FoxIFrameFlags) + 1))))) + (2 * BytesPerWord), aValue);
}

/* CoInterpreter>>#frameHasContext: */
static sqInt NoDbgRegParms
frameHasContext(char *theFP)
Expand Down Expand Up @@ -22801,7 +22782,7 @@ printFrameWithSP(char *theFP, char *theSP)
usqInt index;
sqInt methodField;
usqInt numArgs;
usqInt numTemps;
sqInt numTemps;
char *rcvrAddress;
sqInt rcvrOrClosure;
sqInt theMethod;
Expand Down Expand Up @@ -26961,7 +26942,15 @@ primitiveTerminateTo(void)
senderOop5 = longAt((thisCtx + BaseHeaderSize) + (((sqInt)((usqInt)(SenderIndex) << (shiftForWord())))));
assert((((senderOop5) & 7) == 1));
theFP = pointerForOop(senderOop5 - 1);
frameCallerContextput(theFP, aContextOrNil);
/* begin frameCallerContext:put: */
assert((aContextOrNil == (nilObject()))
|| (isContext(aContextOrNil)));
assert(isBaseFrame(theFP));
assert(((theFP + (frameStackedReceiverOffset(theFP))) + (2 * BytesPerWord)) == (((stackPageFor(theFP))->baseAddress)));
assert((longAt((theFP + (frameStackedReceiverOffset(theFP))) + BytesPerWord)) == (frameContext(theFP)));
longAtput((theFP + (frameStackedReceiverOffsetNumArgs(((((usqInt)(longAt(theFP + FoxMethod)))) < (startOfMemory())
? ((mframeCogMethod(theFP))->cmNumArgs)
: byteAt((theFP + FoxIFrameFlags) + 1))))) + (2 * BytesPerWord), aContextOrNil);
}
else {
/* begin storePointer:ofObject:withValue: */
Expand Down Expand Up @@ -66358,8 +66347,8 @@ void (*functionPointerForinClass(sqInt primIdx,sqInt theClass))(void)
static sqInt
getErrorObjectFromPrimFailCode(void)
{ DECL_MAYBE_SQ_GLOBAL_STRUCT
usqInt clone;
usqInt errObj;
sqInt clone;
sqInt errObj;
sqInt fieldIndex;
sqInt i;
sqInt knownClassIndex;
Expand Down Expand Up @@ -69675,7 +69664,7 @@ maybeLeakCheckExternalPrimCall(sqInt aMethodObj)
to the enclosing block or compiled method. */

/* StackInterpreter>>#maybeSelectorOfMethod: */
static sqInt NoDbgRegParms
sqInt
maybeSelectorOfMethod(sqInt methodObj)
{
sqInt maybeSelector;
Expand Down Expand Up @@ -75594,7 +75583,15 @@ storeSenderOfFramewithValue(char *theFP, sqInt anOop)
StackPage *thePage1;

if ((longAt(theFP + FoxSavedFP)) == 0) {
frameCallerContextput(theFP, anOop);
/* begin frameCallerContext:put: */
assert((anOop == (nilObject()))
|| (isContext(anOop)));
assert(isBaseFrame(theFP));
assert(((theFP + (frameStackedReceiverOffset(theFP))) + (2 * BytesPerWord)) == (((stackPageFor(theFP))->baseAddress)));
assert((longAt((theFP + (frameStackedReceiverOffset(theFP))) + BytesPerWord)) == (frameContext(theFP)));
longAtput((theFP + (frameStackedReceiverOffsetNumArgs(((((usqInt)(longAt(theFP + FoxMethod)))) < (startOfMemory())
? ((mframeCogMethod(theFP))->cmNumArgs)
: byteAt((theFP + FoxIFrameFlags) + 1))))) + (2 * BytesPerWord), anOop);
return theFP;
}
/* begin ensureCallerContext: */
Expand All @@ -75611,19 +75608,19 @@ storeSenderOfFramewithValue(char *theFP, sqInt anOop)
assert(addressCouldBeObj(callerContextOrNil));
assert((callerContextOrNil == (nilObject()))
|| (isContext(callerContextOrNil)));
goto l4;
goto l5;
}
/* begin ensureFrameIsMarried:SP: */
if (((((usqInt)(longAt(callerFP + FoxMethod)))) < (startOfMemory())
? ((longAt(callerFP + FoxMethod)) & MFMethodFlagHasContextFlag) != 0
: (byteAt((callerFP + FoxIFrameFlags) + 2)) != 0)) {
assert(isContext(frameContext(callerFP)));
longAt(callerFP + FoxThisContext);
goto l4;
goto l5;
}
marryFrameSP(callerFP, (assert(!(isBaseFrame(theFP))),
(theFP + (frameStackedReceiverOffset(theFP))) + BytesPerWord));
l4: /* end ensureCallerContext: */;
l5: /* end ensureCallerContext: */;
/* begin stackPageFor: */
thePage = stackPageAtpages((assert((((((char *) theFP)) >= (GIV(stackBasePlus1) - 1)) && ((((char *) theFP)) <= (((char *) GIV(pages)))))),
pageIndexForstackBasePlus1bytesPerPage(theFP, GIV(stackBasePlus1), GIV(bytesPerPage))), GIV(pages));
Expand Down Expand Up @@ -75657,7 +75654,15 @@ storeSenderOfFramewithValue(char *theFP, sqInt anOop)
markStackPageMostRecentlyUsed(newPage);
}
assert(isBaseFrame(theMovedFP));
frameCallerContextput(theMovedFP, anOop);
/* begin frameCallerContext:put: */
assert((anOop == (nilObject()))
|| (isContext(anOop)));
assert(isBaseFrame(theMovedFP));
assert(((theMovedFP + (frameStackedReceiverOffset(theMovedFP))) + (2 * BytesPerWord)) == (((stackPageFor(theMovedFP))->baseAddress)));
assert((longAt((theMovedFP + (frameStackedReceiverOffset(theMovedFP))) + BytesPerWord)) == (frameContext(theMovedFP)));
longAtput((theMovedFP + (frameStackedReceiverOffsetNumArgs(((((usqInt)(longAt(theMovedFP + FoxMethod)))) < (startOfMemory())
? ((mframeCogMethod(theMovedFP))->cmNumArgs)
: byteAt((theMovedFP + FoxIFrameFlags) + 1))))) + (2 * BytesPerWord), anOop);
return theMovedFP;
}

Expand Down Expand Up @@ -79067,7 +79072,7 @@ primitiveSetGCSemaphore(void)
static void
primitiveSignalAtMilliseconds(void)
{ DECL_MAYBE_SQ_GLOBAL_STRUCT
usqLong deltaMsecs;
sqLong deltaMsecs;
usqInt msecs;
sqInt msecsObj;
sqInt sema;
Expand Down Expand Up @@ -79371,7 +79376,6 @@ primitiveSlotAt(void)
static void
primitiveSlotAtPut(void)
{ DECL_MAYBE_SQ_GLOBAL_STRUCT
sqInt badRcvr;
sqInt bs;
sqInt ccIndex;
sqInt fmt;
Expand Down Expand Up @@ -79402,18 +79406,21 @@ primitiveSlotAtPut(void)
(GIV(primFailCode) = PrimErrBadArgument);
return;
}

if (rcvr & (tagMask())) {
/* begin primitiveFailFor: */
(GIV(primFailCode) = PrimErrBadReceiver);
return;
}
if (
# if IMMUTABILITY
/* begin isOopImmutable: */
badRcvr = (rcvr & (tagMask()))
|| (((((usqInt) (longAt(rcvr))) >> (immutableBitShift())) & 1) != 0);
(/* begin isImmutable: */
((((usqInt) (longAt(rcvr))) >> (immutableBitShift())) & 1) != 0)
# else /* IMMUTABILITY */
/* begin isImmediate: */
badRcvr = rcvr & (tagMask());
0
# endif /* IMMUTABILITY */
if (badRcvr) {
) {
/* begin primitiveFailFor: */
(GIV(primFailCode) = PrimErrBadReceiver);
(GIV(primFailCode) = PrimErrNoModification);
return;
}
fmt = (((usqInt) (longAt(rcvr))) >> (formatShift())) & (formatMask());
Expand Down Expand Up @@ -79464,33 +79471,33 @@ primitiveSlotAtPut(void)
GIV(primFailCode) = 1;
}
value = null;
goto l16;
goto l15;
}
value = value1;
goto l16;
goto l15;
}
if (newValue & (tagMask())) {
/* begin primitiveFail */
if (!GIV(primFailCode)) {
GIV(primFailCode) = 1;
}
value = 0;
goto l16;
goto l15;
}
/* begin isClassOfNonImm:equalTo:compactClassIndex: */
assert(!(isImmediate(newValue)));
/* begin classIndexOf: */
ccIndex = (longAt(newValue)) & (classIndexMask());
ok = ClassLargePositiveIntegerCompactIndex == ccIndex;
goto l15;
l15: /* end isClassOfNonImm:equalTo:compactClassIndex: */;
goto l14;
l14: /* end isClassOfNonImm:equalTo:compactClassIndex: */;
if (!ok) {
/* begin primitiveFail */
if (!GIV(primFailCode)) {
GIV(primFailCode) = 1;
}
value = 0;
goto l16;
goto l15;
}
/* begin numBytesOfBytes: */
fmt2 = (((usqInt) (longAt(newValue))) >> (formatShift())) & (formatMask());
Expand All @@ -79502,18 +79509,18 @@ primitiveSlotAtPut(void)
GIV(primFailCode) = 1;
}
value = 0;
goto l16;
goto l15;
}
if (((sizeof(usqIntptr_t)) == 8)
&& (bs > 4)) {
value = SQ_SWAP_8_BYTES_IF_BIGENDIAN((long64At((newValue + BaseHeaderSize) + (0U << 3))));
goto l16;
goto l15;
}
else {
value = ((unsigned int) (SQ_SWAP_4_BYTES_IF_BIGENDIAN((long32At((newValue + BaseHeaderSize) + (0U << 2))))));
goto l16;
goto l15;
}
l16: /* end positiveMachineIntegerValueOf: */;
l15: /* end positiveMachineIntegerValueOf: */;
if (GIV(primFailCode)) {
GIV(primFailCode) = PrimErrBadArgument;
return;
Expand Down Expand Up @@ -79795,7 +79802,7 @@ primitiveStoreStackp(void)
(read-only; Cog only; otherwise nil)
64 the number of methods that currently have jitted machine-code
65 whether the VM supports a certain feature, MULTIPLE_BYTECODE_SETS is
bit 0, IMMTABILITY is bit 1
bit 0, IMMUTABILITY is bit 1
66 the byte size of a stack page
67 the max allowed size of old space (Spur only; nil otherwise; 0 implies
no limit except that of the underlying platform)
Expand Down
3 changes: 2 additions & 1 deletion nsspur64src/vm/cointerp.h
@@ -1,5 +1,5 @@
/* Automatically generated by
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.2320 uuid: e2692e35-5fc8-4623-95d0-b445b3329f75
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.2347 uuid: 062614a7-e3da-4b30-997a-9568911b9ff5
*/


Expand Down Expand Up @@ -327,6 +327,7 @@ extern sqInt literalofMethod(sqInt offset, sqInt methodPointer);
extern void longPrintOop(sqInt oop);
extern sqInt longStoreBytecodeForHeader(sqInt methodHeader);
extern sqInt lookupSelectorinClass(sqInt selector, sqInt class);
extern sqInt maybeSelectorOfMethod(sqInt methodObj);
extern sqInt methodClassAssociationOf(sqInt methodPointer);
extern sqInt methodClassOf(sqInt methodPointer);
extern sqInt methodPrimitiveIndex(void);
Expand Down

0 comments on commit 4749358

Please sign in to comment.