diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-03-08 21:35:40 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-11-05 21:57:13 +0300 |
commit | d855904ef6a0daa0c0475e745fdd33815e760e0c (patch) | |
tree | 56c605726ad3200bd533a3bfab836c45ad48473e /src/node_worker.h | |
parent | 309e1eae797d3060126ef2e13ee0ab124808f575 (diff) |
worker: allow specifying resource limits
Allow specifying resource limits for the JS engine instance created
as part of a Worker.
PR-URL: https://github.com/nodejs/node/pull/26628
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Diffstat (limited to 'src/node_worker.h')
-rw-r--r-- | src/node_worker.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/node_worker.h b/src/node_worker.h index 77f68801e7c..46eab70a499 100644 --- a/src/node_worker.h +++ b/src/node_worker.h @@ -12,6 +12,13 @@ namespace worker { class WorkerThreadData; +enum ResourceLimits { + kMaxYoungGenerationSizeMb, + kMaxOldGenerationSizeMb, + kCodeRangeSizeMb, + kTotalResourceLimitCount +}; + // A worker thread, as represented in its parent thread. class Worker : public AsyncWrap { public: @@ -51,9 +58,14 @@ class Worker : public AsyncWrap { static void StopThread(const v8::FunctionCallbackInfo<v8::Value>& args); static void Ref(const v8::FunctionCallbackInfo<v8::Value>& args); static void Unref(const v8::FunctionCallbackInfo<v8::Value>& args); + static void GetResourceLimits( + const v8::FunctionCallbackInfo<v8::Value>& args); + v8::Local<v8::Float64Array> GetResourceLimits(v8::Isolate* isolate) const; private: void CreateEnvMessagePort(Environment* env); + static size_t NearHeapLimit(void* data, size_t current_heap_limit, + size_t initial_heap_limit); std::shared_ptr<PerIsolateOptions> per_isolate_opts_; std::vector<std::string> exec_argv_; @@ -73,10 +85,15 @@ class Worker : public AsyncWrap { mutable Mutex mutex_; bool thread_joined_ = true; + const char* custom_error_ = nullptr; int exit_code_ = 0; uint64_t thread_id_ = -1; uintptr_t stack_base_ = 0; + // Custom resource constraints: + double resource_limits_[kTotalResourceLimitCount]; + void UpdateResourceConstraints(v8::ResourceConstraints* constraints); + // Full size of the thread's stack. static constexpr size_t kStackSize = 4 * 1024 * 1024; // Stack buffer size that is not available to the JS engine. |