Eliot Miranda uploaded a new version of VMMaker to project VM Maker: http://source.squeak.org/VMMaker/VMMaker.oscog-eem.3165.mcz
==================== Summary ====================
Name: VMMaker.oscog-eem.3165 Author: eem Time: 22 February 2022, 2:41:23.177413 pm UUID: ccbc1741-ef0a-497a-9a42-0e13468fbc2a Ancestors: VMMaker.oscog-eem.3164
Fix STUPID rewrite regression in primitiveSmallFloatLogN (so costly :-( ). Make sure newMethod is set in primitives when turning on the profiler.
compileOnStackExternalPrimitive:flags: should use genLoadNewMethod to do that very thing...
=============== Diff against VMMaker.oscog-eem.3164 ===============
Item was changed: ----- Method: CoInterpreter>>primitivePropertyFlagsForSpur:numArgs: (in category 'cog jit support') ----- primitivePropertyFlagsForSpur: primIndex numArgs: numArgs <inline: true> "Answer any special requirements of the given primitive. Spur needs to set newMethod if and when a primitive fails so primitives can retry on failure due to forwarders, but this isn't done until failure. The primitiveMetadataTable is populated based on the primitiveMetadata: pragma in internal primitives." | baseFlags | baseFlags := profileSemaphore = objectMemory nilObject ifTrue: [0] + ifFalse: [PrimCallCollectsProfileSamples + PrimCallNeedsNewMethod]. - ifFalse: [PrimCallCollectsProfileSamples]. self cppIf: #LRPCheck ifTrue: [longRunningPrimitiveCheckSemaphore ifNotNil: [baseFlags := baseFlags bitOr: PrimCallNeedsNewMethod]].
(primIndex = PrimNumberVMParameter and: [numArgs = 1]) "vmParameterAt:" ifTrue: [^baseFlags + PrimCallOnSmalltalkStack + PrimCallOnSmalltalkStackAlign2x].
^baseFlags bitOr: ((primitiveMetadataTable at: primIndex) bitAnd: SpurPrimitiveFlagsMask)!
Item was changed: ----- Method: CoInterpreter>>primitivePropertyFlagsForV3:numArgs: (in category 'cog jit support') ----- primitivePropertyFlagsForV3: primIndex numArgs: numArgs <inline: true> "Answer any special requirements of the given primitive" | baseFlags | baseFlags := profileSemaphore ~= objectMemory nilObject + ifTrue: [PrimCallCollectsProfileSamples + PrimCallNeedsNewMethod] - ifTrue: [PrimCallNeedsNewMethod + PrimCallCollectsProfileSamples] ifFalse: [0].
self cppIf: #LRPCheck ifTrue: [longRunningPrimitiveCheckSemaphore ifNotNil: [baseFlags := baseFlags bitOr: PrimCallNeedsNewMethod]].
((self isCalloutPrimitiveIndex: primIndex) or: [self isCodeCompactingPrimitiveIndex: primIndex]) ifTrue: + [^baseFlags bitOr: PrimCallMayEndureCodeCompaction + PrimCallNeedsNewMethod]. - [^baseFlags bitOr: PrimCallNeedsNewMethod + PrimCallMayEndureCodeCompaction]. ((self isPerformPrimitive: primIndex) or: [self isMetaPrimitiveIndex: primIndex]) ifTrue: [^baseFlags bitOr: PrimCallNeedsNewMethod]. ^baseFlags!
Item was changed: ----- Method: InterpreterPrimitives>>primitiveSmallFloatLogN (in category 'arithmetic float primitives') ----- primitiveSmallFloatLogN "Natural log." <option: #Spur64BitMemoryManager> <primitiveMetadata: #(PrimCallOnSmalltalkStack PrimCallOnSmalltalkStackAlign2x)> | rcvr | rcvr := objectMemory smallFloatValueOf: self stackTop. + self stackTopPut: (objectMemory floatObjectOf: (self log: rcvr))! - self stackTopPut: (objectMemory floatObjectOf: (objectMemory floatObjectOf: (self log: rcvr)))!
Item was changed: ----- Method: SimpleStackBasedCogit>>compileOnStackExternalPrimitive:flags: (in category 'primitive generators') ----- compileOnStackExternalPrimitive: primitiveRoutine flags: flags "Compile a fast call of a C primitive using the current stack page, avoiding the stack switch except on failure. This convention still uses stackPointer and argumentCount to access operands. Push all operands to the stack, assign stackPointer, argumentCount, and zero primFailCode. Make the call (saving a LinkReg if required). Test for failure and return. On failure on Spur, if there is an accessor depth, assign framePointer and newMethod, do the stack switch, call checkForAndFollowForwardedPrimitiveState, and loop back if forwarders are found. Fall through to frame build." <option: #SpurObjectMemory> <var: #primitiveRoutine declareC: 'void (*primitiveRoutine)(void)'> | calleeSavedRegisterMask linkRegSaveRegister spRegSaveRegister jmpFail retry continueAfterProfileSample jumpToTakeSample | self assert: (objectRepresentation hasSpurMemoryManagerAPI and: [flags anyMask: PrimCallOnSmalltalkStack]). self deny: (backEnd hasVarBaseRegister and: [self register: VarBaseReg isInMask: ABICallerSavedRegisterMask]).
(coInterpreter recordFastCCallPrimTraceForMethod: methodObj) ifTrue: [self genFastPrimTraceUsing: ClassReg and: SendNumArgsReg].
"Clear the primFailCode and set argumentCount" self MoveCq: 0 R: TempReg. self MoveR: TempReg Aw: coInterpreter primFailCodeAddress. methodOrBlockNumArgs ~= 0 ifTrue: [self AddCq: methodOrBlockNumArgs R: TempReg]. "As small or smaller than move on most archs" self MoveR: TempReg Aw: coInterpreter argumentCountAddress. self genExternalizeStackPointerForFastPrimitiveCall. "We may need to save LinkReg and/or SPReg, and given the stack machinations it is much easier to save them in callee saved registers than on the stack itself." calleeSavedRegisterMask := ABICalleeSavedRegisterMask bitClear: (self registerMaskFor: ClassReg). backEnd hasLinkRegister ifTrue: [linkRegSaveRegister := self availableRegisterOrNoneIn: calleeSavedRegisterMask. self deny: linkRegSaveRegister = NoReg. self MoveR: LinkReg R: linkRegSaveRegister. calleeSavedRegisterMask := calleeSavedRegisterMask bitClear: (self registerMaskFor: linkRegSaveRegister)]. spRegSaveRegister := NoReg. (SPReg ~= NativeSPReg and: [(self isCalleeSavedReg: SPReg) not]) ifTrue: [spRegSaveRegister := self availableRegisterOrNoneIn: calleeSavedRegisterMask. self deny: spRegSaveRegister = NoReg. self MoveR: SPReg R: spRegSaveRegister]. retry := self Label. (flags anyMask: PrimCallOnSmalltalkStackAlign2x) ifTrue: [self AndCq: (objectMemory wordSize * 2 - 1) bitInvert R: SPReg R: NativeSPReg] ifFalse: [SPReg ~= NativeSPReg ifTrue: [backEnd genLoadNativeSPRegWithAlignedSPReg]]. backEnd genMarshallNArgs: 0 arg: nil arg: nil arg: nil arg: nil. "If the primitive is in the interpreter then its address won't change relative to the code zone over time, whereas if it is in a plugin its address could change if the module is un/re/over/loaded. So if in the interpreter and in range use a normal call instruction." ((flags noMask: PrimCallIsExternalCall) and: [backEnd isWithinCallRange: primitiveRoutine asInteger]) ifTrue: [self CallRT: primitiveRoutine asInteger] ifFalse: [self CallFullRT: primitiveRoutine asInteger]. backEnd genRemoveNArgsFromStack: 0. "test primFailCode and jump to failure sequence if non-zero" self MoveAw: coInterpreter primFailCodeAddress R: TempReg. spRegSaveRegister ~= NoReg ifTrue: [self MoveR: spRegSaveRegister R: SPReg]. self CmpCq: 0 R: TempReg. jmpFail := self JumpNonZero: 0. "Remember to restore the native stack pointer to point to the C stack, otherwise the Smalltalk frames will get overwritten on an interrupt." SPReg ~= NativeSPReg ifTrue: [backEnd genLoadCStackPointer]. "placing the test here attributes the tick to the primitive plus any checkForAndFollowForwardedPrimitiveState scanning, but attributes all of a failing primitive to the current method (in ceStackOverflow: on frame build)." (backEnd has64BitPerformanceCounter and: [flags anyMask: PrimCallCollectsProfileSamples]) ifTrue: [jumpToTakeSample := self genCheckForProfileTimerTick: (self registerMaskFor: NoReg)]. "At this point the primitive has cut back stackPointer to point to the result." continueAfterProfileSample := self MoveAw: coInterpreter stackPointerAddress R: TempReg. "get result and restore retpc" backEnd hasLinkRegister ifTrue: [self MoveMw: 0 r: TempReg R: ReceiverResultReg; AddCq: objectMemory wordSize R: TempReg R: SPReg; MoveR: linkRegSaveRegister R: LinkReg] ifFalse: [| retpcOffset | "The original retpc is (argumentCount + 1) words below stackPointer." retpcOffset := (methodOrBlockNumArgs + 1 * objectMemory wordSize) negated. self MoveMw: retpcOffset r: TempReg R: ClassReg; "get retpc" MoveR: TempReg R: SPReg; MoveMw: 0 r: TempReg R: ReceiverResultReg; MoveR: ClassReg Mw: 0 r: TempReg "put it back on stack for the return..."]. self RetN: 0.
(backEnd has64BitPerformanceCounter and: [flags anyMask: PrimCallCollectsProfileSamples]) ifTrue: [jumpToTakeSample jmpTarget: self Label. self genTakeProfileSample. self Jump: continueAfterProfileSample].
"primitive failure. if there is an accessor depth, scan and retry on failure (but what if faling for out of memory?)" jmpFail jmpTarget: self Label. (coInterpreter accessorDepthForPrimitiveMethod: methodObj) >= 0 ifTrue: [| skip | "Given that following primitive state to the accessor depth is recursive, we're asking for trouble if we run the fixup on the Smalltalk stack page. Run it on the full C stack instead. This won't be a performance issue since primitive failure should be very rare." self MoveR: FPReg Aw: coInterpreter framePointerAddress. self MoveCw: primitiveRoutine asInteger R: TempReg. self MoveR: TempReg Aw: coInterpreter primitiveFunctionPointerAddress. + self genLoadNewMethod. - methodLabel addDependent: - (self annotateAbsolutePCRef: - (self MoveCw: methodLabel asInteger R: ClassReg)). - self MoveMw: (self offset: CogMethod of: #methodObject) r: ClassReg R: TempReg. - self MoveR: TempReg Aw: coInterpreter newMethodAddress. self genLoadCStackPointersForPrimCall. backEnd genMarshallNArgs: 0 arg: 0 arg: 0 arg: 0 arg: 0. (backEnd isWithinCallRange: (self cCode: [#checkForAndFollowForwardedPrimitiveState asUnsignedIntegerPtr] inSmalltalk: [self simulatedTrampolineFor: #checkForAndFollowForwardedPrimitiveState])) ifTrue: [self CallRT: (self cCode: [#checkForAndFollowForwardedPrimitiveState asUnsignedIntegerPtr] inSmalltalk: [self simulatedTrampolineFor: #checkForAndFollowForwardedPrimitiveState])] ifFalse: [self CallFullRT: (self cCode: [#checkForAndFollowForwardedPrimitiveState asUnsignedIntegerPtr] inSmalltalk: [self simulatedTrampolineFor: #checkForAndFollowForwardedPrimitiveState])]. backEnd genLoadStackPointersForPrimCall: ClassReg. self CmpCq: 0 R: ABIResultReg. skip := self JumpZero: 0. self MoveCq: 0 R: TempReg. self MoveR: TempReg Aw: coInterpreter primFailCodeAddress. self Jump: retry. skip jmpTarget: self Label] ifFalse: "must reload SPReg to undo any alignment change," [(flags anyMask: PrimCallOnSmalltalkStackAlign2x) ifTrue: [backEnd hasLinkRegister ifTrue: [self MoveAw: coInterpreter stackPointerAddress R: SPReg] ifFalse: "remember to include return address; use scratch to avoid an interrupt overwriting retpc" [self MoveAw: coInterpreter stackPointerAddress R: TempReg. self SubCq: objectRepresentation wordSize R: TempReg. self MoveR: TempReg R: SPReg]]]. "Remember to restore the native stack pointer to point to the C stack, otherwise the Smalltalk frames will get overwritten on an interrupt." SPReg ~= NativeSPReg ifTrue: [backEnd genLoadCStackPointer]. "The LinkRegister now contains the return address either of the primitive call or of checkForAndFollowForwardedPrimitiveState. It must be restored to the return address of the send invoking this primtiive method." backEnd hasLinkRegister ifTrue: [self MoveR: linkRegSaveRegister R: LinkReg]. "Finally remember to reload ReceiverResultReg if required. Even if arguments have been pushed, the prolog sequence assumes it is live." (self register: ReceiverResultReg isInMask: ABICallerSavedRegisterMask) ifTrue: [self MoveMw: (methodOrBlockNumArgs + (backEnd hasLinkRegister ifTrue: [0] ifFalse: [1])) * objectMemory wordSize r: SPReg R: ReceiverResultReg]. "continue to frame build..." ^0!
vm-dev@lists.squeakfoundation.org