[squeak-dev] The Trunk: Compiler-nice.417.mcz

Eliot Miranda eliot.miranda at gmail.com
Wed Mar 11 21:33:46 UTC 2020


Hi Nicolas,

    nice, thank you!

On Wed, Mar 11, 2020 at 2:18 PM <commits at source.squeak.org> wrote:

> Nicolas Cellier uploaded a new version of Compiler to project The Trunk:
> http://source.squeak.org/trunk/Compiler-nice.417.mcz
>
> ==================== Summary ====================
>
> Name: Compiler-nice.417
> Author: nice
> Time: 11 March 2020, 10:18:30.802676 pm
> UUID: dabc222a-b8c1-4a9e-9495-938c11b4f17b
> Ancestors: Compiler-eem.416
>
> Fix decompilation of FullBlockClosure
>
> Some Closure with complex jump flow (optimized ifTrue: etc...) will alter
> some of the states required to decompile the method and fool the backward
> return detection logic.
>
> There are so many states to be saved, that the most reasonable thing to do
> is to decompile the block in a shallowCopy, and simply re-initialize the
> states that should not be shared. Note that this is un-necessary for all
> the immediate or immutable values, which are not shared states with the
> shallowCopy, so we don't have to care for most of them.
>
> Same changes could eventually apply to V3 closure, but if it ain't broken
> don't fix it: it's touchy and it would be necessary to test that in a non
> SistaV1 which is superfluous...
>
> Last little detail: don't invoke super method:pc: there is a single
> implementation and self will do the work.
>
> =============== Diff against Compiler-eem.416 ===============
>
> Item was changed:
>   ----- Method: Decompiler>>decompile:in:method:using: (in category
> 'public access') -----
>   decompile: aSelector in: aClass method: aMethod using: aConstructor
>
>         | block node |
>         constructor := aConstructor.
>         method := aMethod.
>         self initSymbols: aClass.  "create symbol tables"
>         method isQuick
>                 ifTrue: [block := self quickMethod]
>                 ifFalse:
>                         [stack := OrderedCollection new: method frameSize.
>                         lastJumpIfPcStack := OrderedCollection new.
>                         caseExits := OrderedCollection new.
>                         statements := OrderedCollection new: 20.
>                         numLocalTemps := 0.
> +                       self method: method pc: method initialPC.
> -                       super method: method pc: method initialPC.
>                         "skip primitive error code store if necessary"
>                         (method primitive ~= 0 and: [self
> skipCallPrimitive; willStore]) ifTrue:
>                                 [pc := pc + (method encoderClass
> bytecodeSize: self firstByte).
>                                  tempVars := tempVars asOrderedCollection].
>                         block := self blockTo: method endPC + 1.
>                         stack isEmpty ifFalse: [self error: 'stack not
> empty']].
>         node := constructor
>                                 codeMethod: aSelector
>                                 block: block
>                                 tempVars: tempVars
>                                 primitive: method primitive
>                                 class: aClass.
>         method primitive > 0 ifTrue:
>                 [node removeAndRenameLastTempIfErrorCode].
>         ^node preen!
>
> Item was changed:
>   ----- Method: Decompiler>>doClosureCopy:copiedValues: (in category
> 'control') -----
>   doClosureCopy: aCompiledBlock copiedValues: blockCopiedValues
> +       "implementation note: must be invoked on a copy because it
> modifies states"
> +       | savedPC blockArgs blockTemps blockTempsOffset block mark |
> -       | savedTemps savedTempVarCount savedNumLocalTemps savedMethod
> savedPC
> -         blockArgs blockTemps blockTempsOffset block |
> -       savedTemps := tempVars.
> -       savedTempVarCount := tempVarCount.
> -       savedNumLocalTemps := numLocalTemps.
>         numLocalTemps := aCompiledBlock numTemps - aCompiledBlock numArgs
> - blockCopiedValues size.
>         blockTempsOffset := aCompiledBlock numArgs + blockCopiedValues
> size.
>         (blockStartsToTempVars notNil "implies we were intialized with
> temp names."
>          and: [blockStartsToTempVars includesKey: aCompiledBlock])
>                 ifTrue:
>                         [tempVars := blockStartsToTempVars at:
> aCompiledBlock]
>                 ifFalse:
>                         [blockArgs := (1 to: aCompiledBlock numArgs)
> collect:
>                                                         [:i| (constructor
>
> codeTemp: i - 1
>
> named: 't', (tempVarCount + i) printString)
>
> beBlockArg].
>                         blockTemps := (1 to: numLocalTemps) collect:
>                                                         [:i| constructor
>
> codeTemp: i + blockTempsOffset - 1
>
> named: 't', (tempVarCount + i + aCompiledBlock numArgs) printString].
>                         tempVars := blockArgs, blockCopiedValues,
> blockTemps].
>         tempVarCount := tempVarCount + aCompiledBlock numArgs +
> numLocalTemps.
> +       lastJumpIfPcStack := OrderedCollection new.
> +       caseExits := OrderedCollection new.
> +       statements := OrderedCollection new: 20.
> +       savedPC := pc.
> +       self method: (method := aCompiledBlock) pc: aCompiledBlock
> initialPC.
> +       mark := stack size.
> +       block := self blockTo: aCompiledBlock endPC.
> +       mark = stack size ifFalse: [self error: 'block did alter the
> stack'].
> +       ^((constructor
> +                       codeArguments: (tempVars copyFrom: 1 to:
> aCompiledBlock numArgs)
> +                       temps: (tempVars copyFrom: blockTempsOffset + 1
> to: blockTempsOffset + numLocalTemps)
> +                       block: block)
> +                               pc: aCompiledBlock -> savedPC; "c.f.
> BytecodeEncoder>>pc"
> +                               yourself).!
> -       savedMethod := self method. savedPC := pc.
> -       super method: (method := aCompiledBlock) pc: aCompiledBlock
> initialPC.
> -       block := [self blockTo: aCompiledBlock endPC]
> -                               ensure: [super method: (method :=
> savedMethod) pc: savedPC].
> -       stack addLast: ((constructor
> -                                               codeArguments: (tempVars
> copyFrom: 1 to: aCompiledBlock numArgs)
> -                                               temps: (tempVars copyFrom:
> blockTempsOffset + 1 to: blockTempsOffset + numLocalTemps)
> -                                               block: block)
> -                                                       pc: aCompiledBlock
> -> pc; "c.f. BytecodeEncoder>>pc"
> -                                                       yourself).
> -       tempVars := savedTemps.
> -       tempVarCount := savedTempVarCount.
> -       numLocalTemps := savedNumLocalTemps!
>
> Item was changed:
>   ----- Method: Decompiler>>pushFullClosure:numCopied: (in category
> 'instruction decoding') -----
>   pushFullClosure: aCompiledBlock numCopied: numCopied
>         | copiedValues |
>         copiedValues := ((1 to: numCopied) collect: [:ign| stack
> removeLast]) reversed.
> +       stack addLast: (self shallowCopy doClosureCopy: aCompiledBlock
> copiedValues: copiedValues)!
> -       self doClosureCopy: aCompiledBlock copiedValues: copiedValues!
>
>
>

-- 
_,,,^..^,,,_
best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200311/0bb53e9b/attachment.html>


More information about the Squeak-dev mailing list