-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
src: implement v8::TaskRunner API in NodePlatform #17134
Conversation
2f9c744
to
c294f9a
Compare
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.
lgtm with nits. Thanks for implementing this so quickly!
src/node_platform.cc
Outdated
@@ -24,6 +24,46 @@ static void BackgroundRunner(void* data) { | |||
} | |||
} | |||
|
|||
BackgroundTaskRunner::BackgroundTaskRunner(int thread_pool_size) { | |||
for (int i = 0; i < thread_pool_size; i++) { | |||
uv_thread_t* t = new uv_thread_t(); |
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.
Make t already a std::unique_ptr<uv_thread_t>. Thereby you don't need the "delete" below, and it is more robust in the future.
src/node_platform.cc
Outdated
void BackgroundTaskRunner::PostDelayedTask(std::unique_ptr<v8::Task> task, | ||
double delay_in_seconds) { | ||
// It's unclear whether this is required at all for background tasks. | ||
PostTask(std::move(task)); |
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.
I think it is better to leave this unimplemented than implementing it incorrectly.
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.
@gahaas Is there any case in which V8 would call this method? What happens when the delay is not being matched?
I am okay with leaving it unimplemented but I’d like to understand better what the implications of each option are
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.
@addaleax At the moment V8 does not call this method. The reason it exists is to share a common interface between the foreground task runner and the background task runner.
I think if a developer ever wants to use this method, the developer does not expect that the platform will just ignore the delay. Therefore posting the task without delay does not provide much value to the developer IMO. Leaving the method unimplemented at least tells the developer explicitly that no implementation with expected behavior exists.
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.
ok, done!
src/node_platform.cc
Outdated
} | ||
|
||
void BackgroundTaskRunner::PostIdleTask(std::unique_ptr<v8::IdleTask> task) { | ||
CHECK(false && "idle tasks not enabled"); |
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.
UNREACHABLE()
? Doesn't print a message although that could be added.
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.
done!
src/node_platform.cc
Outdated
void PerIsolatePlatformData::CallOnForegroundThread( | ||
std::unique_ptr<Task> task) { | ||
void PerIsolatePlatformData::PostIdleTask(std::unique_ptr<v8::IdleTask> task) { | ||
CHECK(false && "idle tasks not enabled"); |
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.
Ditto.
Original commit message: [platform] Add TaskRunner to the platform API With the existing platform API it is not possible to post foreground tasks from background tasks. This is, however, required to implement asynchronous compilation for WebAssembly. With this CL we add the concept of a TaskRunner to the platform API. The TaskRunner contains all data needed to post a foreground task and can be used both from a foreground task and a background task. Eventually the TaskRunner should replace the existing API. In addition, this CL contains a default implementation of the TaskRunner. This implementation has tempory workaround for platforms which do not provide a TaskRunner implementation yet. This default implementation should be deleted again when all platforms provide a TaskRunner implementation. [email protected] Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: I6ea4a1c9da1eb9a19e8ce8f2163000dbc2598802 Reviewed-on: https://chromium-review.googlesource.com/741588 Commit-Queue: Andreas Haas <[email protected]> Reviewed-by: Ross McIlroy <[email protected]> Cr-Commit-Position: refs/heads/master@{nodejs#49041} Refs: v8/v8@c690f54
Original commit message: [platform] Return task runners as shared_ptr At the moment, task runners are returned as unique_ptr. This is inconvenient, however. In all implementations I did, the platform holds a shared pointer of the task runner and wraps it in a wrapper class just to return it as a unique_ptr. With this CL the platform API is changed to return a shared_ptr directly. [email protected] Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: Ide278db855199ea239ad0ae14d97fd17349dac8c Reviewed-on: https://chromium-review.googlesource.com/768867 Commit-Queue: Andreas Haas <[email protected]> Reviewed-by: Ross McIlroy <[email protected]> Cr-Commit-Position: refs/heads/master@{nodejs#49366} Refs: v8/v8@98c40a4
V8 is switching APIs for scheduling tasks. Implement the new APIs. Fixes: nodejs/node-v8#24 Refs: v8/v8@c690f54
5a3abae
to
9bd517e
Compare
Original commit message: [platform] Add TaskRunner to the platform API With the existing platform API it is not possible to post foreground tasks from background tasks. This is, however, required to implement asynchronous compilation for WebAssembly. With this CL we add the concept of a TaskRunner to the platform API. The TaskRunner contains all data needed to post a foreground task and can be used both from a foreground task and a background task. Eventually the TaskRunner should replace the existing API. In addition, this CL contains a default implementation of the TaskRunner. This implementation has tempory workaround for platforms which do not provide a TaskRunner implementation yet. This default implementation should be deleted again when all platforms provide a TaskRunner implementation. [email protected] Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: I6ea4a1c9da1eb9a19e8ce8f2163000dbc2598802 Reviewed-on: https://chromium-review.googlesource.com/741588 Commit-Queue: Andreas Haas <[email protected]> Reviewed-by: Ross McIlroy <[email protected]> Cr-Commit-Position: refs/heads/master@{#49041} Refs: v8/v8@c690f54 PR-URL: #17134 Fixes: nodejs/node-v8#24 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
Original commit message: [platform] Return task runners as shared_ptr At the moment, task runners are returned as unique_ptr. This is inconvenient, however. In all implementations I did, the platform holds a shared pointer of the task runner and wraps it in a wrapper class just to return it as a unique_ptr. With this CL the platform API is changed to return a shared_ptr directly. [email protected] Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: Ide278db855199ea239ad0ae14d97fd17349dac8c Reviewed-on: https://chromium-review.googlesource.com/768867 Commit-Queue: Andreas Haas <[email protected]> Reviewed-by: Ross McIlroy <[email protected]> Cr-Commit-Position: refs/heads/master@{#49366} Refs: v8/v8@98c40a4 PR-URL: #17134 Fixes: nodejs/node-v8#24 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
V8 is switching APIs for scheduling tasks. Implement the new APIs. Fixes: nodejs/node-v8#24 Refs: v8/v8@c690f54 PR-URL: #17134 Fixes: nodejs/node-v8#24 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
Each cherry-pick should have incremented the |
Original commit message: [platform] Add TaskRunner to the platform API With the existing platform API it is not possible to post foreground tasks from background tasks. This is, however, required to implement asynchronous compilation for WebAssembly. With this CL we add the concept of a TaskRunner to the platform API. The TaskRunner contains all data needed to post a foreground task and can be used both from a foreground task and a background task. Eventually the TaskRunner should replace the existing API. In addition, this CL contains a default implementation of the TaskRunner. This implementation has tempory workaround for platforms which do not provide a TaskRunner implementation yet. This default implementation should be deleted again when all platforms provide a TaskRunner implementation. [email protected] Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: I6ea4a1c9da1eb9a19e8ce8f2163000dbc2598802 Reviewed-on: https://chromium-review.googlesource.com/741588 Commit-Queue: Andreas Haas <[email protected]> Reviewed-by: Ross McIlroy <[email protected]> Cr-Commit-Position: refs/heads/master@{nodejs#49041} Refs: v8/v8@c690f54 PR-URL: nodejs#17134 Fixes: nodejs/node-v8#24 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
Original commit message: [platform] Return task runners as shared_ptr At the moment, task runners are returned as unique_ptr. This is inconvenient, however. In all implementations I did, the platform holds a shared pointer of the task runner and wraps it in a wrapper class just to return it as a unique_ptr. With this CL the platform API is changed to return a shared_ptr directly. [email protected] Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: Ide278db855199ea239ad0ae14d97fd17349dac8c Reviewed-on: https://chromium-review.googlesource.com/768867 Commit-Queue: Andreas Haas <[email protected]> Reviewed-by: Ross McIlroy <[email protected]> Cr-Commit-Position: refs/heads/master@{nodejs#49366} Refs: v8/v8@98c40a4 PR-URL: nodejs#17134 Fixes: nodejs/node-v8#24 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
Original commit message: [platform] Add TaskRunner to the platform API With the existing platform API it is not possible to post foreground tasks from background tasks. This is, however, required to implement asynchronous compilation for WebAssembly. With this CL we add the concept of a TaskRunner to the platform API. The TaskRunner contains all data needed to post a foreground task and can be used both from a foreground task and a background task. Eventually the TaskRunner should replace the existing API. In addition, this CL contains a default implementation of the TaskRunner. This implementation has tempory workaround for platforms which do not provide a TaskRunner implementation yet. This default implementation should be deleted again when all platforms provide a TaskRunner implementation. [email protected] Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: I6ea4a1c9da1eb9a19e8ce8f2163000dbc2598802 Reviewed-on: https://chromium-review.googlesource.com/741588 Commit-Queue: Andreas Haas <[email protected]> Reviewed-by: Ross McIlroy <[email protected]> Cr-Commit-Position: refs/heads/master@{#49041} Refs: v8/v8@c690f54 PR-URL: #17134 Fixes: nodejs/node-v8#24 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
Original commit message: [platform] Return task runners as shared_ptr At the moment, task runners are returned as unique_ptr. This is inconvenient, however. In all implementations I did, the platform holds a shared pointer of the task runner and wraps it in a wrapper class just to return it as a unique_ptr. With this CL the platform API is changed to return a shared_ptr directly. [email protected] Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: Ide278db855199ea239ad0ae14d97fd17349dac8c Reviewed-on: https://chromium-review.googlesource.com/768867 Commit-Queue: Andreas Haas <[email protected]> Reviewed-by: Ross McIlroy <[email protected]> Cr-Commit-Position: refs/heads/master@{#49366} Refs: v8/v8@98c40a4 PR-URL: #17134 Fixes: nodejs/node-v8#24 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
Original commit message: [platform] Add TaskRunner to the platform API With the existing platform API it is not possible to post foreground tasks from background tasks. This is, however, required to implement asynchronous compilation for WebAssembly. With this CL we add the concept of a TaskRunner to the platform API. The TaskRunner contains all data needed to post a foreground task and can be used both from a foreground task and a background task. Eventually the TaskRunner should replace the existing API. In addition, this CL contains a default implementation of the TaskRunner. This implementation has tempory workaround for platforms which do not provide a TaskRunner implementation yet. This default implementation should be deleted again when all platforms provide a TaskRunner implementation. [email protected] Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: I6ea4a1c9da1eb9a19e8ce8f2163000dbc2598802 Reviewed-on: https://chromium-review.googlesource.com/741588 Commit-Queue: Andreas Haas <[email protected]> Reviewed-by: Ross McIlroy <[email protected]> Cr-Commit-Position: refs/heads/master@{#49041} Refs: v8/v8@c690f54 PR-URL: #17134 Fixes: nodejs/node-v8#24 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
Original commit message: [platform] Return task runners as shared_ptr At the moment, task runners are returned as unique_ptr. This is inconvenient, however. In all implementations I did, the platform holds a shared pointer of the task runner and wraps it in a wrapper class just to return it as a unique_ptr. With this CL the platform API is changed to return a shared_ptr directly. [email protected] Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: Ide278db855199ea239ad0ae14d97fd17349dac8c Reviewed-on: https://chromium-review.googlesource.com/768867 Commit-Queue: Andreas Haas <[email protected]> Reviewed-by: Ross McIlroy <[email protected]> Cr-Commit-Position: refs/heads/master@{#49366} Refs: v8/v8@98c40a4 PR-URL: #17134 Fixes: nodejs/node-v8#24 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
V8 is switching APIs for scheduling tasks. Implement the new APIs. Fixes: nodejs/node-v8#24 Refs: v8/v8@c690f54 PR-URL: #17134 Fixes: nodejs/node-v8#24 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
V8 is switching APIs for scheduling tasks. Implement the new APIs. Fixes: nodejs/node-v8#24 Refs: v8/v8@c690f54 PR-URL: nodejs#17134 Fixes: nodejs/node-v8#24 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
V8 is switching APIs for scheduling tasks. Implement the new APIs.
Fixes: nodejs/node-v8#24
Refs: v8/v8@c690f54
Note: This cherry-picks the API change itself (which is scheduled for V8 6.4) into this branch. We can wait for that release to perform the change if we like, but I’m not sure how we’d do node-canary coverage without this?
/cc @nodejs/v8 @gahaas
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
src/node_platform
CI: https://ci.nodejs.org/job/node-test-commit/14146/CI: https://ci.nodejs.org/job/node-test-commit/14147/