[Vm-dev] VM Maker: VMMaker.oscog-eem.3282.mcz

commits at source.squeak.org commits at source.squeak.org
Mon Dec 12 17:23:17 UTC 2022


Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-eem.3282.mcz

==================== Summary ====================

Name: VMMaker.oscog-eem.3282
Author: eem
Time: 12 December 2022, 9:23:01.283007 am
UUID: c6ec4e7f-ae4d-4ead-a0d1-4be83e94848a
Ancestors: VMMaker.oscog-eem.3281

Check the argument count of the target method in the jitted perform primitive. Thanks to Boris Shingarov and Juan Vuletich for finding this.

=============== Diff against VMMaker.oscog-eem.3281 ===============

Item was added:
+ ----- Method: SimpleStackBasedCogit>>genLoadcmNumArgsOf:into: (in category 'primitive generators') -----
+ genLoadcmNumArgsOf: cogMethodReg into: targetReg
+ 	"Currently cmNumArgs is the first byte following the objectHeader."
+ 	<inline: true>
+ 	self MoveMb: objectRepresentation wordSize r: cogMethodReg R: targetReg!

Item was changed:
  ----- Method: SimpleStackBasedCogit>>genLookupForPerformNumArgs: (in category 'primitive generators') -----
  genLookupForPerformNumArgs: numArgs
  	"Compile the code for a probe of the first-level method cache for a perform primitive.
  	 The selector is assumed to be in Arg0Reg.  Defer to adjustArgumentsForPerform: to
  	 adjust the arguments before the jump to the method."
+ 	| jumpSelectorMiss jumpClassMiss jumpInterpret jumpBadNumArgs itsAHit cacheBaseReg |
- 	| jumpSelectorMiss jumpClassMiss jumpInterpret itsAHit cacheBaseReg |
- 	<var: #jumpSelectorMiss type: #'AbstractInstruction *'>
- 	<var: #jumpClassMiss type: #'AbstractInstruction *'>
- 	<var: #jumpInterpret type: #'AbstractInstruction *'>
- 	<var: #itsAHit type: #'AbstractInstruction *'>
  
  	"N.B.  Can't assume TempReg already contains the tag because a method can
  	 of course be invoked via the unchecked entry-point, e.g. as does perform:."
  	objectRepresentation genGetInlineCacheClassTagFrom: ReceiverResultReg into: SendNumArgsReg forEntry: false.
  
  	self flag: #lookupInMethodCacheSel:classTag:. "so this method shows up as a sender of lookupInMethodCacheSel:class:"
  
  	cacheBaseReg := NoReg.
  	(backEnd isWithinMwOffsetRange: coInterpreter methodCacheAddress) ifFalse:
  		[self MoveCq: coInterpreter methodCacheAddress R: (cacheBaseReg := Extra0Reg)].
  
  	"Do first of three probes.  See CoInterpreter>>lookupInMethodCacheSel:classTag:"
  	jumpSelectorMiss := self compilePerformMethodCacheProbeFor: Arg0Reg withShift: 0 baseRegOrNone: cacheBaseReg.
  	jumpClassMiss := self JumpNonZero: 0.
  
  	"Fetch the method, and check if it is cogged."
  	itsAHit := self MoveMw: (cacheBaseReg = NoReg
  								ifTrue: [coInterpreter methodCacheAddress + (MethodCacheMethod << objectMemory shiftForWord)]
  								ifFalse: [MethodCacheMethod << objectMemory shiftForWord])
  					r: ClassReg
  					R: SendNumArgsReg.
  	"If the method is not compiled fall back on the interpreter primitive."
  	objectRepresentation genLoadSlot: HeaderIndex sourceReg: SendNumArgsReg destReg: ClassReg.
  	jumpInterpret := objectRepresentation genJumpImmediate: ClassReg.
+ 	"check the argument count; if it's wrong fall back on the interpreter primitive."
+ 	self genLoadcmNumArgsOf: ClassReg into: SendNumArgsReg.
+ 	self CmpCq: numArgs R: SendNumArgsReg.
+ 	jumpBadNumArgs := self JumpNonZero: 0.
+ 	
  	"Adjust arguments and jump to the method's unchecked entry-point."
  	self AddCq: cmNoCheckEntryOffset R: ClassReg.
  	self adjustArgumentsForPerform: numArgs.
  	self JumpR: ClassReg.
  
  	"First probe missed.  Do second of three probes.  Shift hash right one and retry."
  	jumpSelectorMiss jmpTarget: (jumpClassMiss jmpTarget: self Label).
  	jumpSelectorMiss := self compilePerformMethodCacheProbeFor: Arg0Reg withShift: 1 baseRegOrNone: cacheBaseReg.
  	self JumpZero: itsAHit.
  
  	"Second probe missed.  Do last probe.  Shift hash right two and retry."
  	jumpSelectorMiss jmpTarget: self Label.
  	jumpSelectorMiss := self compilePerformMethodCacheProbeFor: Arg0Reg withShift: 2 baseRegOrNone: cacheBaseReg.
  	self JumpZero: itsAHit.
  
+ 	"Last probe missed/not jitted/bad num args.  Caller will generate the call to fall back on the interpreter primitive."
- 	"Last probe missed.  Caller will generate the call to fall back on the interpreter primitive."
  	jumpSelectorMiss jmpTarget:
+ 	(jumpInterpret jmpTarget:
+ 	(jumpBadNumArgs jmpTarget: self Label)).
- 	(jumpInterpret jmpTarget: self Label).
  	^0!



More information about the Vm-dev mailing list