-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
[v8.x] backport some V8 platform changes #20901
Conversation
This splits the task queue used for asynchronous tasks scheduled by V8 in per-isolate queues, so that multiple threads can be supported. Original-PR-URL: ayojs/ayo#89 Original-Reviewed-By: Timothy Gu <[email protected]> PR-URL: nodejs#16700 Reviewed-By: James M Snell <[email protected]>
Worker threads need an event loop without active libuv handles in order to shut down. One source of handles that was previously not accounted for were delayed V8 tasks; these create timers that would be standing in the way of clearing the event loop. To solve this, keep track of the scheduled tasks in a list and close their timer handles before the corresponding isolate/loop is removed from the platform. It is not clear from the V8 documentation what the expectation is with respect to pending background tasks at the end of the isolate lifetime; however, an alternative approach of executing these scheduled tasks when flushing them led to an infinite loop of tasks scheduling each other; so it seems safe to assume that the behaviour implemented in this patch is at least acceptable. Original-PR-URL: ayojs/ayo#120 Original-Reviewed-By: Stephen Belanger <[email protected]> PR-URL: nodejs#16700 Reviewed-By: James M Snell <[email protected]>
Replace raw pointers in task queues with std::unique_ptr. This makes ownership obvious. PR-URL: nodejs#16970 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
Use std::unique_ptr for delayed tasks in the scheduled delayed tasks vector. This makes it clear that the vector has ownership of the delayed tasks and is responsible for deleting them. Use a custom deleter for the pointers because libuv needs to close the handle and then delete the data. Provide the handle when creating the pointer instead of invoking the special delete action everytime an element is removed from the vector. PR-URL: nodejs#17083 Reviewed-By: Anna Henningsen <[email protected]>
flush_tasks_.data = static_cast<void*>(this); | ||
uv_unref(reinterpret_cast<uv_handle_t*>(&flush_tasks_)); | ||
PerIsolatePlatformData::PerIsolatePlatformData( | ||
v8::Isolate* isolate, uv_loop_t* loop) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Perhaps use an unqualified name for the Isolate
type here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a backport is it safe to assume this is what already landed upstream
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I’d prefer to avoid stylistic changes outside of master
:)
Could you also include #17133? |
@MylesBorins Already included that as part of the backporting process (in order to make Or are you seeing errors because of that? |
@addaleax didn't know it was included because not documented. Was just going through the backlog 😄 |
landed in 35055a1...beb45ac |
084ef60
to
859dc64
Compare
This splits the task queue used for asynchronous tasks scheduled by V8 in per-isolate queues, so that multiple threads can be supported. Backport-PR-URL: #20901 Original-PR-URL: ayojs/ayo#89 Original-Reviewed-By: Timothy Gu <[email protected]> PR-URL: #16700 Reviewed-By: James M Snell <[email protected]>
Worker threads need an event loop without active libuv handles in order to shut down. One source of handles that was previously not accounted for were delayed V8 tasks; these create timers that would be standing in the way of clearing the event loop. To solve this, keep track of the scheduled tasks in a list and close their timer handles before the corresponding isolate/loop is removed from the platform. It is not clear from the V8 documentation what the expectation is with respect to pending background tasks at the end of the isolate lifetime; however, an alternative approach of executing these scheduled tasks when flushing them led to an infinite loop of tasks scheduling each other; so it seems safe to assume that the behaviour implemented in this patch is at least acceptable. Backport-PR-URL: #20901 Original-PR-URL: ayojs/ayo#120 Original-Reviewed-By: Stephen Belanger <[email protected]> PR-URL: #16700 Reviewed-By: James M Snell <[email protected]>
Replace raw pointers in task queues with std::unique_ptr. This makes ownership obvious. Backport-PR-URL: #20901 PR-URL: #16970 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
Use std::unique_ptr for delayed tasks in the scheduled delayed tasks vector. This makes it clear that the vector has ownership of the delayed tasks and is responsible for deleting them. Use a custom deleter for the pointers because libuv needs to close the handle and then delete the data. Provide the handle when creating the pointer instead of invoking the special delete action everytime an element is removed from the vector. Backport-PR-URL: #20901 PR-URL: #17083 Reviewed-By: Anna Henningsen <[email protected]>
This splits the task queue used for asynchronous tasks scheduled by V8 in per-isolate queues, so that multiple threads can be supported. Backport-PR-URL: #20901 Original-PR-URL: ayojs/ayo#89 Original-Reviewed-By: Timothy Gu <[email protected]> PR-URL: #16700 Reviewed-By: James M Snell <[email protected]>
Worker threads need an event loop without active libuv handles in order to shut down. One source of handles that was previously not accounted for were delayed V8 tasks; these create timers that would be standing in the way of clearing the event loop. To solve this, keep track of the scheduled tasks in a list and close their timer handles before the corresponding isolate/loop is removed from the platform. It is not clear from the V8 documentation what the expectation is with respect to pending background tasks at the end of the isolate lifetime; however, an alternative approach of executing these scheduled tasks when flushing them led to an infinite loop of tasks scheduling each other; so it seems safe to assume that the behaviour implemented in this patch is at least acceptable. Backport-PR-URL: #20901 Original-PR-URL: ayojs/ayo#120 Original-Reviewed-By: Stephen Belanger <[email protected]> PR-URL: #16700 Reviewed-By: James M Snell <[email protected]>
Replace raw pointers in task queues with std::unique_ptr. This makes ownership obvious. Backport-PR-URL: #20901 PR-URL: #16970 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
Use std::unique_ptr for delayed tasks in the scheduled delayed tasks vector. This makes it clear that the vector has ownership of the delayed tasks and is responsible for deleting them. Use a custom deleter for the pointers because libuv needs to close the handle and then delete the data. Provide the handle when creating the pointer instead of invoking the special delete action everytime an element is removed from the vector. Backport-PR-URL: #20901 PR-URL: #17083 Reviewed-By: Anna Henningsen <[email protected]>
Backport #16700 + #16970 + #17083 (the latter two depend on the first one)