Thanks Eliot. So I assume that the correcet way to implement #flushCache in my object as method is this:<br><br>MyObjectAsMethod>>flushCache<br>
<primitive: 116><br><br><br>thanks Eliot<br><br>Mariano<br><br><div class="gmail_quote">On Sun, Mar 20, 2011 at 5:32 PM, Eliot Miranda <span dir="ltr"><<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> <br>Hi Mariano,<div><br></div><div> VMMaker-oscog.52 is uploading:</div><div><br></div><div><div>primitiveFlushCacheByMethod</div>
<div><span style="white-space:pre-wrap">        </span>"The receiver is a compiledMethod. Clear all entries in the method lookup cache that</div>
<div><span style="white-space:pre-wrap">        </span> refer to this method, presumably because it has been redefined, overridden or removed.</div><div><span style="white-space:pre-wrap">        </span> Override to flush appropriate machine code caches also."</div>
<div><span style="white-space:pre-wrap">        </span>| probe oldMethod primIdx |</div><div><span style="white-space:pre-wrap">        </span>oldMethod := self stackTop.</div><div><span style="white-space:pre-wrap">        </span>probe := 0.</div>
<div><span style="white-space:pre-wrap">        </span>1 to: MethodCacheEntries do:</div><div><span style="white-space:pre-wrap">                </span>[:i |</div><div><span style="white-space:pre-wrap">                </span>(methodCache at: probe + MethodCacheMethod) = oldMethod ifTrue:</div>
<div><span style="white-space:pre-wrap">                        </span>[methodCache at: probe + MethodCacheSelector put: 0].</div><div><span style="white-space:pre-wrap">                </span>probe := probe + MethodCacheEntrySize].</div>
<div><span style="white-space:pre-wrap">        </span>(objectMemory isOopCompiledMethod: oldMethod) ifTrue:</div><div><span style="white-space:pre-wrap">                </span>[primIdx := self primitiveIndexOf: oldMethod.</div>
<div><span style="white-space:pre-wrap">                </span> primIdx = PrimitiveExternalCallIndex ifTrue:</div><div><span style="white-space:pre-wrap">                        </span>["It's primitiveExternalCall"</div>
<div><span style="white-space:pre-wrap">                        </span>self flushExternalPrimitiveOf: oldMethod].</div><div><span style="white-space:pre-wrap">                </span> (self methodHasCogMethod: oldMethod) ifTrue:</div>
<div><span style="white-space:pre-wrap">                        </span>[cogit unlinkSendsTo: (self cogMethodOf: oldMethod)]]</div><br><div class="gmail_quote">On Wed, Mar 16, 2011 at 3:20 AM, Mariano Martinez Peck <span dir="ltr"><<a href="mailto:marianopeck@gmail.com" target="_blank">marianopeck@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br>Hi Eliot. I am implementing some kind of MethodWrappes/ObjectsAsMethod, whihc basically use the #run:with:in trick.<br>
My question is that I am not sure how to implement #flushCache in my wrappers. This method is called by MethodDictionary>>#at:put: when I want to put back the original CompiledMethod.<br>
<br>MyClass methodDict at: #foo put: MyWrapper withMethod: (MyClass>>#foo). <br>...<br>MyClass methodDict at: #foo put: wrapper wrappedMethod <br>-> here it sends #flushCache to my wrapper instance. <br><br>In the StandardVM, I realised that at that moment, there is an entry in the cache that has selector: #foo, method: my wrapped instance, class: MyClass, etc...<br>
<br>So, to flush this, I have to options:<br><br>MyWrappers>>flushCache<br>self wrappedMethod selector flushCache<br><br>or....<br><br>MyWrappers>>flushCache<br>
<primitive: 116><br><br>this is because "self" will be found in the entry as "method" in the cache table...<br><br>So, first, are my assumptions correct? <br><br>Now, in cog I am not sure if both solutions are still valid. If I see CoInterpreterPrimitives>> primitiveFlushCacheByMethod<br>
<br>you do at the end:<br><br>(self methodHasCogMethod: oldMethod) ifTrue:<br> [cogit unlinkSendsTo: (self cogMethodOf: oldMethod)]<br><br>and <br><br>methodHasCogMethod: aMethodOop<br> <api><br> self assert: (objectMemory isNonIntegerObject: aMethodOop).<br>
^self isCogMethodReference: (self rawHeaderOf: aMethodOop)<br><br><br>So, it is not safe if the method is something different than a compiled method. <br><br>Is that correct? should I flush the cache entering by selector instead? which is the safe way to clean the cache in this case?<br>
<br>thanks<br><br>Mariano<br>
<br></blockquote></div><br></div>
<br></blockquote></div><br>