Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Side by Side Diff: test/cctest/wasm/test-run-wasm-module.cc

Issue 2695813005: [wasm] Split the compilation and instantiation API into sync and async methods. (Closed)
Patch Set: [wasm] Split the compilation and instantiation API into sync and async methods. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | test/common/wasm/wasm-module-runner.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 7
8 #include "src/objects-inl.h" 8 #include "src/objects-inl.h"
9 #include "src/snapshot/code-serializer.h" 9 #include "src/snapshot/code-serializer.h"
10 #include "src/version.h" 10 #include "src/version.h"
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 { 264 {
265 DisallowHeapAllocation assume_no_gc; 265 DisallowHeapAllocation assume_no_gc;
266 Handle<WasmCompiledModule> compiled_part( 266 Handle<WasmCompiledModule> compiled_part(
267 WasmCompiledModule::cast(module_object->GetInternalField(0)), 267 WasmCompiledModule::cast(module_object->GetInternalField(0)),
268 current_isolate()); 268 current_isolate());
269 CHECK_EQ(memcmp(compiled_part->module_bytes()->GetCharsAddress(), 269 CHECK_EQ(memcmp(compiled_part->module_bytes()->GetCharsAddress(),
270 wire_bytes().first, wire_bytes().second), 270 wire_bytes().first, wire_bytes().second),
271 0); 271 0);
272 } 272 }
273 Handle<JSObject> instance = 273 Handle<JSObject> instance =
274 WasmModule::Instantiate(current_isolate(), &thrower, module_object, 274 SyncInstantiate(current_isolate(), &thrower, module_object,
275 Handle<JSReceiver>::null(), 275 Handle<JSReceiver>::null(),
276 Handle<JSArrayBuffer>::null()) 276 MaybeHandle<JSArrayBuffer>())
277 .ToHandleChecked(); 277 .ToHandleChecked();
278 Handle<Object> params[1] = { 278 Handle<Object> params[1] = {
279 Handle<Object>(Smi::FromInt(41), current_isolate())}; 279 Handle<Object>(Smi::FromInt(41), current_isolate())};
280 int32_t result = testing::CallWasmFunctionForTesting( 280 int32_t result = testing::CallWasmFunctionForTesting(
281 current_isolate(), instance, &thrower, kFunctionName, 1, params, 281 current_isolate(), instance, &thrower, kFunctionName, 1, params,
282 ModuleOrigin::kWasmOrigin); 282 ModuleOrigin::kWasmOrigin);
283 CHECK(result == 42); 283 CHECK(result == 42);
284 } 284 }
285 285
286 Isolate* current_isolate() { 286 Isolate* current_isolate() {
(...skipping 24 matching lines...) Expand all
311 WasmSerializationTest::BuildWireBytes(zone(), &buffer); 311 WasmSerializationTest::BuildWireBytes(zone(), &buffer);
312 312
313 Isolate* serialization_isolate = CcTest::InitIsolateOnce(); 313 Isolate* serialization_isolate = CcTest::InitIsolateOnce();
314 ErrorThrower thrower(serialization_isolate, ""); 314 ErrorThrower thrower(serialization_isolate, "");
315 uint8_t* bytes = nullptr; 315 uint8_t* bytes = nullptr;
316 size_t bytes_size = 0; 316 size_t bytes_size = 0;
317 { 317 {
318 HandleScope scope(serialization_isolate); 318 HandleScope scope(serialization_isolate);
319 testing::SetupIsolateForWasmModule(serialization_isolate); 319 testing::SetupIsolateForWasmModule(serialization_isolate);
320 320
321 ModuleResult decoding_result = 321 MaybeHandle<WasmModuleObject> module_object =
322 DecodeWasmModule(serialization_isolate, buffer.begin(), buffer.end(), 322 SyncCompile(serialization_isolate, &thrower,
323 false, kWasmOrigin); 323 ModuleWireBytes(buffer.begin(), buffer.end()));
324 CHECK(!decoding_result.failed());
325 324
326 Handle<WasmModuleWrapper> module_wrapper = WasmModuleWrapper::New( 325 MaybeHandle<WasmCompiledModule> compiled_module(
327 serialization_isolate, const_cast<WasmModule*>(decoding_result.val)); 326 module_object.ToHandleChecked()->compiled_module(),
328 327 serialization_isolate);
329 MaybeHandle<WasmCompiledModule> compiled_module =
330 decoding_result.val->CompileFunctions(
331 serialization_isolate, module_wrapper, &thrower,
332 ModuleWireBytes(buffer.begin(), buffer.end()),
333 Handle<Script>::null(), Vector<const byte>::empty());
334 CHECK(!compiled_module.is_null()); 328 CHECK(!compiled_module.is_null());
335 Handle<JSObject> module_obj = WasmModuleObject::New( 329 Handle<JSObject> module_obj = WasmModuleObject::New(
336 serialization_isolate, compiled_module.ToHandleChecked()); 330 serialization_isolate, compiled_module.ToHandleChecked());
337 v8::Local<v8::Object> v8_module_obj = v8::Utils::ToLocal(module_obj); 331 v8::Local<v8::Object> v8_module_obj = v8::Utils::ToLocal(module_obj);
338 CHECK(v8_module_obj->IsWebAssemblyCompiledModule()); 332 CHECK(v8_module_obj->IsWebAssemblyCompiledModule());
339 333
340 v8::Local<v8::WasmCompiledModule> v8_compiled_module = 334 v8::Local<v8::WasmCompiledModule> v8_compiled_module =
341 v8_module_obj.As<v8::WasmCompiledModule>(); 335 v8_module_obj.As<v8::WasmCompiledModule>();
342 v8::Local<v8::String> uncompiled_bytes = 336 v8::Local<v8::String> uncompiled_bytes =
343 v8_compiled_module->GetWasmWireBytes(); 337 v8_compiled_module->GetWasmWireBytes();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 v8::internal::AccountingAllocator allocator; 424 v8::internal::AccountingAllocator allocator;
431 Zone zone(&allocator, ZONE_NAME); 425 Zone zone(&allocator, ZONE_NAME);
432 ZoneBuffer buffer(&zone); 426 ZoneBuffer buffer(&zone);
433 WasmSerializationTest::BuildWireBytes(&zone, &buffer); 427 WasmSerializationTest::BuildWireBytes(&zone, &buffer);
434 Isolate* isolate = CcTest::InitIsolateOnce(); 428 Isolate* isolate = CcTest::InitIsolateOnce();
435 HandleScope scope(isolate); 429 HandleScope scope(isolate);
436 testing::SetupIsolateForWasmModule(isolate); 430 testing::SetupIsolateForWasmModule(isolate);
437 CcTest::isolate()->SetAllowCodeGenerationFromStringsCallback(False); 431 CcTest::isolate()->SetAllowCodeGenerationFromStringsCallback(False);
438 432
439 ErrorThrower thrower(isolate, "block codegen"); 433 ErrorThrower thrower(isolate, "block codegen");
440 MaybeHandle<WasmModuleObject> ret = wasm::CreateModuleObjectFromBytes( 434 MaybeHandle<WasmModuleObject> ret = wasm::SyncCompile(
441 isolate, buffer.begin(), buffer.end(), &thrower, 435 isolate, &thrower, ModuleWireBytes(buffer.begin(), buffer.end()));
442 wasm::ModuleOrigin::kWasmOrigin, Handle<v8::internal::Script>::null(),
443 Vector<const byte>::empty());
444 CcTest::isolate()->SetAllowCodeGenerationFromStringsCallback(nullptr); 436 CcTest::isolate()->SetAllowCodeGenerationFromStringsCallback(nullptr);
445 CHECK(ret.is_null()); 437 CHECK(ret.is_null());
446 CHECK(thrower.error()); 438 CHECK(thrower.error());
447 } 439 }
448 440
449 TEST(BlockWasmCodeGenAtDeserialization) { 441 TEST(BlockWasmCodeGenAtDeserialization) {
450 WasmSerializationTest test; 442 WasmSerializationTest test;
451 { 443 {
452 HandleScope scope(test.current_isolate()); 444 HandleScope scope(test.current_isolate());
453 test.current_isolate_v8()->SetAllowCodeGenerationFromStringsCallback(False); 445 test.current_isolate_v8()->SetAllowCodeGenerationFromStringsCallback(False);
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 }; 948 };
957 949
958 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data, 950 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data,
959 data + arraysize(data), 951 data + arraysize(data),
960 ModuleOrigin::kWasmOrigin); 952 ModuleOrigin::kWasmOrigin);
961 // It should not be possible to instantiate this module. 953 // It should not be possible to instantiate this module.
962 CHECK(thrower.error()); 954 CHECK(thrower.error());
963 } 955 }
964 Cleanup(); 956 Cleanup();
965 } 957 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | test/common/wasm/wasm-module-runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698