| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 124f715 commit 85542b0
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1237,6 +1237,11 @@ void Environment::RunCleanup() { | |||
| 1237 | 1237 | // Defer the BaseObject cleanup after handles are cleaned up. | |
| 1238 | 1238 | CleanupHandles(); | |
| 1239 | 1239 | ||
| 1240 | + while (!cleanable_queue_.IsEmpty()) { | ||
| 1241 | + Cleanable* cleanable = cleanable_queue_.PopFront(); | ||
| 1242 | + cleanable->Clean(); | ||
| 1243 | + } | ||
| 1244 | + | ||
| 1240 | 1245 | while (!cleanup_queue_.empty() || principal_realm_->HasCleanupHooks() || | |
| 1241 | 1246 | native_immediates_.size() > 0 || | |
| 1242 | 1247 | native_immediates_threadsafe_.size() > 0 || | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -599,6 +599,18 @@ void DefaultProcessExitHandlerInternal(Environment* env, ExitCode exit_code); | |||
| 599 | 599 | v8::Maybe<ExitCode> SpinEventLoopInternal(Environment* env); | |
| 600 | 600 | v8::Maybe<ExitCode> EmitProcessExitInternal(Environment* env); | |
| 601 | 601 | ||
| 602 | + class Cleanable { | ||
| 603 | + public: | ||
| 604 | + virtual ~Cleanable() = default; | ||
| 605 | + | ||
| 606 | + protected: | ||
| 607 | + ListNode<Cleanable> cleanable_queue_; | ||
| 608 | + | ||
| 609 | + private: | ||
| 610 | + virtual void Clean() = 0; | ||
| 611 | + friend class Environment; | ||
| 612 | + }; | ||
| 613 | + | ||
| 602 | 614 | /** | |
| 603 | 615 | * Environment is a per-isolate data structure that represents an execution | |
| 604 | 616 | * environment. Each environment has a principal realm. An environment can | |
@@ -905,8 +917,12 @@ class Environment : public MemoryRetainer { | |||
| 905 | 917 | ||
| 906 | 918 | typedef ListHead<HandleWrap, &HandleWrap::handle_wrap_queue_> HandleWrapQueue; | |
| 907 | 919 | typedef ListHead<ReqWrapBase, &ReqWrapBase::req_wrap_queue_> ReqWrapQueue; | |
| 920 | + typedef ListHead<Cleanable, &Cleanable::cleanable_queue_> CleanableQueue; | ||
| 908 | 921 | ||
| 909 | 922 | inline HandleWrapQueue* handle_wrap_queue() { return &handle_wrap_queue_; } | |
| 923 | + inline CleanableQueue* cleanable_queue() { | ||
| 924 | + return &cleanable_queue_; | ||
| 925 | + } | ||
| 910 | 926 | inline ReqWrapQueue* req_wrap_queue() { return &req_wrap_queue_; } | |
| 911 | 927 | ||
| 912 | 928 | // https://w3c.github.io/hr-time/#dfn-time-origin | |
@@ -1182,6 +1198,7 @@ class Environment : public MemoryRetainer { | |||
| 1182 | 1198 | // memory are predictable. For more information please refer to | |
| 1183 | 1199 | // `doc/contributing/node-postmortem-support.md` | |
| 1184 | 1200 | friend int GenDebugSymbols(); | |
| 1201 | + CleanableQueue cleanable_queue_; | ||
| 1185 | 1202 | HandleWrapQueue handle_wrap_queue_; | |
| 1186 | 1203 | ReqWrapQueue req_wrap_queue_; | |
| 1187 | 1204 | std::list<HandleCleanup> handle_cleanup_queue_; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,7 +81,7 @@ using v8::Value; | |||
| 81 | 81 | ||
| 82 | 82 | namespace { | |
| 83 | 83 | ||
| 84 | - class CallbackInfo { | ||
| 84 | + class CallbackInfo : public Cleanable { | ||
| 85 | 85 | public: | |
| 86 | 86 | static inline Local<ArrayBuffer> CreateTrackedArrayBuffer( | |
| 87 | 87 | Environment* env, | |
@@ -94,7 +94,7 @@ class CallbackInfo { | |||
| 94 | 94 | CallbackInfo& operator=(const CallbackInfo&) = delete; | |
| 95 | 95 | ||
| 96 | 96 | private: | |
| 97 | - static void CleanupHook(void* data); | ||
| 97 | + void Clean(); | ||
| 98 | 98 | inline void OnBackingStoreFree(); | |
| 99 | 99 | inline void CallAndResetCallback(); | |
| 100 | 100 | inline CallbackInfo(Environment* env, | |
@@ -109,7 +109,6 @@ class CallbackInfo { | |||
| 109 | 109 | Environment* const env_; | |
| 110 | 110 | }; | |
| 111 | 111 | ||
| 112 | - | ||
| 113 | 112 | Local<ArrayBuffer> CallbackInfo::CreateTrackedArrayBuffer( | |
| 114 | 113 | Environment* env, | |
| 115 | 114 | char* data, | |
@@ -149,25 +148,23 @@ CallbackInfo::CallbackInfo(Environment* env, | |||
| 149 | 148 | data_(data), | |
| 150 | 149 | hint_(hint), | |
| 151 | 150 | env_(env) { | |
| 152 | - env->AddCleanupHook(CleanupHook, this); | ||
| 151 | + env->cleanable_queue()->PushFront(this); | ||
| 153 | 152 | env->isolate()->AdjustAmountOfExternalAllocatedMemory(sizeof(*this)); | |
| 154 | 153 | } | |
| 155 | 154 | ||
| 156 | - void CallbackInfo::CleanupHook(void* data) { | ||
| 157 | - CallbackInfo* self = static_cast<CallbackInfo*>(data); | ||
| 158 | - | ||
| 155 | + void CallbackInfo::Clean() { | ||
| 159 | 156 | { | |
| 160 | - HandleScope handle_scope(self->env_->isolate()); | ||
| 161 | - Local<ArrayBuffer> ab = self->persistent_.Get(self->env_->isolate()); | ||
| 157 | + HandleScope handle_scope(env_->isolate()); | ||
| 158 | + Local<ArrayBuffer> ab = persistent_.Get(env_->isolate()); | ||
| 162 | 159 | if (!ab.IsEmpty() && ab->IsDetachable()) { | |
| 163 | 160 | ab->Detach(Local<Value>()).Check(); | |
| 164 | - self->persistent_.Reset(); | ||
| 161 | + persistent_.Reset(); | ||
| 165 | 162 | } | |
| 166 | 163 | } | |
| 167 | 164 | ||
| 168 | 165 | // Call the callback in this case, but don't delete `this` yet because the | |
| 169 | 166 | // BackingStore deleter callback will do so later. | |
| 170 | - self->CallAndResetCallback(); | ||
| 167 | + CallAndResetCallback(); | ||
| 171 | 168 | } | |
| 172 | 169 | ||
| 173 | 170 | void CallbackInfo::CallAndResetCallback() { | |
@@ -179,7 +176,7 @@ void CallbackInfo::CallAndResetCallback() { | |||
| 179 | 176 | } | |
| 180 | 177 | if (callback != nullptr) { | |
| 181 | 178 | // Clean up all Environment-related state and run the callback. | |
| 182 | - env_->RemoveCleanupHook(CleanupHook, this); | ||
| 179 | + cleanable_queue_.Remove(); | ||
| 183 | 180 | int64_t change_in_bytes = -static_cast<int64_t>(sizeof(*this)); | |
| 184 | 181 | env_->isolate()->AdjustAmountOfExternalAllocatedMemory(change_in_bytes); | |
| 185 | 182 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments