diff options
Diffstat (limited to 'deps/v8/test/cctest/wasm/test-wasm-shared-engine.cc')
-rw-r--r-- | deps/v8/test/cctest/wasm/test-wasm-shared-engine.cc | 116 |
1 files changed, 57 insertions, 59 deletions
diff --git a/deps/v8/test/cctest/wasm/test-wasm-shared-engine.cc b/deps/v8/test/cctest/wasm/test-wasm-shared-engine.cc index b5bacf57d4..2d6e930397 100644 --- a/deps/v8/test/cctest/wasm/test-wasm-shared-engine.cc +++ b/deps/v8/test/cctest/wasm/test-wasm-shared-engine.cc @@ -27,7 +27,7 @@ namespace test_wasm_shared_engine { class SharedEngine { public: explicit SharedEngine(size_t max_committed = kMaxWasmCodeMemory) - : wasm_engine_(base::make_unique<WasmEngine>()) {} + : wasm_engine_(std::make_unique<WasmEngine>()) {} ~SharedEngine() { // Ensure no remaining uses exist. CHECK(wasm_engine_.unique()); @@ -112,19 +112,19 @@ class SharedEngineIsolate { class SharedEngineThread : public v8::base::Thread { public: SharedEngineThread(SharedEngine* engine, - std::function<void(SharedEngineIsolate&)> callback) + std::function<void(SharedEngineIsolate*)> callback) : Thread(Options("SharedEngineThread")), engine_(engine), callback_(callback) {} void Run() override { SharedEngineIsolate isolate(engine_); - callback_(isolate); + callback_(&isolate); } private: SharedEngine* engine_; - std::function<void(SharedEngineIsolate&)> callback_; + std::function<void(SharedEngineIsolate*)> callback_; }; namespace { @@ -159,43 +159,39 @@ class MockInstantiationResolver : public InstantiationResultResolver { class MockCompilationResolver : public CompilationResultResolver { public: - MockCompilationResolver( - SharedEngineIsolate& isolate, // NOLINT(runtime/references) - Handle<Object>* out_instance) + MockCompilationResolver(SharedEngineIsolate* isolate, + Handle<Object>* out_instance) : isolate_(isolate), out_instance_(out_instance) {} void OnCompilationSucceeded(Handle<WasmModuleObject> result) override { - isolate_.isolate()->wasm_engine()->AsyncInstantiate( - isolate_.isolate(), - base::make_unique<MockInstantiationResolver>(out_instance_), result, - {}); + isolate_->isolate()->wasm_engine()->AsyncInstantiate( + isolate_->isolate(), + std::make_unique<MockInstantiationResolver>(out_instance_), result, {}); } void OnCompilationFailed(Handle<Object> error_reason) override { UNREACHABLE(); } private: - SharedEngineIsolate& isolate_; + SharedEngineIsolate* isolate_; Handle<Object>* out_instance_; }; -void PumpMessageLoop( - SharedEngineIsolate& isolate) { // NOLINT(runtime/references) +void PumpMessageLoop(SharedEngineIsolate* isolate) { v8::platform::PumpMessageLoop(i::V8::GetCurrentPlatform(), - isolate.v8_isolate(), + isolate->v8_isolate(), platform::MessageLoopBehavior::kWaitForWork); - isolate.isolate()->default_microtask_queue()->RunMicrotasks( - isolate.isolate()); + isolate->isolate()->default_microtask_queue()->RunMicrotasks( + isolate->isolate()); } Handle<WasmInstanceObject> CompileAndInstantiateAsync( - SharedEngineIsolate& isolate, // NOLINT(runtime/references) - ZoneBuffer* buffer) { - Handle<Object> maybe_instance = handle(Smi::kZero, isolate.isolate()); - auto enabled_features = WasmFeaturesFromIsolate(isolate.isolate()); + SharedEngineIsolate* isolate, ZoneBuffer* buffer) { + Handle<Object> maybe_instance = handle(Smi::kZero, isolate->isolate()); + auto enabled_features = WasmFeaturesFromIsolate(isolate->isolate()); constexpr const char* kAPIMethodName = "Test.CompileAndInstantiateAsync"; - isolate.isolate()->wasm_engine()->AsyncCompile( - isolate.isolate(), enabled_features, - base::make_unique<MockCompilationResolver>(isolate, &maybe_instance), + isolate->isolate()->wasm_engine()->AsyncCompile( + isolate->isolate(), enabled_features, + std::make_unique<MockCompilationResolver>(isolate, &maybe_instance), ModuleWireBytes(buffer->begin(), buffer->end()), true, kAPIMethodName); while (!maybe_instance->IsWasmInstanceObject()) PumpMessageLoop(isolate); Handle<WasmInstanceObject> instance = @@ -261,17 +257,19 @@ TEST(SharedEngineRunImported) { TEST(SharedEngineRunThreadedBuildingSync) { SharedEngine engine; - SharedEngineThread thread1(&engine, [](SharedEngineIsolate& isolate) { - HandleScope scope(isolate.isolate()); - ZoneBuffer* buffer = BuildReturnConstantModule(isolate.zone(), 23); - Handle<WasmInstanceObject> instance = isolate.CompileAndInstantiate(buffer); - CHECK_EQ(23, isolate.Run(instance)); + SharedEngineThread thread1(&engine, [](SharedEngineIsolate* isolate) { + HandleScope scope(isolate->isolate()); + ZoneBuffer* buffer = BuildReturnConstantModule(isolate->zone(), 23); + Handle<WasmInstanceObject> instance = + isolate->CompileAndInstantiate(buffer); + CHECK_EQ(23, isolate->Run(instance)); }); - SharedEngineThread thread2(&engine, [](SharedEngineIsolate& isolate) { - HandleScope scope(isolate.isolate()); - ZoneBuffer* buffer = BuildReturnConstantModule(isolate.zone(), 42); - Handle<WasmInstanceObject> instance = isolate.CompileAndInstantiate(buffer); - CHECK_EQ(42, isolate.Run(instance)); + SharedEngineThread thread2(&engine, [](SharedEngineIsolate* isolate) { + HandleScope scope(isolate->isolate()); + ZoneBuffer* buffer = BuildReturnConstantModule(isolate->zone(), 42); + Handle<WasmInstanceObject> instance = + isolate->CompileAndInstantiate(buffer); + CHECK_EQ(42, isolate->Run(instance)); }); CHECK(thread1.Start()); CHECK(thread2.Start()); @@ -281,19 +279,19 @@ TEST(SharedEngineRunThreadedBuildingSync) { TEST(SharedEngineRunThreadedBuildingAsync) { SharedEngine engine; - SharedEngineThread thread1(&engine, [](SharedEngineIsolate& isolate) { - HandleScope scope(isolate.isolate()); - ZoneBuffer* buffer = BuildReturnConstantModule(isolate.zone(), 23); + SharedEngineThread thread1(&engine, [](SharedEngineIsolate* isolate) { + HandleScope scope(isolate->isolate()); + ZoneBuffer* buffer = BuildReturnConstantModule(isolate->zone(), 23); Handle<WasmInstanceObject> instance = CompileAndInstantiateAsync(isolate, buffer); - CHECK_EQ(23, isolate.Run(instance)); + CHECK_EQ(23, isolate->Run(instance)); }); - SharedEngineThread thread2(&engine, [](SharedEngineIsolate& isolate) { - HandleScope scope(isolate.isolate()); - ZoneBuffer* buffer = BuildReturnConstantModule(isolate.zone(), 42); + SharedEngineThread thread2(&engine, [](SharedEngineIsolate* isolate) { + HandleScope scope(isolate->isolate()); + ZoneBuffer* buffer = BuildReturnConstantModule(isolate->zone(), 42); Handle<WasmInstanceObject> instance = CompileAndInstantiateAsync(isolate, buffer); - CHECK_EQ(42, isolate.Run(instance)); + CHECK_EQ(42, isolate->Run(instance)); }); CHECK(thread1.Start()); CHECK(thread2.Start()); @@ -311,15 +309,15 @@ TEST(SharedEngineRunThreadedExecution) { Handle<WasmInstanceObject> instance = isolate.CompileAndInstantiate(buffer); module = isolate.ExportInstance(instance); } - SharedEngineThread thread1(&engine, [module](SharedEngineIsolate& isolate) { - HandleScope scope(isolate.isolate()); - Handle<WasmInstanceObject> instance = isolate.ImportInstance(module); - CHECK_EQ(23, isolate.Run(instance)); + SharedEngineThread thread1(&engine, [module](SharedEngineIsolate* isolate) { + HandleScope scope(isolate->isolate()); + Handle<WasmInstanceObject> instance = isolate->ImportInstance(module); + CHECK_EQ(23, isolate->Run(instance)); }); - SharedEngineThread thread2(&engine, [module](SharedEngineIsolate& isolate) { - HandleScope scope(isolate.isolate()); - Handle<WasmInstanceObject> instance = isolate.ImportInstance(module); - CHECK_EQ(23, isolate.Run(instance)); + SharedEngineThread thread2(&engine, [module](SharedEngineIsolate* isolate) { + HandleScope scope(isolate->isolate()); + Handle<WasmInstanceObject> instance = isolate->ImportInstance(module); + CHECK_EQ(23, isolate->Run(instance)); }); CHECK(thread1.Start()); CHECK(thread2.Start()); @@ -340,23 +338,23 @@ TEST(SharedEngineRunThreadedTierUp) { constexpr int kNumberOfThreads = 5; std::list<SharedEngineThread> threads; for (int i = 0; i < kNumberOfThreads; ++i) { - threads.emplace_back(&engine, [module](SharedEngineIsolate& isolate) { + threads.emplace_back(&engine, [module](SharedEngineIsolate* isolate) { constexpr int kNumberOfIterations = 100; - HandleScope scope(isolate.isolate()); - Handle<WasmInstanceObject> instance = isolate.ImportInstance(module); + HandleScope scope(isolate->isolate()); + Handle<WasmInstanceObject> instance = isolate->ImportInstance(module); for (int j = 0; j < kNumberOfIterations; ++j) { - CHECK_EQ(23, isolate.Run(instance)); + CHECK_EQ(23, isolate->Run(instance)); } }); } - threads.emplace_back(&engine, [module](SharedEngineIsolate& isolate) { - HandleScope scope(isolate.isolate()); - Handle<WasmInstanceObject> instance = isolate.ImportInstance(module); + threads.emplace_back(&engine, [module](SharedEngineIsolate* isolate) { + HandleScope scope(isolate->isolate()); + Handle<WasmInstanceObject> instance = isolate->ImportInstance(module); WasmFeatures detected = kNoWasmFeatures; WasmCompilationUnit::CompileWasmFunction( - isolate.isolate(), module.get(), &detected, + isolate->isolate(), module.get(), &detected, &module->module()->functions[0], ExecutionTier::kTurbofan); - CHECK_EQ(23, isolate.Run(instance)); + CHECK_EQ(23, isolate->Run(instance)); }); for (auto& thread : threads) CHECK(thread.Start()); for (auto& thread : threads) thread.Join(); |