summaryrefslogtreecommitdiff
path: root/deps/v8/src/wasm/compilation-manager.cc
blob: 4779a9f423728325c1342fb2f3f8c1661ca261a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/wasm/compilation-manager.h"
#include "src/base/template-utils.h"
#include "src/wasm/module-compiler.h"

#include "src/objects-inl.h"

namespace v8 {
namespace internal {
namespace wasm {

AsyncCompileJob* CompilationManager::CreateAsyncCompileJob(
    Isolate* isolate, std::unique_ptr<byte[]> bytes_copy, size_t length,
    Handle<Context> context, Handle<JSPromise> promise) {
  std::shared_ptr<AsyncCompileJob> job(new AsyncCompileJob(
      isolate, std::move(bytes_copy), length, context, promise));
  jobs_.insert({job.get(), job});
  return job.get();
}

void CompilationManager::StartAsyncCompileJob(
    Isolate* isolate, std::unique_ptr<byte[]> bytes_copy, size_t length,
    Handle<Context> context, Handle<JSPromise> promise) {
  AsyncCompileJob* job = CreateAsyncCompileJob(isolate, std::move(bytes_copy),
                                               length, context, promise);
  job->Start();
}

std::shared_ptr<StreamingDecoder> CompilationManager::StartStreamingCompilation(
    Isolate* isolate, Handle<Context> context, Handle<JSPromise> promise) {
  AsyncCompileJob* job = CreateAsyncCompileJob(
      isolate, std::unique_ptr<byte[]>(nullptr), 0, context, promise);
  return job->CreateStreamingDecoder();
}

std::shared_ptr<AsyncCompileJob> CompilationManager::RemoveJob(
    AsyncCompileJob* job) {
  auto item = jobs_.find(job);
  DCHECK(item != jobs_.end());
  std::shared_ptr<AsyncCompileJob> result = std::move(item->second);
  jobs_.erase(item);
  return result;
}

void CompilationManager::TearDown() { jobs_.clear(); }

void CompilationManager::AbortAllJobs() {
  // Iterate over a copy of {jobs_}, because {job->Abort} modifies {jobs_}.
  std::vector<AsyncCompileJob*> copy;

  for (auto entry : jobs_) copy.push_back(entry.first);

  for (auto job : copy) job->Abort();
}

}  // namespace wasm
}  // namespace internal
}  // namespace v8