[Vm-dev] Questions related to immutability in Cog

Eliot Miranda eliot.miranda at gmail.com
Wed Nov 11 07:46:55 UTC 2015


Hi Clément,

> On Nov 10, 2015, at 6:17 AM, Clément Bera <bera.clement at gmail.com> wrote:
> 
> Hello everyone,
> 
> I tried to understand how immutability is implemented in the CogVM (NewSpeak flavor). I have some questions:

Ryan's answers are good, but I'll give a little more detail.
> 
> - Does it actually work and is it used ?

The scheme is identical to the VisualWorks one, and the VW version has been in use for over ten years, so the scheme definitely works.  But it's not yet implemented in Cog.

> - Does an object being immutable means that you can't edit its variable fields only or that you can't either edit its instance variables ? Because I don't see any code checking for instance variable stores in the Newspeak interpreter.

When implemented, the VM  checks the immutability bit before each write, which means before writing to an inst var or global variable when executing an inst var write bytecode or global var write bytecode, or when writing to an object in a primitive.  So the bit protects an object from any write.

The bit can also be checked before a become.  In VW the bit protects two-way become but not one-way become IIRC.

If the bit is set when a write bytecode is executed the VM sends attemptToWrite: aValue atIndex: index to the immutable object.  If the bit is set when a write in a primitive is attempted the primitive fails with a suitable error code (#'no modification' ?).

> - How does the immutability check works in machine code ? In the Newspeak interpreter there is an immutability check in #at:put: . In the at:put: generated by the JIT (for example CogObjectRepresentationFor32BitSpur) I don't see any immutability check. Did I miss some clever bit trick ? Does the Newspeak spur VMs use the #at:put: machine code version of the primitive ?

It's not implemented yet.  The code to perform the checks and the send back need to be implemented.  It is not a lot of work.  Perhaps two weeks.

> 
> Thanks ! 

_,,,^..^,,,_ (phone)


More information about the Vm-dev mailing list