<div dir="ltr"><div>Instead of grouping methods into classes what happens if you</div>
<div>group classes into methods instead.</div>
<div>&nbsp;</div>
<div>In picoLARC all the methods that have the same name are</div>
<div>grouped together into something I call a generic function.</div>
<div>&nbsp;</div>
<div>Message dispatch works like this:</div>
<div>&nbsp;</div>
<div>The generic function is looked up and the classIndex of the receiver</div>
<div>is looked up in the message send.</div>
<div>&nbsp;</div>
<div>The generic function has a dictionary of &lt; classIndex method &gt;</div>
<div>pairs.&nbsp; The classIndex is looked up to return the method which</div>
<div>is then evaluated.</div>
<div>&nbsp;</div>
<div>When you do it this way then methods that are implemented in</div>
<div>just one leaf class have a generic function that has only one</div>
<div>pair in it so no lookup is needed.&nbsp; A leaf class has no subclasses.</div>
<div>&nbsp;</div>
<div>Like you say there is an Array of Classes and when a method is</div>
<div>implemented in the Object Class then the dictionary in the</div>
<div>generic function for that method can be replaced by the Array</div>
<div>of Classes so the dictionary lookup becomes an Array lookup</div>
<div>in that generic function.</div>
<div>&nbsp;</div>
<div>So doing it this way you have a speed up in the message</div>
<div>dispatch when the method is unique in a leaf Class or when</div>
<div>the method&nbsp;has an&nbsp;implemention in the Object Class.<br><br></div>
<div class="gmail_quote">On Mon, Sep 1, 2008 at 1:25 PM, Eliot Miranda <span dir="ltr">&lt;<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div dir="ltr"><br><br>
<div class="gmail_quote">
<div class="Ih2E3d">On Sun, Aug 31, 2008 at 7:37 AM, Igor Stasenko <span dir="ltr">&lt;<a href="mailto:siguctua@gmail.com" target="_blank">siguctua@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hi all,<br><br>I wanted to ask Eliot about some details how he planning to use new<br>object format in Cog.<br>
I think it may be interesting to others, so i posted it here.<br><br>At ESUG, Eliot mentioned that new object format will be 64 bit<br>(regadless of platform), and he will use a class indexes (pointing to<br>entry in a global classes table) in header instead of direct class<br>
oop.<br>Currently, in Squeak VM same principle is used for so-called compact<br>classes, where in oop header is stored an index of compact classes<br>array entry, which allowing to have a smallest possible oop header (32<br>
bits).<br><br>So, in Cog, to determine an oop class, first it reads an index from<br>its header, and then reads a class oop from classes global table.<br>But you need a reverse operation as well - translating class oop into index.<br>
Every time you doing #basicNew , or #primitiveChangeClass , you need<br>to determine a class index by its oop value.<br><br>So, the question is how this will be done?</blockquote>
<div><br></div></div>
<div>In VisualWorks the identity hash of an object is determined lazily when doing one of the following:</div>
<div><br></div>
<div>- sending a message to an object. &nbsp;The object&#39;s class and the message&#39;s selector are quertied for their identity hash. &nbsp;If either object does not have one it is assigned. &nbsp;So the class object is identified from context; it is the class of the receiver.</div>

<div><br></div>
<div>- sending identityHash to a class. &nbsp;In VisualWorks classes have a different version of the identityHash primitive .</div>
<div><br></div>
<div>In either case the class is assigned a hash that is the next unused slot in the class table, and entered into the table at that index.</div>
<div><br></div>
<div>In Squeak we assign hashes when objects are instantiated. &nbsp;So we would need a special version of the new primitive to create instances of classes. &nbsp;So Metaclass would have to do something like implement new and basicNew with a primitive that assigned the identity hash and enter it into the class table, or override new and basicNew with a primitive that assigns the hash and enters it into the table after instantiation.</div>

<div class="Ih2E3d">
<div><br></div>
<div><br></div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Also, some classes may die, and obviously VM needs to do a compaction<br>of global classes table at some point, to prevent maintaining a big<br>
table where only few of entries is used.<br>Suppose i created 1000+1 classes &nbsp;=&gt; each class gets own index in table.<br>Then first 1000 classes is gone (when user uninstalling something).<br>Now you having 1000 free entries in table. But last one is still in<br>
use, and if you want to make table more compact it would require to<br>visit each instance of that class and set a new index value.</blockquote>
<div><br></div>
<div><br></div></div>
<div>With either the VW lazy or Squeak eager approach the class table is weak (a strong Array of WeakArray pages) and so the indexes/hashes of garbage collected classes can be reused. &nbsp;In the VW VM I maintained an index to the first unused slot. &nbsp;Whenever a class is reclaimed its page in the class table is finalized. &nbsp;The VM notices this and sets the index to the unused slot to the minimum of the newly reclaimed slot and its current value. &nbsp;This way the class table stays compact and doesn&#39;t grow unnecessarily large.</div>

<div><br></div>
<div>One nice thing I didn&#39;t mention is that one can use &quot;class index puns&quot;. &nbsp;There is nothing to prevent the VM from entering a class into the class table more than once. &nbsp;So I entered in WeakArray twice into the class table, and used one as a hidden class index for the pages of the class table itself. &nbsp;When one does WeakArray allInstances, therefore, the class table pages are not found. &nbsp;Further, the finalization machinery can easily identify a class table page, because it has a unique class index, and so the maintennance of the first unused class table slot index is very cheap.</div>

<div><br></div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><font color="#888888">-- 
<div class="Ih2E3d"><br>Best regards,<br>Igor Stasenko AKA sig.<span style="COLOR: rgb(0,0,0)"><br></span></div></font></blockquote></div><br>
<div><br></div>
<div>Cheers!</div>
<div><br></div><font color="#888888">
<div>Eliot</div></font></div><br><br><br></blockquote></div><br></div>