[Vm-dev] VM Maker: VMMaker.oscog-cb.1654.mcz

Clément Bera bera.clement at gmail.com
Wed Jan 20 07:44:26 UTC 2016


2016-01-20 2:35 GMT+01:00 Eliot Miranda <eliot.miranda at gmail.com>:

> Hi Clément,
>
>
>
>     alas the bytecode <-> machine code mapping machinery isn't capable of
> distinguishing different variants of a complex bytecode such
> as extendedStoreAndPopBytecode.  The map machinery is based on parsing
> bytecodes by looking up their descriptors.  So if a bytecode descriptor is
> marked as mapped, all instantiations of the bytecode in machine code must
> be mapped, not just the ones we know we're going to need a map entry for
> for message handling etc.
>
So where you write
>
> extendedStoreAndPopBytecode
> | variableType variableIndex |
> variableType := byte1 >> 6 bitAnd: 3.
> variableIndex := byte1 bitAnd: 63.
> variableType = 0 ifTrue:
> [^self genStorePop: true ReceiverVariable: variableIndex].
> variableType = 1 ifTrue:
> [self genStorePop: true TemporaryVariable: variableIndex.
> "needs a fake map entry is Immutability is ON..."
> self cppIf: IMMUTABILITY ifTrue: [ self annotateBytecode: self Label. ].
> ^ 0].
> variableType = 3 ifTrue:
> [^self genStorePop: true LiteralVariable: variableIndex].
> ^EncounteredUnknownBytecode
>
> you're actually going to have to write something like
>
> extendedStoreAndPopBytecode
> | variableType variableIndex |
> variableType := byte1 >> 6 bitAnd: 3.
> variableIndex := byte1 bitAnd: 63.
> variableType = 0 ifTrue:
> [self genStorePop: true ReceiverVariable: variableIndex].
> variableType = 1 ifTrue:
> [self genStorePop: true TemporaryVariable: variableIndex].
> variableType = 2 ifTrue:
> [^EncounteredUnknownBytecode].
> variableType = 3 ifTrue:
> [self genStorePop: true LiteralVariable: variableIndex].
> "If IMMUTABILITY is on then this bytecode could send back and so must be
> mapped."
> self cppIf: IMMUTABILITY ifTrue: [self annotateBytecode: self lastOpcode]
>
>
I think this should fix your instabilities.  What's happening is that your
> nearly-correct code creates the occasional method with a bad map and if the
> map is used (which it isn't often, but is in the debugger) then method
> execution can get screwed up.
>
>
As stated in the commit comment, my code generates a correct map for all
methods but the ones with primitive with error code... The
test #testPCMappingFor:options: proves it (you can run it on all methods to
check).

I don't think your change is a good idea because the mcpc mapped would be
incorrect.

However, if you have an idea on how to handle correctly primitive with
error code (the extStore for error code is compiled differently and lacks
the map entry), it would be helpful. I tried to generate an entry at the
beginning of the method body but it didn't work.





> HTH
>
> On Tue, Jan 19, 2016 at 5:29 AM, <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-cb.1654.mcz
>>
>> ==================== Summary ====================
>>
>> Name: VMMaker.oscog-cb.1654
>> Author: cb
>> Time: 19 January 2016, 2:28:37.278 pm
>> UUID: 35bdf68b-ea60-4f01-8799-14baa71ab416
>> Ancestors: VMMaker.oscog-cb.1653
>>
>> In the SqueakV3Bytecode set, extendedStore and extStoreAndPop are now
>> mapped as instVar and LiteralVar stores need to be mapped for immutability.
>> We need to generate a fake mapping to make the mcpc to bcpc mapping happy.
>>
>> Starting from this version, the mcpc to bcpc is happy *except* for
>> primitive error code. In this case, an extStore bytecode is used for the
>> error code but is still not mapped.
>>
>> =============== Diff against VMMaker.oscog-cb.1653 ===============
>>
>> Item was changed:
>>   ----- Method: SimpleStackBasedCogit>>extendedStoreAndPopBytecode (in
>> category 'bytecode generators') -----
>>   extendedStoreAndPopBytecode
>>         | variableType variableIndex |
>>         variableType := byte1 >> 6 bitAnd: 3.
>>         variableIndex := byte1 bitAnd: 63.
>>         variableType = 0 ifTrue:
>>                 [^self genStorePop: true ReceiverVariable: variableIndex].
>>         variableType = 1 ifTrue:
>> +               [self genStorePop: true TemporaryVariable: variableIndex.
>> +               "needs a fake map entry is Immutability is ON..."
>> +               self cppIf: IMMUTABILITY ifTrue: [ self annotateBytecode:
>> self Label. ].
>> +               ^ 0].
>> -               [^self genStorePop: true TemporaryVariable:
>> variableIndex].
>>         variableType = 3 ifTrue:
>>                 [^self genStorePop: true LiteralVariable: variableIndex].
>>         ^EncounteredUnknownBytecode!
>>
>> Item was changed:
>>   ----- Method: SimpleStackBasedCogit>>extendedStoreBytecode (in category
>> 'bytecode generators') -----
>>   extendedStoreBytecode
>>         | variableType variableIndex |
>>         variableType := byte1 >> 6 bitAnd: 3.
>>         variableIndex := byte1 bitAnd: 63.
>>         variableType = 0 ifTrue:
>>                 [^self genStorePop: false ReceiverVariable:
>> variableIndex].
>>         variableType = 1 ifTrue:
>> +               [self genStorePop: false TemporaryVariable: variableIndex.
>> +               "needs a fake map entry is Immutability is ON..."
>> +               self cppIf: IMMUTABILITY ifTrue: [ self annotateBytecode:
>> self Label. ].
>> +               ^ 0].
>> -               [^self genStorePop: false TemporaryVariable:
>> variableIndex].
>>         variableType = 3 ifTrue:
>>                 [^self genStorePop: false LiteralVariable: variableIndex].
>>         ^EncounteredUnknownBytecode!
>>
>> Item was changed:
>>   ----- Method:
>> StackToRegisterMappingCogit>>doubleExtendedDoAnythingBytecode (in category
>> 'bytecode generators') -----
>>   doubleExtendedDoAnythingBytecode
>>         "Replaces the Blue Book double-extended send [132], in which the
>> first byte was wasted on 8 bits of argument count.
>>         Here we use 3 bits for the operation sub-type (opType),  and the
>> remaining 5 bits for argument count where needed.
>>         The last byte give access to 256 instVars or literals.
>>         See also secondExtendedSendBytecode"
>>         | opType |
>>         opType := byte1 >> 5.
>>         opType = 0 ifTrue:
>>                 [^self genSend: byte2 numArgs: (byte1 bitAnd: 31)].
>>         opType = 1 ifTrue:
>>                 [^self genSendSuper: byte2 numArgs: (byte1 bitAnd: 31)].
>>         "We need a map entry for this bytecode for correct parsing.
>>          The sends will get an IsSend entry anyway.  The other cases need
>> a
>>          fake one.  We could of course special case the scanning but
>> that's silly."
>>         opType caseOf: {
>>                         [2]     ->      [(coInterpreter
>> isReadMediatedContextInstVarIndex: byte2)
>>                                                 ifTrue: [self
>> genPushMaybeContextReceiverVariable: byte2]
>>                                                 ifFalse: [self
>> genPushReceiverVariable: byte2.
>>                                                                 self
>> ssTop annotateUse: true.
>>                                                                 ^0]].
>>                         [3]     ->      [self genPushLiteralIndex: byte2.
>>                                          self ssTop annotateUse: true.
>>                                          ^0].
>>                         [4]     ->      [self genPushLiteralVariable:
>> byte2.].
>> +                       [7]     ->      [self genStorePop: false
>> LiteralVariable: byte2.
>> +                                       self cppIf: IMMUTABILITY ifTrue:
>> [ "instruction is mapped" ^0 ] ] }
>> -                       [7]     ->      [self genStorePop: false
>> LiteralVariable: byte2] }
>>                 otherwise: "5 & 6"
>>                         [(coInterpreter
>> isWriteMediatedContextInstVarIndex: byte2)
>>                                 ifTrue: [self genStorePop: opType = 6
>> MaybeContextReceiverVariable: byte2]
>> +                               ifFalse: [self genStorePop: opType = 6
>> ReceiverVariable: byte2].
>> +                       self cppIf: IMMUTABILITY ifTrue: [ "instruction
>> is mapped" ^0 ]].
>> -                               ifFalse: [self genStorePop: opType = 6
>> ReceiverVariable: byte2]].
>>         "We need a map entry for this bytecode for correct parsing (if
>> the method builds a frame).
>>          We could of course special case the scanning but that's silly
>> (or is it?)."
>>         self assert: needsFrame.
>>         "genPushMaybeContextInstVar, pushListVar, store & storePop all
>> generate code"
>>         self assert: self prevInstIsPCAnnotated not.
>>         self annotateBytecode: self Label.
>>         ^0!
>>
>>
>
>
> --
> _,,,^..^,,,_
> best, Eliot
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20160120/88cef9e0/attachment-0001.htm


More information about the Vm-dev mailing list