<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> </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>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><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
<br>
On 2013-03-25, at 19:52, Eliot Miranda &lt;<a href="mailto:eliot.miranda@gmail.com">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">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><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div>