The explanations of "Isolate" what I found so far.
exp #1: http://izs.me/v8-docs/classv8_1_1Isolate.html
"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 can be used to synchronize."
exp #2: https://developers.google.com/v8/get_started
"An isolate is a VM instance with its own heap."
OK, I see. "Isolate" is an isolate thread that can operate seperately. Followings are my questions.
It looks like just thread for me, except that it has its own heap. is there any difference?
I think "Isolate" can be used for implementing concurrent GC. The definition above says that each "Isolate" cannot be used in other "Isolate". But concurrent GC should check(or mark) the main(or other) thread(or Isolate)'s live objects. How can it be possible?
How can it be possible to protect their own objects? "Isolate" is a thread not a process. So other thread can access that thread's object if it knows the address. How could protect it? And I cannot understand the meaning of own heap. Because it can be accessed by other thread if other thread knows the address. And normal thread can have their heap in memory space. Since address space of heap is not seperated exactly but if one thread malloc a memory, how could other thread use it unless others know the address? What's the difference each thread just malloc their own heap space and "Isolate" have its own heap space?
My questions can be easily summarized that what is the role of the "Isolate" and how can it be possible to have their own heap space and why does it have to have its own heap.
It will be very helpful if someone shares some good documentations of "Isolate". Thanks for reading.
---- Make the question clear ---- The key point of my question is that Q: What makes google to implement isolate in V8? what's the benefit of isolate and what would be a good example of using isolate in V8? What are they(isolates) executing concurrently?
An isolate is a VM instance with its own heap. A local handle is a pointer to an object. All V8 objects are accessed using handles. They are necessary because of the way the V8 garbage collector works. A handle scope can be thought of as a container for any number of handles.
V8 orchestrates isolates: lightweight contexts that group variables with the code allowed to mutate them. You could even consider an isolate a “sandbox” for your function to run in. A single runtime can run hundreds or thousands of isolates, seamlessly switching between them.
Chrome V8 is a JavaScript engine, which means that it executes JavaScript code. Originally, JavaScript was written to be executed by web browsers. Chrome V8, or just V8, can execute JavaScript code either within or outside of a browser, which makes server-side scripting possible.
- It looks like just thread for me, except that it has its own heap. is there any difference?
They are orthogonal, a thread can execute multiple isolates at a time while an isolate can only be executed by one thread at a time. And of course one isolate can be executed by different threads at different times but it's probably not common. An isolate is only an instance of a JavaScript VM and it only has its own JavaScript heap, the normal process heap is still shared in the process as normal.
- I think "Isolate" can be used for implementing concurrent GC. The definition above says that each "Isolate" cannot be used in other "Isolate". But concurrent GC should check(or mark) the main(or other) thread(or Isolate)'s live objects. How can it be possible?
Noncompacting sweep operation in a Mark&Sweep GC can be performed concurrently from another thread. Other GC operations, like compacting sweep, scavenge, marking can only be performed while JS is not executing in an isolate.
- How can it be possible to protect their own objects? "Isolate" is a thread not a process. So other thread can access that thread's object if it knows the address. How could protect it? And I cannot understand the meaning of own heap. Because it can be accessed by other thread if other thread knows the address. And normal thread can have their heap in memory space. Since address space of heap is not seperated exactly but if one thread malloc a memory, how could other thread use it unless others know the address? What's the difference each thread just malloc their own heap space and "Isolate" have its own heap space?
Well you don't know the address and it's not possible to get it sticking to V8 API. Even if you could get the address, the address is not safe to use because V8 moves stuff in its heap constantly. And malloc will not return addresses that point to some isolate's js heap because obviously that memory has been malloced by the isolate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With