<div dir="auto">Hi Denis,<div dir="auto">Special bytecodes don't have to be changed: just don't use them and replace by regular sends at bytecode generation (with a special compiler, or some IR translater). All can be done at image side then. Or did I miss something?</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le jeu. 28 mars 2019 à 20:05, Denis Kudriashov <<a href="mailto:dionisiydk@gmail.com">dionisiydk@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi.<div><br></div><div>I found interesting case where tempVectors can be used in remote scenarios. The store into remote temp can be really remote (not just about outer context). </div><div>I played with following example:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>| temp | </div><div>temp := 10.</div><div>remote evaluate: [temp := temp + 1].</div><div>temp.</div></blockquote><div><br></div><div>For the moment forget about remote thing and look into it as a normal local case:</div><div>temp var here is managed indirectly through tempVector. You can see it using expression after first assignment:</div><div><br></div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>thisContext at: 1 "=>#(10)"</div></blockquote></div><div><br></div><div>So the value in fact is stored in the array instance and read from it. </div><div>But because of optimization it happens out of the array control. No #at: and #at:put: messages are sent during this code. VM magically changes the state of this array (there are special bytecodes for this).</div><div><br></div><div>Now my remote use case. Imagine that vm actually sends #at: and #at:put: messages to tempVector. Then remoting engine can transfer temp vector (as part of context) as a proxy. So on remote side the block [temp := temp + 1] will actually ask the sender (client) for the value and for the storage. So all block semantics will be supported. Temp in remote outer context will be modified. I think it would be super cool if such transparency would be possible.</div><div><br></div><div>I played with this example using Seamless in Pharo. It already works in the way I described but due to VM optimization it does not provide expected behavior. And worse than that it actually corrupts transferred proxy because in place of array the proxy instance is materialized. </div><div><br></div><div>This leads us to the issue with safety of tempVector operations. Following example shows how we can affect the state of tempVector using reflection:<br></div><div><br></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div>| temp | </div></div></div><div><div><div>temp := 10.</div></div></div><div><div><div>(thisContext at: 1) at: 1 put: 50.</div></div></div><div><div><div>[temp := temp + 1] value.</div></div></div><div><div><div>temp. "==>51"</div></div></div><div><br></div></blockquote><div>It is cool that we can do it. But there is no any safety check in the VM level over tempVector object: </div><div><br></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div>| temp | </div></div></div><div><div>temp := 10.</div></div><div><div>thisContext at: 1 put: Object new.</div></div><div><div>[temp := temp + 1] value.</div></div><div><div>temp.</div></div></blockquote><div dir="ltr"><div><br></div><div>It breaks with DNU: #+ is sent to nil. Temp became nil.</div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><br class="m_6661563869218237041gmail-Apple-interchange-newline">| temp | </div></div></div><div><div>temp := 10.</div></div><div><div>thisContext at: 1 put: #() copy.</div></div><div><div>[temp := temp + 1] value.</div></div><div><div>temp.</div></div></blockquote><div dir="ltr"><div><br></div><div>Sometimes it breaks with same error. Sometimes it returns random number. </div><div>I guess in these cases VM breaks memory boundary of tempVector.</div><div><br></div><div>And two exotic cases: </div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><br class="m_6661563869218237041gmail-Apple-interchange-newline">| temp | </div></div></div><div><div>temp := 10.</div></div><div><div>(thisContext at: 1) beReadOnlyObject.</div></div><div><div>[temp := temp + 1] value.</div></div><div><div>temp.</div></div></blockquote><div dir="ltr"><div><br></div><div>It silently return 11. It does not break read only protection. But no error is signalled.</div><br class="m_6661563869218237041gmail-Apple-interchange-newline"></div></div></div></div></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div><div><div><div>| temp | </div></div></div></div></div><div><div><div><div><div>temp := 10.</div></div></div></div></div><div><div><div><div><div>(thisContext at: 1) become: #() copy.</div></div></div></div></div><div><div><div><div><div>[temp := temp + 1] value.</div></div></div></div></div><div><div><div><div><div>temp.</div></div></div></div></div></blockquote><div dir="ltr"><div dir="ltr"><div><br></div><div>It returns #().  (In Pharo  #() + 1 = #()  ).</div><div>I use become to check how forwarding is working in that case. (it works fine when array has correct size)</div><div><br></div><div dir="ltr"><div>How we can improve this behavior? How it would effect performance?</div><div>My proposal is to send real messages to tempVector when it is not an array instance. Then image will decide what to do.</div><div><br></div><div>Best regards,</div><div>Denis</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div></div></div></div>
</blockquote></div>