[squeak-dev] The Inbox: Kernel-ct.1448.mcz
christoph.thiede at student.hpi.uni-potsdam.de
christoph.thiede at student.hpi.uni-potsdam.de
Fri Mar 25 17:49:52 UTC 2022
Hi Eliot,
I just have implemented your idea in Kernel-ct.1451 (inbox). Hope you like it! :-)
Do you have any further suggestions or may I move KernelTests-ct.420, Kernel-ct.1448, KernelTests-ct.421, Kernel-ct.1449, and Kernel-ct.1451 to the Trunk?
Best,
Christoph
---
Sent from Squeak Inbox Talk
On 2022-03-14T00:37:07+00:00, christoph.thiede at student.hpi.uni-potsdam.de wrote:
> Hi Eliot, thanks for the fast feedback.
>
>
> > Wow that's a huge side-effect for such a basic operation. Not only that, the method lives in the method dictionary until the ensure: block us run and that could potentially be never. Isn't it preferable to determine if compiledMethod has a primitive, if so to use the doPrimitive:.../tryNamedPrimitiveIn:/tryPrimitive: machinery to execute the primitive, and then if the primitive fails create an activation of compiledMethod via Context class>>sender:receiver:method:arguments: and set that going via swapSender: tricks?
>
> Very nice idea! So basically Context>>#send:to:with:lookupIn: without the lookup part. I'm looking forward to implementing this, but it might take me some more days ... Busy times ... :-)
>
> Best,
> Christoph
>
> ________________________________
> Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von Eliot Miranda <eliot.miranda at gmail.com>
> Gesendet: Samstag, 12. März 2022 02:41:49
> An: The general-purpose Squeak developers list
> Betreff: Re: [squeak-dev] The Inbox: Kernel-ct.1448.mcz
>
> Hi Christoph,
>
> your fixes look good. I was on the verge of moving them to trunk when I looked at the failure code in Object>>withArgs:executeMethod:
>
> Object>>withArgs: argArray executeMethod: compiledMethod
> "Execute compiledMethod against the receiver and args in argArray"
>
> | selector |
> <primitive: 188>
> selector := Symbol new.
> self class addSelectorSilently: selector withMethod: compiledMethod.
> ^ [self perform: selector withArguments: argArray]
> ensure: [self class basicRemoveSelector: selector]
>
> Wow that's a huge side-effect for such a basic operation. Not only that, the method lives in the method dictionary until the ensure: block us run and that could potentially be never. Isn't it preferable to determine if compiledMethod has a primitive, if so to use the doPrimitive:.../tryNamedPrimitiveIn:/tryPrimitive: machinery to execute the primitive, and then if the primitive fails create an activation of compiledMethod via Context class>>sender:receiver:method:arguments: and set that going via swapSender: tricks?
>
> If you agree can I ask you to submit a Kernel with the implementation?
>
> On Fri, Mar 11, 2022 at 4:56 PM Thiede, Christoph <Christoph.Thiede at student.hpi.uni-potsdam.de<mailto:Christoph.Thiede at student.hpi.uni-potsdam.de>> wrote:
>
> Hi Eliot, hi all,
>
>
> I have dropped a few versions in the inbox that improve the simulation of primitive 189, 183, 184 and also add tests for them. Please see: KernelTests-ct.420, Kernel-ct.1448, KernelTests-ct.421, and Kernel-ct.1449. Also, there are even more primitive tests in KernelTests-ct.409 (inbox), but they do not need to be reviewed together. I am looking forward to your feedback, please let me know when I can move these changes to the Trunk! :-)
>
>
> Best,
>
> Christoph
>
>
> ________________________________
> Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org<mailto:squeak-dev-bounces at lists.squeakfoundation.org>> im Auftrag von commits at source.squeak.org<mailto:commits at source.squeak.org> <commits at source.squeak.org<mailto:commits at source.squeak.org>>
> Gesendet: Samstag, 12. März 2022 00:42:12
> An: squeak-dev at lists.squeakfoundation.org<mailto:squeak-dev at lists.squeakfoundation.org>
> Betreff: [squeak-dev] The Inbox: Kernel-ct.1448.mcz
>
> A new version of Kernel was added to project The Inbox:
> http://source.squeak.org/inbox/Kernel-ct.1448.mcz
>
> ==================== Summary ====================
>
> Name: Kernel-ct.1448
> Author: ct
> Time: 12 March 2022, 12:42:08.516359 am
> UUID: 7659c202-5fcc-084e-84b4-a5d233717b2d
> Ancestors: Kernel-nice.1447
>
> Implements missing simulation of primitive 189 primitiveExecuteMethod (Object>>with:...executeMethod:).
>
> =============== Diff against Kernel-nice.1447 ===============
>
> Item was changed:
> ----- Method: Context>>doPrimitive:method:receiver:args: (in category 'private') -----
> doPrimitive: primitiveIndex method: meth receiver: receiver args: arguments
> "Simulate a primitive method whose index is primitiveIndex. The simulated receiver and
> arguments are given as arguments to this message. If successful, push result and return
> resuming context, else ^ {errCode, PrimitiveFailToken}. Any primitive which provokes
> execution needs to be intercepted and simulated to avoid execution running away."
>
> | value |
> "Judicious use of primitive 19 (a null primitive that doesn't do anything) prevents
> the debugger from entering various run-away activities such as spawning a new
> process, etc. Injudicious use results in the debugger not being able to debug
> interesting code, such as the debugger itself. Hence use primitive 19 with care :-)"
> "SystemNavigation new browseAllSelect: [:m| m primitive = 19]"
> primitiveIndex = 19 ifTrue: [
> [self notify: ('The code being simulated is trying to control a process ({1}). Process controlling cannot be simulated. If you proceed, things may happen outside the observable area of the simulator.' translated format: {meth reference})]
> ifCurtailed: [self push: nil "Cheap fix of the context's internal state"]].
>
> ((primitiveIndex between: 201 and: 222)
> and: [(self objectClass: receiver) includesBehavior: BlockClosure]) ifTrue:
> [(primitiveIndex = 206
> or: [primitiveIndex = 208]) ifTrue: "[Full]BlockClosure>>valueWithArguments:"
> [^receiver simulateValueWithArguments: arguments first caller: self].
> ((primitiveIndex between: 201 and: 209) "[Full]BlockClosure>>value[:value:...]"
> or: [primitiveIndex between: 221 and: 222]) ifTrue: "[Full]BlockClosure>>valueNoContextSwitch[:]"
> [^receiver simulateValueWithArguments: arguments caller: self]].
>
> primitiveIndex = 83 ifTrue: "afr 9/11/1998 19:50" "Object>>perform:[with:...]"
> [| selector |
> selector := arguments at: 1 ifAbsent:
> [^ self class primitiveFailTokenFor: #'bad argument'].
> arguments size - 1 = selector numArgs ifFalse:
> [^ self class primitiveFailTokenFor: #'bad number of arguments'].
> ^self send: selector to: receiver with: arguments allButFirst].
> primitiveIndex = 84 ifTrue: "afr 9/11/1998 19:50 & eem 8/18/2009 17:04" "Object>>perform:withArguments:"
> [| selector args |
> arguments size = 2 ifFalse:
> [^ self class primitiveFailTokenFor: #'bad argument'].
> selector := arguments first.
> args := arguments second.
> args isArray ifFalse:
> [^ self class primitiveFailTokenFor: #'bad argument'].
> args size = selector numArgs ifFalse:
> [^ self class primitiveFailTokenFor: #'bad number of arguments'].
> ^self send: selector to: receiver with: args].
> primitiveIndex = 100 ifTrue: "eem 8/18/2009 16:57" "Object>>perform:withArguments:inSuperclass:"
> [| rcvr selector args superclass |
> arguments size
> caseOf: {
> [3] -> [
> rcvr := receiver.
> selector := arguments first.
> args := arguments second.
> superclass := arguments third].
> [4] -> ["mirror primitive"
> rcvr := arguments first.
> selector := arguments second.
> args := arguments third.
> superclass := arguments fourth] }
> otherwise: [^ self class primitiveFailTokenFor: #'bad argument'].
> args isArray ifFalse:
> [^ self class primitiveFailTokenFor: #'bad argument'].
> args size = selector numArgs ifFalse:
> [^ self class primitiveFailTokenFor: #'bad number of arguments'].
> ((self objectClass: rcvr) includesBehavior: superclass) ifFalse:
> [^ self class primitiveFailTokenFor: #'bad argument'].
> ^self send: selector to: rcvr with: args lookupIn: superclass].
>
> "Mutex>>primitiveEnterCriticalSection
> Mutex>>primitiveTestAndSetOwnershipOfCriticalSection"
> (primitiveIndex = 186 or: [primitiveIndex = 187]) ifTrue:
> [| effective |
> effective := Processor activeProcess effectiveProcess.
> "active == effective"
> value := primitiveIndex = 186
> ifTrue: [receiver primitiveEnterCriticalSectionOnBehalfOf: effective]
> ifFalse: [receiver primitiveTestAndSetOwnershipOfCriticalSectionOnBehalfOf: effective].
> ^(self isPrimFailToken: value)
> ifTrue: [value]
> ifFalse: [self push: value]].
> +
> + (primitiveIndex = 188 or: [primitiveIndex = 189]) ifTrue:
> -
> - primitiveIndex = 188 ifTrue: "Object>>withArgs:executeMethod:
> - CompiledMethod class>>receiver:withArguments:executeMethod:
> - VMMirror>>ifFail:object:with:executeMethod: et al"
> [| n args methodArg thisReceiver |
> + primitiveIndex caseOf:
> + {[188 "primitiveExecuteMethodArgsArray"] ->
> + ["Object>>withArgs:executeMethod:
> + CompiledMethod class>>receiver:withArguments:executeMethod:
> + VMMirror>>ifFail:object:with:executeMethod: et al"
> + ((n := arguments size) between: 2 and: 4) ifFalse:
> + [^self class primitiveFailTokenFor: #'unsupported operation'].
> + ((self objectClass: (args := arguments at: n - 1)) == Array
> + and: [(self objectClass: (methodArg := arguments at: n)) includesBehavior: CompiledMethod]) ifFalse:
> + [^self class primitiveFailTokenFor: #'bad argument'].
> + thisReceiver := arguments at: n - 2 ifAbsent: [receiver]].
> + [189 "primitiveExecuteMethod"] ->
> + ["Object>>executeMethod:
> + Object>>with:...executeMethod:"
> + (arguments size > 0) ifFalse:
> + [^self class primitiveFailTokenFor: #'bad argument'].
> + ((self objectClass: (methodArg := arguments atLast: 1)) includesBehavior: CompiledMethod) ifFalse:
> + [^self class primitiveFailTokenFor: #'bad argument'].
> + args := arguments allButLast.
> + thisReceiver := receiver]}.
> - ((n := arguments size) between: 2 and: 4) ifFalse:
> - [^self class primitiveFailTokenFor: #'unsupported operation'].
> - ((self objectClass: (args := arguments at: n - 1)) == Array
> - and: [(self objectClass: (methodArg := arguments at: n)) includesBehavior: CompiledMethod]) ifFalse:
> - [^self class primitiveFailTokenFor: #'bad argument'].
> methodArg numArgs = args size ifFalse:
> [^self class primitiveFailTokenFor: #'bad number of arguments'].
> - thisReceiver := arguments at: n - 2 ifAbsent: [receiver].
> methodArg primitive > 0 ifTrue:
> [methodArg isQuick ifTrue:
> [^self push: (methodArg valueWithReceiver: thisReceiver arguments: args)].
> ^self doPrimitive: methodArg primitive method: meth receiver: thisReceiver args: args].
> ^self
> activateMethod: methodArg
> withArgs: args
> receiver: thisReceiver].
>
> primitiveIndex = 118 ifTrue: "[receiver:]tryPrimitive:withArgs:; avoid recursing in the VM"
> [(arguments size = 3
> and: [(self objectClass: arguments second) == SmallInteger
> and: [(self objectClass: arguments last) == Array]]) ifTrue:
> [^self doPrimitive: arguments second method: meth receiver: arguments first args: arguments last].
> (arguments size = 2
> and: [(self objectClass: arguments first) == SmallInteger
> and: [(self objectClass: arguments last) == Array]]) ifFalse:
> [^self class primitiveFailTokenFor: nil].
> ^self doPrimitive: arguments first method: meth receiver: receiver args: arguments last].
>
> value := primitiveIndex = 120 "FFI method"
> ifTrue: [(meth literalAt: 1) tryInvokeWithArguments: arguments]
> ifFalse:
> [primitiveIndex = 117 "named primitives"
> ifTrue: [self tryNamedPrimitiveIn: meth for: receiver withArgs: arguments]
> ifFalse: "should use self receiver: receiver tryPrimitive: primitiveIndex withArgs: arguments but this is only in later VMs (and appears to be broken)"
> [receiver tryPrimitive: primitiveIndex withArgs: arguments]].
>
> ^(self isPrimFailToken: value)
> ifTrue: [value]
> ifFalse: [self push: value]!
>
>
>
>
>
> --
> _,,,^..^,,,_
> best, Eliot
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20220314/91ddf63a/attachment.html>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20220325/5de16b74/attachment-0001.html>
More information about the Squeak-dev
mailing list
|