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

Eliot Miranda eliot.miranda at gmail.com
Wed Apr 29 00:25:02 UTC 2015


Hi Clément,

    the issue with the assert fail on starting the current Sista is one of
incorrect pc mapping.  The only difference
between SistaStackToRegisterMappingCogit and StackToRegisterMappingCogit is
that in the Sista cogit #== is mapped, see

SistaStackToRegisterMappingCogit class>>generatorTableFrom: anArray
"Override to replace the unmapped, non-counting inlined #== with a mapped
counting inlined #==."
| table |
table := super generatorTableFrom: anArray.
table object do:
[:descriptor|
 descriptor generator == #genSpecialSelectorEqualsEquals ifTrue:
[descriptor
isMapped: true;
isMappedInBlock: true;
needsFrameFunction: nil]].
^table

Loking at what you've done I guess you've removed the need to map #==
mapped, in which case the above should be deleted and #== unmapped.  But
looking at the generated code for #== followed by a jump I can't understand
how the code works.

What I see is counting instructions followed by the #== comparison, as in

SistaStackToRegisterMappingCogit
genAndDis: IdentityDictionary>>#scanFor:
options: #( SistaVM true
ObjectMemory Spur32BitCoMemoryManager
MULTIPLEBYTECODESETS true
ISA IA32
bytecodeTableInitializer
initializeBytecodeTableForSqueakV3PlusClosuresSistaV1Hybrid)

which generates the following for the "(element := array at: index) == nil"
#== comparison:

000014c6: movl $0x00100098=#at:, %ecx : B9 98 00 10 00
000014cb: call .+0xffffefa0 (0x00000470=ceSend1Args) : E8 A0 EF FF FF
IsSendCall bc 49/50:
000014d0: movl %edx, -24(%ebp) : 89 55 E8

do the "executed jump" count for the following jump:
000014d3: movl %ds:0x40090, %edi : 8B 3D 90 00 04 00
000014d9: subl $0x00010000, %edi : 81 EF 00 00 01 00
"If the count trips, jump to a second occurrence of the comparison code"
000014df: jb .+0x00000035 (0x00001516) : 72 35
"write back modified count"
000014e1: movl %edi, %ds:0x40090 : 89 3D 90 00 04 00

"do the #== nil comparison"
000014e7: cmpl $0x00100000=nil, %edx : 81 FA 00 00 10 00
"jump to the #== nil being true continuation"
000014ed: jz .+0x00000086 (0x00001579) : 0F 84 86 00 00 00
"fall throguh to unforwarding code given that the #== nil could be false
because of forwarding, and it should be retried"
000014f3: movl %edx, %eax : 89 D0
000014f5: andl $0x00000003, %eax : 83 E0 03
000014f8: jnz .+0x0000000e (0x00001508) : 75 0E

What I don't understand is if you trip the count how is the #== ever
executed?  Don't you just continue assuming the result was either true or
false?  That can't be right.  So I'm confused and hence I haven't deleted
the generatorTableFrom: method.  I don't understand the code and so
shouldn't mess with it :)

On Tue, Apr 28, 2015 at 5:12 PM, <commits at source.squeak.org> wrote:

>
> Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
> http://source.squeak.org/VMMaker/VMMaker.oscog-eem.1270.mcz
>
> ==================== Summary ====================
>
> Name: VMMaker.oscog-eem.1270
> Author: eem
> Time: 28 April 2015, 5:11:29.049 pm
> UUID: a6737c7e-fb6b-4fe9-a44e-6b01396cff34
> Ancestors: VMMaker.oscog-eem.1269
>
> Nuke obsolete printMcpc:Bcpc:on:
>
> Correct SistaStackToRegisterMappingCogit>>genJumpIf:to:
> to reload counterReg instead of saving and
> restoring it around counter callback trampoline.
>
> =============== Diff against VMMaker.oscog-eem.1269 ===============
>
> Item was removed:
> - ----- Method: Cogit>>printMcpc:Bcpc:on: (in category 'method map') -----
> - printMcpc: mcpc Bcpc: bcpc on: aStream
> -       <doNotGenerate>
> -       aStream ensureCr.
> -       mcpc printOn: aStream base: 16.
> -       aStream space; tab; print: bcpc; cr; flush.
> -       ^0!
>
> Item was changed:
>   ----- Method: SistaStackToRegisterMappingCogit>>genJumpIf:to: (in
> category 'bytecode generator support') -----
>   genJumpIf: boolean to: targetBytecodePC
>         "The heart of performance counting in Sista.  Conditional branches
> are 6 times less
>          frequent than sends and can provide basic block frequencies (send
> counters can't).
>          Each conditional has a 32-bit counter split into an upper 16 bits
> counting executions
>          and a lower half counting untaken executions of the branch.
> Executing the branch
>          decrements the upper half, tripping if the count goes negative.
> Not taking the branch
>          decrements the lower half.  N.B. We *do not* eliminate dead
> branches (true ifTrue:/true ifFalse:)
>          so that scanning for send and branch data is simplified and that
> branch data is correct."
>         <inline: false>
>         | desc ok counterAddress countTripped retry counterReg |
>         <var: #ok type: #'AbstractInstruction *'>
>         <var: #desc type: #'CogSimStackEntry *'>
>         <var: #retry type: #'AbstractInstruction *'>
>         <var: #countTripped type: #'AbstractInstruction *'>
>
>         (coInterpreter isOptimizedMethod: methodObj) ifTrue: [ ^ super
> genJumpIf: boolean to: targetBytecodePC ].
>
>         self ssFlushTo: simStackPtr - 1.
>         desc := self ssTop.
>         self ssPop: 1.
>         desc popToReg: TempReg.
> +
> -
>         "We prefer calleeSaved to avoid saving it across the trap trip
> trampoline"
>         counterReg := self
> allocateRegPreferringCalleeSavedNotConflictingWith: 0.
>         retry := self Label.
>         self
>                 genExecutionCountLogicInto: [ :cAddress :countTripBranch |
>                         counterAddress := cAddress.
>                         countTripped := countTripBranch ]
>                 counterReg: counterReg.
>         counterIndex := counterIndex + 1.
> +
> -
>         "Cunning trick by LPD.  If true and false are contiguous subtract
> the smaller.
>          Correct result is either 0 or the distance between them.  If
> result is not 0 or
>          their distance send mustBeBoolean."
>         self assert: (objectMemory objectAfter: objectMemory falseObject)
> = objectMemory trueObject.
>         self annotate: (self SubCw: boolean R: TempReg) objRef: boolean.
>         self JumpZero: (self ensureFixupAt: targetBytecodePC - initialPC).
>
>         self genFallsThroughCountLogicCounterReg: counterReg
> counterAddress: counterAddress.
>
>         self CmpCq: (boolean == objectMemory falseObject
>                                         ifTrue: [objectMemory trueObject -
> objectMemory falseObject]
>                                         ifFalse: [objectMemory falseObject
> - objectMemory trueObject])
>                 R: TempReg.
>         ok := self JumpZero: 0.
>         self MoveCq: 0 R: counterReg. "if counterReg is 0 this is a
> mustBeBoolean, not a counter trip."
> +
> +       self flag: 'Hi Clément.  You can''t just save things to the
> Smalltalk stack.  You can /only/ save things that execution expects to be
> there on a context''s stack, because this frame may get mapped to a context
> object and then back, and gc''ed etc.  The counter reg does not contain an
> object so is a complete no-no on the Smalltalk stack.  On the C stack in
> the trampoline is OK, not on the Smalltalk stack in method execution.  So
> instead of saving and restoring the counterReg around the call, something
> we can''t do, we can reload it after the call'.
> +       false ifTrue:
> +               ["If counterReg is caller saved then save it"
> +               (self register: counterReg isInMask: callerSavedRegMask)
> ifTrue: [ self PushR: counterReg ]].
> +
> -
> -       "If counterReg is caller saved then save it"
> -       (self register: counterReg isInMask: callerSavedRegMask) ifTrue: [
> self PushR: counterReg ].
> -
>         countTripped jmpTarget:
>                 (self CallRT: (boolean == objectMemory falseObject
>                                                 ifTrue:
> [ceSendMustBeBooleanAddFalseTrampoline]
>                                                 ifFalse:
> [ceSendMustBeBooleanAddTrueTrampoline])).
>
>         "If we're in an image which hasn't got the Sista code loaded then
> the ceCounterTripped:
>          trampoline will return directly to machine code, returning the
> boolean.  So the code should
>          jump back to the retry point. The trampoline makes sure that
> TempReg has been reloaded."
>         self annotateBytecode: self Label.
> +
> +       self flag: 'see above'.
> +       false ifTrue:
> +               ["If counterReg is caller saved then restore it"
> +               (self register: counterReg isInMask: callerSavedRegMask)
> ifTrue: [ self PopR: counterReg ]].
> +
> +       "Note we /can't/ save and restore the counterReg's contents around
> the call since the stack can
> +        only contain what an interpreted context's stack would contain at
> the corresponding point.  The
> +        counter is not an object, so can't be written to the stack. Hence
> we reload it after the call."
> +       self MoveAw: counterAddress R: counterReg.
> +
> -
> -       "If counterReg is caller saved then restore it"
> -       (self register: counterReg isInMask: callerSavedRegMask) ifTrue: [
> self PopR: counterReg ].
> -
>         self Jump: retry.
>         ok jmpTarget: self Label.
>         ^0!
>
> Item was removed:
> - ----- Method: SistaStackToRegisterMappingCogit>>printMcpc:Bcpc:on: (in
> category 'method map') -----
> - printMcpc: mcpc Bcpc: bcpc on: aStream
> -       <doNotGenerate>
> -       self shouldNotImplement!
>
>


-- 
best,
Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20150428/ada9b038/attachment-0001.htm


More information about the Vm-dev mailing list