[Vm-dev] VM Maker: VMMaker.oscog-eem.1024.mcz
commits at source.squeak.org
commits at source.squeak.org
Tue Jan 20 00:25:03 UTC 2015
Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-eem.1024.mcz
==================== Summary ====================
Name: VMMaker.oscog-eem.1024
Author: eem
Time: 19 January 2015, 4:23:45.415 pm
UUID: f6cf904e-36ea-4109-a415-b8564601d19e
Ancestors: VMMaker.oscog-eem.1023
Newspeak:
Integrate Ryan's newer absent receiver sends,
which first apeared in VMMaker.oscog-eem.919,
abandoned because of Glue issues now resolved.
Includes nice refactoring of absent send argument
marshalling into its own routine.
Spur: Provide a validFreeTree checker.
=============== Diff against VMMaker.oscog-eem.1023 ===============
Item was changed:
----- Method: CoInterpreter>>implicitReceiverFor:mixin:implementing: (in category 'newspeak bytecode support') -----
+ implicitReceiverFor: methodReceiver mixin: methodMixin implementing: selector
+ "This is used to implement implicit receiver sends in Newspeak. Find the nearest
+ lexically-enclosing implementation of selector by searching up the static chain of the
+ method's receiver, starting at mixin's application. This implementation is derived from
- implicitReceiverFor: rcvr mixin: mixin implementing: selector
- "This is used to implement the innards of the pushImplicitReceiverBytecode,
- used for implicit receiver sends in NS2/NS3. Find the nearest lexically-enclosing
- implementation of selector by searching up the static chain of anObject,
- starting at mixin's application. This is an iterative implementation derived from
+ <ContextPart> implicitReceiverFor: methodReceiver <Object>
+ in: methodMixin <Mixin>
- <ContextPart> implicitReceiverFor: obj <Object>
- withMixin: mixin <Mixin>
implementing: selector <Symbol> ^<Object>"
<api>
<option: #NewspeakVM>
cogit breakOnImplicitReceiver ifTrue:
[self sendBreakpoint: selector receiver: nil].
+ ^super implicitReceiverFor: methodReceiver mixin: methodMixin implementing: selector!
- ^super implicitReceiverFor: rcvr mixin: mixin implementing: selector!
Item was changed:
----- Method: SimpleStackBasedCogit class>>initializeBytecodeTableForNewspeakV4 (in category 'class initialization') -----
initializeBytecodeTableForNewspeakV4
"SimpleStackBasedCogit initializeBytecodeTableForNewspeakV4"
NSSendIsPCAnnotated := false. "IsNSSendCall used by SendAbsentImplicit"
FirstSpecialSelector := 80.
self flag:
'Special selector send class must be inlined to agree with the interpreter, which
inlines class. If class is sent to e.g. a general instance of ProtoObject then unless
class is inlined there will be an MNU. It must be that the Cointerpreter and Cogit
have identical semantics. We get away with not hardwiring the other special
selectors either because in the Cointerpreter they are not inlined or because they
are inlined only to instances of classes for which there will always be a method.'.
self generatorTableFrom: #(
"1 byte bytecodes"
(1 0 15 genPushReceiverVariableBytecode)
(1 16 31 genPushLiteralVariable16CasesBytecode needsFrameNever: 1)
(1 32 63 genPushLiteralConstantBytecode needsFrameNever: 1)
(1 64 75 genPushTemporaryVariableBytecode)
(1 76 76 genPushReceiverBytecode)
(1 77 77 genExtPushPseudoVariableOrOuterBytecode)
(1 78 78 genPushConstantZeroBytecode)
(1 79 79 genPushConstantOneBytecode)
(1 80 101 genSpecialSelectorSend isMapped) "#+ #- #< #> #<= #>= #= #~= #* #/ #\\ #@ #bitShift: #// #bitAnd: #bitOr: #at: #at:put: #size #next #nextPut: #atEnd"
(1 102 102 genSpecialSelectorEqualsEquals needsFrameNever: notMapped -1) "not mapped because it is directly inlined (for now)"
(1 103 103 genSpecialSelectorClass needsFrameNever: notMapped 0) "not mapped because it is directly inlined (for now)"
(1 104 111 genSpecialSelectorSend isMapped) "#blockCopy: #value #value: #do: #new #new: #x #y"
(1 112 127 genSendLiteralSelector0ArgsBytecode isMapped)
(1 128 143 genSendLiteralSelector1ArgBytecode isMapped)
(1 144 159 genSendLiteralSelector2ArgsBytecode isMapped)
(1 160 175 genSendAbsentImplicit0ArgsBytecode isMapped hasIRC)
(1 176 183 genStoreAndPopReceiverVariableBytecode needsFrameNever: -1) "N.B. not frameless if immutability"
(1 184 191 genStoreAndPopTemporaryVariableBytecode)
(1 192 199 genShortUnconditionalJump branch v3:ShortForward:Branch:Distance:)
(1 200 207 genShortJumpIfTrue branch isBranchTrue isMapped "because of mustBeBoolean"
v3:ShortForward:Branch:Distance:)
(1 208 215 genShortJumpIfFalse branch isBranchFalse isMapped "because of mustBeBoolean"
v3:ShortForward:Branch:Distance:)
(1 216 216 genReturnReceiver return needsFrameIfInBlock: isMappedInBlock 0)
(1 217 217 genReturnTopFromMethod return needsFrameIfInBlock: isMappedInBlock -1)
(1 218 218 genExtReturnTopFromBlock return needsFrameNever: -1)
(1 219 219 duplicateTopBytecode needsFrameNever: 1)
(1 220 220 genPopStackBytecode needsFrameNever: -1)
(1 221 221 genExtNopBytecode needsFrameNever: 0)
(1 222 223 unknownBytecode)
"2 byte bytecodes"
(2 224 224 extABytecode extension)
(2 225 225 extBBytecode extension)
(2 226 226 genExtPushReceiverVariableBytecode)
(2 227 227 genExtPushLiteralVariableBytecode needsFrameNever: 1)
(2 228 228 genExtPushLiteralBytecode needsFrameNever: 1)
(2 229 229 genExtPushIntegerBytecode needsFrameNever: 1)
(2 230 230 genLongPushTemporaryVariableBytecode)
(2 231 231 genPushNewArrayBytecode)
(2 232 232 genExtStoreReceiverVariableBytecode)
(2 233 233 genExtStoreLiteralVariableBytecode)
(2 234 234 genLongStoreTemporaryVariableBytecode)
(2 235 235 genExtStoreAndPopReceiverVariableBytecode)
(2 236 236 genExtStoreAndPopLiteralVariableBytecode)
(2 237 237 genLongStoreAndPopTemporaryVariableBytecode)
(2 238 238 genExtSendBytecode isMapped)
(2 239 239 genExtSendSuperBytecode isMapped)
(2 240 240 genExtSendAbsentImplicitBytecode isMapped hasIRC)
(2 241 241 genExtSendAbsentDynamicSuperBytecode isMapped)
(2 242 242 genExtUnconditionalJump branch isMapped "because of interrupt check" v4:Long:Branch:Distance:)
(2 243 243 genExtJumpIfTrue branch isBranchTrue isMapped "because of mustBeBoolean" v4:Long:Branch:Distance:)
(2 244 244 genExtJumpIfFalse branch isBranchFalse isMapped "because of mustBeBoolean" v4:Long:Branch:Distance:)
+ (2 245 245 genExtSendAbsentSelfBytecode isMapped)
- (2 245 248 unknownBytecode)
+ (2 246 248 unknownBytecode)
+
"3 byte bytecodes"
(3 249 249 callPrimitiveBytecode)
(3 250 250 genPushRemoteTempLongBytecode)
(3 251 251 genStoreRemoteTempLongBytecode)
(3 252 252 genStoreAndPopRemoteTempLongBytecode)
(3 253 253 genExtPushClosureBytecode block v4:Block:Code:Size:)
+ (3 254 254 genExtSendAbsentOuterBytecode isMapped)
+ (3 255 255 unknownBytecode))!
- (3 254 255 unknownBytecode))!
Item was added:
+ ----- Method: SimpleStackBasedCogit>>genExtSendAbsentOuterBytecode (in category 'bytecode generators') -----
+ genExtSendAbsentOuterBytecode
+ "254 11111110 i i i i i j j j kkkkkkkk Send To Absent Outer Literal Selector #iiiii (+ Extend A * 32) with jjj (+ Extend B * 8) Arguments at Depth kkkkkkkk "
+ | litIndex nArgs depth |
+ litIndex := (byte1 >> 3) + (extA << 5).
+ extA := 0.
+ nArgs := (byte1 bitAnd: 7) + (extB << 3).
+ extB := 0.
+ depth := byte2.
+ ^self genSendAbsentOuter: (self getLiteral: litIndex) numArgs: nArgs depth: depth
+ !
Item was added:
+ ----- Method: SimpleStackBasedCogit>>genExtSendAbsentSelfBytecode (in category 'bytecode generators') -----
+ genExtSendAbsentSelfBytecode
+ "245 11110101 i i i i i j j j Send To Absent Self Literal Selector #iiiii (+ Extend A * 32) with jjj (+ Extend B * 8) Arguments"
+ | litIndex nArgs |
+ litIndex := (byte1 >> 3) + (extA << 5).
+ extA := 0.
+ nArgs := (byte1 bitAnd: 7) + (extB << 3).
+ extB := 0.
+ ^self genSendAbsentSelf: (self getLiteral: litIndex) numArgs: nArgs!
Item was changed:
----- Method: SimpleStackBasedCogit>>genPushEnclosingObjectAt: (in category 'bytecode generators') -----
genPushEnclosingObjectAt: level
"Uncached push enclosing object"
self MoveCq: level R: SendNumArgsReg.
self CallRT: ceEnclosingObjectTrampoline.
self PushR: ReceiverResultReg.
^0!
Item was changed:
----- Method: SimpleStackBasedCogit>>genSendAbsentDynamicSuper:numArgs: (in category 'bytecode generators') -----
genSendAbsentDynamicSuper: selector numArgs: numArgs
"Shuffle arguments if necessary and push receiver.
Then send."
<inline: false>
+ self marshallAbsentReceiverSendArguments: numArgs.
- numArgs = 0
- ifTrue:
- [self PushR: ReceiverResultReg]
- ifFalse:
- [self MoveMw: 0 r: SPReg R: TempReg.
- self PushR: TempReg.
- 2 to: numArgs do:
- [:index|
- self MoveMw: index * objectMemory wordSize r: SPReg R: TempReg.
- self MoveR: TempReg Mw: index - 1 * objectMemory wordSize r: SPReg].
- "if we copied the code in genSendDynamicSuper: we could save an instruction.
- But we care not; the smarts are in StackToRegisterMappingCogit et al"
- self MoveR: ReceiverResultReg Mw: numArgs * objectMemory wordSize r: SPReg].
^self genSendDynamicSuper: selector numArgs: numArgs!
Item was changed:
----- Method: SimpleStackBasedCogit>>genSendAbsentImplicit:numArgs: (in category 'bytecode generators') -----
genSendAbsentImplicit: selector numArgs: numArgs
"Get the implicit receiver and shuffle arguments if necessary.
Then send."
<inline: false>
| result |
result := self genGetImplicitReceiverFor: selector forPush: false.
result ~= 0 ifTrue:
[^result].
+ self marshallAbsentReceiverSendArguments: numArgs.
- numArgs = 0
- ifTrue:
- [self PushR: ReceiverResultReg]
- ifFalse:
- [self MoveMw: 0 r: SPReg R: TempReg.
- self PushR: TempReg.
- 2 to: numArgs do:
- [:index|
- self MoveMw: index * objectMemory wordSize r: SPReg R: TempReg.
- self MoveR: TempReg Mw: index - 1 * objectMemory wordSize r: SPReg].
- "if we copied the code in genSend:numArgs: we could save an instruction.
- But we care not; the smarts are in StackToRegisterMappingCogit et al"
- self MoveR: ReceiverResultReg Mw: numArgs * objectMemory wordSize r: SPReg].
^self genSend: selector numArgs: numArgs!
Item was added:
+ ----- Method: SimpleStackBasedCogit>>genSendAbsentOuter:numArgs:depth: (in category 'bytecode generators') -----
+ genSendAbsentOuter: selector numArgs: numArgs depth: depth
+ "Shuffle arguments if necessary and push receiver.
+ Then send."
+ <inline: false>
+ self genPushEnclosingObjectAt: depth.
+ self PopR: ReceiverResultReg.
+ self marshallAbsentReceiverSendArguments: numArgs.
+ ^self genSend: selector numArgs: numArgs!
Item was added:
+ ----- Method: SimpleStackBasedCogit>>genSendAbsentSelf:numArgs: (in category 'bytecode generators') -----
+ genSendAbsentSelf: selector numArgs: numArgs
+ "Shuffle arguments if necessary and push receiver.
+ Then send."
+ <inline: false>
+ self marshallAbsentReceiverSendArguments: numArgs.
+ ^self genSend: selector numArgs: numArgs!
Item was added:
+ ----- Method: SimpleStackBasedCogit>>marshallAbsentReceiverSendArguments: (in category 'bytecode generators') -----
+ marshallAbsentReceiverSendArguments: numArgs
+ "Shuffle arguments if necessary and push receiver."
+ numArgs = 0
+ ifTrue:
+ [self PushR: ReceiverResultReg]
+ ifFalse:
+ [self MoveMw: 0 r: SPReg R: TempReg.
+ self PushR: TempReg.
+ 2 to: numArgs do:
+ [:index|
+ self MoveMw: index * BytesPerWord r: SPReg R: TempReg.
+ self MoveR: TempReg Mw: index - 1 * BytesPerWord r: SPReg].
+ self MoveR: ReceiverResultReg Mw: numArgs * BytesPerWord r: SPReg].!
Item was added:
+ ----- Method: SpurMemoryManager>>validFreeTree (in category 'free space') -----
+ validFreeTree
+ <api>
+ ^(self validFreeTreeChunk: (freeLists at: 0) parent: 0) isNil!
Item was added:
+ ----- Method: SpurMemoryManager>>validFreeTreeChunk:parent: (in category 'free space') -----
+ validFreeTreeChunk: chunk parent: parent
+ <returnTypeC: 'const char *'>
+ chunk = 0 ifTrue:
+ [^nil].
+ (self addressCouldBeOldObj: chunk) ifFalse:
+ [^'not in old space'].
+ (self bytesInObject: chunk) / self allocationUnit < self numFreeLists ifTrue:
+ [^'too small'].
+ parent ~= (self fetchPointer: self freeChunkParentIndex ofFreeChunk: chunk) ifTrue:
+ [^'bad parent'].
+ (self validFreeTreeChunk: (self fetchPointer: self freeChunkSmallerIndex ofFreeChunk: chunk) parent: chunk) ifNotNil:
+ [:reason| ^reason].
+ (self validFreeTreeChunk: (self fetchPointer: self freeChunkLargerIndex ofFreeChunk: chunk) parent: chunk) ifNotNil:
+ [:reason| ^reason].
+ ^nil!
Item was changed:
----- Method: StackInterpreter class>>initializeBytecodeTableForNewspeakV4 (in category 'initialization') -----
initializeBytecodeTableForNewspeakV4
"StackInterpreter initializeBytecodeTableForNewspeakV4"
"Note: This table will be used to generate a C switch statement."
BytecodeTable := Array new: 256.
BytecodeEncoderClassName := #EncoderForNewsqueakV4.
LongStoreBytecode := 234.
self table: BytecodeTable from:
#( "1 byte bytecodes"
( 0 15 pushReceiverVariableBytecode)
( 16 31 pushLiteralVariable16CasesBytecode)
( 32 63 pushLiteralConstantBytecode)
( 64 75 pushTemporaryVariableBytecode)
( 76 pushReceiverBytecode)
( 77 extPushPseudoVariableOrOuterBytecode)
( 78 pushConstantZeroBytecode)
( 79 pushConstantOneBytecode)
( 80 bytecodePrimAdd)
( 81 bytecodePrimSubtract)
( 82 bytecodePrimLessThanV4) "for booleanCheatV4:"
( 83 bytecodePrimGreaterThanV4) "for booleanCheatV4:"
( 84 bytecodePrimLessOrEqualV4) "for booleanCheatV4:"
( 85 bytecodePrimGreaterOrEqualV4) "for booleanCheatV4:"
( 86 bytecodePrimEqualV4) "for booleanCheatV4:"
( 87 bytecodePrimNotEqualV4) "for booleanCheatV4:"
( 88 bytecodePrimMultiply)
( 89 bytecodePrimDivide)
( 90 bytecodePrimMod)
( 91 bytecodePrimMakePoint)
( 92 bytecodePrimBitShift)
( 93 bytecodePrimDiv)
( 94 bytecodePrimBitAnd)
( 95 bytecodePrimBitOr)
( 96 bytecodePrimAt)
( 97 bytecodePrimAtPut)
( 98 bytecodePrimSize)
( 99 bytecodePrimNext)
(100 bytecodePrimNextPut)
(101 bytecodePrimAtEnd)
(102 bytecodePrimIdenticalV4) "for booleanCheatV4:"
(103 bytecodePrimClass)
(104 bytecodePrimSpecialSelector24) "was blockCopy:"
(105 bytecodePrimValue)
(106 bytecodePrimValueWithArg)
(107 bytecodePrimDo)
(108 bytecodePrimNew)
(109 bytecodePrimNewWithArg)
(110 bytecodePrimPointX)
(111 bytecodePrimPointY)
(112 127 sendLiteralSelector0ArgsBytecode)
(128 143 sendLiteralSelector1ArgBytecode)
(144 159 sendLiteralSelector2ArgsBytecode)
(160 175 sendAbsentImplicit0ArgsBytecode)
(176 183 storeAndPopReceiverVariableBytecode)
(184 191 storeAndPopTemporaryVariableBytecode)
(192 199 shortUnconditionalJump)
(200 207 shortConditionalJumpTrue)
(208 215 shortConditionalJumpFalse)
(216 returnReceiver)
(217 returnTopFromMethod)
(218 extReturnTopFromBlock)
(219 duplicateTopBytecode)
(220 popStackBytecode)
(221 extNopBytecode)
(222 223 unknownBytecode)
"2 byte bytecodes"
(224 extABytecode)
(225 extBBytecode)
(226 extPushReceiverVariableBytecode)
(227 extPushLiteralVariableBytecode)
(228 extPushLiteralBytecode)
(229 extPushIntegerBytecode)
(230 longPushTemporaryVariableBytecode)
(231 pushNewArrayBytecode)
(232 extStoreReceiverVariableBytecode)
(233 extStoreLiteralVariableBytecode)
(234 longStoreTemporaryVariableBytecode)
(235 extStoreAndPopReceiverVariableBytecode)
(236 extStoreAndPopLiteralVariableBytecode)
(237 longStoreAndPopTemporaryVariableBytecode)
(238 extSendBytecode)
(239 extSendSuperBytecode)
(240 extSendAbsentImplicitBytecode)
(241 extSendAbsentDynamicSuperBytecode)
(242 extUnconditionalJump)
(243 extJumpIfTrue)
(244 extJumpIfFalse)
+ (245 extSendAbsentSelfBytecode)
- (245 248 unknownBytecode)
+ (246 248 unknownBytecode)
+
"3 byte bytecodes"
(249 callPrimitiveBytecode)
(250 pushRemoteTempLongBytecode)
(251 storeRemoteTempLongBytecode)
(252 storeAndPopRemoteTempLongBytecode)
(253 extPushClosureBytecode)
+ (254 extSendAbsentOuterBytecode)
+ (255 unknownBytecode)
- (254 255 unknownBytecode)
)!
Item was changed:
----- Method: StackInterpreter>>enclosingObjectAt:withObject:withMixin: (in category 'newspeak bytecode support') -----
+ enclosingObjectAt: depth withObject: methodReceiver withMixin: methodMixin
+ "This is used to implement outer sends and outer expressions in Newspeak."
- enclosingObjectAt: n withObject: anObject withMixin: mixin
- "This is used to implement the innards of the pushEnclosingObjectBytecode,
- used for explicit outer sends in NS2/NS3. "
| enclosingObject mixinApplication targetMixin count |
+ enclosingObject := methodReceiver.
+ targetMixin := methodMixin.
- enclosingObject := anObject.
- targetMixin := mixin.
count := 0.
+ [count < depth] whileTrue:
- [count < n] whileTrue:
[count := count + 1.
+ self deny: (targetMixin = objectMemory nilObject).
- (targetMixin = objectMemory nilObject
- or: [enclosingObject = objectMemory nilObject]) ifTrue:
- [^objectMemory nilObject].
mixinApplication := self
+ findApplicationOfTargetMixin: targetMixin
+ startingAtBehavior: (self fetchClassOf: enclosingObject).
+ self deny: (mixinApplication = objectMemory nilObject).
+ enclosingObject := self followObjField: EnclosingObjectIndex ofObject: mixinApplication.
+ targetMixin := self followObjField: EnclosingMixinIndex ofObject: targetMixin].
- findApplicationOfTargetMixin: targetMixin
- startingAtNonMetaClass: (objectMemory fetchClassOf: enclosingObject).
- mixinApplication = objectMemory nilObject ifTrue:
- [^objectMemory nilObject]. "should never happen!!"
- enclosingObject := objectMemory followObjField: EnclosingObjectIndex ofObject: mixinApplication.
- targetMixin := objectMemory followObjField: EnclosingMixinIndex ofObject: targetMixin].
^enclosingObject!
Item was added:
+ ----- Method: StackInterpreter>>extSendAbsentOuterBytecode (in category 'send bytecodes') -----
+ extSendAbsentOuterBytecode
+ "254 11111110 i i i i i j j j kkkkkkkk Send To Enclosing Object at Depth kkkkkkkk Literal Selector #iiiii (+ Extend A * 32) with jjj (+ Extend B * 8) Arguments"
+ | byte depth absentReceiver |
+ byte := self fetchByte.
+ messageSelector := self literal: (byte >> 3) + (extA << 5).
+ extA := 0.
+ argumentCount := (byte bitAnd: 7) + (extB << 3).
+ extB := 0.
+ depth := self fetchByte.
+ absentReceiver := self
+ enclosingObjectAt: depth
+ withObject: self receiver
+ withMixin: (self methodClassOf: method).
+ self shuffleArgumentsAndStoreAbsentReceiver: absentReceiver.
+ lkupClassTag := objectMemory classTagForClass: (objectMemory fetchClassOf: absentReceiver).
+ self commonSend!
Item was added:
+ ----- Method: StackInterpreter>>extSendAbsentSelfBytecode (in category 'send bytecodes') -----
+ extSendAbsentSelfBytecode
+ "245 11110101 i i i i i j j j Send To Self Literal Selector #iiiii (+ Extend A * 32) with jjj (+ Extend B * 8) Arguments"
+ | byte |
+ byte := self fetchByte.
+ messageSelector := self literal: (byte >> 3) + (extA << 5).
+ extA := 0.
+ argumentCount := (byte bitAnd: 7) + (extB << 3).
+ extB := 0.
+ self shuffleArgumentsAndStoreAbsentReceiver: self receiver.
+ lkupClassTag := objectMemory classTagForClass: (objectMemory fetchClassOf: self receiver).
+ self commonSend!
Item was changed:
----- Method: StackInterpreter>>findApplicationOfTargetMixin:startingAtBehavior: (in category 'newspeak bytecode support') -----
findApplicationOfTargetMixin: targetMixin startingAtBehavior: aBehavior
+ "This is used to implement implicit receiver and enclosing object lookup
+ for Newspeak. Find the mixin applcation of which aClass is a subclass that
+ is an application of targetMixin. This is an implementation derived from
- "This is used to implement the innards of the pushImplicitReceiverBytecode,
- used for outer sends in NS2/NS3. Find the MixinApplcation of which aBehavior
- is a subclass that is an application of targetMixin. This is an implementation derived from
+ <ContextPart> findApplicationOf: targetMixin startingAt: aBehavior
- <ContextPart> findApplicationOfTargetMixin: targetMixin startingAtBehavior: aBehavior
"
+ | mixinApplication mixin |
+ mixinApplication := aBehavior.
+ [mixinApplication = objectMemory nilObject
+ or: [mixinApplication = targetMixin
+ or: [(mixin := objectMemory fetchPointer: MixinIndex ofObject: mixinApplication) = targetMixin]]] whileFalse:
+ [mixinApplication := objectMemory fetchPointer: SuperclassIndex ofObject: mixinApplication].
+ ^mixinApplication!
- | mixinOrMixinApplication mixin |
- mixinOrMixinApplication := aBehavior.
- [mixinOrMixinApplication = objectMemory nilObject
- or: [mixinOrMixinApplication = targetMixin
- or: [(mixin := objectMemory followObjField: MixinIndex ofObject: mixinOrMixinApplication) = targetMixin
- or: [(objectMemory fetchClassOfNonImm: mixin) = targetMixin]]]] whileFalse:
- [mixinOrMixinApplication := objectMemory followObjField: SuperclassIndex ofObject: mixinOrMixinApplication].
- ^mixinOrMixinApplication!
Item was removed:
- ----- Method: StackInterpreter>>findApplicationOfTargetMixin:startingAtNonMetaClass: (in category 'newspeak bytecode support') -----
- findApplicationOfTargetMixin: targetMixin startingAtNonMetaClass: aClass
- "This is used to implement the innards of the pushImplicitReceiverBytecode,
- used for outer sends in NS2/NS3. Find the MixinApplcation of which aClass
- is a subclass that is an application of targetMixin. This is an implementation derived from
-
- <ContextPart> findApplicationOfTargetMixin: targetMixin startingAtNonMetaClass: aClass
- "
- | mixinOrMixinApplication |
- self deny: (objectMemory isForwarded: targetMixin).
- self deny: (objectMemory isForwarded: aClass).
- mixinOrMixinApplication := aClass.
- [mixinOrMixinApplication = objectMemory nilObject
- or: [mixinOrMixinApplication = targetMixin
- or: [(objectMemory followObjField: MixinIndex ofObject: mixinOrMixinApplication) = targetMixin]]] whileFalse:
- [mixinOrMixinApplication := objectMemory followObjField: SuperclassIndex ofObject: mixinOrMixinApplication].
- ^mixinOrMixinApplication!
Item was changed:
----- Method: StackInterpreter>>implicitReceiverFor:mixin:implementing: (in category 'newspeak bytecode support') -----
+ implicitReceiverFor: methodReceiver mixin: methodMixin implementing: selector
+ "This is used to implement implicit receiver sends in Newspeak. Find the nearest
+ lexically-enclosing implementation of selector by searching up the static chain of the
+ method's receiver, starting at mixin's application. This implementation is derived from
- implicitReceiverFor: rcvr mixin: mixin implementing: selector
- "This is used to implement the innards of the pushImplicitReceiverBytecode,
- used for implicit receiver sends in NS2/NS3. Find the nearest lexically-enclosing
- implementation of selector by searching up the static chain of anObject,
- starting at mixin's application. This is an iterative implementation derived from
+ <ContextPart> implicitReceiverFor: methodReceiver <Object>
+ in: methodMixin <Mixin>
- <ContextPart> implicitReceiverFor: obj <Object>
- withMixin: mixin <Mixin>
implementing: selector <Symbol> ^<Object>"
<api>
<option: #NewspeakVM>
+ | candidateReceiver candidateMixin candidateMixinApplication dictionary found |
+ self deny: (objectMemory isOopForwarded: methodReceiver).
+ self deny: (objectMemory isForwarded: methodMixin).
- | mixinApplication dictionary found |
- self deny: (objectMemory isOopForwarded: rcvr).
- self deny: (objectMemory isForwarded: mixin).
"messageSelector is an implicit parameter of lookupMethodInDictionary:"
messageSelector := objectMemory followMaybeForwarded: selector.
+ candidateReceiver := methodReceiver.
+ candidateMixin := methodMixin.
+ [candidateMixinApplication := self
+ findApplicationOfTargetMixin: candidateMixin
+ startingAtBehavior: (objectMemory fetchClassOf: candidateReceiver).
+ self deny: (candidateMixinApplication = objectMemory nilObject).
+ dictionary := objectMemory followObjField: MethodDictionaryIndex ofObject: candidateMixinApplication.
- mixinApplication := self
- findApplicationOfTargetMixin: mixin
- startingAtBehavior: (objectMemory fetchClassOf: rcvr).
- mixinApplication = objectMemory nilObject ifTrue:
- [^rcvr].
- dictionary := objectMemory followObjField: MethodDictionaryIndex ofObject: mixinApplication.
found := self lookupMethodInDictionary: dictionary.
+ found ifTrue: [^candidateReceiver].
+ candidateMixin := objectMemory followObjField: EnclosingMixinIndex ofObject: candidateMixin.
+ candidateMixin = objectMemory nilObject]
+ whileFalse:
+ [candidateReceiver := objectMemory followObjField: EnclosingObjectIndex ofObject: candidateMixinApplication].
+ ^methodReceiver!
- found ifFalse:
- [| implicitReceiverOrNil theMixin |
- theMixin := objectMemory followObjField: MixinIndex ofObject: mixinApplication.
- implicitReceiverOrNil := self nextImplicitReceiverFor: (objectMemory
- followObjField: EnclosingObjectIndex
- ofObject: mixinApplication)
- withMixin: (objectMemory
- followObjField: EnclosingMixinIndex
- ofObject: theMixin).
- implicitReceiverOrNil ~= objectMemory nilObject ifTrue:
- [^implicitReceiverOrNil]].
- ^rcvr!
Item was removed:
- ----- Method: StackInterpreter>>nextImplicitReceiverFor:withMixin: (in category 'newspeak bytecode support') -----
- nextImplicitReceiverFor: anObject withMixin: mixin
- "This is used to implement the innards of the pushImplicitReceiverBytecode,
- used for implicit receiver sends in NS2/NS3. Find the nearest lexically-enclosing
- implementation of selector by searching up the static chain of anObject,
- starting at mixin's application. This is an iterative implementation derived from
-
- <ContextPart> nextImplicitReceiverFor: obj <Object>
- withMixin: mixin <Mixin>
- implementing: selector <Symbol> ^<Object>"
- | implicitReceiver mixinApplication theMixin targetMixin dictionary found |
- self deny: (objectMemory isOopForwarded: anObject).
- self deny: (objectMemory isForwarded: mixin).
- implicitReceiver := anObject.
- targetMixin := mixin.
- [(targetMixin = objectMemory nilObject "or: [implicitReceiver = objectMemory nilObject]") ifTrue:
- [^objectMemory nilObject].
- mixinApplication := self findApplicationOfTargetMixin: targetMixin
- startingAtNonMetaClass: (objectMemory fetchClassOf: implicitReceiver).
- mixinApplication = objectMemory nilObject ifTrue:
- [^objectMemory nilObject].
- dictionary := objectMemory followObjField: MethodDictionaryIndex ofObject: mixinApplication.
- found := self lookupMethodInDictionary: dictionary.
- found]
- whileFalse:
- [implicitReceiver := objectMemory followObjField: EnclosingObjectIndex ofObject: mixinApplication.
- theMixin := objectMemory followObjField: MixinIndex ofObject: mixinApplication.
- theMixin = objectMemory nilObject ifTrue:
- [^objectMemory nilObject].
- targetMixin := objectMemory followObjField: EnclosingMixinIndex ofObject: theMixin].
- ^implicitReceiver!
Item was removed:
- ----- Method: StackInterpreterSimulator>>nextImplicitReceiverFor:withMixin: (in category 'newspeak bytecode support') -----
- nextImplicitReceiverFor: anObject withMixin: mixin
- lookupCount := lookupCount + 1.
- ^super nextImplicitReceiverFor: anObject withMixin: mixin!
Item was changed:
----- Method: StackToRegisterMappingCogit class>>initializeBytecodeTableForNewspeakV4 (in category 'class initialization') -----
initializeBytecodeTableForNewspeakV4
"StackToRegisterMappingCogit initializeBytecodeTableForNewspeakV4"
numPushNilsFunction := #v4:Num:Push:Nils:.
pushNilSizeFunction := #v4PushNilSize:.
NSSendIsPCAnnotated := false. "IsNSSendCall used by SendAbsentImplicit"
FirstSpecialSelector := 80.
self flag:
'Special selector send class must be inlined to agree with the interpreter, which
inlines class. If class is sent to e.g. a general instance of ProtoObject then unless
class is inlined there will be an MNU. It must be that the Cointerpreter and Cogit
have identical semantics. We get away with not hardwiring the other special
selectors either because in the Cointerpreter they are not inlined or because they
are inlined only to instances of classes for which there will always be a method.'.
self generatorTableFrom: #(
"1 byte bytecodes"
(1 0 15 genPushReceiverVariableBytecode needsFrameNever: 1)
(1 16 31 genPushLiteralVariable16CasesBytecode needsFrameNever: 1)
(1 32 63 genPushLiteralConstantBytecode needsFrameNever: 1)
(1 64 75 genPushTemporaryVariableBytecode needsFrameIfMod16GENumArgs: 1)
(1 76 76 genPushReceiverBytecode needsFrameNever: 1)
(1 77 77 genExtPushPseudoVariableOrOuterBytecode needsFrameIfExtBGT2: 1)
(1 78 78 genPushConstantZeroBytecode needsFrameNever: 1)
(1 79 79 genPushConstantOneBytecode needsFrameNever: 1)
(1 80 80 genSpecialSelectorArithmetic isMapped AddRR)
(1 81 81 genSpecialSelectorArithmetic isMapped SubRR)
(1 82 82 genSpecialSelectorComparison isMapped JumpLess)
(1 83 83 genSpecialSelectorComparison isMapped JumpGreater)
(1 84 84 genSpecialSelectorComparison isMapped JumpLessOrEqual)
(1 85 85 genSpecialSelectorComparison isMapped JumpGreaterOrEqual)
(1 86 86 genSpecialSelectorComparison isMapped JumpZero)
(1 87 87 genSpecialSelectorComparison isMapped JumpNonZero)
(1 88 93 genSpecialSelectorSend isMapped) " #* #/ #\\ #@ #bitShift: //"
(1 94 94 genSpecialSelectorArithmetic isMapped AndRR)
(1 95 95 genSpecialSelectorArithmetic isMapped OrRR)
(1 96 101 genSpecialSelectorSend isMapped) "#at: #at:put: #size #next #nextPut: #atEnd"
(1 102 102 genSpecialSelectorEqualsEquals needsFrameNever: notMapped -1) "not mapped because it is directly inlined (for now)"
(1 103 103 genSpecialSelectorClass needsFrameIfStackGreaterThanOne: notMapped 0) "not mapped because it is directly inlined (for now)"
(1 104 111 genSpecialSelectorSend isMapped) "#blockCopy: #value #value: #do: #new #new: #x #y"
(1 112 127 genSendLiteralSelector0ArgsBytecode isMapped)
(1 128 143 genSendLiteralSelector1ArgBytecode isMapped)
(1 144 159 genSendLiteralSelector2ArgsBytecode isMapped)
(1 160 175 genSendAbsentImplicit0ArgsBytecode isMapped hasIRC)
(1 176 183 genStoreAndPopReceiverVariableBytecode needsFrameNever: -1) "N.B. not frameless if immutability"
(1 184 191 genStoreAndPopTemporaryVariableBytecode)
(1 192 199 genShortUnconditionalJump branch v3:ShortForward:Branch:Distance:)
(1 200 207 genShortJumpIfTrue branch isBranchTrue isMapped "because of mustBeBoolean"
v3:ShortForward:Branch:Distance:)
(1 208 215 genShortJumpIfFalse branch isBranchFalse isMapped "because of mustBeBoolean"
v3:ShortForward:Branch:Distance:)
(1 216 216 genReturnReceiver return needsFrameIfInBlock: isMappedInBlock 0)
(1 217 217 genReturnTopFromMethod return needsFrameIfInBlock: isMappedInBlock -1)
(1 218 218 genExtReturnTopFromBlock return needsFrameNever: -1)
(1 219 219 duplicateTopBytecode needsFrameNever: 1)
(1 220 220 genPopStackBytecode needsFrameNever: -1)
(1 221 221 genExtNopBytecode needsFrameNever: 0)
(1 222 223 unknownBytecode)
"2 byte bytecodes"
(2 224 224 extABytecode extension needsFrameNever: 0)
(2 225 225 extBBytecode extension needsFrameNever: 0)
(2 226 226 genExtPushReceiverVariableBytecode)
(2 227 227 genExtPushLiteralVariableBytecode needsFrameNever: 1)
(2 228 228 genExtPushLiteralBytecode needsFrameNever: 1)
(2 229 229 genExtPushIntegerBytecode needsFrameNever: 1)
(2 230 230 genLongPushTemporaryVariableBytecode)
(2 231 231 genPushNewArrayBytecode)
(2 232 232 genExtStoreReceiverVariableBytecode)
(2 233 233 genExtStoreLiteralVariableBytecode)
(2 234 234 genLongStoreTemporaryVariableBytecode)
(2 235 235 genExtStoreAndPopReceiverVariableBytecode)
(2 236 236 genExtStoreAndPopLiteralVariableBytecode)
(2 237 237 genLongStoreAndPopTemporaryVariableBytecode)
(2 238 238 genExtSendBytecode isMapped)
(2 239 239 genExtSendSuperBytecode isMapped)
(2 240 240 genExtSendAbsentImplicitBytecode isMapped hasIRC)
(2 241 241 genExtSendAbsentDynamicSuperBytecode isMapped)
(2 242 242 genExtUnconditionalJump branch isMapped "because of interrupt check" v4:Long:Branch:Distance:)
(2 243 243 genExtJumpIfTrue branch isBranchTrue isMapped "because of mustBeBoolean" v4:Long:Branch:Distance:)
(2 244 244 genExtJumpIfFalse branch isBranchFalse isMapped "because of mustBeBoolean" v4:Long:Branch:Distance:)
+ (2 245 245 genExtSendAbsentSelfBytecode isMapped)
- (2 245 248 unknownBytecode)
+ (2 246 248 unknownBytecode)
+
"3 byte bytecodes"
(3 249 249 callPrimitiveBytecode)
(3 250 250 genPushRemoteTempLongBytecode)
(3 251 251 genStoreRemoteTempLongBytecode)
(3 252 252 genStoreAndPopRemoteTempLongBytecode)
(3 253 253 genExtPushClosureBytecode block v4:Block:Code:Size:)
+ (3 254 254 genExtSendAbsentOuterBytecode isMapped)
+ (3 255 255 unknownBytecode))!
- (3 254 255 unknownBytecode))!
Item was changed:
----- Method: StackToRegisterMappingCogit>>genSendAbsentDynamicSuper:numArgs: (in category 'bytecode generators') -----
genSendAbsentDynamicSuper: selector numArgs: numArgs
"OK, we could do better and avoid spilling ReceiverResultReg if we refactored
marshallImplicitReceiverSendArguments: to take a flag saying whether the
receiver was in ReceiverResultReg (absent receiver send) or on the stack
(absent dynamic super send) and in the latter case loading ReceiverResultReg
from the stack after marshalling. But this is a rare bytecode so for the moment
don't bother."
self ssAllocateCallReg: ReceiverResultReg.
self MoveMw: FoxMFReceiver r: FPReg R: ReceiverResultReg.
+ self marshallAbsentReceiverSendArguments: numArgs.
- self marshallImplicitReceiverSendArguments: numArgs.
^self genMarshalledSendDynamicSuper: selector numArgs: numArgs!
Item was changed:
----- Method: StackToRegisterMappingCogit>>genSendAbsentImplicit:numArgs: (in category 'bytecode generators') -----
genSendAbsentImplicit: selector numArgs: numArgs
"Get the implicit receiver and marshall arguments, shuffling the
stack to push the implicit receiver if necessary. Then send."
<inline: false>
| result |
"This must not be PC-mapped"
result := self genGetImplicitReceiverFor: selector forPush: false.
result ~= 0 ifTrue:
[^result].
+ self marshallAbsentReceiverSendArguments: numArgs.
- self marshallImplicitReceiverSendArguments: numArgs.
^self genMarshalledSend: selector numArgs: numArgs!
Item was added:
+ ----- Method: StackToRegisterMappingCogit>>genSendAbsentOuter:numArgs:depth: (in category 'bytecode generators') -----
+ genSendAbsentOuter: selector numArgs: numArgs depth: depth
+ "OK, we could do better and avoid spilling ReceiverResultReg if we refactored
+ marshallAbsentReceiverSendArguments: to take a flag saying whether the
+ receiver was in ReceiverResultReg (absent receiver send) or on the stack
+ (absent dynamic super send) and in the latter case loading ReceiverResultReg
+ from the stack after marshalling. But this is a rare bytecode so for the moment
+ don't bother."
+ optStatus isReceiverResultRegLive: false.
+ self ssAllocateCallReg: SendNumArgsReg.
+ self MoveCq: depth R: SendNumArgsReg.
+ self CallRT: ceEnclosingObjectTrampoline.
+ self marshallAbsentReceiverSendArguments: numArgs.
+ ^self genMarshalledSend: selector numArgs: numArgs!
Item was added:
+ ----- Method: StackToRegisterMappingCogit>>genSendAbsentSelf:numArgs: (in category 'bytecode generators') -----
+ genSendAbsentSelf: selector numArgs: numArgs
+ "OK, we could do better and avoid spilling ReceiverResultReg if we refactored
+ marshallAbsentReceiverSendArguments: to take a flag saying whether the
+ receiver was in ReceiverResultReg (absent receiver send) or on the stack
+ (absent dynamic super send) and in the latter case loading ReceiverResultReg
+ from the stack after marshalling. But this is a rare bytecode so for the moment
+ don't bother."
+ self ssAllocateCallReg: ReceiverResultReg.
+ self MoveMw: FoxMFReceiver r: FPReg R: ReceiverResultReg.
+ self marshallAbsentReceiverSendArguments: numArgs.
+ ^self genMarshalledSend: selector numArgs: numArgs!
Item was added:
+ ----- Method: StackToRegisterMappingCogit>>marshallAbsentReceiverSendArguments: (in category 'simulation stack') -----
+ marshallAbsentReceiverSendArguments: numArgs
+ "Spill everything on the simulated stack that needs spilling (that below arguments).
+ Marshall arguments to stack and/or registers depending on arg count.
+ If the args don't fit in registers push receiver and args (spill everything). Assume
+ receiver already in ResultReceiverReg so shuffle args and push it if necessary."
+ self ssFlushTo: simStackPtr - numArgs.
+ numArgs > self numRegArgs
+ ifTrue:
+ ["The arguments must be pushed to the stack, and hence the receiver
+ must be inserted beneath the args. Reduce or eliminate the argument
+ shuffle by only moving already spilled items."
+ | numSpilled |
+ numSpilled := self numberOfSpillsInTopNItems: numArgs.
+ numSpilled > 0
+ ifTrue:
+ [self MoveMw: 0 r: SPReg R: TempReg.
+ self PushR: TempReg.
+ 2 to: numSpilled do:
+ [:index|
+ self MoveMw: index * objectMemory wordSize r: SPReg R: TempReg.
+ self MoveR: TempReg Mw: index - 1 * objectMemory wordSize r: SPReg].
+ self MoveR: ReceiverResultReg Mw: numSpilled * objectMemory wordSize r: SPReg]
+ ifFalse:
+ [self PushR: ReceiverResultReg].
+ self ssFlushTo: simStackPtr]
+ "Move the args to the register arguments, being careful to do
+ so last to first so e.g. previous contents don't get overwritten.
+ Also check for any arg registers in use by other args."
+ ifFalse:
+ [numArgs > 0 ifTrue:
+ [(self numRegArgs > 1 and: [numArgs > 1])
+ ifTrue:
+ [self ssAllocateRequiredReg: Arg0Reg upThrough: simStackPtr - 2.
+ self ssAllocateRequiredReg: Arg1Reg upThrough: simStackPtr - 1]
+ ifFalse:
+ [self ssAllocateRequiredReg: Arg0Reg upThrough: simStackPtr - 1]].
+ (self numRegArgs > 1 and: [numArgs > 1]) ifTrue:
+ [(self simStackAt: simStackPtr) popToReg: Arg1Reg].
+ numArgs > 0 ifTrue:
+ [(self simStackAt: simStackPtr - numArgs + 1)
+ popToReg: Arg0Reg]].
+ self ssPop: numArgs!
Item was removed:
- ----- Method: StackToRegisterMappingCogit>>marshallImplicitReceiverSendArguments: (in category 'simulation stack') -----
- marshallImplicitReceiverSendArguments: numArgs
- "Spill everything on the simulated stack that needs spilling (that below arguments).
- Marshall arguments to stack and/or registers depending on arg count.
- If the args don't fit in registers push receiver and args (spill everything). Assume
- receiver already in ResultReceiverReg so shuffle args and push it if necessary."
- self ssFlushTo: simStackPtr - numArgs.
- numArgs > self numRegArgs
- ifTrue:
- ["The arguments must be pushed to the stack, and hence the receiver
- must be inserted beneath the args. Reduce or eliminate the argument
- shuffle by only moving already spilled items."
- | numSpilled |
- numSpilled := self numberOfSpillsInTopNItems: numArgs.
- numSpilled > 0
- ifTrue:
- [self MoveMw: 0 r: SPReg R: TempReg.
- self PushR: TempReg.
- 2 to: numSpilled do:
- [:index|
- self MoveMw: index * objectMemory wordSize r: SPReg R: TempReg.
- self MoveR: TempReg Mw: index - 1 * objectMemory wordSize r: SPReg].
- self MoveR: ReceiverResultReg Mw: numSpilled * objectMemory wordSize r: SPReg]
- ifFalse:
- [self PushR: ReceiverResultReg].
- self ssFlushTo: simStackPtr]
- "Move the args to the register arguments, being careful to do
- so last to first so e.g. previous contents don't get overwritten.
- Also check for any arg registers in use by other args."
- ifFalse:
- [numArgs > 0 ifTrue:
- [(self numRegArgs > 1 and: [numArgs > 1])
- ifTrue:
- [self ssAllocateRequiredReg: Arg0Reg upThrough: simStackPtr - 2.
- self ssAllocateRequiredReg: Arg1Reg upThrough: simStackPtr - 1]
- ifFalse:
- [self ssAllocateRequiredReg: Arg0Reg upThrough: simStackPtr - 1]].
- (self numRegArgs > 1 and: [numArgs > 1]) ifTrue:
- [(self simStackAt: simStackPtr) popToReg: Arg1Reg].
- numArgs > 0 ifTrue:
- [(self simStackAt: simStackPtr - numArgs + 1)
- popToReg: Arg0Reg]].
- self ssPop: numArgs!
More information about the Vm-dev
mailing list