Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why we use V8::Isolate and why use in V8::Isolate in Node js? #1768

Closed
adarshsaraogi opened this issue Feb 13, 2019 · 3 comments
Closed

Why we use V8::Isolate and why use in V8::Isolate in Node js? #1768

adarshsaraogi opened this issue Feb 13, 2019 · 3 comments

Comments

@adarshsaraogi
Copy link

In Advance, I am sorry if I am asking the stupid question.
But in a Stage of learning the Node internally, I am stuck Up with Keyword Isolate using in c++ from chrome v8 API library.
I have currently known it's a V8 instance or VM which is allocated. but what is exact use of this api in nodeJs and is it working heart of the node.

@addaleax addaleax transferred this issue from nodejs/node Feb 13, 2019
@addaleax
Copy link
Member

@adarshsaraogi A V8 Isolate is something that Node.js uses to run JS code.

It consists (mostly) of a single JS heap, that is, JS values and code inside a single Isolate can refer to other values and pieces of code inside that Isolate, but not values from another Isolate.

Practically speaking, Node.js uses 1 Isolate per thread; one, if you are only running the main thread, and an additional Isolate for each new Worker thread instance. That allows the different threads to run in parallel, but has the disadvantage that it forbids them from accessing each other’s contents directly.

@adarshsaraogi
Copy link
Author

@addaleax is v8 also having its own V8 heap to manage the isolate.

@addaleax
Copy link
Member

@adarshsaraogi Maybe to disambiguate; when talking about the “heap”, there’s two things you could be referring to:

  • The JS heap. This is a memory full of JS objects (and some JS-related objects, e.g. Contexts in V8, the microtask queue, etc.) – basically everything managed through the JS engine’s garbage collector. This is what people are usually referring to when talking about the “heap” in a Node.js context.
  • The native heap. This is memory allocated directly C++ using e.g. malloc() or new Foo(). A lot of metadata that is about managing code, such as the V8 Isolate object itself, is allocated this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants