https://forum.world.st/VM-Maker-Inbox-VMMaker-oscog-dtl-2968-mcz-tp5130394p5130395.html
for merging the fix_include_order branch into Cog. It also includes a fix
by Alistair Grant for keeping the global session ID in the range of a C int.
it will be possible to merge Nicolas' fix_include_order branch.
>
> David T. Lewis uploaded a new version of VMMaker to project VM Maker Inbox:
>
http://source.squeak.org/VMMakerInbox/VMMaker.oscog-dtl.2968.mcz>
> ==================== Summary ====================
>
> Name: VMMaker.oscog-dtl.2968
> Author: dtl
> Time: 13 June 2021, 6:26:53.146819 pm
> UUID: 603814ef-caa5-45c5-a0bd-896866381b01
> Ancestors: VMMaker.oscog-eem.2967, VMMaker.oscog-nice.2957
>
> Merge VMMaker.oscog-nice.2957 from inbox required for fix_include_order:
>
https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/562>
> Fix from Alistair Grant for globalSessionID range overflow:
>
https://github.com/pharo-project/opensmalltalk-vm/issues/233>
http://lists.squeakfoundation.org/pipermail/vm-dev/2021-May/036291.html>
> =============== Diff against VMMaker.oscog-eem.2967 ===============
>
> Item was changed:
> ----- Method: CCodeGenerator>>emitCHeaderOn: (in category 'C code generator') -----
> emitCHeaderOn: aStream
> "Emit the initial part of a source file on aStream, comprising the version stamp,
> the global struct usage flags, the header files and preamble code."
>
> | headerClass |
> headerClass := [vmClass coreInterpreterClass]
> on: MessageNotUnderstood
> do: [:ex| vmClass].
> aStream nextPutAll: (self fileHeaderVersionStampForSourceClass: headerClass); cr; cr.
> self emitGlobalStructFlagOn: aStream.
>
> (vmClass isNil or: [vmClass wantsSqDotH]) ifTrue:
> [self addHeaderFileFirst: '"sq.h"'].
> + "Additional header files; use the prescribed order."
> + self emitHeaderFiles: headerFiles on: aStream.
> - "Additional header files; include C library ones first."
> - self emitHeaderFiles: (headerFiles select: [:hdr| hdr includes: $<]) on: aStream.
> - "Additional header files; include squeak VM ones last"
> - self emitHeaderFiles: (headerFiles reject: [:hdr| hdr includes: $<]) on: aStream.
>
> self maybePutPreambleFor: vmClass on: aStream.
>
> aStream cr!
>
> Item was changed:
> ----- Method: Cogit class>>declareCVarsIn: (in category 'translation') -----
> declareCVarsIn: aCCodeGenerator
> | backEnd |
> backEnd := CogCompilerClass basicNew.
> #( 'coInterpreter' 'objectMemory' 'methodZone' 'objectRepresentation'
> 'cogBlockMethodSurrogateClass' 'cogMethodSurrogateClass' 'nsSendCacheSurrogateClass'
> 'threadManager' 'processor' 'lastNInstructions' 'simulatedAddresses'
> 'simulatedTrampolines' 'simulatedVariableGetters' 'simulatedVariableSetters'
> 'processorFrameValid' 'printRegisters' 'printInstructions' 'clickConfirm' 'singleStep') do:
> [:simulationVariableNotNeededForRealVM|
> aCCodeGenerator removeVariable: simulationVariableNotNeededForRealVM].
> NewspeakVM ifFalse:
> [#( 'selfSendTrampolines' 'dynamicSuperSendTrampolines'
> 'implicitReceiverSendTrampolines' 'outerSendTrampolines'
> 'ceEnclosingObjectTrampoline' 'numIRCs' 'indexOfIRC' 'theIRCs') do:
> [:variableNotNeededInNormalVM|
> aCCodeGenerator removeVariable: variableNotNeededInNormalVM]].
> aCCodeGenerator removeConstant: #COGMTVM. "this should be defined at compile time"
> "N.B. We *do not* include sq.h; it pulls in conflicting definitions now that sqVirtualMachine.h
> declares cointerp's functions, and declares some of them inaccurately for histrical reasons.
> We pull in CoInterpreter's api via cointerp.h which is accurate."
> aCCodeGenerator
> + addHeaderFile:'"sqConfig.h"'; "config.h must be first on linux"
> addHeaderFile:'<stddef.h>'; "for e.g. offsetof"
> addHeaderFile:'<stdio.h>';
> addHeaderFile:'<stdlib.h>';
> addHeaderFile:'<string.h>';
> - addHeaderFile:'"sqConfig.h"';
> addHeaderFile:'"sqPlatformSpecific.h"'; "e.g. solaris overrides things for sqCogStackAlignment.h"
> addHeaderFile:'"sqMemoryAccess.h"';
> addHeaderFile:'"sqCogStackAlignment.h"';
> addHeaderFile:'"dispdbg.h"'; "must precede cointerp.h & cogit.h otherwise NoDbgRegParms gets screwed up"
> addHeaderFile:'"cogmethod.h"'.
> NewspeakVM ifTrue:
> [aCCodeGenerator addHeaderFile:'"nssendcache.h"'].
> aCCodeGenerator
> addHeaderFile:'#if COGMTVM';
> addHeaderFile:'"cointerpmt.h"';
> addHeaderFile:'#else';
> addHeaderFile:'"cointerp.h"';
> addHeaderFile:'#endif';
> addHeaderFile:'"cogit.h"'.
> aCCodeGenerator
> var: #ceGetFP
> declareC: 'usqIntptr_t (*ceGetFP)(void)';
> var: #ceGetSP
> declareC: 'usqIntptr_t (*ceGetSP)(void)';
> var: #ceCaptureCStackPointers
> declareC: 'void (*ceCaptureCStackPointers)(void)';
> var: #ceInvokeInterpret
> declareC: 'void (*ceInvokeInterpret)(void)';
> var: #ceEnterCogCodePopReceiverReg
> declareC: 'void (*ceEnterCogCodePopReceiverReg)(void)';
> var: #realCEEnterCogCodePopReceiverReg
> declareC: 'void (*realCEEnterCogCodePopReceiverReg)(void)';
> var: #ceCallCogCodePopReceiverReg
> declareC: 'void (*ceCallCogCodePopReceiverReg)(void)';
> var: #realCECallCogCodePopReceiverReg
> declareC: 'void (*realCECallCogCodePopReceiverReg)(void)';
> var: #ceCallCogCodePopReceiverAndClassRegs
> declareC: 'void (*ceCallCogCodePopReceiverAndClassRegs)(void)';
> var: #realCECallCogCodePopReceiverAndClassRegs
> declareC: 'void (*realCECallCogCodePopReceiverAndClassRegs)(void)';
> var: #postCompileHook
> declareC: 'void (*postCompileHook)(CogMethod *)';
> var: #openPICList declareC: 'CogMethod *openPICList = 0';
> var: #maxMethodBefore type: #'CogBlockMethod *';
> var: 'enumeratingCogMethod' type: #'CogMethod *'.
>
> aCCodeGenerator
> var: #ceTryLockVMOwner
> declareC: '#if COGMTVM\usqIntptr_t (*ceTryLockVMOwner)(usqIntptr_t)\#endif'.
>
> backEnd numICacheFlushOpcodes > 0 ifTrue:
> [aCCodeGenerator
> var: #ceFlushICache
> declareC: 'static void (*ceFlushICache)(usqIntptr_t from, usqIntptr_t to)'].
> aCCodeGenerator
> var: #ceFlushDCache
> declareC: '#if DUAL_MAPPED_CODE_ZONE\static void (*ceFlushDCache)(usqIntptr_t from, usqIntptr_t to)\#endif';
> var: #codeToDataDelta
> declareC: '#if DUAL_MAPPED_CODE_ZONE\static sqInt codeToDataDelta\#else\# define codeToDataDelta 0\#endif'.
>
> aCCodeGenerator
> declareVar: 'aMethodLabel' type: #'AbstractInstruction'; "Has to come lexicographically before backEnd & methodLabel"
> var: #backEnd declareC: 'AbstractInstruction * const backEnd = &aMethodLabel';
> var: #methodLabel declareC: 'AbstractInstruction * const methodLabel = &aMethodLabel'.
> self declareC: #(abstractOpcodes stackCheckLabel
> blockEntryLabel blockEntryNoContextSwitch
> stackOverflowCall sendMiss
> entry noCheckEntry selfSendEntry dynSuperEntry
> fullBlockNoContextSwitchEntry fullBlockEntry
> picMNUAbort picInterpretAbort endCPICCase0 endCPICCase1 cPICEndOfCodeLabel)
> as: #'AbstractInstruction *'
> in: aCCodeGenerator.
> aCCodeGenerator
> declareVar: #cPICPrototype type: #'CogMethod *';
> declareVar: #blockStarts type: #'BlockStart *';
> declareVar: #fixups type: #'BytecodeFixup *';
> declareVar: #methodZoneBase type: #usqInt.
> aCCodeGenerator
> var: #ordinarySendTrampolines
> declareC: 'sqInt ordinarySendTrampolines[NumSendTrampolines]';
> var: #superSendTrampolines
> declareC: 'sqInt superSendTrampolines[NumSendTrampolines]'.
> BytecodeSetHasDirectedSuperSend ifTrue:
> [aCCodeGenerator
> var: #directedSuperSendTrampolines
> declareC: 'sqInt directedSuperSendTrampolines[NumSendTrampolines]';
> var: #directedSuperBindingSendTrampolines
> declareC: 'sqInt directedSuperBindingSendTrampolines[NumSendTrampolines]'].
> NewspeakVM ifTrue:
> [aCCodeGenerator
> var: #selfSendTrampolines
> declareC: 'sqInt selfSendTrampolines[NumSendTrampolines]';
> var: #dynamicSuperSendTrampolines
> declareC: 'sqInt dynamicSuperSendTrampolines[NumSendTrampolines]';
> var: #implicitReceiverSendTrampolines
> declareC: 'sqInt implicitReceiverSendTrampolines[NumSendTrampolines]';
> var: #outerSendTrampolines
> declareC: 'sqInt outerSendTrampolines[NumSendTrampolines]'].
> aCCodeGenerator
> addConstantForBinding: self bindingForNumTrampolines;
> var: #trampolineAddresses
> declareC: 'static char *trampolineAddresses[NumTrampolines*2]';
> var: #objectReferencesInRuntime
> declareC: 'static usqInt objectReferencesInRuntime[NumObjRefsInRuntime+1]';
> var: #labelCounter
> type: #int;
> var: #traceFlags
> declareC: 'int traceFlags = 8 /* prim trace log on by default */';
> var: #cStackAlignment
> declareC: 'const int cStackAlignment = STACK_ALIGN_BYTES'.
> aCCodeGenerator
> declareVar: #minValidCallAddress type: #'usqIntptr_t'.
> aCCodeGenerator vmClass generatorTable ifNotNil:
> [:bytecodeGenTable|
> aCCodeGenerator
> var: #generatorTable
> declareC: 'static BytecodeDescriptor generatorTable[', bytecodeGenTable size printString, ']',
> (self tableInitializerFor: bytecodeGenTable
> in: aCCodeGenerator)].
> "In C the abstract opcode names clash with the Smalltalk generator syntactic sugar.
> Most of the syntactic sugar is inlined, but alas some remains. Rename the syntactic
> sugar to avoid the clash."
> (self organization listAtCategoryNamed: #'abstract instructions') do:
> [:s|
> aCCodeGenerator addSelectorTranslation: s to: 'g', (aCCodeGenerator cFunctionNameFor: s)].
> aCCodeGenerator addSelectorTranslation: #halt: to: 'haltmsg'.
> self declareFlagVarsAsByteIn: aCCodeGenerator!
>
> Item was changed:
> ----- Method: StackInterpreter>>initializeInterpreter: (in category 'initialization') -----
> initializeInterpreter: bytesToShift
> "Initialize Interpreter state before starting execution of a new image."
> interpreterProxy := self sqGetInterpreterProxy.
> self dummyReferToProxy.
> objectMemory initializeObjectMemory: bytesToShift.
> self checkAssumedCompactClasses.
> self initializeExtraClassInstVarIndices.
> method := newMethod := objectMemory nilObject.
> self cCode: '' inSmalltalk:
> [breakSelectorLength ifNil:
> [breakSelectorLength := objectMemory minSmallInteger].
> breakLookupClassTag ifNil: [breakLookupClassTag := -1].
> reenterInterpreter := ReenterInterpreter new].
> methodDictLinearSearchLimit := 8.
> self initialCleanup.
> LowcodeVM ifTrue: [ self setupNativeStack ].
> profileSemaphore := profileProcess := profileMethod := objectMemory nilObject.
> interruptKeycode := 2094. "cmd-. as used for Mac but no other OS"
> [globalSessionID = 0] whileTrue:
> [globalSessionID := self
> + cCode: [((self time: #NULL) + self ioMSecs) bitAnd: 16r7FFFFFFF]
> + inSmalltalk: [(Random new next * (SmallInteger maxVal min: 16r7FFFFFFF)) asInteger]].
> - cCode: [(self time: #NULL) + self ioMSecs]
> - inSmalltalk: [(Random new next * (SmallInteger maxVal min: 16rFFFFFFFF)) asInteger]].
> metaAccessorDepth := -2.
> super initializeInterpreter: bytesToShift!
>