OLD | NEW |
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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "src/base/atomic-utils.h" | 7 #include "src/base/atomic-utils.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 | 9 |
10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
(...skipping 1366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 ProcessExports(globals, code_table, instance); | 1377 ProcessExports(globals, code_table, instance); |
1378 | 1378 |
1379 if (num_imported_functions > 0 || !owner.is_null()) { | 1379 if (num_imported_functions > 0 || !owner.is_null()) { |
1380 // If the code was cloned, or new imports were compiled, patch. | 1380 // If the code was cloned, or new imports were compiled, patch. |
1381 PatchDirectCalls(old_code_table, code_table, num_imported_functions); | 1381 PatchDirectCalls(old_code_table, code_table, num_imported_functions); |
1382 } | 1382 } |
1383 | 1383 |
1384 FlushICache(isolate_, code_table); | 1384 FlushICache(isolate_, code_table); |
1385 | 1385 |
1386 //-------------------------------------------------------------------------- | 1386 //-------------------------------------------------------------------------- |
1387 // Run the start function if one was specified. | 1387 // Set up and link the new instance. |
1388 //-------------------------------------------------------------------------- | 1388 //-------------------------------------------------------------------------- |
1389 if (compiled_module_->has_startup_function()) { | |
1390 Handle<FixedArray> startup_data = compiled_module_->startup_function(); | |
1391 HandleScope scope(isolate_); | |
1392 int32_t start_index = | |
1393 startup_data->GetValueChecked<Smi>(isolate_, kExportIndex)->value(); | |
1394 Handle<Code> startup_code = | |
1395 code_table->GetValueChecked<Code>(isolate_, start_index); | |
1396 int arity = Smi::cast(startup_data->get(kExportArity))->value(); | |
1397 MaybeHandle<ByteArray> startup_signature = | |
1398 startup_data->GetValue<ByteArray>(isolate_, kExportedSignature); | |
1399 Handle<JSFunction> startup_fct = WrapExportCodeAsJSFunction( | |
1400 isolate_, startup_code, factory->InternalizeUtf8String("start"), | |
1401 arity, startup_signature, instance); | |
1402 RecordStats(isolate_, *startup_code); | |
1403 // Call the JS function. | |
1404 Handle<Object> undefined = factory->undefined_value(); | |
1405 MaybeHandle<Object> retval = | |
1406 Execution::Call(isolate_, startup_fct, undefined, 0, nullptr); | |
1407 | |
1408 if (retval.is_null()) { | |
1409 thrower_->Error("WASM.instantiateModule(): start function failed"); | |
1410 return nothing; | |
1411 } | |
1412 } | |
1413 | |
1414 { | 1389 { |
1415 Handle<Object> global_handle = | 1390 Handle<Object> global_handle = |
1416 isolate_->global_handles()->Create(*instance); | 1391 isolate_->global_handles()->Create(*instance); |
1417 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_); | 1392 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_); |
1418 Handle<WeakCell> link_to_owning_instance = factory->NewWeakCell(instance); | 1393 Handle<WeakCell> link_to_owning_instance = factory->NewWeakCell(instance); |
1419 MaybeHandle<WeakCell> link_to_original; | 1394 MaybeHandle<WeakCell> link_to_original; |
1420 MaybeHandle<WasmCompiledModule> original; | 1395 MaybeHandle<WasmCompiledModule> original; |
1421 if (!owner.is_null()) { | 1396 if (!owner.is_null()) { |
1422 // prepare the data needed for publishing in a chain, but don't link | 1397 // prepare the data needed for publishing in a chain, but don't link |
1423 // just yet, because | 1398 // just yet, because |
(...skipping 15 matching lines...) Expand all Loading... |
1439 } | 1414 } |
1440 module_object_->SetInternalField(0, *compiled_module_); | 1415 module_object_->SetInternalField(0, *compiled_module_); |
1441 instance->SetInternalField(kWasmCompiledModule, *compiled_module_); | 1416 instance->SetInternalField(kWasmCompiledModule, *compiled_module_); |
1442 compiled_module_->set_weak_owning_instance(link_to_owning_instance); | 1417 compiled_module_->set_weak_owning_instance(link_to_owning_instance); |
1443 GlobalHandles::MakeWeak(global_handle.location(), | 1418 GlobalHandles::MakeWeak(global_handle.location(), |
1444 global_handle.location(), &InstanceFinalizer, | 1419 global_handle.location(), &InstanceFinalizer, |
1445 v8::WeakCallbackType::kFinalizer); | 1420 v8::WeakCallbackType::kFinalizer); |
1446 } | 1421 } |
1447 } | 1422 } |
1448 | 1423 |
| 1424 //-------------------------------------------------------------------------- |
| 1425 // Run the start function if one was specified. |
| 1426 //-------------------------------------------------------------------------- |
| 1427 if (compiled_module_->has_startup_function()) { |
| 1428 Handle<FixedArray> startup_data = compiled_module_->startup_function(); |
| 1429 HandleScope scope(isolate_); |
| 1430 int32_t start_index = |
| 1431 startup_data->GetValueChecked<Smi>(isolate_, kExportIndex)->value(); |
| 1432 Handle<Code> startup_code = |
| 1433 code_table->GetValueChecked<Code>(isolate_, start_index); |
| 1434 int arity = Smi::cast(startup_data->get(kExportArity))->value(); |
| 1435 MaybeHandle<ByteArray> startup_signature = |
| 1436 startup_data->GetValue<ByteArray>(isolate_, kExportedSignature); |
| 1437 Handle<JSFunction> startup_fct = WrapExportCodeAsJSFunction( |
| 1438 isolate_, startup_code, factory->InternalizeUtf8String("start"), |
| 1439 arity, startup_signature, instance); |
| 1440 RecordStats(isolate_, *startup_code); |
| 1441 // Call the JS function. |
| 1442 Handle<Object> undefined = factory->undefined_value(); |
| 1443 MaybeHandle<Object> retval = |
| 1444 Execution::Call(isolate_, startup_fct, undefined, 0, nullptr); |
| 1445 |
| 1446 if (retval.is_null()) { |
| 1447 thrower_->Error("WASM.instantiateModule(): start function failed"); |
| 1448 // It's unfortunate that the new instance is already linked in the |
| 1449 // chain. However, we need to set up everything before executing the |
| 1450 // start function, such that stack trace information can be generated |
| 1451 // correctly already in the start function. |
| 1452 return nothing; |
| 1453 } |
| 1454 } |
| 1455 |
1449 DCHECK(wasm::IsWasmObject(*instance)); | 1456 DCHECK(wasm::IsWasmObject(*instance)); |
1450 | 1457 |
1451 TRACE("Finishing instance %d\n", compiled_module_->instance_id()); | 1458 TRACE("Finishing instance %d\n", compiled_module_->instance_id()); |
1452 TRACE_CHAIN(WasmCompiledModule::cast(module_object_->GetInternalField(0))); | 1459 TRACE_CHAIN(WasmCompiledModule::cast(module_object_->GetInternalField(0))); |
1453 return instance; | 1460 return instance; |
1454 } | 1461 } |
1455 | 1462 |
1456 private: | 1463 private: |
1457 Isolate* isolate_; | 1464 Isolate* isolate_; |
1458 ErrorThrower* thrower_; | 1465 ErrorThrower* thrower_; |
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2313 CHECK(IsWasmObject(*instance)); | 2320 CHECK(IsWasmObject(*instance)); |
2314 WasmCompiledModule* compiled_module = GetCompiledModule(*instance); | 2321 WasmCompiledModule* compiled_module = GetCompiledModule(*instance); |
2315 CHECK(compiled_module->has_weak_module_object()); | 2322 CHECK(compiled_module->has_weak_module_object()); |
2316 CHECK(compiled_module->ptr_to_weak_module_object()->cleared()); | 2323 CHECK(compiled_module->ptr_to_weak_module_object()->cleared()); |
2317 } | 2324 } |
2318 | 2325 |
2319 } // namespace testing | 2326 } // namespace testing |
2320 } // namespace wasm | 2327 } // namespace wasm |
2321 } // namespace internal | 2328 } // namespace internal |
2322 } // namespace v8 | 2329 } // namespace v8 |
OLD | NEW |