<br><br><div class="gmail_quote">On Thu, Mar 18, 2010 at 8:23 AM, Bert Freudenberg <span dir="ltr">&lt;<a href="mailto:bert@freudenbergs.de">bert@freudenbergs.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On 18.03.2010, at 15:51, Colin Putney wrote:<br>
&gt;<br>
&gt;<br>
&gt; On 2010-03-18, at 5:39 AM, Bert Freudenberg wrote:<br>
&gt;<br>
&gt;&gt; HO there should be no way to reset the immutable flag. You can implement &quot;soft&quot; immutability in the image, but &quot;hard&quot; VM-level immutability needs to be permanent, no fiddling possible. Once set, the object stays immutable. Only a copy of an immutable object will be mutable again.<br>

&gt;<br>
&gt; This would be good for some use cases - literals, for example, but not so good for others. One of the common uses of &quot;immutability&quot; is not so much to *prevent* mutation, as to control it: databases, concurrency etc. Do you have another feature in mind for these cases, or some overriding interest in immutable immutability that you want to pursue?<br>

&gt;<br>
&gt; Colin<br>
<br>
<br>
</div></div>Seems to me like two separate issues - one being informed of modifications, and one preventing modifications. Immutability to me means the latter. The former is more like a write barrier.<br>
<br>
With true immutables you can start developing in a mixed object/functional style, which would allow interesting optimizations, e.g. for concurrency, memoization etc.<br></blockquote><div><br></div><div>But the same VM support can allow both styles.  The VM support is a per-object bit that marks an object as immutable along with modifications to inst var assign and at:put: primitives to check for the immutability bit, and a pair of primitives to fetch and set the per-object isImmutable flag.    If the primitive to set immutablity is removed and replaced with a primitive that can only enable immutability, or if use of the primitive is suitably restricted then one can prevent clearing of the flag.  The VM is the same in oth cases; it simply has to check for the immtability flag on each write, but above that one can use this as a write-barrier or to implement &quot;true&quot; immutability.</div>
<div><br></div><div>Note that the cost of checking immutability on each write is quite small in the at:put: primitives because these must fetch the object header containing an object&#39;s size to do bounds checking, and testing a bit in a register containng the header merely adds a register operation not a more expensive read.  It does add to the cost of inst var write, but again the overhead is not that large because inst var write also involves the GC&#39;s write barrier.  So overall the performance impact is in my experience (VW &amp; Newspeak) &lt; 5% overall speed decrease for macro benchmarks.</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<font color="#888888"><br>
- Bert -<br>
<br>
<br>
</font></blockquote></div><br>