[Vm-dev] Changing numArgs of primitive CompiledMethod in Spur

Denis Kudriashov dionisiydk at gmail.com
Fri Feb 26 14:15:44 UTC 2016


In Pharo we have special logic to debug failure code of primitives. When
debugger detects named prim it tries to create same prim method but without
failure code. Then if it fails debugger step into primitive failure code.

To create such cleaned primitive method Pharo uses template method like

"This method is a template that the Smalltalk simulator uses to
execute primitives. See Object documentation whatIsAPrimitive."
<primitive:' module:' error: errorCode>
^ Context primitiveFailTokenFor: errorCode

Then it changes arguments count to be like given method:

theMethod := self class tryNamedPrimitiveTemplateMethod.

theMethod prepareForSimulationWith: arguments size.
self setNamedPrimitiveInformationFrom: *aCompiledMethod* toMethod:

CompiledMethod>>prepareForSimulationWith: numArgs
"This method changes the argument count of a CompiledMethod header to
numArgs, its temporary count to numArgs + 1 and change the code handling
primitive error to store the error code in the unique temporary of the
| newHeader xpc |
newHeader := (((self header bitAnd: 2r01110000000000111111111111111111)
bitOr: (numArgs bitShift: 24))
bitOr: (numArgs + 1 bitShift: 18)).
newHeader := newHeader + (self class headerFlagForEncoder: self
self objectAt: 1 put: newHeader.
xpc := self initialPC.
"long store temp"
(self at: xpc) = 129
ifTrue: [
self at: xpc + 1 put: (16r40 + numArgs).
self at: xpc + 3 put: (16r10 + numArgs)]

Then method executed by:

theMethod flushCache

theMethod valueWithReceiver: aReceiver arguments: arguments

This approach works correctly on Cog and not working in Spur.
In Spur result of theMethod execution become wrong when given method has
Which means that changing method arguments of CompiledMethod is incorrect
for Spur.

Is there any solution to make it working?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20160226/5de9cb9f/attachment.htm

More information about the Vm-dev mailing list