So given that the Interpreter VM now supports the mirror primitives, does anyone object if I add the debugger changes to trunk that use the mirror primitives and hence make accurate debugging of proxies possible?  The downside of doing this is that the debugger will be broken on older VMs.<div>
<br></div><div>As an example of the changes here are the old and new methods form pushing an inst var in the debugger/execution simulator.  The first one sends a message to the receiver, and hence if it is a proxy will invoke the proxy&#39;s doesNotUnderstand: handling rather than answering the relevant inst var.  The second one directly accesses the relevant inst var, accurately simulating what the VM does for the bytecode.  The changes replace direct sends with use of mirror primitives throughout execution simulation in all the places where the VM would do a direct access rather than send a message.<br>
<br></div><div>ContextPart methods for instruction decoding</div><div><div>pushReceiverVariable: offset </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&quot;Simulate the action of bytecode that pushes the contents of the receiver&#39;s </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>instance variable whose index is the argument, index, on the top of the stack.&quot;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>self push: (self receiver instVarAt: offset + 1)</div>
<div><br></div><div>ContextPart methods for instruction decoding</div><div><div>pushReceiverVariable: offset </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&quot;Simulate the action of bytecode that pushes the contents of the receiver&#39;s </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>instance variable whose index is the argument, index, on the top of the stack.&quot;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>self push: (self object: self receiver instVarAt: offset + 1)</div>
</div><div><br></div><div>and here&#39;s the mirror method.  c.f. Object&gt;instVarAt:.  They share the same primitive number because internally the VM implements varargs primitives.</div><div>ContextPart methods for mirror primitives</div>
<div><div>object: anObject instVarAt: anIndex</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&quot;Primitive. Answer a fixed variable in an object. The numbering of the </div><div><span class="Apple-tab-span" style="white-space:pre">        </span> variables corresponds to the named instance variables. Fail if the index </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> is not an Integer or is not the index of a fixed variable. Essential for the</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> debugger. See  Object documentation whatIsAPrimitive.&quot;</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&lt;primitive: 73&gt;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&quot;Access beyond fixed variables.&quot;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>^self object: anObject basicAt: anIndex - (self objectClass: anObject) instSize</div></div><div><br></div><div class="gmail_quote">On Tue, May 22, 2012 at 8:17 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">On Tue, May 22, 2012 at 03:24:34PM -0700, Eliot Miranda wrote:<br>
&gt; On Tue, May 22, 2012 at 12:07 AM, Colin Putney &lt;<a href="mailto:colin@wiresong.com">colin@wiresong.com</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt; Hi all,<br>
&gt; &gt;<br>
&gt; &gt; I&#39;ve just uploaded a package to the Inbox for review by the community:<br>
&gt; &gt;<br>
&gt; &gt; <a href="http://source.squeak.org/inbox/Mirrors-cwp.2.mcz" target="_blank">http://source.squeak.org/inbox/Mirrors-cwp.2.mcz</a><br>
&gt; &gt;<br>
&gt; &gt; It&#39;s a simple first step at creating a mirror API for Squeak. I&#39;ve only<br>
&gt; &gt; implemented ObjectMirror and ObjectVmMirror, which provide high- and<br>
&gt; &gt; low-level reflection on an object. This implementation has a twist,<br>
&gt; &gt; however: it sends no messages to the object it&#39;s reflecting. That allows us<br>
&gt; &gt; to reflect on network proxies, ORM stubs, mock objects and the like without<br>
&gt; &gt; triggering any state changes.<br>
&gt; &gt;<br>
&gt; &gt; As a proof of the concept, I&#39;ve implemented a rudimentary non-invasive<br>
&gt; &gt; MirrorInspector. The main thing that&#39;s missing is non-invasive printing,<br>
&gt; &gt; which would take a bit of work to implement, but isn&#39;t necessary for a<br>
&gt; &gt; demo. To see it in action do try the following in a workspace.<br>
&gt; &gt;<br>
&gt; &gt; WARNING: Read the comments carefully, and don&#39;t do this in an image you<br>
&gt; &gt; care about!<br>
&gt; &gt;<br>
&gt; &gt; &quot;This creates a very dangerous object&quot;<br>
&gt; &gt; Object subclass: #Nuke<br>
&gt; &gt; instanceVariableNames: &#39;one two three&#39;<br>
&gt; &gt; classVariableNames: &#39;&#39;<br>
&gt; &gt; poolDictionaries: &#39;&#39;<br>
&gt; &gt; category: &#39;Test&#39;.<br>
&gt; &gt; class := Smalltalk at: #Nuke.<br>
&gt; &gt; class superclass: nil.<br>
&gt; &gt; inst := class basicNew.<br>
&gt; &gt;<br>
&gt; &gt; &quot;This is harmless&quot;<br>
&gt; &gt; MirrorInspector inspect: inst.<br>
&gt; &gt;<br>
&gt; &gt; &quot;This will crash your image&quot;<br>
&gt; &gt; inst yourself.<br>
&gt; &gt;<br>
&gt; &gt; The implementation uses primitive 188 to directly execute CompiledMethods<br>
&gt; &gt; with the reflected object as the receiver, thus giving us access to the<br>
&gt; &gt; object&#39;s state without sending it a message.<br>
&gt; &gt;<br>
&gt;<br>
&gt; In part you can use the light-weigth mirror methods in ContextPart, these<br>
&gt; take the object operated on as an argument.  Non-invasive printing could be<br>
&gt; done via execution simulation.  I&#39;ve already modified the Squeak debugger<br>
&gt; in Qwaq/Teleplace images to use these light-weight mirror primitives so<br>
&gt; that messages are not sent to receivers when simulating execution in the<br>
&gt; debugger (i.e. when doing send instead of step).  If the mirror primitives<br>
&gt; now work on the interpreter I can fold this into trunk.  David, do the<br>
&gt; mirror primitive tests pass on the interpreter?<br>
<br>
</div></div>All mirror primitive tests pass on the interpreter VM if built with the<br>
latest VMMaker and SVN sources. However, the mirror primitive support is<br>
not yet present in any officially released standard VM.<br>
<br>
The updates for mirror primitive support were added in VMMaker-dtl.262 and<br>
VMMaker-dtl.261. Note the update comment in VMMaker-dtl.262, as the<br>
implementation differs from Cog and a code review would be welcome:<br>
<br>
    Name: VMMaker-dtl.262<br>
    Author: dtl<br>
    Time: 5 January 2012, 12:41:29.745 am<br>
<br>
    VMMaker 4.7.19<br>
<br>
    Reference Mantis 7429: Add Mirror Primitives to the VM<br>
<br>
    Update primitivePerformInSuperclass to support ContextPart&gt;&gt;object:perform:withArguments:inClass:<br>
<br>
    Implementation differs from that of oscog in that the original primitivePerformAt:<br>
    is retained unmodified, and the necessary stack adjustments are done in<br>
    primitivePerformInSuperclass for the special case of argumentCount 4<br>
    (mirror primitive call) rather than 3. The oscog approach may be prefered<br>
    (not least for its clearer method naming), but making the change in<br>
    primitivePerformInSuperclass is low risk and more easily implemented by<br>
    a Sunday Squeaker.<br>
<br>
    All MirrorPrimitiveTests pass.<br>
<br>
Dave<br>
<br>
<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div><br>
</div>