Skip to content

Commit

Permalink
CogVM source as per VMMaker.oscog-eem.3454
Browse files Browse the repository at this point in the history
Fix the image leak checker build on Unix (must define
INCLUDE_SIF_CODE before including sqImageFileAccess.h;
export readImageFromFile:HeapSize:StartingAt: via <api>)

Allow the StackIntrerpreter to print sends if printSends
is set ande the vm compiled with SEND_PRINTING
  • Loading branch information
eliotmiranda committed Aug 28, 2024
1 parent a837b70 commit 71e0893
Show file tree
Hide file tree
Showing 12 changed files with 1,752 additions and 602 deletions.
216 changes: 163 additions & 53 deletions src/spur32.stack.lowcode/gcc3x-interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@


/* Automatically generated by
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.3453 uuid: 6917573f-1029-4681-87bc-5f02f287102b
CCodeGeneratorGlobalStructure VMMaker.oscog-eem.3454 uuid: 664d9f13-edf2-4e42-8308-3ad5c07699c3
from
StackInterpreter VMMaker.oscog-eem.3453 uuid: 6917573f-1029-4681-87bc-5f02f287102b
StackInterpreter VMMaker.oscog-eem.3454 uuid: 664d9f13-edf2-4e42-8308-3ad5c07699c3
*/
static char __buildInfo[] = "StackInterpreter VMMaker.oscog-eem.3453 uuid: 6917573f-1029-4681-87bc-5f02f287102b " __DATE__ ;
static char __buildInfo[] = "StackInterpreter VMMaker.oscog-eem.3454 uuid: 664d9f13-edf2-4e42-8308-3ad5c07699c3 " __DATE__ ;
char *__interpBuildInfo = __buildInfo;


Expand Down Expand Up @@ -1314,6 +1314,7 @@ static NoDbgRegParms int primitiveFloatLessOrEqualtoArg(sqInt rcvrOop, sqInt arg
static NoDbgRegParms int primitiveFloatLessthanArg(sqInt rcvrOop, sqInt argOop);
extern sqInt primitiveIndexOfMethodheader(sqInt theMethod, sqInt methodHeader);
extern sqInt primitiveIndexOf(sqInt methodPointer);
static NoDbgRegParms void printActivationNameForSelectorstartClass(sqInt aSelector, sqInt startClass);
static NoDbgRegParms void printActivationNameForreceiverisBlockfirstTemporary(sqInt aMethod, sqInt anObject, sqInt isBlock, sqInt maybeMessage);
extern void printAllStacks(void);
extern void printAllStacksOn(FILE *aStdioStream);
Expand Down Expand Up @@ -1552,9 +1553,9 @@ _iss sqInt * rememberedSet;
_iss usqInt firstFreeObject;
_iss usqInt freeListsMask;
_iss sqInt remapBufferCount;
_iss sqInt classTableFirstPage;
_iss StackPage * mostRecentlyUsedPage;
_iss usqInt newSpaceStart;
_iss sqInt classTableFirstPage;
_iss usqInt totalHeapSizeIncludingBridges;
_iss char * nativeStackPointer;
_iss sqInt classTableIndex;
Expand Down Expand Up @@ -1635,6 +1636,7 @@ _iss sqInt interruptPending;
_iss sqInt longRunningPrimitiveCheckSequenceNumber;
#endif
_iss sqInt oldImageBaseAddress;
_iss sqInt printSends;
_iss sqInt savedWindowSize;
_iss sqInt statGrowMemory;
_iss sqInt statMaxPageCountWhenMapping;
Expand Down Expand Up @@ -2388,7 +2390,7 @@ sqInt debugCallbackInvokes;
sqInt debugCallbackReturns;
sqInt cannotDeferDisplayUpdates;
sqInt checkedPluginName;
const char *interpreterVersion = "Open Smalltalk Stack VM [StackInterpreterPrimitives VMMaker.oscog-eem.3453]";
const char *interpreterVersion = "Open Smalltalk Stack VM [StackInterpreterPrimitives VMMaker.oscog-eem.3454]";
sqInt suppressHeartbeatFlag;
char expensiveAsserts = 0;
int (*showSurfaceFn)(sqIntptr_t, int, int, int, int);
Expand Down Expand Up @@ -5390,6 +5392,16 @@ interpret(void)
? 1
: tagBits)
: (longAt(longAtPointer(localSP + (GIV(argumentCount) * BytesPerOop)))) & (classIndexMask())));
if (
# if SEND_PRINTING
GIV(printSends)
# else
0
# endif
) {
printActivationNameForSelectorstartClass(GIV(messageSelector), classForClassTag(lkupClassTag));
cr();
}
/* begin internalFindNewMethodOrdinary */
/* shift drops two low-order zeros from addresses */
hash1 = GIV(messageSelector) ^ (((sqInt)((usqInt)(lkupClassTag) << 2)));
Expand Down Expand Up @@ -32962,6 +32974,7 @@ primitivePerformInSuperclass(void)
sqInt tagBits;
sqInt tagBits1;
sqInt tagBits2;
sqInt tagBits3;
sqInt top;

rcvr = longAt(GIV(stackPointer) + (3 * BytesPerWord));
Expand Down Expand Up @@ -33071,18 +33084,34 @@ primitivePerformInSuperclass(void)
GIV(argumentCount) = arraySize;
GIV(messageSelector) = selector;
/* begin sendBreakpoint:receiver: */
sendBreakpointclassTag(firstFixedFieldOfMaybeImmediate(GIV(messageSelector)), lengthOfMaybeImmediate(GIV(messageSelector)), (((tagBits1 = rcvr & (tagMask()))) != 0
? ((tagBits1 & 1) != 0
sendBreakpointclassTag(firstFixedFieldOfMaybeImmediate(GIV(messageSelector)), lengthOfMaybeImmediate(GIV(messageSelector)), (((tagBits2 = rcvr & (tagMask()))) != 0
? ((tagBits2 & 1) != 0
? 1
: tagBits1)
: tagBits2)
: (longAt(rcvr)) & (classIndexMask())));
if (
# if SEND_PRINTING
GIV(printSends)
# else
0
# endif
) {
printActivationNameForSelectorstartClass(GIV(messageSelector), (lookupClass == null
?
/* begin fetchClassOf: */
(((tagBits3 = rcvr & (tagMask()))) != 0
? longAt((GIV(classTableFirstPage) + BaseHeaderSize) + (((sqInt)((usqInt)(tagBits3) << (shiftForWord())))))
: fetchClassOfNonImm(rcvr))
: lookupClass));
cr();
}
findNewMethodInClassTag((lookupClass == null
?
/* begin fetchClassTagOf: */
(((tagBits2 = rcvr & (tagMask()))) != 0
? ((tagBits2 & 1) != 0
(((tagBits1 = rcvr & (tagMask()))) != 0
? ((tagBits1 & 1) != 0
? 1
: tagBits2)
: tagBits1)
: (longAt(rcvr)) & (classIndexMask()))
: ( /* begin ensureBehaviorHash: */
assert(addressCouldBeClassObj(lookupClass)),
Expand Down Expand Up @@ -33168,6 +33197,7 @@ primitivePerformWithArgs(void)
char *sp2;
sqInt tagBits;
sqInt tagBits1;
sqInt tagBits2;
sqInt top;

actualReceiver = longAt(GIV(stackPointer) + (2 * BytesPerWord));
Expand Down Expand Up @@ -33236,16 +33266,30 @@ primitivePerformWithArgs(void)
GIV(argumentCount) = arraySize;
GIV(messageSelector) = selector;
/* begin sendBreakpoint:receiver: */
sendBreakpointclassTag(firstFixedFieldOfMaybeImmediate(GIV(messageSelector)), lengthOfMaybeImmediate(GIV(messageSelector)), (((tagBits1 = actualReceiver & (tagMask()))) != 0
? ((tagBits1 & 1) != 0
sendBreakpointclassTag(firstFixedFieldOfMaybeImmediate(GIV(messageSelector)), lengthOfMaybeImmediate(GIV(messageSelector)), (((tagBits2 = actualReceiver & (tagMask()))) != 0
? ((tagBits2 & 1) != 0
? 1
: tagBits1)
: tagBits2)
: (longAt(actualReceiver)) & (classIndexMask())));
if (
# if SEND_PRINTING
GIV(printSends)
# else
0
# endif
) {
printActivationNameForSelectorstartClass(GIV(messageSelector),
/* begin fetchClassOf: */
(((tagBits = actualReceiver & (tagMask()))) != 0
? longAt((GIV(classTableFirstPage) + BaseHeaderSize) + (((sqInt)((usqInt)(tagBits) << (shiftForWord())))))
: fetchClassOfNonImm(actualReceiver)));
cr();
}
findNewMethodInClassTag( /* begin fetchClassTagOf: */
(((tagBits = actualReceiver & (tagMask()))) != 0
? ((tagBits & 1) != 0
(((tagBits1 = actualReceiver & (tagMask()))) != 0
? ((tagBits1 & 1) != 0
? 1
: tagBits)
: tagBits1)
: (longAt(actualReceiver)) & (classIndexMask())));
if (( /* begin isOopCompiledMethod: */
((!(GIV(newMethod) & (tagMask()))))
Expand Down Expand Up @@ -67968,6 +68012,98 @@ primitiveIndexOf(sqInt methodPointer)
: 0);
}

/* StackInterpreter>>#printActivationNameForSelector:startClass: */
static NoDbgRegParms void
printActivationNameForSelectorstartClass(sqInt aSelector, sqInt startClass)
{ DECL_MAYBE_SQ_GLOBAL_STRUCT
sqInt classDict;
usqInt classDictSize;
sqInt currClass;
sqInt i;
sqInt methClass;
usqInt numSlots;
sqInt objOop;

if (addressCouldBeObj(startClass)) {
/* begin findClassForSelector:lookupClass:do: */
currClass = startClass;
do {
classDict = longAt((currClass + BaseHeaderSize) + (((int)((usqInt)(MethodDictionaryIndex) << (shiftForWord())))));
/* begin numSlotsOf: */
assert((classIndexOf(classDict)) > (isForwardedObjectClassIndexPun()));
if (((numSlots = byteAt(classDict + 7))) == (numSlotsMask())) {
/* overflow slots; at least (2^32)-1 slots, which is plenty */
classDictSize = longAt(classDict - BaseHeaderSize);
}
else {
classDictSize = numSlots;
}
i = SelectorStart;
while (i < classDictSize) {
if (aSelector == (longAt((classDict + BaseHeaderSize) + (((sqInt)((usqInt)(i) << (shiftForWord()))))))) {
methClass = currClass;
goto l2;
}
i += 1;
}
/* begin superclassOf: */
objOop = longAt((currClass + BaseHeaderSize) + (((int)((usqInt)(SuperclassIndex) << (shiftForWord())))));
assert(isNonImmediate(objOop));
if ((!((longAt(objOop)) & ((classIndexMask()) - (isForwardedObjectClassIndexPun()))))) {
objOop = fixFollowedFieldofObjectwithInitialValue(SuperclassIndex, currClass, objOop);
}
currClass = objOop;
} while(!(currClass == GIV(nilObj)));
methClass = null;
l2: /* end findClassForSelector:lookupClass:do: */;
if ((methClass == null)
|| (startClass == methClass)) {
printNameOfClasscount(methClass, 5);
printChar('>');
if (!methClass) {
printStringOf(longAt((GIV(specialObjectsOop) + BaseHeaderSize) + (((int)((usqInt)(SelectorDoesNotUnderstand) << (shiftForWord()))))));
/* begin print: */
fprintf(GIV(transcript),
"%s",
" ");
}
}
else {
printNameOfClasscount(startClass, 5);
printChar('(');
printNameOfClasscount(methClass, 5);
printChar(')');
printChar('>');
}
}
else {
/* begin print: */
fprintf(GIV(transcript),
"%s",
"INVALID CLASS");
}
if ( /* begin addressCouldBeOop: */
(((aSelector & (tagMask())) != 0))
|| (addressCouldBeObj(aSelector))) {
if ( /* begin isBytes: */
((!(aSelector & (tagMask()))))
&& (((((usqInt)((longAt(aSelector)))) >> (formatShift())) & (formatMask())) >= (firstByteFormat()))) {
printStringOf(aSelector);
}
else {
/* begin printOopShort: */
printOopShortInner(aSelector);
fflush(GIV(transcript));
}
}
else {
/* begin print: */
fprintf(GIV(transcript),
"%s",
"INVALID SELECTOR");
}
}

/* StackInterpreter>>#printActivationNameFor:receiver:isBlock:firstTemporary: */
static NoDbgRegParms void
printActivationNameForreceiverisBlockfirstTemporary(sqInt aMethod, sqInt anObject, sqInt isBlock, sqInt maybeMessage)
Expand Down Expand Up @@ -70633,36 +70769,6 @@ readableFormat(sqInt imageVersion)
return (((imageVersion | MultipleBytecodeSetsBitmask) - MultipleBytecodeSetsBitmask)) == 6521 /* begin imageFormatVersion */;
}


/* Read an image from the given file stream, allocating an amount of memory
to its object heap.

V3: desiredHeapSize is the total size of the heap. Fail if the image has
an unknown format or
requires more than the specified amount of memory.

Spur: desiredHeapSize is ignored; this routine will attempt to provide at
least extraVMMemory's
ammount of free space after the image is loaded, taking any free space in
teh image into account.
extraVMMemory is stored in the image header and is accessible as
vmParameterAt: 23. If
extraVMMemory is 0, the value defaults to the default grow headroom. Fail
if the image has an
unknown format or if sufficient memory cannot be allocated.

Details: This method detects when the image was stored on a machine with
the opposite byte
ordering from this machine and swaps the bytes automatically. Furthermore,
it allows the header
information to start 512 bytes into the file, since some file transfer
programs for the Macintosh
apparently prepend a Mac-specific header of this size. Note that this same
512 bytes of prefix
area could also be used to store an exec command on Unix systems, allowing
one to launch
Smalltalk by invoking the image name as a command. */

/* StackInterpreter>>#readImageFromFile:HeapSize:StartingAt: */
size_t
readImageFromFileHeapSizeStartingAt(sqImageFile f, usqInt desiredHeapSize, squeakFileOffsetType imageOffset)
Expand Down Expand Up @@ -70719,11 +70825,8 @@ readImageFromFileHeapSizeStartingAt(sqImageFile f, usqInt desiredHeapSize, squea
unsigned short w9;

rawVersion = 0;
/* stdout is not available at compile time. this is the earliest available point. */
GIV(transcript) = stdout;
/* guess Metaclass instSize */
GIV(metaclassNumSlots) = 6;
/* guess (Class instVarIndexFor: 'name' ifAbsent: []) - 1 */
GIV(classNameIndex) = 6;
version = checkImageVersionFromstartingAtassignRawVersion(f, imageOffset, (&rawVersion));
if (version == 0) {
Expand Down Expand Up @@ -70753,7 +70856,6 @@ readImageFromFileHeapSizeStartingAt(sqImageFile f, usqInt desiredHeapSize, squea
}
swapBytes = rawVersion != version;
GIV(multipleBytecodeSetsActive) = ((version & MultipleBytecodeSetsBitmask) != 0);
/* record header start position */
headerStart = (sqImageFilePosition(f)) - 4;
/* begin getWord32FromFile:swap: */
w = 0;
Expand Down Expand Up @@ -70837,8 +70939,6 @@ readImageFromFileHeapSizeStartingAt(sqImageFile f, usqInt desiredHeapSize, squea
: (hdrNumStackPages == 0
? defaultNumStackPages()
: hdrNumStackPages));
/* pad to word boundary. This slot can be used for anything else that will fit in 16 bits.
It is used for the cog code size in Cog. Preserve it to be polite to other VMs. */
desiredNumStackPages = hdrNumStackPages;
/* begin getShortFromFile:swap: */
w7 = 0;
Expand Down Expand Up @@ -78269,6 +78369,16 @@ primitivePerform(void)
? 1
: tagBits1)
: (longAt(newReceiver)) & (classIndexMask())));
if (
# if SEND_PRINTING
GIV(printSends)
# else
0
# endif
) {
printActivationNameForSelectorstartClass(GIV(messageSelector), classForClassTag(lookupClassTag));
cr();
}
findNewMethodInClassTag(lookupClassTag);
if (!(( /* begin isOopCompiledMethod: */
((!(GIV(newMethod) & (tagMask()))))
Expand Down
Loading

0 comments on commit 71e0893

Please sign in to comment.