Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
src: track async resources via pointers to stack-allocated handles#59704
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
Merged
nodejs-github-bot merged 2 commits into nodejs:main from addaleax:async-resource-stack-abistableSep 4, 2025
+47 −34
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -122,7 +122,8 @@ void Environment::ResetPromiseHooks(Local<Function> init, | ||
| // Remember to keep this code aligned with pushAsyncContext() in JS. | ||
| void AsyncHooks::push_async_context(double async_id, | ||
| double trigger_async_id, | ||
| Local<Object> resource){ | ||
| Local<Object>* resource){ | ||
| CHECK_IMPLIES(resource != nullptr, !resource->IsEmpty()); | ||
| // Since async_hooks is experimental, do only perform the check | ||
| // when async_hooks is enabled. | ||
| if (fields_[kCheck] > 0){ | ||
| @@ -140,14 +141,14 @@ void AsyncHooks::push_async_context(double async_id, | ||
| #ifdef DEBUG | ||
| for (uint32_t i = offset; i < native_execution_async_resources_.size(); i++) | ||
| CHECK(native_execution_async_resources_[i].IsEmpty()); | ||
| CHECK_NULL(native_execution_async_resources_[i]); | ||
| #endif | ||
| // When this call comes from JS (as a way of increasing the stack size), | ||
| // `resource` will be empty, because JS caches these values anyway. | ||
| if (!resource.IsEmpty()){ | ||
| if (resource != nullptr){ | ||
Flarna marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| native_execution_async_resources_.resize(offset + 1); | ||
| // Caveat: This is a v8::Local<> assignment, we do not keep a v8::Global<>! | ||
| // Caveat: This is a v8::Local<>* assignment, we do not keep a v8::Global<>! | ||
| native_execution_async_resources_[offset] = resource; | ||
| } | ||
| } | ||
| @@ -172,11 +173,11 @@ bool AsyncHooks::pop_async_context(double async_id){ | ||
| fields_[kStackLength] = offset; | ||
| if (offset < native_execution_async_resources_.size() && | ||
| !native_execution_async_resources_[offset].IsEmpty()) [[likely]]{ | ||
| native_execution_async_resources_[offset] != nullptr) [[likely]]{ | ||
| #ifdef DEBUG | ||
| for (uint32_t i = offset + 1; i < native_execution_async_resources_.size(); | ||
| i++){ | ||
| CHECK(native_execution_async_resources_[i].IsEmpty()); | ||
| CHECK_NULL(native_execution_async_resources_[i]); | ||
| } | ||
| #endif | ||
| native_execution_async_resources_.resize(offset); | ||
| @@ -1721,7 +1722,6 @@ AsyncHooks::AsyncHooks(Isolate* isolate, const SerializeInfo* info) | ||
| fields_(isolate, kFieldsCount, MAYBE_FIELD_PTR(info, fields)), | ||
| async_id_fields_( | ||
| isolate, kUidFieldsCount, MAYBE_FIELD_PTR(info, async_id_fields)), | ||
| native_execution_async_resources_(isolate), | ||
| info_(info){ | ||
| HandleScope handle_scope(isolate); | ||
| if (info == nullptr){ | ||
| @@ -1810,10 +1810,9 @@ AsyncHooks::SerializeInfo AsyncHooks::Serialize(Local<Context> context, | ||
| native_execution_async_resources_.size()); | ||
| for (size_t i = 0; i < native_execution_async_resources_.size(); i++){ | ||
| info.native_execution_async_resources[i] = | ||
| native_execution_async_resources_[i].IsEmpty() ? SIZE_MAX : | ||
| creator->AddData( | ||
| context, | ||
| native_execution_async_resources_[i]); | ||
| native_execution_async_resources_[i] == nullptr | ||
| ? SIZE_MAX | ||
| : creator->AddData(context, *native_execution_async_resources_[i]); | ||
| } | ||
| // At the moment, promise hooks are not supported in the startup snapshot. | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.