-
Notifications
You must be signed in to change notification settings - Fork 322
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
feat: isolate groups #1695
Open
piscisaureus
wants to merge
1
commit into
main
Choose a base branch
from
isolate-groups
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+174
−8
Open
feat: isolate groups #1695
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright 2019-2021 the Deno authors. All rights reserved. MIT license. | ||
|
||
use crate::support::Opaque; | ||
|
||
#[repr(C)] | ||
struct InternalIsolateGroup(Opaque); | ||
|
||
extern "C" { | ||
fn v8__IsolateGroup__GetDefault() -> *const InternalIsolateGroup; | ||
fn v8__IsolateGroup__CanCreateNewGroups() -> bool; | ||
fn v8__IsolateGroup__Create() -> *const InternalIsolateGroup; | ||
|
||
fn v8__IsolateGroup__DESTRUCT(this: *mut IsolateGroup); | ||
fn v8__IsolateGroup__EQ( | ||
this: *const IsolateGroup, | ||
other: *const IsolateGroup, | ||
) -> bool; | ||
} | ||
|
||
/// The set of V8 isolates in a process is partitioned into groups. Each group | ||
/// has its own sandbox (if V8 was configured with support for the sandbox) and | ||
/// pointer-compression cage (if configured with pointer compression). | ||
/// | ||
/// By default, all isolates are placed in the same group. This is the most | ||
/// efficient configuration in terms of speed and memory use. However, with | ||
/// pointer compression enabled, total heap usage of isolates in a group cannot | ||
/// exceed 4 GB, not counting array buffers and other off-heap storage. Using | ||
/// multiple isolate groups can allow embedders to allocate more than 4GB of | ||
/// objects with pointer compression enabled, if the embedder's use case can | ||
/// span multiple isolates. | ||
/// | ||
/// Creating an isolate group reserves a range of virtual memory addresses. A | ||
/// group's memory mapping will be released when the last isolate in the group | ||
/// is disposed, and there are no more live IsolateGroup objects that refer to | ||
/// it. | ||
/// | ||
/// Note that Isolate groups are reference counted, and the IsolateGroup type is | ||
/// a reference to one. | ||
/// | ||
/// Note that it's not going to be possible to pass shared JS objects across | ||
/// IsolateGroup boundary. | ||
#[repr(C)] | ||
pub struct IsolateGroup(*const InternalIsolateGroup); | ||
|
||
unsafe impl Send for IsolateGroup {} | ||
unsafe impl Sync for IsolateGroup {} | ||
|
||
impl IsolateGroup { | ||
/// Return true if new isolate groups can be created at run-time, or false if | ||
/// all isolates must be in the same group. | ||
pub fn can_create_new_groups() -> bool { | ||
unsafe { v8__IsolateGroup__CanCreateNewGroups() } | ||
} | ||
|
||
/// Get the default isolate group. If this V8's build configuration only | ||
/// supports a single group, this is a reference to that single group. | ||
/// Otherwise this is a group like any other, distinguished only in that it is | ||
/// the first group. | ||
pub fn get_default() -> Self { | ||
IsolateGroup(unsafe { v8__IsolateGroup__GetDefault() }) | ||
} | ||
|
||
/// Create a new isolate group. If this V8's build configuration only supports | ||
/// a single group, abort. | ||
pub fn create() -> Self { | ||
IsolateGroup(unsafe { v8__IsolateGroup__Create() }) | ||
} | ||
} | ||
|
||
impl Default for IsolateGroup { | ||
fn default() -> Self { | ||
IsolateGroup::get_default() | ||
} | ||
} | ||
|
||
impl Drop for IsolateGroup { | ||
fn drop(&mut self) { | ||
unsafe { v8__IsolateGroup__DESTRUCT(self) } | ||
} | ||
} | ||
|
||
impl Eq for IsolateGroup {} | ||
|
||
impl PartialEq for IsolateGroup { | ||
fn eq(&self, other: &Self) -> bool { | ||
unsafe { v8__IsolateGroup__EQ(self, other) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unfortunate that
IsolateGroup
currently does not implementClone
.This is because the C++ class explicitly deletes the copy constructor.
We could probably work around this somehow, although a fairly naive hack that calls
internal_isolate_group->Acquire()
didn't work when I tried.