| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 121245f commit 37a60a8
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,41 +37,9 @@ | |||
| 37 | 37 | ||
| 38 | 38 | namespace node { | |
| 39 | 39 | ||
| 40 | - inline IsolateData::IsolateData(v8::Isolate* isolate, uv_loop_t* event_loop, | ||
| 41 | - uint32_t* zero_fill_field) : | ||
| 42 | - | ||
| 43 | - // Create string and private symbol properties as internalized one byte strings. | ||
| 44 | - // | ||
| 45 | - // Internalized because it makes property lookups a little faster and because | ||
| 46 | - // the string is created in the old space straight away. It's going to end up | ||
| 47 | - // in the old space sooner or later anyway but now it doesn't go through | ||
| 48 | - // v8::Eternal's new space handling first. | ||
| 49 | - // | ||
| 50 | - // One byte because our strings are ASCII and we can safely skip V8's UTF-8 | ||
| 51 | - // decoding step. It's a one-time cost, but why pay it when you don't have to? | ||
| 52 | - #define V(PropertyName, StringValue) \ | ||
| 53 | - PropertyName ## _( \ | ||
| 54 | - isolate, \ | ||
| 55 | - v8::Private::New( \ | ||
| 56 | - isolate, \ | ||
| 57 | - v8::String::NewFromOneByte( \ | ||
| 58 | - isolate, \ | ||
| 59 | - reinterpret_cast<const uint8_t*>(StringValue), \ | ||
| 60 | - v8::NewStringType::kInternalized, \ | ||
| 61 | - sizeof(StringValue) - 1).ToLocalChecked())), | ||
| 62 | - PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(V) | ||
| 63 | - #undef V | ||
| 64 | - #define V(PropertyName, StringValue) \ | ||
| 65 | - PropertyName ## _( \ | ||
| 66 | - isolate, \ | ||
| 67 | - v8::String::NewFromOneByte( \ | ||
| 68 | - isolate, \ | ||
| 69 | - reinterpret_cast<const uint8_t*>(StringValue), \ | ||
| 70 | - v8::NewStringType::kInternalized, \ | ||
| 71 | - sizeof(StringValue) - 1).ToLocalChecked()), | ||
| 72 | - PER_ISOLATE_STRING_PROPERTIES(V) | ||
| 73 | - #undef V | ||
| 74 | - event_loop_(event_loop), zero_fill_field_(zero_fill_field) {} | ||
| 40 | + inline v8::Isolate* IsolateData::isolate() const { | ||
| 41 | + return isolate_; | ||
| 42 | + } | ||
| 75 | 43 | ||
| 76 | 44 | inline uv_loop_t* IsolateData::event_loop() const { | |
| 77 | 45 | return event_loop_; | |
@@ -81,6 +49,10 @@ inline uint32_t* IsolateData::zero_fill_field() const { | |||
| 81 | 49 | return zero_fill_field_; | |
| 82 | 50 | } | |
| 83 | 51 | ||
| 52 | + inline MultiIsolatePlatform* IsolateData::platform() const { | ||
| 53 | + return platform_; | ||
| 54 | + } | ||
| 55 | + | ||
| 84 | 56 | inline Environment::AsyncHooks::AsyncHooks(v8::Isolate* isolate) | |
| 85 | 57 | : isolate_(isolate), | |
| 86 | 58 | fields_(isolate, kFieldsCount), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,10 +16,62 @@ namespace node { | |||
| 16 | 16 | using v8::Context; | |
| 17 | 17 | using v8::FunctionTemplate; | |
| 18 | 18 | using v8::HandleScope; | |
| 19 | + using v8::Isolate; | ||
| 19 | 20 | using v8::Local; | |
| 20 | 21 | using v8::Message; | |
| 22 | + using v8::Private; | ||
| 21 | 23 | using v8::StackFrame; | |
| 22 | 24 | using v8::StackTrace; | |
| 25 | + using v8::String; | ||
| 26 | + | ||
| 27 | + IsolateData::IsolateData(Isolate* isolate, | ||
| 28 | + uv_loop_t* event_loop, | ||
| 29 | + MultiIsolatePlatform* platform, | ||
| 30 | + uint32_t* zero_fill_field) : | ||
| 31 | + | ||
| 32 | + // Create string and private symbol properties as internalized one byte strings. | ||
| 33 | + // | ||
| 34 | + // Internalized because it makes property lookups a little faster and because | ||
| 35 | + // the string is created in the old space straight away. It's going to end up | ||
| 36 | + // in the old space sooner or later anyway but now it doesn't go through | ||
| 37 | + // v8::Eternal's new space handling first. | ||
| 38 | + // | ||
| 39 | + // One byte because our strings are ASCII and we can safely skip V8's UTF-8 | ||
| 40 | + // decoding step. It's a one-time cost, but why pay it when you don't have to? | ||
| 41 | + #define V(PropertyName, StringValue) \ | ||
| 42 | + PropertyName ## _( \ | ||
| 43 | + isolate, \ | ||
| 44 | + Private::New( \ | ||
| 45 | + isolate, \ | ||
| 46 | + String::NewFromOneByte( \ | ||
| 47 | + isolate, \ | ||
| 48 | + reinterpret_cast<const uint8_t*>(StringValue), \ | ||
| 49 | + v8::NewStringType::kInternalized, \ | ||
| 50 | + sizeof(StringValue) - 1).ToLocalChecked())), | ||
| 51 | + PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(V) | ||
| 52 | + #undef V | ||
| 53 | + #define V(PropertyName, StringValue) \ | ||
| 54 | + PropertyName ## _( \ | ||
| 55 | + isolate, \ | ||
| 56 | + String::NewFromOneByte( \ | ||
| 57 | + isolate, \ | ||
| 58 | + reinterpret_cast<const uint8_t*>(StringValue), \ | ||
| 59 | + v8::NewStringType::kInternalized, \ | ||
| 60 | + sizeof(StringValue) - 1).ToLocalChecked()), | ||
| 61 | + PER_ISOLATE_STRING_PROPERTIES(V) | ||
| 62 | + #undef V | ||
| 63 | + isolate_(isolate), | ||
| 64 | + event_loop_(event_loop), | ||
| 65 | + zero_fill_field_(zero_fill_field), | ||
| 66 | + platform_(platform) { | ||
| 67 | + if (platform_ != nullptr) | ||
| 68 | + platform_->RegisterIsolate(this, event_loop); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + IsolateData::~IsolateData() { | ||
| 72 | + if (platform_ != nullptr) | ||
| 73 | + platform_->UnregisterIsolate(this); | ||
| 74 | + } | ||
| 23 | 75 | ||
| 24 | 76 | void Environment::Start(int argc, | |
| 25 | 77 | const char* const* argv, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -344,10 +344,13 @@ struct node_async_ids { | |||
| 344 | 344 | ||
| 345 | 345 | class IsolateData { | |
| 346 | 346 | public: | |
| 347 | - inline IsolateData(v8::Isolate* isolate, uv_loop_t* event_loop, | ||
| 348 | - uint32_t* zero_fill_field = nullptr); | ||
| 347 | + IsolateData(v8::Isolate* isolate, uv_loop_t* event_loop, | ||
| 348 | + MultiIsolatePlatform* platform = nullptr, | ||
| 349 | + uint32_t* zero_fill_field = nullptr); | ||
| 350 | + ~IsolateData(); | ||
| 349 | 351 | inline uv_loop_t* event_loop() const; | |
| 350 | 352 | inline uint32_t* zero_fill_field() const; | |
| 353 | + inline MultiIsolatePlatform* platform() const; | ||
| 351 | 354 | ||
| 352 | 355 | #define VP(PropertyName, StringValue) V(v8::Private, PropertyName) | |
| 353 | 356 | #define VS(PropertyName, StringValue) V(v8::String, PropertyName) | |
@@ -360,6 +363,7 @@ class IsolateData { | |||
| 360 | 363 | #undef VP | |
| 361 | 364 | ||
| 362 | 365 | std::unordered_map<nghttp2_rcbuf*, v8::Eternal<v8::String>> http2_static_strs; | |
| 366 | + inline v8::Isolate* isolate() const; | ||
| 363 | 367 | ||
| 364 | 368 | private: | |
| 365 | 369 | #define VP(PropertyName, StringValue) V(v8::Private, PropertyName) | |
@@ -372,8 +376,10 @@ class IsolateData { | |||
| 372 | 376 | #undef VS | |
| 373 | 377 | #undef VP | |
| 374 | 378 | ||
| 379 | + v8::Isolate* const isolate_; | ||
| 375 | 380 | uv_loop_t* const event_loop_; | |
| 376 | 381 | uint32_t* const zero_fill_field_; | |
| 382 | + MultiIsolatePlatform* platform_; | ||
| 377 | 383 | ||
| 378 | 384 | DISALLOW_COPY_AND_ASSIGN(IsolateData); | |
| 379 | 385 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -309,7 +309,7 @@ class NodeInspectorClient : public V8InspectorClient { | |||
| 309 | 309 | terminated_ = false; | |
| 310 | 310 | running_nested_loop_ = true; | |
| 311 | 311 | while (!terminated_ && channel_->waitForFrontendMessage()) { | |
| 312 | - platform_->FlushForegroundTasksInternal(); | ||
| 312 | + platform_->FlushForegroundTasks(env_->isolate()); | ||
| 313 | 313 | } | |
| 314 | 314 | terminated_ = false; | |
| 315 | 315 | running_nested_loop_ = false; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -262,10 +262,10 @@ node::DebugOptions debug_options; | |||
| 262 | 262 | ||
| 263 | 263 | static struct { | |
| 264 | 264 | #if NODE_USE_V8_PLATFORM | |
| 265 | - void Initialize(int thread_pool_size, uv_loop_t* loop) { | ||
| 265 | + void Initialize(int thread_pool_size) { | ||
| 266 | 266 | tracing_agent_ = | |
| 267 | 267 | trace_enabled ? new tracing::Agent() : nullptr; | |
| 268 | - platform_ = new NodePlatform(thread_pool_size, loop, | ||
| 268 | + platform_ = new NodePlatform(thread_pool_size, | ||
| 269 | 269 | trace_enabled ? tracing_agent_->GetTracingController() : nullptr); | |
| 270 | 270 | V8::InitializePlatform(platform_); | |
| 271 | 271 | tracing::TraceEventHelper::SetTracingController( | |
@@ -280,8 +280,8 @@ static struct { | |||
| 280 | 280 | tracing_agent_ = nullptr; | |
| 281 | 281 | } | |
| 282 | 282 | ||
| 283 | - void DrainVMTasks() { | ||
| 284 | - platform_->DrainBackgroundTasks(); | ||
| 283 | + void DrainVMTasks(Isolate* isolate) { | ||
| 284 | + platform_->DrainBackgroundTasks(isolate); | ||
| 285 | 285 | } | |
| 286 | 286 | ||
| 287 | 287 | #if HAVE_INSPECTOR | |
@@ -306,12 +306,16 @@ static struct { | |||
| 306 | 306 | tracing_agent_->Stop(); | |
| 307 | 307 | } | |
| 308 | 308 | ||
| 309 | + NodePlatform* Platform() { | ||
| 310 | + return platform_; | ||
| 311 | + } | ||
| 312 | + | ||
| 309 | 313 | tracing::Agent* tracing_agent_; | |
| 310 | 314 | NodePlatform* platform_; | |
| 311 | 315 | #else // !NODE_USE_V8_PLATFORM | |
| 312 | - void Initialize(int thread_pool_size, uv_loop_t* loop) {} | ||
| 316 | + void Initialize(int thread_pool_size) {} | ||
| 313 | 317 | void Dispose() {} | |
| 314 | - void DrainVMTasks() {} | ||
| 318 | + void DrainVMTasks(Isolate* isolate) {} | ||
| 315 | 319 | bool StartInspector(Environment *env, const char* script_path, | |
| 316 | 320 | const node::DebugOptions& options) { | |
| 317 | 321 | env->ThrowError("Node compiled with NODE_USE_V8_PLATFORM=0"); | |
@@ -323,6 +327,10 @@ static struct { | |||
| 323 | 327 | "so event tracing is not available.\n"); | |
| 324 | 328 | } | |
| 325 | 329 | void StopTracingAgent() {} | |
| 330 | + | ||
| 331 | + NodePlatform* Platform() { | ||
| 332 | + return nullptr; | ||
| 333 | + } | ||
| 326 | 334 | #endif // !NODE_USE_V8_PLATFORM | |
| 327 | 335 | ||
| 328 | 336 | #if !NODE_USE_V8_PLATFORM || !HAVE_INSPECTOR | |
@@ -4769,7 +4777,14 @@ int EmitExit(Environment* env) { | |||
| 4769 | 4777 | ||
| 4770 | 4778 | ||
| 4771 | 4779 | IsolateData* CreateIsolateData(Isolate* isolate, uv_loop_t* loop) { | |
| 4772 | - return new IsolateData(isolate, loop); | ||
| 4780 | + return new IsolateData(isolate, loop, nullptr); | ||
| 4781 | + } | ||
| 4782 | + | ||
| 4783 | + IsolateData* CreateIsolateData( | ||
| 4784 | + Isolate* isolate, | ||
| 4785 | + uv_loop_t* loop, | ||
| 4786 | + MultiIsolatePlatform* platform) { | ||
| 4787 | + return new IsolateData(isolate, loop, platform); | ||
| 4773 | 4788 | } | |
| 4774 | 4789 | ||
| 4775 | 4790 | ||
@@ -4854,7 +4869,7 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data, | |||
| 4854 | 4869 | do { | |
| 4855 | 4870 | uv_run(env.event_loop(), UV_RUN_DEFAULT); | |
| 4856 | 4871 | ||
| 4857 | - v8_platform.DrainVMTasks(); | ||
| 4872 | + v8_platform.DrainVMTasks(isolate); | ||
| 4858 | 4873 | ||
| 4859 | 4874 | more = uv_loop_alive(env.event_loop()); | |
| 4860 | 4875 | if (more) | |
@@ -4875,7 +4890,7 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data, | |||
| 4875 | 4890 | RunAtExit(&env); | |
| 4876 | 4891 | uv_key_delete(&thread_local_env); | |
| 4877 | 4892 | ||
| 4878 | - v8_platform.DrainVMTasks(); | ||
| 4893 | + v8_platform.DrainVMTasks(isolate); | ||
| 4879 | 4894 | WaitForInspectorDisconnect(&env); | |
| 4880 | 4895 | #if defined(LEAK_SANITIZER) | |
| 4881 | 4896 | __lsan_do_leak_check(); | |
@@ -4918,7 +4933,11 @@ inline int Start(uv_loop_t* event_loop, | |||
| 4918 | 4933 | Locker locker(isolate); | |
| 4919 | 4934 | Isolate::Scope isolate_scope(isolate); | |
| 4920 | 4935 | HandleScope handle_scope(isolate); | |
| 4921 | - IsolateData isolate_data(isolate, event_loop, allocator.zero_fill_field()); | ||
| 4936 | + IsolateData isolate_data( | ||
| 4937 | + isolate, | ||
| 4938 | + event_loop, | ||
| 4939 | + v8_platform.Platform(), | ||
| 4940 | + allocator.zero_fill_field()); | ||
| 4922 | 4941 | exit_code = Start(isolate, &isolate_data, argc, argv, exec_argc, exec_argv); | |
| 4923 | 4942 | } | |
| 4924 | 4943 | ||
@@ -4965,7 +4984,7 @@ int Start(int argc, char** argv) { | |||
| 4965 | 4984 | V8::SetEntropySource(crypto::EntropySource); | |
| 4966 | 4985 | #endif // HAVE_OPENSSL | |
| 4967 | 4986 | ||
| 4968 | - v8_platform.Initialize(v8_thread_pool_size, uv_default_loop()); | ||
| 4987 | + v8_platform.Initialize(v8_thread_pool_size); | ||
| 4969 | 4988 | // Enable tracing when argv has --trace-events-enabled. | |
| 4970 | 4989 | if (trace_enabled) { | |
| 4971 | 4990 | fprintf(stderr, "Warning: Trace event is an experimental feature " | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,6 +61,7 @@ | |||
| 61 | 61 | #endif | |
| 62 | 62 | ||
| 63 | 63 | #include "v8.h" // NOLINT(build/include_order) | |
| 64 | + #include "v8-platform.h" // NOLINT(build/include_order) | ||
| 64 | 65 | #include "node_version.h" // NODE_MODULE_VERSION | |
| 65 | 66 | ||
| 66 | 67 | #define NODE_MAKE_VERSION(major, minor, patch) \ | |
@@ -209,8 +210,27 @@ NODE_EXTERN void Init(int* argc, | |||
| 209 | 210 | class IsolateData; | |
| 210 | 211 | class Environment; | |
| 211 | 212 | ||
| 212 | - NODE_EXTERN IsolateData* CreateIsolateData(v8::Isolate* isolate, | ||
| 213 | - struct uv_loop_s* loop); | ||
| 213 | + class MultiIsolatePlatform : public v8::Platform { | ||
| 214 | + public: | ||
| 215 | + virtual ~MultiIsolatePlatform() { } | ||
| 216 | + virtual void DrainBackgroundTasks(v8::Isolate* isolate) = 0; | ||
| 217 | + | ||
| 218 | + // These will be called by the `IsolateData` creation/destruction functions. | ||
| 219 | + virtual void RegisterIsolate(IsolateData* isolate_data, | ||
| 220 | + struct uv_loop_s* loop) = 0; | ||
| 221 | + virtual void UnregisterIsolate(IsolateData* isolate_data) = 0; | ||
| 222 | + }; | ||
| 223 | + | ||
| 224 | + // If `platform` is passed, it will be used to register new Worker instances. | ||
| 225 | + // It can be `nullptr`, in which case creating new Workers inside of | ||
| 226 | + // Environments that use this `IsolateData` will not work. | ||
| 227 | + NODE_EXTERN IsolateData* CreateIsolateData( | ||
| 228 | + v8::Isolate* isolate, | ||
| 229 | + struct uv_loop_s* loop); | ||
| 230 | + NODE_EXTERN IsolateData* CreateIsolateData( | ||
| 231 | + v8::Isolate* isolate, | ||
| 232 | + struct uv_loop_s* loop, | ||
| 233 | + MultiIsolatePlatform* platform); | ||
| 214 | 234 | NODE_EXTERN void FreeIsolateData(IsolateData* isolate_data); | |
| 215 | 235 | ||
| 216 | 236 | NODE_EXTERN Environment* CreateEnvironment(IsolateData* isolate_data, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments