<div dir="ltr"><br><br><div class="gmail_quote">On Wed, Sep 3, 2008 at 8:05 AM, David Griswold <span dir="ltr">&lt;<a href="mailto:david.griswold.256@gmail.com">david.griswold.256@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;">
<div dir="ltr">After sleeping on it, I woke up and realized that V8 is almost certainly not multi-threaded at the client code level (within a single VM instance), since they have that indirection... the indirection sounds more like a traditional object table, like VisualWorks, and I don&#39;t see how they could possibly have made something like that multi-threaded since performance would critically depend on caching the body pointer within a method activation.&nbsp; But they can&#39;t do that because another method might be adding or removing properties while the method is running, and that is way too fine-grained to be doing any kind of check.</div>
</blockquote><div><br></div><div>Look at include/v8.h which explains the concurrency model which sounds very similar to Strongtalk:</div><div><br></div><div><div>&nbsp;* Multiple threads in V8 are allowed, but only one thread at a time</div>
<div>&nbsp;* is allowed to use V8. &nbsp;The definition of &#39;using V8&#39; includes</div><div>&nbsp;* accessing handles or holding onto object pointers obtained from V8</div><div>&nbsp;* handles. &nbsp;It is up to the user of V8 to ensure (perhaps with</div>
<div>&nbsp;* locking) that this constraint is not violated.</div><div>&nbsp;*</div><div>&nbsp;* If you wish to start using V8 in a thread you can do this by constructing</div><div>&nbsp;* a v8::Locker object. &nbsp;After the code using V8 has completed for the</div>
<div>&nbsp;* current thread you can call the destructor. &nbsp;This can be combined</div><div>&nbsp;* with C++ scope-based construction as follows:</div><div>&nbsp;*</div><div>&nbsp;* \code</div><div>&nbsp;* ...</div><div>&nbsp;* {</div><div>&nbsp;* &nbsp; v8::Locker locker;</div>
<div>&nbsp;* &nbsp; ...</div><div>&nbsp;* &nbsp; // Code using V8 goes here.</div><div>&nbsp;* &nbsp; ...</div><div>&nbsp;* } // Destructor called here</div><div>&nbsp;* \endcode</div><div>&nbsp;*</div><div>&nbsp;* If you wish to stop using V8 in a thread A you can do this by either</div>
<div>&nbsp;* by destroying the v8::Locker object as above or by constructing a</div><div>&nbsp;* v8::Unlocker object:</div><div>&nbsp;*</div><div>&nbsp;* \code</div><div>&nbsp;* {</div><div>&nbsp;* &nbsp; v8::Unlocker unlocker;</div><div>&nbsp;* &nbsp; ...</div><div>
&nbsp;* &nbsp; // Code not using V8 goes here while V8 can run in another thread.</div><div>&nbsp;* &nbsp; ...</div><div>&nbsp;* } // Destructor called here.</div><div>&nbsp;* \endcode</div><div>&nbsp;*</div><div>&nbsp;* The Unlocker object is intended for use in a long-running callback</div>
<div>&nbsp;* from V8, where you want to release the V8 lock for other threads to</div><div>&nbsp;* use.</div><div>&nbsp;*</div><div>&nbsp;* The v8::Locker is a recursive lock. &nbsp;That is, you can lock more than</div><div>&nbsp;* once in a given thread. &nbsp;This can be useful if you have code that can</div>
<div>&nbsp;* be called either from code that holds the lock or from code that does</div><div>&nbsp;* not. &nbsp;The Unlocker is not recursive so you can not have several</div><div>&nbsp;* Unlockers on the stack at once, and you can not use an Unlocker in a</div>
<div>&nbsp;* thread that is not inside a Locker&#39;s scope.</div><div>&nbsp;*</div><div>&nbsp;* An unlocker will unlock several lockers if it has to and reinstate</div><div>&nbsp;* the correct depth of locking on its destruction. eg.:</div>
<div>&nbsp;*</div><div>&nbsp;* \code</div><div>&nbsp;* // V8 not locked.</div><div>&nbsp;* {</div><div>&nbsp;* &nbsp; v8::Locker locker;</div><div>&nbsp;* &nbsp; // V8 locked.</div><div>&nbsp;* &nbsp; {</div><div>&nbsp;* &nbsp; &nbsp; v8::Locker another_locker;</div><div>&nbsp;* &nbsp; &nbsp; // V8 still locked (2 levels).</div>
<div>&nbsp;* &nbsp; &nbsp; {</div><div>&nbsp;* &nbsp; &nbsp; &nbsp; v8::Unlocker unlocker;</div><div>&nbsp;* &nbsp; &nbsp; &nbsp; // V8 not locked.</div><div>&nbsp;* &nbsp; &nbsp; }</div><div>&nbsp;* &nbsp; &nbsp; // V8 locked again (2 levels).</div><div>&nbsp;* &nbsp; }</div><div>&nbsp;* &nbsp; // V8 still locked (1 level).</div>
<div>&nbsp;* }</div><div>&nbsp;* // V8 Now no longer locked.</div><div>&nbsp;* \endcode</div><div><br></div><div>and</div><div><br></div><div><div>&nbsp;&nbsp; * Start preemption.</div><div>&nbsp;&nbsp; *</div><div>&nbsp;&nbsp; * When preemption is started, a timer is fired every n milli seconds</div>
<div>&nbsp;&nbsp; * that will switch between multiple threads that are in contention</div><div>&nbsp;&nbsp; * for the V8 lock.</div></div></div><div>&nbsp;</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div dir="ltr"><br>

<br>Having an object-table indirection isn&#39;t as bad for performance as it sounds because you can cache the body pointer within a method activation, which I seem to remember L. Peter Deutsch pointing out a long time ago. &nbsp; But if the average method is very small it will have very few instvar/property accesses, which reduces the effectiveness of the caching (although if there are *no* property accesses you can skip the indirection altogether, which helps compensate).&nbsp;&nbsp; So that is something that can benefit tremendously from inlining à la Strongtalk, which merges activations and thus increases the possible scope of the cached pointer.&nbsp; But if they are not inlining, the performance sounds like it would be more restricted to a sort of VisualWorks kind of range (which of course is not bad, but wouldn&#39;t threaten Strongtalk).<br>

<br>Plus, the additional word for the indirection is one more word of overhead in the header, so I don&#39;t see how they could get less than a two word header.&nbsp; I thought Lars told me it was one word, but I don&#39;t see how they could do that; maybe he wasn&#39;t counting the indirection as part of the header.<br>

-Dave<br>
<br><div class="gmail_quote"><div class="Ih2E3d">On Tue, Sep 2, 2008 at 11:15 PM, Andreas Raab <span dir="ltr">&lt;<a href="mailto:andreas.raab@gmx.de" target="_blank">andreas.raab@gmx.de</a>&gt;</span> wrote:<br></div><blockquote class="gmail_quote" style="border-left:1px solid rgb(204, 204, 204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex">
<div class="Ih2E3d">

<div>&gt; state-of-the-art multi-threaded design<br>
<br></div>
Can you say more about this? I can&#39;t find any information about V8&#39;s thread handling and concurrency options.<br>
<br>
Cheers,<br>
 &nbsp;- Andreas<br>
<br></div>
[...]</blockquote></div><br></div>
<br><br>
<br></blockquote></div><br></div>