[Vm-dev] Questions related to immutability in Cog

Clément Bera bera.clement at gmail.com
Wed Nov 11 10:03:42 UTC 2015

Thanks for your answers.

The implementation implies:
- adding support for the callback attemptToWrite: aValue atIndex: index which
is partially done
- checking for immutability at each write (at:put:, bytecoded inst var
access, instVarAt:put:, become: , ... ). both in the interpreter and jitted
- I guess adding 2 primitives to mark the object as immutable and mark it
back as mutable.

I believe it's not a lot of work. If no one has done that before May (a phd
student was interested at some point, he may do it) I could try to
supervise an intern on this task. When he finishes the implementation he
could work in actually using the immutability in the image.

2015-11-11 4:46 GMT-03:00 Eliot Miranda <eliot.miranda at gmail.com>:

> 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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20151111/27896abe/attachment.htm

More information about the Vm-dev mailing list