-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
src: implement minimal v8 snapshot integration #27321
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
Changes from all commits
076c31f
e354795
de02be6
52c5c05
8248be6
3055cb1
2ac1d81
1e0210b
0324fe3
90b5d8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,17 +183,33 @@ void SetIsolateCreateParamsForNode(Isolate::CreateParams* params) { | |
#endif | ||
} | ||
|
||
void SetIsolateUpForNode(v8::Isolate* isolate, IsolateSettingCategories cat) { | ||
switch (cat) { | ||
case IsolateSettingCategories::kErrorHandlers: | ||
isolate->AddMessageListenerWithErrorLevel( | ||
OnMessage, | ||
Isolate::MessageErrorLevel::kMessageError | | ||
Isolate::MessageErrorLevel::kMessageWarning); | ||
isolate->SetAbortOnUncaughtExceptionCallback( | ||
ShouldAbortOnUncaughtException); | ||
isolate->SetFatalErrorHandler(OnFatalError); | ||
break; | ||
case IsolateSettingCategories::kMisc: | ||
isolate->SetMicrotasksPolicy(MicrotasksPolicy::kExplicit); | ||
isolate->SetAllowWasmCodeGenerationCallback( | ||
AllowWasmCodeGenerationCallback); | ||
isolate->SetPromiseRejectCallback(task_queue::PromiseRejectCallback); | ||
v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(isolate); | ||
break; | ||
default: | ||
UNREACHABLE(); | ||
break; | ||
} | ||
} | ||
|
||
void SetIsolateUpForNode(v8::Isolate* isolate) { | ||
isolate->AddMessageListenerWithErrorLevel( | ||
OnMessage, | ||
Isolate::MessageErrorLevel::kMessageError | | ||
Isolate::MessageErrorLevel::kMessageWarning); | ||
isolate->SetAbortOnUncaughtExceptionCallback(ShouldAbortOnUncaughtException); | ||
isolate->SetMicrotasksPolicy(MicrotasksPolicy::kExplicit); | ||
isolate->SetFatalErrorHandler(OnFatalError); | ||
isolate->SetAllowWasmCodeGenerationCallback(AllowWasmCodeGenerationCallback); | ||
isolate->SetPromiseRejectCallback(task_queue::PromiseRejectCallback); | ||
v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(isolate); | ||
SetIsolateUpForNode(isolate, IsolateSettingCategories::kErrorHandlers); | ||
SetIsolateUpForNode(isolate, IsolateSettingCategories::kMisc); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is kind of a bad API (although it's not a public API so it matters less) in that order might be important but that's easy to get wrong for callers. A single call where you pass in an options bitmask would be more robust. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the APIs that are called here...I don't think the order actually matters for now? The only dangerous bit is that you could call with one category twice, but that's also true before this change. I think the current categories is not good as final for sure, but I don't really know the use cases for this other than this patch, so we might as well polish it as we add more use cases (I tried to organize the setup a bit better in another cctest attempt before but that didn't really go anywhere). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, but as a caller I don't know that unless I (closely) read the function's source. It would just be a bit easier all around if I could just say "do this and that" without having to worry about order. Declarative vs. imperative if you will. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is more like a temporary DRY thing here, when we figure out other use cases we could just tweak it for them, but it’s probably too early to spend time designing it. In the initial prototype I actually copy pasted this into SetIsolateUpForSnapshot() but it looked worse.. |
||
} | ||
|
||
Isolate* NewIsolate(ArrayBufferAllocator* allocator, uv_loop_t* event_loop) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -885,8 +885,25 @@ int Start(int argc, char** argv) { | |
} | ||
|
||
{ | ||
NodeMainInstance main_instance( | ||
uv_default_loop(), result.args, result.exec_args); | ||
Isolate::CreateParams params; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not move this bit into the NodeMainInstance main_instance({nullptr},
uv_default_loop(),
per_process::v8_platform.Platform(),
result.args,
result.exec_args);
...
NodeMainInstance main_instance(const std::vector<intptr_t> external_references&&,
uv_loop_t* event_loop,
MultiIsolatePlatform* platform,
const std::vector<std::string>& args,
const std::vector<std::string>& exec_args);
Isolate::CreateParams params;
v8::StartupData* blob = NodeMainInstance::GetEmbeddedSnapshotBlob();
const NodeMainInstance::IndexArray* indexes =
NodeMainInstance::GetIsolateDataIndexes();
if (blob != nullptr) {
params.external_references = external_references.data();
params.snapshot_blob = blob;
}
... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about moving the |
||
// TODO(joyeecheung): collect external references and set it in | ||
// params.external_references. | ||
std::vector<intptr_t> external_references = { | ||
reinterpret_cast<intptr_t>(nullptr)}; | ||
v8::StartupData* blob = NodeMainInstance::GetEmbeddedSnapshotBlob(); | ||
const std::vector<size_t>* indexes = | ||
NodeMainInstance::GetIsolateDataIndexes(); | ||
if (blob != nullptr) { | ||
params.external_references = external_references.data(); | ||
params.snapshot_blob = blob; | ||
} | ||
|
||
NodeMainInstance main_instance(¶ms, | ||
uv_default_loop(), | ||
per_process::v8_platform.Platform(), | ||
result.args, | ||
result.exec_args, | ||
indexes); | ||
result.exit_code = main_instance.Run(); | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.