Is there only one V8 instances ?

1,156 views
Skip to first unread message

Ashish Negi

unread,
Sep 23, 2013, 6:33:01 AM9/23/13
to chromi...@chromium.org
When we open a new tab in chromium it starts a new process. Does it makes it own instance of v8 engine or Do all of them share one v8 engine ?

Somebody told me there is only one v8 engine. Just asking here for the accurate answer

Thanks in advance.

Jakob Kummerow

unread,
Sep 23, 2013, 7:28:32 AM9/23/13
to thisismy...@gmail.com, chromium-dev
Every renderer process has its own V8 instance.
When several tabs share a renderer, they also share that renderer's V8 instance, but a feature called "isolates" is used to give them completely isolated environments in V8.

From a website's point of view all of this is an invisible implementation detail -- no JavaScript state is shared between tabs either way.


--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

Ashish Negi

unread,
Sep 23, 2013, 7:45:20 AM9/23/13
to chromi...@chromium.org, thisismy...@gmail.com
So when many tabs use same v8, Does all of them push the javascript code on the main thread or can their be multi-threaded execution for each of these single-threaded tabs?

PhistucK

unread,
Sep 23, 2013, 7:51:06 AM9/23/13
to thisismy...@gmail.com, Chromium-dev
As far as I have experienced, all of them execute on the same main thread.


PhistucK


On Mon, Sep 23, 2013 at 2:45 PM, Ashish Negi <thisismy...@gmail.com> wrote:
So when many tabs use same v8, Does all of them push the javascript code on the main thread or can their be multi-threaded execution for each of these single-threaded tabs?

> When several tabs share a renderer, they also share that renderer's V8 instance, 

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.

Ashish Negi

unread,
Sep 23, 2013, 7:57:32 AM9/23/13
to chromi...@chromium.org, thisismy...@gmail.com
I am making an application with v8 as a library. I created 2 threads with each of them having different isolates. And it was "able" to run javascript in both the threads. Was that just by chance or it  is possible ? When different threads ask for executing code to v8 parallely, would they get into a line automatically ? Is there a chance of them getting lost ?

Ashish Negi

unread,
Sep 23, 2013, 7:58:40 AM9/23/13
to chromi...@chromium.org, thisismy...@gmail.com
I think this is the situation of different tabs sharing the same v8.

PhistucK

unread,
Sep 23, 2013, 8:02:58 AM9/23/13
to thisismy...@gmail.com, Chromium-dev
Perhaps when they are not from the same domain.
I have experienced lock downs in a tab due to the fact that another tab (that share the same Chrome process, which means the same V8 engine) was executing long operations.
Perhaps this is more of a Blink thread than a V8 thread, though. Perhaps if both of them were executing JavaScript only code (meaning, no DOM and other web platform features), they could go on in parallel. 


PhistucK


On Mon, Sep 23, 2013 at 2:58 PM, Ashish Negi <thisismy...@gmail.com> wrote:
I think this is the situation of different tabs sharing the same v8.

--

Torne (Richard Coles)

unread,
Sep 23, 2013, 8:17:10 AM9/23/13
to thisismy...@gmail.com, Chromium-dev
On 23 September 2013 12:57, Ashish Negi <thisismy...@gmail.com> wrote:
I am making an application with v8 as a library. I created 2 threads with each of them having different isolates. And it was "able" to run javascript in both the threads. Was that just by chance or it  is possible ? When different threads ask for executing code to v8 parallely, would they get into a line automatically ? Is there a chance of them getting lost ?

Someone correct me if I'm wrong, but my understanding is:

You can run different isolates on different threads at the same time with V8, yes. However, there is only one Blink thread per renderer process in Chromium, and because V8 shares the DOM with Blink, V8 must run on the single Blink thread.

So, if you're just embedding V8 in your app standalone, then what you're doing is fine, but Chromium can't do that because our V8 shares state with the non-multithreaded rendering engine; even though they are separate isolates only one can run at a time.

Mikhail Naganov

unread,
Sep 23, 2013, 8:45:37 AM9/23/13
to Torne (Richard Coles), thisismy...@gmail.com, Chromium-dev
See V8 API docs in https://code.google.com/p/chromium/codesearch#chromium/src/v8/include/v8.h

/**
 * Isolate represents an isolated instance of the V8 engine.  V8
 * isolates have completely separate states.  Objects from one isolate
 * must not be used in other isolates.  When V8 is initialized a
 * default isolate is implicitly created and entered.  The embedder
 * can create additional isolates and use them in parallel in multiple
 * threads.  An isolate can be entered by at most one thread at any
 * given time.  The Locker/Unlocker API must be used to synchronize.
 */

/**
 * Multiple threads in V8 are allowed, but only one thread at a time is allowed
 * to use any given V8 isolate, see the comments in the Isolate class. The
 * definition of 'using a V8 isolate' includes accessing handles or holding onto
 * object pointers obtained from V8 handles while in the particular V8 isolate.
 * It is up to the user of V8 to ensure, perhaps with locking, that this
 * constraint is not violated. In addition to any other synchronization
 * mechanism that may be used, the v8::Locker and v8::Unlocker classes must be
 * used to signal thead switches to V8.
 */

Joshua Bell

unread,
Sep 23, 2013, 12:32:46 PM9/23/13
to to...@google.com, thisismy...@gmail.com, Chromium-dev
On Mon, Sep 23, 2013 at 5:17 AM, Torne (Richard Coles) <to...@chromium.org> wrote:
On 23 September 2013 12:57, Ashish Negi <thisismy...@gmail.com> wrote:
I am making an application with v8 as a library. I created 2 threads with each of them having different isolates. And it was "able" to run javascript in both the threads. Was that just by chance or it  is possible ? When different threads ask for executing code to v8 parallely, would they get into a line automatically ? Is there a chance of them getting lost ?

Someone correct me if I'm wrong, but my understanding is:

You can run different isolates on different threads at the same time with V8, yes. However, there is only one Blink thread per renderer process in Chromium, and because V8 shares the DOM with Blink, V8 must run on the single Blink thread.

So, if you're just embedding V8 in your app standalone, then what you're doing is fine, but Chromium can't do that because our V8 shares state with the non-multithreaded rendering engine; even though they are separate isolates only one can run at a time.
 

Workers[1] are an example of multiple threads running JavaScript via V8 within a single Chromium process, with the threads and V8-fu managed by Blink.

[1] technically, "Dedicated Workers". Shared Workers get their own "headless" renderer process AND a Worker thread.

Torne (Richard Coles)

unread,
Sep 23, 2013, 12:48:52 PM9/23/13
to Joshua Bell, ashish negi, Chromium-dev
On 23 September 2013 17:32, Joshua Bell <jsb...@chromium.org> wrote:
On Mon, Sep 23, 2013 at 5:17 AM, Torne (Richard Coles) <to...@chromium.org> wrote:
On 23 September 2013 12:57, Ashish Negi <thisismy...@gmail.com> wrote:
I am making an application with v8 as a library. I created 2 threads with each of them having different isolates. And it was "able" to run javascript in both the threads. Was that just by chance or it  is possible ? When different threads ask for executing code to v8 parallely, would they get into a line automatically ? Is there a chance of them getting lost ?

Someone correct me if I'm wrong, but my understanding is:

You can run different isolates on different threads at the same time with V8, yes. However, there is only one Blink thread per renderer process in Chromium, and because V8 shares the DOM with Blink, V8 must run on the single Blink thread.

So, if you're just embedding V8 in your app standalone, then what you're doing is fine, but Chromium can't do that because our V8 shares state with the non-multithreaded rendering engine; even though they are separate isolates only one can run at a time.
 

Workers[1] are an example of multiple threads running JavaScript via V8 within a single Chromium process, with the threads and V8-fu managed by Blink.

Right, but the "normal" non-worker JS running on web pages in different tabs that share a renderer process are all running on the same Blink main thread, no?
 
[1] technically, "Dedicated Workers". Shared Workers get their own "headless" renderer process AND a Worker thread.

 

On Monday, 23 September 2013 17:21:06 UTC+5:30, PhistucK wrote:
As far as I have experienced, all of them execute on the same main thread.


PhistucK


On Mon, Sep 23, 2013 at 2:45 PM, Ashish Negi <thisismy...@gmail.com> wrote:
So when many tabs use same v8, Does all of them push the javascript code on the main thread or can their be multi-threaded execution for each of these single-threaded tabs?

> When several tabs share a renderer, they also share that renderer's V8 instance, 

--
--
Chromium Developers mailing list: chromi...@chromium.org

View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev




--
Torne (Richard Coles)
to...@google.com

Joshua Bell

unread,
Sep 23, 2013, 1:55:03 PM9/23/13
to Torne (Richard Coles), ashish negi, Chromium-dev
On Mon, Sep 23, 2013 at 9:48 AM, Torne (Richard Coles) <to...@google.com> wrote:
On 23 September 2013 17:32, Joshua Bell <jsb...@chromium.org> wrote:
On Mon, Sep 23, 2013 at 5:17 AM, Torne (Richard Coles) <to...@chromium.org> wrote:
On 23 September 2013 12:57, Ashish Negi <thisismy...@gmail.com> wrote:
I am making an application with v8 as a library. I created 2 threads with each of them having different isolates. And it was "able" to run javascript in both the threads. Was that just by chance or it  is possible ? When different threads ask for executing code to v8 parallely, would they get into a line automatically ? Is there a chance of them getting lost ?

Someone correct me if I'm wrong, but my understanding is:

You can run different isolates on different threads at the same time with V8, yes. However, there is only one Blink thread per renderer process in Chromium, and because V8 shares the DOM with Blink, V8 must run on the single Blink thread.

So, if you're just embedding V8 in your app standalone, then what you're doing is fine, but Chromium can't do that because our V8 shares state with the non-multithreaded rendering engine; even though they are separate isolates only one can run at a time.
 

Workers[1] are an example of multiple threads running JavaScript via V8 within a single Chromium process, with the threads and V8-fu managed by Blink.

Right, but the "normal" non-worker JS running on web pages in different tabs that share a renderer process are all running on the same Blink main thread, no?

Correct. Only one Blink main thread per renderer process, used as the UI thread for tabs (and iframes) and hence non-Worker JS.

(I was just being nitpicky since the thread seemed to be implying that multi-threaded use of V8 was foreign to Chromium/Blink and that the OP was doing something unusual. Workers are a counter-example.)

Mingwei Zhang

unread,
Nov 4, 2018, 5:57:44 PM11/4/18
to Chromium-dev, to...@google.com, thisismy...@gmail.com
I has been quite a while since the last reply.

So I am wondering whether there a way to have two V8 instances when two tabs are sharing the same process? I understand that site isolation is now enforced. So i am curious that if I disable 1) site-isolation and 2)  --process-per-site or --process-per-tab, how many V8 instances in one renderer process in current Chrome implementation?

Thanks.
Reply all
Reply to author
Forward
0 new messages