<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 24, 2020 at 5:14 AM Thiede, Christoph <<a href="mailto:Christoph.Thiede@student.hpi.uni-potsdam.de">Christoph.Thiede@student.hpi.uni-potsdam.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">




<div dir="ltr">
<div id="gmail-m_6907733815746923416divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif" dir="ltr">
<p>Hi all,</p>
<p><br>
</p>
<p>one curious question:</p>
<p><br>
</p>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<p></p>
<div></div>
<p></p>
<div></div>
<div>c := Object newSubclass.</div>
<div>c compile: 'foo ^#foo'.</div>
<div>c methodDict: (ObjectTracer on: c methodDict).</div>
<div>c flushCache.</div>
<div>o := c new.</div>
<div>o foo.</div>
<div></div>
<p></p>
<div></div>
<p></p>
</blockquote>
<p><br>
</p>
<p>I would have expected to get a notification from the ObjectTracer when executing the last line, because somehow the execution machinery must resolve the method to be executed. But actually, what I get is an MNU (Object1 >> #foo).</p>
<p>For comparison: If I skip the ObjectTracer line, the example works and #foo is returned.</p></div></div></blockquote><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,0)"><span style="font-size:small"></span>The VM assumes the object in the methodDict slot of a class is a MethodDictionary. It will look for a method with the #foo selector, and if it does not find that, it will invoke #doesNotUnderstand instead.</div><br></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">There is only one special value the VM recognizes instead, and that is nil. If a nil methodDict is encountered, the VM will send #cannotInterpret:.</div><br></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">This lets the image intercept the VM's method lookup. The default handler for cannotInterpret: invokes the class's #lookupSelector: method and retries the message send if found.</div></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">This was used for example to swap out classes to disk when memory was still expensive. The class is replaced (via become:) by a stub that has a nil in the slot that normally is the method dict. So when a message is sent to an instance of a swapped-out class, the cannotInterpret: mechanism loads the actual class from disc, replaces the stub, and then continues execution as if nothing ever happened.</div><div><br></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">I find looking at the SqueakJS sources quite instructive, since they are not obscured by all the optimizations in the OpenSmalltalk VM. Here's the relevant part, <span style="background-color:rgb(255,251,221);color:rgb(111,66,193);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre">findSelectorInClass()</span> which is invoked from <span style="color:rgb(111,66,193);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre">send()</span></div></div><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,0)"><br></div><a href="https://github.com/bertfreudenberg/SqueakJS/blob/13581caeb489875c4a39a78aa9d95866cc8892a5/vm.interpreter.js#L619">https://github.com/bertfreudenberg/SqueakJS/blob/13581caeb489875c4a39a78aa9d95866cc8892a5/vm.interpreter.js#L619</a><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr"></div></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">Have fun!</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">- Bert -</div></div></div>