<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p>Hi Bert,</p>
<p><br>
</p>
<p>thanks for the helpful answer. So there is no chance to use a first-class object for the method dictionary - unless I set the instance variable methodDictionary to nil and force the VM to send #cannotInterpret: for every message? :-)</p>
<div id="Signature">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;">
<div name="divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:; margin:0">
<div>
<div class="_rp_T4" id="Item.MessagePartBody">
<div class="_rp_U4 ms-font-weight-regular ms-font-color-neutralDark rpHighlightAllClass rpHighlightBodyClass" id="Item.MessageUniqueBody" style="font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont">
<div dir="ltr">
<div id="divtagdefaultwrapper"><font face="Calibri,Helvetica,sans-serif,EmojiFont,Apple Color Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI Symbol,Android Emoji,EmojiSymbols">
<div id="Signature">
<div style="margin:0px"><font style="font-family:Calibri,Arial,Helvetica,sans-serif,serif,EmojiFont">
<div><font size="3" color="black"><span style="font-size:12pt"><a href="http://www.hpi.de/" target="_blank" rel="noopener noreferrer" id="LPNoLP"><font size="2"><span id="LPlnk909538"><font color="#757B80"></font></span></font></a></span></font></div>
</font></div>
</div>
</font></div>
</div>
</div>
</div>
<div class="_rp_T4" id="Item.MessagePartBody"><br>
</div>
<div class="_rp_T4" id="Item.MessagePartBody">Your SqueakJS sources are indeed very helpful for studying a VM implementation. Great work!</div>
<div class="_rp_T4" id="Item.MessagePartBody"><br>
</div>
<div class="_rp_T4" id="Item.MessagePartBody">Best,</div>
<div class="_rp_T4" id="Item.MessagePartBody">Christoph</div>
</div>
<div><font size="2" color="#808080"></font></div>
</div>
</div>
</div>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>Von:</b> Squeak-dev <squeak-dev-bounces@lists.squeakfoundation.org> im Auftrag von Bert Freudenberg <bert@freudenbergs.de><br>
<b>Gesendet:</b> Montag, 24. Februar 2020 23:21:44<br>
<b>An:</b> The general-purpose Squeak developers list<br>
<b>Betreff:</b> Re: [squeak-dev] How does the VM deal with method dictionaries?</font>
<div> </div>
</div>
<div>
<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>
</div>
</body>
</html>