[Vm-dev] Questions related to immutability in Cog

Eliot Miranda eliot.miranda at gmail.com
Wed Nov 11 15:14:44 UTC 2015


Hi Stephane,

> On Nov 11, 2015, at 2:30 AM, stephane ducasse <stephane.ducasse at gmail.com> wrote:
> 
> 
> 
>>> - 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.
> 
> 
> eliot why the become?
> is it when the become tackles instance variables of an object and that such object should be immutable?

It's more that one use of the scheme is to make sure literals are immutable and so one shouldn't just be able to become them by mistake.  Remember one can always turn off the bit so if you really want to you can become a literal.  So checking in two-way become makes sense to me.

>> 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' ?).
> 
> Like that we can use it for write barrier. 

Right.  That's the most compelling use case.  For example the Gemstone system uses this to trap writes to objects.

> 
>>> - 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 ?
> 
> I think that sebastian could have a look at that with clement. 
> 
> Syef


More information about the Vm-dev mailing list