Commit f5ff422b authored by Mircea Trofin's avatar Mircea Trofin Committed by Commit Bot

[wasm] Ensure sync (forward) tasks execute in a context.

We need the job_'s context to reify errors, for example.
Some tasks already managed their context, so centralized
that logic in a SyncCompileTask all sync tasks derive from.

Bug: 
Change-Id: I90f462476b47bb8d5777db93d8dfb5c72fbd885b
Reviewed-on: https://chromium-review.googlesource.com/495392
Commit-Queue: Mircea Trofin <mtrofin@google.com>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45112}
parent d5878122
...@@ -2662,6 +2662,18 @@ class AsyncCompileJob { ...@@ -2662,6 +2662,18 @@ class AsyncCompileJob {
void Run() override = 0; // Force sub-classes to override Run(). void Run() override = 0; // Force sub-classes to override Run().
}; };
class SyncCompileTask : public CompileTask<SYNC> {
public:
void Run() final {
SaveContext saved_context(job_->isolate_);
job_->isolate_->set_context(*job_->context_);
RunImpl();
}
protected:
virtual void RunImpl() = 0;
};
template <typename Task, typename... Args> template <typename Task, typename... Args>
void DoSync(Args... args) { void DoSync(Args... args) {
static_assert(Task::type == SYNC, "Scheduled type must be sync"); static_assert(Task::type == SYNC, "Scheduled type must be sync");
...@@ -2710,13 +2722,13 @@ class AsyncCompileJob { ...@@ -2710,13 +2722,13 @@ class AsyncCompileJob {
//========================================================================== //==========================================================================
// Step 1b: (sync) Fail decoding the module. // Step 1b: (sync) Fail decoding the module.
//========================================================================== //==========================================================================
class DecodeFail : public CompileTask<SYNC> { class DecodeFail : public SyncCompileTask {
public: public:
explicit DecodeFail(ModuleResult result) : result_(std::move(result)) {} explicit DecodeFail(ModuleResult result) : result_(std::move(result)) {}
private: private:
ModuleResult result_; ModuleResult result_;
void Run() override { void RunImpl() override {
TRACE_COMPILE("(1b) Decoding failed.\n"); TRACE_COMPILE("(1b) Decoding failed.\n");
HandleScope scope(job_->isolate_); HandleScope scope(job_->isolate_);
ErrorThrower thrower(job_->isolate_, "AsyncCompile"); ErrorThrower thrower(job_->isolate_, "AsyncCompile");
...@@ -2729,8 +2741,8 @@ class AsyncCompileJob { ...@@ -2729,8 +2741,8 @@ class AsyncCompileJob {
//========================================================================== //==========================================================================
// Step 2 (sync): Create heap-allocated data and start compile. // Step 2 (sync): Create heap-allocated data and start compile.
//========================================================================== //==========================================================================
class PrepareAndStartCompile : public CompileTask<SYNC> { class PrepareAndStartCompile : public SyncCompileTask {
void Run() override { void RunImpl() override {
TRACE_COMPILE("(2) Prepare and start compile...\n"); TRACE_COMPILE("(2) Prepare and start compile...\n");
HandleScope scope(job_->isolate_); HandleScope scope(job_->isolate_);
...@@ -2846,8 +2858,8 @@ class AsyncCompileJob { ...@@ -2846,8 +2858,8 @@ class AsyncCompileJob {
//========================================================================== //==========================================================================
// Step 4 (sync x each function): Finish a single compilation unit. // Step 4 (sync x each function): Finish a single compilation unit.
//========================================================================== //==========================================================================
class FinishCompilationUnit : public CompileTask<SYNC> { class FinishCompilationUnit : public SyncCompileTask {
void Run() override { void RunImpl() override {
TRACE_COMPILE("(4a) Finishing compilation unit...\n"); TRACE_COMPILE("(4a) Finishing compilation unit...\n");
HandleScope scope(job_->isolate_); HandleScope scope(job_->isolate_);
if (job_->failed_) return; // already failed if (job_->failed_) return; // already failed
...@@ -2906,14 +2918,14 @@ class AsyncCompileJob { ...@@ -2906,14 +2918,14 @@ class AsyncCompileJob {
//========================================================================== //==========================================================================
// Step 5a (sync): Fail compilation (reject promise). // Step 5a (sync): Fail compilation (reject promise).
//========================================================================== //==========================================================================
class FailCompile : public CompileTask<SYNC> { class FailCompile : public SyncCompileTask {
public: public:
explicit FailCompile(ErrorThrower thrower) : thrower_(std::move(thrower)) {} explicit FailCompile(ErrorThrower thrower) : thrower_(std::move(thrower)) {}
private: private:
ErrorThrower thrower_; ErrorThrower thrower_;
void Run() override { void RunImpl() override {
TRACE_COMPILE("(5a) Fail compilation...\n"); TRACE_COMPILE("(5a) Fail compilation...\n");
HandleScope scope(job_->isolate_); HandleScope scope(job_->isolate_);
return job_->AsyncCompileFailed(thrower_); return job_->AsyncCompileFailed(thrower_);
...@@ -2923,12 +2935,10 @@ class AsyncCompileJob { ...@@ -2923,12 +2935,10 @@ class AsyncCompileJob {
//========================================================================== //==========================================================================
// Step 5b (sync): Finish heap-allocated data structures. // Step 5b (sync): Finish heap-allocated data structures.
//========================================================================== //==========================================================================
class FinishCompile : public CompileTask<SYNC> { class FinishCompile : public SyncCompileTask {
void Run() override { void RunImpl() override {
TRACE_COMPILE("(5b) Finish compile...\n"); TRACE_COMPILE("(5b) Finish compile...\n");
HandleScope scope(job_->isolate_); HandleScope scope(job_->isolate_);
SaveContext saved_context(job_->isolate_);
job_->isolate_->set_context(*job_->context_);
// At this point, compilation has completed. Update the code table. // At this point, compilation has completed. Update the code table.
for (size_t i = FLAG_skip_compiling_wasm_funcs; for (size_t i = FLAG_skip_compiling_wasm_funcs;
i < job_->temp_instance_->function_code.size(); ++i) { i < job_->temp_instance_->function_code.size(); ++i) {
...@@ -2987,8 +2997,8 @@ class AsyncCompileJob { ...@@ -2987,8 +2997,8 @@ class AsyncCompileJob {
//========================================================================== //==========================================================================
// Step 6 (sync): Compile JS->WASM wrappers. // Step 6 (sync): Compile JS->WASM wrappers.
//========================================================================== //==========================================================================
class CompileWrappers : public CompileTask<SYNC> { class CompileWrappers : public SyncCompileTask {
void Run() override { void RunImpl() override {
TRACE_COMPILE("(6) Compile wrappers...\n"); TRACE_COMPILE("(6) Compile wrappers...\n");
// Compile JS->WASM wrappers for exported functions. // Compile JS->WASM wrappers for exported functions.
HandleScope scope(job_->isolate_); HandleScope scope(job_->isolate_);
...@@ -3015,12 +3025,10 @@ class AsyncCompileJob { ...@@ -3015,12 +3025,10 @@ class AsyncCompileJob {
//========================================================================== //==========================================================================
// Step 7 (sync): Finish the module and resolve the promise. // Step 7 (sync): Finish the module and resolve the promise.
//========================================================================== //==========================================================================
class FinishModule : public CompileTask<SYNC> { class FinishModule : public SyncCompileTask {
void Run() override { void RunImpl() override {
TRACE_COMPILE("(7) Finish module...\n"); TRACE_COMPILE("(7) Finish module...\n");
HandleScope scope(job_->isolate_); HandleScope scope(job_->isolate_);
SaveContext saved_context(job_->isolate_);
job_->isolate_->set_context(*job_->context_);
Handle<WasmModuleObject> result = Handle<WasmModuleObject> result =
WasmModuleObject::New(job_->isolate_, job_->compiled_module_); WasmModuleObject::New(job_->isolate_, job_->compiled_module_);
// {job_} is deleted in AsyncCompileSucceeded, therefore the {return}. // {job_} is deleted in AsyncCompileSucceeded, therefore the {return}.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment