<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jan 13, 2014 at 3:59 PM, David T. Lewis <span dir="ltr">&lt;<a href="mailto:lewis@mail.msen.com" target="_blank">lewis@mail.msen.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
On Mon, Jan 13, 2014 at 09:26:31AM -0800, Eliot Miranda wrote:<br>
&gt; Hi David,<br>
&gt;<br>
&gt; On Sun, Jan 12, 2014 at 5:13 PM, David T. Lewis &lt;<a href="mailto:lewis@mail.msen.com">lewis@mail.msen.com</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt; On Sun, Jan 12, 2014 at 09:53:27PM +0100, Bert Freudenberg wrote:<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; On 12.01.2014, at 20:42, David T. Lewis &lt;<a href="mailto:lewis@mail.msen.com">lewis@mail.msen.com</a>&gt; wrote:<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; It is worth noting that allObjectsDo: relies on assumptions about how<br>
&gt; &gt; &gt; &gt; the objects memory works internally. It requires that #someObject will<br>
&gt; &gt; &gt; &gt; always answer the object at the lowest address in the object memory,<br>
&gt; &gt; and<br>
&gt; &gt; &gt; &gt; also that a newly allocated object will always be placed at a higher<br>
&gt; &gt; &gt; &gt; address location than all other objects. Either of these assumptions is<br>
&gt; &gt; &gt; &gt; likely to be a problem as new and better object memories and garbage<br>
&gt; &gt; &gt; &gt; collectors are implemented.<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; Dave<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Right (as Eliot&#39;s vm-dev post shows).<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; So IMHO the only sensible semantics of allObjectsDo: is as in<br>
&gt; &gt; &quot;allObjects do:&quot; -<br>
&gt; &gt; &gt; which might be implemented as a primitive in some VMs soonish. It<br>
&gt; &gt; *should not*<br>
&gt; &gt; &gt; enumerate objects created after calling the method.<br>
&gt; &gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; On Sun, Jan 12, 2014 at 12:01:00PM -0800, Eliot Miranda wrote:<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; The bug is in implementing allObjects in terms of someObject and<br>
&gt; &gt; nextObject<br>
&gt; &gt; &gt; in the first place.  It&#39;s cheap and cheerful but horribly error-prone and<br>
&gt; &gt; &gt; restrictive.  It&#39;s cheap because the collection of objects doesn&#39;t have<br>
&gt; &gt; to<br>
&gt; &gt; &gt; be created, and on the original 16-bit Smalltalk machines that was really<br>
&gt; &gt; &gt; important.  It&#39;s horribly restrictive because it assumes much about the<br>
&gt; &gt; &gt; implementation.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Before closures a sentinel wasn&#39;t even needed because enumerating the<br>
&gt; &gt; block<br>
&gt; &gt; &gt; didn&#39;t create a new object (the block context was reused).  So the code<br>
&gt; &gt; had<br>
&gt; &gt; &gt; to be rewritten just to support closures.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Spur has a generation scavenger operating in a distinct new space and<br>
&gt; &gt; that<br>
&gt; &gt; &gt; doesn&#39;t jive well with a consistent ordering at all.  So far the system<br>
&gt; &gt; is<br>
&gt; &gt; &gt; limping along by tenuring all objects on someObject and someInstance (so<br>
&gt; &gt; &gt; that newSpace is either empty, or doesn&#39;t contain any instances of a<br>
&gt; &gt; &gt; specific class) and having nextObject enumerate only objects in oldSpace.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; But I think now we can afford a primitive that answers all the objects<br>
&gt; &gt; &gt; (remember that average object size means that such a collection will be ~<br>
&gt; &gt; &gt; 10% of the heap, average object size in Squeak V3 is about 10.6 words).<br>
&gt; &gt;  At<br>
&gt; &gt; &gt; least that&#39;s what Spur will do, along with an allInstancesOf: primitive.<br>
&gt; &gt; &gt;  And then the become example won&#39;t cause any problems at all.  Far more<br>
&gt; &gt; &gt; reliable.  I suppose there are circumstances when enumerating without a<br>
&gt; &gt; &gt; container is the only feasible approach, but VisualWorks has got along<br>
&gt; &gt; with<br>
&gt; &gt; &gt; only an allObjects primitive for a long time now.  I suspect we can too.<br>
&gt; &gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; Implementation attached. Works on interpreter VM, not yet tested on Cog but<br>
&gt; &gt; it should be ok there also. If no objections or better suggestions I will<br>
&gt; &gt; commit it to VMMaker tomorrow.<br>
&gt; &gt;<br>
&gt; &gt; InterpreterPrimitives&gt;&gt;primitiveAllObjects<br>
&gt; &gt;         &quot;Answer an array of all objects that exist when the primitive is<br>
&gt; &gt; called, excluding those<br>
&gt; &gt;         that may be garbage collected as a side effect of allocating the<br>
&gt; &gt; result array. Multiple<br>
&gt; &gt;         references to nil in the last slots of the array are an indication<br>
&gt; &gt; that garbage collection<br>
&gt; &gt;         occured, such that some of the unreferenced objects that existed<br>
&gt; &gt; at the time of calling<br>
&gt; &gt;         the primitive no longer exist. Sender is responsible for handling<br>
&gt; &gt; multiple references to<br>
&gt; &gt;         nil in the result array.&quot;<br>
&gt; &gt;<br>
&gt;<br>
&gt; Instead of filling the unused slots with nil or 0, I think you should<br>
&gt; shorten the object so that it contains each object only once, and contains<br>
&gt; only the objects.  Cog contains some code for shortening.  See<br>
&gt; [New]ObjectMemory&gt;&gt;shorten:toIndexableSize:.<br>
&gt;<br>
<br>
</div></div>That would be a better solution. However, I cannot offer an implementation<br>
in the near term because of:<br>
<br>
  shorten: obj toIndexableSize: nSlots<br>
      &quot;Currently this works for pointer objects only, and is almost certainly wrong for 64 bits.&quot;<br>
<br>
Given that this is currently intended for pointer objects, it is probably<br>
fairly straightforward to get it working on the 64-bit object memory. In fact,<br>
it might already work as written. But I think that it will take some time to<br>
test so it&#39;s not going to happen tonight.<br>
<br>
We could consider a variation on Bert&#39;s suggestion, in which the result array<br>
might have trailing zeros if garbage collection has occurred. Later the primitive<br>
can be improved with shorten:toIndexableSize: after which the trailing zeros<br>
will never occur in practice. That would still put the burden on the image<br>
to ignore the trailing junk, so I don&#39;t know if it would be worth doing.<br></blockquote><div><br></div><div>There&#39;s no point hurrying a thing like this.  Best to do it right.  Take your time and answer an Array of the objects and nothing but the objects :-).  We&#39;re essentially aiming at 4.6 now so there&#39;s lots of time to test.</div>
</div>-- <br>best,<div>Eliot</div>
</div></div>