compilation-manager.cc 1.72 KB
Newer Older
1 2 3 4 5
// 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"
6
#include "src/base/template-utils.h"
7 8 9 10 11 12 13

#include "src/objects-inl.h"

namespace v8 {
namespace internal {
namespace wasm {

14
AsyncCompileJob* CompilationManager::CreateAsyncCompileJob(
15 16 17 18 19
    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});
20 21 22 23 24 25 26 27
  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);
28 29 30
  job->Start();
}

31 32 33 34 35 36 37 38 39 40 41 42 43 44
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;
45 46 47 48 49 50 51
}

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

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