Ok, as a summary. I&#39;ve tried<div><br></div><div>1) not recreating the compact classes array without voiding vm caches: works ok.</div><div><br></div><div>2) making another compact classes array, voiding the vm caches (primitive 214): random crashes :/. Sometimes it works, some times it does not...</div>
<div>I&#39;ve tried, just for the record, to void the cache before, after and (before and after) the become forward of the special objects array:</div><div><br></div><div>a)</div><div>| newSpecialObjectsArray |</div><div>
self vm voidCogVMState.</div><div>newSpecialObjectsArray := self newSpecialObjectsArray.</div><div>self specialObjectsArray becomeForward: newSpecialObjectsArray.<br><div><br></div><div><div>b)</div><div>| newSpecialObjectsArray |</div>
<div>newSpecialObjectsArray := self newSpecialObjectsArray.</div><div>self specialObjectsArray becomeForward: newSpecialObjectsArray.</div></div><div>self vm voidCogVMState.</div><div><br></div><div><div>c)</div><div>| newSpecialObjectsArray |</div>
<div>self vm voidCogVMState.</div><div>newSpecialObjectsArray := self newSpecialObjectsArray.</div><div>self specialObjectsArray becomeForward: newSpecialObjectsArray.</div></div><div>self vm voidCogVMState.</div><div><br>
</div><div>All with different results when executing several times... :/</div><div><br></div><div>voidCogVMState is the following in Pharo:</div><div><br></div><div>VirtualMachine class&gt;&gt;voidCogVMState</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&quot;Void any internal caches the VM maintains other than the method lookup caches.</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> These comprise</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>- the stack zone, where method activations are stored, and</div><div>
<span class="Apple-tab-span" style="white-space:pre">                </span>- the machine code zone, where the machine code form of CompiledMethods is held.&quot;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&lt;primitive: 214&gt;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>^self primitiveFailed</div><div><br></div><div>The comment says it does not clean method lookup caches...</div><div><br></div><div>any ideas?</div><div>Guille</div>
<div><br></div><div><div class="gmail_quote">On Tue, Mar 26, 2013 at 11:48 AM, Guillermo Polito <span dir="ltr">&lt;<a href="mailto:guillermopolito@gmail.com" target="_blank">guillermopolito@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Ok, first I&#39;m sorry for the evil upload. That was the first at hand :$. I&#39;ll get a more trustful way to do it the next one...<div>
Second, thanks for taking the time to look at it :).</div><div><br></div><div>Now, I&#39;ve some questions:</div>
<div><br></div><div>- this &quot;bug&quot; is particular to Cog, isn&#39;t it? I mean, only related to inlining with JIT, so a Stack vm does not play with these rules, right?</div><div>- Why is voiding the cache hackish? I mean, replacing the special objects array is a very low level operation, and a very special one which is not commonly performed. Voiding the cache looks like normal to me in such a case...</div>

<div><br></div><div>Tx!</div><div>Guille</div><div><br><div class="gmail_quote">On Mon, Mar 25, 2013 at 11:56 PM, Eliot Miranda <span dir="ltr">&lt;<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br><br><br><div class="gmail_quote">On Mon, Mar 25, 2013 at 3:22 PM, Camillo Bruni <span dir="ltr">&lt;<a href="mailto:camillobruni@gmail.com" target="_blank">camillobruni@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Thanks for the findings!<br></blockquote><div><br></div><div>you&#39;re welcome :)</div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I opened an issue <a href="http://bugs.pharo.org/issues/id/10134" target="_blank">http://bugs.pharo.org/issues/id/10134</a> with the contents<br>
of your solution.<br>
<br>
I think for completeness we should implement both solution, and of course<br>
use the one that does not #becomeForward: in the standard case.<br></blockquote><div><br></div></div><div>To be clear, becomeForward: is the correct way to install the specialObjectsArray.  The issue is what entries in the specialObjectsArray need to remain constant.  The Character table, the compactClassesArray, all the classes and a few other entries (semaphores, etc) must remain the same.  This could do with better documenting of the method :-/</div>
<div><div class="h5">

<div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div><br>
<br>
On 2013-03-25, at 19:52, Eliot Miranda &lt;<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>&gt; wrote:<br>
&gt; Hi Guille,<br>
&gt;<br>
&gt;    thanks for this.  The problem is that Pharo&#39;s<br>
&gt; recreateSpecialObjectsArray uses newCompactClassesArray to recreate the<br>
&gt; compact classes array and on Cog that is not supported.  Cog caches the<br>
&gt; compactClassesArray (specialObjectsArray at: 29) in every jitted method<br>
&gt; prolog to reduce the time taken to derive the receiver&#39;s class in message<br>
&gt; lookup.  The Pharo 2.0 code for recreating the specialObjectsArray can<br>
&gt; therefore create a dangling pointer where the only reference to the old<br>
&gt; compactClassesArray is in machine code, and the machine code GC doesn&#39;t<br>
&gt; cope with there being roots in machine code.  Note that Cog also caches the<br>
&gt; characterTable and class SmallInteger in machine code.<br>
&gt;<br>
&gt; There are two solutions to this.<br>
&gt; One would be to reuse the compactClassesArray (my recommendation).  So that<br>
&gt; recreateSpecialObjectsArray looks like<br>
&gt;<br>
&gt; ...<br>
&gt; &quot;An array of the 255 Characters in ascii order.<br>
&gt; Cog inlines table into machine code at: prim so do not regenerate it.&quot;<br>
&gt; newArray at: 25 put: Character characterTable.<br>
&gt; ...<br>
&gt; &quot;A 32-element array with up to 32 classes that have compact instances.<br>
&gt; Cog inlines table into machine code class lookup so do not regenerate it.&quot;<br>
&gt; newArray at: 29 put: self compactClassesArray.<br>
&gt; ...<br>
&gt;<br>
&gt; where compactClassesArray, like Character characterTable, answers the<br>
&gt; existing object.<br>
&gt;<br>
&gt; The second solution (rather hackish) is to void all machine code on<br>
&gt; installing the new specialObjectsArray.  e.g.<br>
&gt; recreateSpecialObjectsArray<br>
&gt; &quot;Smalltalk recreateSpecialObjectsArray&quot;<br>
&gt; &quot;To external package developers:<br>
&gt; **** DO NOT OVERRIDE THIS METHOD.  *****<br>
&gt; If you are writing a plugin and need additional special object(s) for your<br>
&gt; own use,<br>
&gt; use addGCRoot() function and use own, separate special objects registry &quot;<br>
&gt; &quot;The Special Objects Array is an array of objects used by the Squeak<br>
&gt; virtual machine.<br>
&gt; Its contents are critical and accesses to it by the VM are unchecked, so<br>
&gt; don&#39;t even<br>
&gt; think of playing here unless you know what you are doing.&quot;<br>
&gt; &quot;Replace the interpreter&#39;s reference in one atomic operation.<br>
&gt; Void machine code to avoid crashing Cog.&quot;<br>
&gt; | newSpecialObjectsArray |<br>
&gt; newSpecialObjectsArray := self newSpecialObjectsArray.<br>
&gt; self specialObjectsArray becomeForward: newSpecialObjectsArray.<br>
&gt; Smalltalk vm voidCogVMState<br>
&gt;<br>
&gt;<br>
&gt; this is my fault for not ensuring recreateSpecialObjectsArray was properly<br>
&gt; commented.  I had commented the inlining of Character table, but not the<br>
&gt; inlining of the CompactClasses array. Apologies.<br>
&gt;<br>
&gt; HTH,<br>
&gt; Eliot<br>
&gt;<br>
&gt; On Sat, Mar 23, 2013 at 10:19 AM, Guillermo Polito &lt;<br>
&gt; <a href="mailto:guillermopolito@gmail.com" target="_blank">guillermopolito@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; Hi!<br>
&gt;&gt;<br>
&gt;&gt; In my quest to crash the vm, i&#39;ve found an ugly common case :(.<br>
&gt;&gt; I am trying to port the opendbx driver to 2.0, but I&#39;m getting vm crashes<br>
&gt;&gt; when my configuration loads FFI :(. I updated my configuration to load<br>
&gt;&gt; version 1.7 of FFI (which I assume is the latest).<br>
&gt;&gt;<br>
&gt;&gt; I tried to do it in Pharo 2.0 with latest pharovm, and with eliot&#39;s Cog<br>
&gt;&gt; 2701 from his website, failing in both cases.<br>
&gt;&gt; The snippet of code that gets a sistematic crash is:<br>
&gt;&gt;<br>
&gt;&gt; Gofer it<br>
&gt;&gt; smalltalkhubUser: &#39;DBXTalk&#39; project: &#39;DBXTalkDriver&#39;;<br>
&gt;&gt; package: &#39;ConfigurationOfOpenDBXDriver&#39;;<br>
&gt;&gt; load.<br>
&gt;&gt; ((Smalltalk at: #ConfigurationOfOpenDBXDriver) project version:#stable)<br>
&gt;&gt; load<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; This snippet crashes always with a segmentation fault (at least the<br>
&gt;&gt; fifteen times i tried :), with several different output in the console...<br>
&gt;&gt;<br>
&gt;&gt; Surprisingly, if I load FFI alone and not from the OpenDBXDriver<br>
&gt;&gt; configuration, it loads well... :/<br>
&gt;&gt;<br>
&gt;&gt; So I&#39;m deferring the OpenDBX port a bit longer :(<br>
&gt;&gt;<br>
&gt;&gt; Thanks!<br>
&gt;&gt; Guille<br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; best,<br>
&gt; Eliot<br>
<br>
</div></div></blockquote></div></div></div><br><br clear="all"><span class="HOEnZb"><font color="#888888"><div><br></div>-- <br>best,<div>Eliot</div>
<br></font></span></blockquote></div><br></div>
</blockquote></div><br></div></div>