<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta content="text/html;charset=UTF-8" http-equiv="Content-Type"></head><body ><div style='font-size:10pt;font-family:Verdana,Arial,Helvetica,sans-serif;'>If the "Tim" referred to here is "tty" then I have this message bookmarked. I am a bit sidetracked at the moment but will be returning to getting the StackVM soon.<br><br>cheers.<br><br>tty<br><div id="1"><br>---- On Tue, 25 Mar 2014 09:46:30 -0700 <b>Eliot Miranda &lt;eliot.miranda@gmail.com&gt;</b> wrote ---- <br></div><br><blockquote style="border-left: 1px solid #0000FF; padding-left: 6px; margin:0 0 0 5px"><div dir="ltr"><div dir="auto"><div>Hi Phil, Hi ClassBuilder people,</div><div><br>On Mar 25, 2014, at 5:16 AM, "<a href="mailto:phil@highoctane.be" target="_blank">phil@highoctane.be</a>" &lt;<a href="mailto:phil@highoctane.be" target="_blank">phil@highoctane.be</a>&gt; wrote:<br> <br></div><div><span></span></div><blockquote type="cite"><div><div dir="ltr"><div><div><div dir="ltr"><div>On Tue, Mar 25, 2014 at 1:05 PM, Igor Stasenko <span dir="ltr">&lt;<a href="mailto:siguctua@gmail.com" target="_blank">siguctua@gmail.com</a>&gt;</span> wrote:<br> </div></div></div><div><blockquote style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"> <br><div><br><br><div>On 24 March 2014 22:54, <a href="mailto:phil@highoctane.be" target="_blank">phil@highoctane.be</a> <span dir="ltr">&lt;<a href="mailto:phil@highoctane.be" target="_blank">phil@highoctane.be</a>&gt;</span> wrote:<br> <blockquote style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div> <div><div>On Mon, Mar 24, 2014 at 8:23 PM, Alexandre Bergel <span dir="ltr">&lt;<a href="mailto:alexandre.bergel@me.com" target="_blank">alexandre.bergel@me.com</a>&gt;</span> wrote:<br> <blockquote style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">&gt;&gt; I am working on a memory model for expandable collection in Pharo. Currently, OrderedCollection, Dictionary and other expandable collections use a internal array to store their data. My new collection library recycle these array instead of letting the garbage collector dispose them. I simply insert the arrays in an ordered collection when an array is not necessary anymore. And I remove one when I need one.<br> &gt;<br> &gt; Hm, is that really going to be worth the trouble?<br> <br> This technique reduces the consumption of about 15% of memory.<br> <br> &gt;&gt; At the end, #add: &nbsp;and #remove: are performed on these polls of arrays. I haven’t been able to spot any problem regarding concurrency and I made no effort in preventing them. I have a simple global collection and each call site of "OrderedCollection new” can pick an element of my global collection.<br> &gt;&gt;<br> &gt;&gt; I have the impression that I simply need to guard the access to the global poll, which is basically guarding #add: &nbsp;#remove: and #includes:<br> &gt;<br> &gt; One of the AtomicCollections might be the right things for you?<br> <br> I will have a look at it.<br> <br> &gt;&gt; What is funny, is that I did not care at all about multi-threading and concurrency, and I have not spotted any problem so far.<br> &gt;<br> &gt; There isn’t any ‘multi-threading’ like in Java, you got a much more control version: cooperative on the same priority, preemptive between priorities.<br> &gt; So, I am not surprised. And well, these operations are likely not to be problematic when they are racy, except when the underling data structure could get into an inconsistent state itself. The overall operations (adding/removing/searing) are racy on the application level anyway.<br> &gt;<br> &gt; However, much more interesting would be to know what kind of benefit do you see for such reuse?<br> &gt; And especially, with Spur around the corner, will it still pay off then? Or is it an application-specific optimization?<br> <br> I am exploring a new design of the collection library of Pharo. Not all the (academic) ideas will be worth porting into the mainstream of Pharo. But some of them yes.<br> <br> Thanks for all your help guys! You’re great!<br> <br> Cheers,<br> Alexandre<br> <span><font color="#888888"><br> --<br> _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:<br> Alexandre Bergel &nbsp;<a href="http://www.bergel.eu" target="_blank">http://www.bergel.eu</a><br> ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.<br> <br> <br> <br></font></span></blockquote><div><br></div></div></div><div>An interesting method I stumbled upon which may help in understanding how these things do work.&nbsp;</div><div><br></div><div>BlockClosure&gt;&gt;valueUnpreemptively</div> <div> <span style="white-space:pre-wrap">        </span>"Evaluate the receiver (block), without the possibility of preemption by higher priority processes. Use this facility VERY sparingly!"</div><div><span style="white-space:pre-wrap">        </span>"Think about using Block&gt;&gt;valueUninterruptably first, and think about using Semaphore&gt;&gt;critical: before that, and think about redesigning your application even before that!&nbsp;</div> <div><span style="white-space:pre-wrap">        </span>After you've done all that thinking, go right ahead and use it..."</div><div><span style="white-space:pre-wrap">        </span>| activeProcess oldPriority result semaphore |</div> <div><span style="white-space:pre-wrap">        </span>activeProcess := Processor activeProcess.</div><div><span style="white-space:pre-wrap">        </span>oldPriority := activeProcess priority.</div><div><span style="white-space:pre-wrap">        </span>activeProcess priority: Processor highestPriority.</div> <div><span style="white-space:pre-wrap">        </span>result := self ensure: [activeProcess priority: oldPriority].&nbsp;</div></div><br></div></div> </blockquote></div><br>I would not recommend you to use this method for anything.<br></div><div>This method heavily relies on how process scheduler works, and in case of any changes, it may break everything.<br> </div><div>For the sake of programming, one shall never assume there is a way to "stop the world while i busy doing something".</div></div></blockquote><div><br></div><div>If you reshape the world, it makes sense. I was looking at how classes were migrated, that's why I found it.&nbsp;</div> <div>And all of the new Pharo way of doing these things.</div><div><br></div><div>Hey, it is becoming really cool down there. Martin and Camille have been hard at work. Kudos!</div><div><br></div><div>migrateClasses: old to: new using: anInstanceModification</div> <div><span style="white-space:pre-wrap">        </span>instanceModification := anInstanceModification.</div><div><span style="white-space:pre-wrap">        </span>old ifEmpty: &nbsp;[ ^ self ].</div><div><span style="white-space:pre-wrap">        </span>[</div> <div><span style="white-space:pre-wrap">                </span>1 to: old size do: [ :index |</div><div><span style="white-space:pre-wrap">                        </span>self updateClass: (old at: index) to: (new at: index)].</div><div><span style="white-space:pre-wrap">                </span>old elementsForwardIdentityTo: new.</div> <div><span style="white-space:pre-wrap">                </span>" Garbage collect away the zombie instances left behind in garbage memory in #updateInstancesFrom: "</div><div><span style="white-space:pre-wrap">                </span>" If we don't clean up this garbage, a second update would revive them with a wrong layout! "</div> <div><span style="white-space:pre-wrap">                </span>" (newClass rather than oldClass, since they are now both newClass) "</div><div><span style="white-space:pre-wrap">                </span>Smalltalk garbageCollect.</div> <div><span style="white-space:pre-wrap">        </span>] valueUnpreemptively</div></div></div></div></div></blockquote><div><br></div><div><br></div>The global GC here is pretty unfortunate. &nbsp;It is there because the VM used to leave old instances lying around. &nbsp;It works like this:</div> <div dir="auto"><br></div><div>we want to reshape instances of class C, e.g. by adding an inst var, and so</div><div><br></div><div>1. create C', which is C plus an inst var</div><div dir="auto">2. create a parallel set of instances of class C', one for each instance of class C</div> <div dir="auto">3. for each corresponding pair of instances copy state from the instance of C to the instance of C'</div><div dir="auto">4. forward-become the instances of C to the instances of C' (now no references to the instances of C remain)</div> <div dir="auto">5. become C to C' (now C' is the new C)</div><div dir="auto"><br></div><div dir="auto">The bug is that the old instances of C are still in the heap. &nbsp;Because of the become in 5. they look like instances of the new C, but are the wrong size; they lack space for the new inst var. &nbsp;They're not reachable (4. replaced all references to them with references to the instances of C') but they can be resurrected through allInstances (someInstance,nextInstance) which works not by following references from the roots (Smalltalk and the activeProcess) but by scanning objects in the heap.</div> <div dir="auto"><br></div><div dir="auto">However, this was "fixed" in</div><div dir="auto"><br></div><div dir="auto"><div dir="auto"><span style="white-space:pre">        </span>Name: VMMaker.oscog-eem.254</div> <div dir="auto"><span style="white-space:pre">        </span>Author: eem</div><div dir="auto"><span style="white-space:pre">        </span>Time: 11 January 2013, 7:05:37.389 pm</div><div dir="auto"><span style="white-space:pre">        </span>UUID: 74e6a299-691e-4f7d-986c-1a7d3d0ec02c</div> <div dir="auto"><span style="white-space:pre">        </span>Ancestors: VMMaker.oscog-eem.253</div><div dir="auto"><br></div><div dir="auto"><span style="white-space:pre">        </span>Fix becomeForward: so that objects whose references are deleted are</div> <div dir="auto"><span style="white-space:pre">        </span>freed and can no longer be resurrected via allObjects or allInstances.</div><div dir="auto"><br></div><div>The change is to free the objects replaced in a forwardBecome so they are no longer objects (effectively their class is null (not nil, but 0)). &nbsp;So they can't be resurrected and hence the global GC is un necessary. &nbsp;The Newspeak folks, in particular Ryan Macnak, spotted this and encouraged me to make the change. &nbsp;It of course speeds up instance mutation considerably.</div> <div><br></div><div>I say fixed because there was a bug tail:</div><div><br></div></div><div dir="auto"><div dir="auto"><span style="white-space:pre">        </span>Name: VMMaker.oscog-eem.258</div><div dir="auto"><span style="white-space:pre">        </span>Author: eem</div> <div dir="auto"><span style="white-space:pre">        </span>Time: 18 January 2013, 11:01:23.072 am</div><div dir="auto"><span style="white-space:pre">        </span>UUID: da1433f1-de50-475f-be33-f462b300a2ea</div><div dir="auto"> <span style="white-space:pre">        </span>Ancestors: VMMaker.oscog-eem.257</div><div dir="auto"><br></div><div dir="auto"><span style="white-space:pre">        </span>Fix becomeForward: when the rootTable overflows. &nbsp;There were two</div> <div dir="auto"><span style="white-space:pre">        </span>bugs here. &nbsp;One is that initializeMemoryFirstFree: used to clear the</div><div dir="auto"><span style="white-space:pre">        </span>needGCFlag so if the rootTable overflowed noteAsRoot:headerLoc:'s setting of the needGCFlag would be undone after the sweep.</div> <div dir="auto"><span style="white-space:pre">        </span>The other is that&nbsp;rootTable&nbsp;overflow was indicated by</div><div dir="auto"><span style="white-space:pre">        </span>rootTableCount &gt;= RootTableSize which could be undone by</div> <div dir="auto"><span style="white-space:pre">        </span>becomeForward: freeing roots which need to be removed from</div><div dir="auto"><span style="white-space:pre">        </span>the rootTable. &nbsp;At some point in becomeForward the rootTable would</div> <div dir="auto"><span style="white-space:pre">        </span>fill but at a later point a root would be freed, causing the table to</div><div dir="auto"><span style="white-space:pre">        </span>become not full.</div> <div dir="auto"><br></div><div dir="auto"><span style="white-space:pre">        </span>The fix is two fold. &nbsp;1. Add an explicit rootTableOverflowed flag</div><div dir="auto"><span style="white-space:pre">        </span>instead of relying on rootTableCount &gt;= RootTableSize.</div> <div dir="auto"><span style="white-space:pre">        </span>2. move the clearing of the needGCFlag to the GC routines.</div><div dir="auto"><span style="white-space:pre">        </span>Remove unnecessary senders of needGCFlag: false, and remove</div> <div dir="auto"><span style="white-space:pre">        </span>the accessor.</div><div dir="auto"><br></div><div dir="auto"><span style="white-space:pre">        </span>Name: VMMaker.oscog-eem.255</div><div dir="auto"><span style="white-space:pre">        </span>Author: eem</div> <div dir="auto"><span style="white-space:pre">        </span>Time: 12 January 2013, 6:28:41.398 pm</div><div dir="auto"><span style="white-space:pre">        </span>UUID: 51e53ec1-8caf-41f6-9293-1088ef4b82d8</div><div dir="auto"> <span style="white-space:pre">        </span>Ancestors: VMMaker.oscog-eem.254</div><div dir="auto"><br></div><div dir="auto"><span style="white-space:pre">        </span>[New[Co]]ObjectMemory:</div><div dir="auto"><span style="white-space:pre">        </span>Fix freeing of objects for becomeForward:. &nbsp;Remove freed young</div> <div dir="auto"><span style="white-space:pre">        </span>roots from the rootsTable. &nbsp;Filter freed objects pointet to from the</div><div dir="auto"><span style="white-space:pre">        </span>extraRootsTable (because these locations can change it is wrong</div> <div dir="auto"><span style="white-space:pre">        </span>to remove entries from the extraRootsTable).</div><div><span><br></span></div><div><span>But the bottom line is that, at least on the current Cog VM, that global GC is unnecessary. &nbsp;David, Tim, this still needs to be folded into ObjectMemory in the standard interpreter. But doing so is very worth-while. &nbsp;Monticello loads are noticeably faster.</span></div> <div><span><br></span><blockquote type="cite"><div dir="ltr"><div><div><div>KR</div><div>Phil&nbsp;</div><blockquote style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> <div dir="ltr"><div><span><font color="#888888"></font></span></div><span><font color="#888888"><div><br><br></div><div> -- <br>Best regards,<br>Igor Stasenko. </div></font></span></div> </blockquote></div></div></div></blockquote><br><br><span>Eliot (phone)</span></div></div></div> <br></blockquote><br></div></body></html>