<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2014-09-16 1:46 GMT+02:00 Eliot Miranda <span dir="ltr">&lt;<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> <br><div dir="ltr">Hi Ronie,<br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 15, 2014 at 2:37 PM, Ronie Salgado <span dir="ltr">&lt;<a href="mailto:roniesalg@gmail.com" target="_blank">roniesalg@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> <br><div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div>Hello,<br><br></div><div>I am segmenting this mail in several sections.<br><br>---------------------------------------------------------------<br></div><div>- On Lowcode and Cog<br><br></div>I have been working in the last week with the Cog VM, implementing the Lowcode instructions in Cog.<br></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></blockquote><div><br></div><div>remember to send me code for integration.  I&#39;m eagerly waiting to use your code!</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div>Lowcode is currently a spec of new bytecode instructions. These instructions can be used for:<br></div>- Implementing a C like language compiler.<br></div>- Making FFI calls<br><br></div>I am implementing these instructions using a feature of the new bytecode set for SistaV1, which is called &quot;inline primitives&quot;. Because of this, these new instructions can be mixed freely with the standard VM bytecode set. This also allows the Sista adaptive optimizer to inline FFI calls.<br><br></div>These instructions provides features for:<br></div>- Int32 and Int64 integer arithmetic without type checking.<br></div>- Pointers, with arithmetics.<br></div>- Memory access and memory manipulation.<br></div>- Single and double precision floating point arithmetics.<br></div>- Conversion between primitive types.<br></div><div>- Boxing and unboxing of primitive types.<br></div>- Unchecked comparisons.<br></div>- Native function call. Direct and indirect calls.<br></div><div>- The atomic operation compare and swap.<br></div><div>- Object pin/unpin (requires Spur).<br></div><div>- VM releasing and grabbing for threaded ffi.<br><br></div><div>Current I have implemented the following backends:<br></div><div>- A C interpreter plugin.<br></div><div>- A LLVM based backend.<br><br></div><div>Currently I am working in getting this working using the Cog code generator. So far I am already generating code for int32/pointer/float32/float64. I am starting to generate C functions calls and object boxing/unboxing.<br><br></div><div>During this work I learned a lot about Cog. Specially that Cog is missing a better Slang generator, that allows to force better inlining and more code reviews. There is a lot of code duplication in Cog, that can be attributed to limitations of Slang. In my opinion, if we could use Slang not only for building the VM we should end with a better code generator. In addition we, need more people working in Cog. We need people that performs code reviews and documentation of Cog.<br><br></div><div>After these weeks, I learned that working in Cogit it is not that hard. Our biggest problem is lack of documentation. Our second problem could be the lack of documentation about Slang.<br></div></div></div></div></div></blockquote></div></div></div></blockquote><div><br></div><div>Lack of documentation ?</div><div><br></div><div>About Cog  there are these documentation:</div><div><a href="http://ftp.squeak.org/docs/OOPSLA.Squeak.html">Back to the future</a> </div><div><a href="http://wiki.squeak.org/squeak/2105">About VMMaker</a> </div><div><a href="http://www.rowledge.org/resources/tim%27s-Home-page/Squeak/OE-Tour.pdf">Object engine</a> </div><div><a href="http://squeakvm.org/index.html">General information</a> </div><div><a href="http://stephane.ducasse.free.fr/FreeBooks/BlueBook/Bluebook.pdf">Blue book part 4</a> </div><div><a href="http://www.deepintopharo.com/">Deep into Pharo part 4 about blocks and exceptions</a> </div><div><a href="http://design.cs.iastate.edu/vmil/2011/papers/p03-miranda.pdf">VMIL paper about Cogit</a> </div><div><a href="http://www.mirandabanda.org/cogblog/">The Cog blog</a> </div><div>About Spur: <a href="http://clementbera.wordpress.com/2014/02/06/7-points-summary-of-the-spur-memory-manager/">summary</a> and <a href="http://clementbera.wordpress.com/2014/01/16/spurs-new-object-format/">object format</a> </div><div><a href="http://clementbera.wordpress.com/2013/08/09/the-cog-vm-lookup/">This post</a> </div><div>And many useful class and method comments that taught me a lot.</div><div><br></div><div>When I try to work with Pharo frameworks, even recent ones, it is very rare that I see as much documentation than it exists for Cog. Some frameworks are documented in the Pharo books and a few other as Zinc have good documentation, but in general, there are few documentation and <i>even fewer people writing documentation</i>. The website about Cog has existed for over 6 years now. I think Cog is far from the worst documented part of Pharo.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div><div><div></div></div></div></div></div></blockquote><div><br></div><div>Yes, and that&#39;s difficult because it&#39;s a moving target and I have been lazy, not writing tests, instead using the Cog VM as &quot;the test&quot;. </div><div><br></div></div></div></div></blockquote><div>It&#39;s also difficult because the first tests to write are the hardest to write.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div>I am so happy to have your involvement.  You and Clément bring such strength and competence.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>---------------------------------------------------------------<br>- Smalltalk -&gt; LLVM ?<br><br></div><div>As for having a Smalltalk -&gt; LLVM code generator. The truth is that we will not gain anything. LLVM is a C compiler, which is designed to optimize things such as loops with lot of arithmetics. It is designed to optimize large sections of code. In Smalltalk, most of our code is composed mostly of message sends. LLVM cannot optimize a message send.<br><br></div><div>To optimize a message send, you have to determine which is the method that is going to respond to the message. Then you have to inline the method. And then you can start performing the actual optimizations, such as constant folding, common subexpressions, dead branch elimination, loop unrolling, and a long etc.<br><br></div>Because we don&#39;t have information in the actual language (e.g. static types a la C/C++/Java/C#) that tells us what is going to be the actual method invoked by a message send, we have the following alternatives to determine it:<br>- Don&#39;t optimize anything.<br></div>- Perform a costly static global analysis of the whole program.<br></div>- Measure in runtime and hope for the best.<br></div>- Extend the language.<br><div><div><div><div><div><div><div><br></div><div>In other words, our best bet is in the work of Clément in Sista. The only problem with this bet are real time applications.<br></div></div></div></div></div></div></div></div></blockquote><div><br></div><div>Ah!  But!  Sista has an advantage that other adaptive optimizers don&#39;t.  Because it optimizes from bytecode to bytecode it can be used during a training phase and then switched off.</div></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div>Real time applications requires an upper bound guarantee in their response time. In some cases, the lack of this guarantee can be just an annoyance, as happens in video games. In some mission critical applications the results can not be good, if this time constraint is not met. An example of a mission critical system could the flight controls of an airplane, or the cooling system of a nuclear reactor.<br></div><div><br></div><div>For these application, it is not possible to rely in an adaptive optimizer that can be triggered sometimes. In these application you have to either:<br></div><div>- Extend the language to hand optimize some performance critical sections of code.<br></div><div>- Use another language to optimize these critical section.<br></div><div>- Use another language for the whole project.<br></div></div></div></div></div></div></div></div></blockquote><div><br></div><div>The additional option is to &quot;train&quot; the optimizer by running the application before deploying and capturing the optimised methods.  Discuss this with Clément and he&#39;ll explain how straight-forward it should be.  This still leaves the latency in the Cogit when it compiles from bytecode to machine code.  But</div><div><br></div><div>a) I&#39;ve yet to see anybody raise JIT latency as an issue in Cog</div><div>b) it would be easy to extend the VM to cause the Cogit to precompile specified methods.  We could easily provide a &quot;lock-down&quot; facility that would prevent Cog from discarding specific machine code methods.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div>And of course, you have to perform lot of profiling.<br></div></div></div></div></div></div></div></div></blockquote><div><br></div><div>Early and often :-).</div><div><br></div><div>Because we can have complete control over the optimizer, and because Sista is byetcode-to-bytecode and can hence store its results in the image in the form of optimized methods, I believe that Sista is well-positioned for real-time since it can be used before deployment.  In fact we should emphasise this in the papers we write on Sista.<br></div></div></div></div></blockquote><div><br></div><div>The solution of Eliot makes sense.</div><div>To write a paper about that I need benchs showing result on real time applications.</div><div>So there&#39;s quite some work to do before.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div>Greetings,<br></div><div>Ronie<br></div></div></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2014-09-15 16:38 GMT-03:00 Craig Latta <span dir="ltr">&lt;<a href="mailto:craig@netjam.org" target="_blank">craig@netjam.org</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
<br>
     Hear hear!<br>
<br>
<br>
-C<br>
<br>
[1] <a href="http://tinyurl.com/m66fx8y" target="_blank">http://tinyurl.com/m66fx8y</a> (original message)<br>
<br>
--<br>
Craig Latta<br>
<a href="http://netjam.org" target="_blank">netjam.org</a><br>
<a href="tel:%2B31%20%20%206%202757%207177" value="+31627577177" target="_blank">+31   6 2757 7177</a> (SMS ok)<br>
<a href="tel:%2B%201%20415%20%20287%203547" value="+14152873547" target="_blank">+ 1 415  287 3547</a> (no SMS)<br>
<br>
</blockquote></div><br></div>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div>
</div></div>
<br></blockquote></div><br></div></div>