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/assembler-inl.h" | 7 #include "src/assembler-inl.h" |
8 #include "src/base/adapters.h" | 8 #include "src/base/adapters.h" |
9 #include "src/base/atomic-utils.h" | 9 #include "src/base/atomic-utils.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
11 #include "src/compiler/wasm-compiler.h" | 11 #include "src/compiler/wasm-compiler.h" |
12 #include "src/debug/interface-types.h" | 12 #include "src/debug/interface-types.h" |
13 #include "src/objects.h" | 13 #include "src/objects.h" |
14 #include "src/property-descriptor.h" | 14 #include "src/property-descriptor.h" |
15 #include "src/simulator.h" | 15 #include "src/simulator.h" |
16 #include "src/snapshot/snapshot.h" | 16 #include "src/snapshot/snapshot.h" |
| 17 #include "src/trap-handler/trap-handler.h" |
17 #include "src/v8.h" | 18 #include "src/v8.h" |
18 | 19 |
19 #include "src/wasm/function-body-decoder.h" | 20 #include "src/wasm/function-body-decoder.h" |
20 #include "src/wasm/module-decoder.h" | 21 #include "src/wasm/module-decoder.h" |
21 #include "src/wasm/wasm-js.h" | 22 #include "src/wasm/wasm-js.h" |
22 #include "src/wasm/wasm-limits.h" | 23 #include "src/wasm/wasm-limits.h" |
23 #include "src/wasm/wasm-module.h" | 24 #include "src/wasm/wasm-module.h" |
24 #include "src/wasm/wasm-objects.h" | 25 #include "src/wasm/wasm-objects.h" |
25 #include "src/wasm/wasm-result.h" | 26 #include "src/wasm/wasm-result.h" |
26 | 27 |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 WasmInstanceObject* owner = reinterpret_cast<WasmInstanceObject*>(*p); | 594 WasmInstanceObject* owner = reinterpret_cast<WasmInstanceObject*>(*p); |
594 Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate()); | 595 Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate()); |
595 // If a link to shared memory instances exists, update the list of memory | 596 // If a link to shared memory instances exists, update the list of memory |
596 // instances before the instance is destroyed. | 597 // instances before the instance is destroyed. |
597 if (owner->has_instance_wrapper()) MemoryInstanceFinalizer(isolate, owner); | 598 if (owner->has_instance_wrapper()) MemoryInstanceFinalizer(isolate, owner); |
598 WasmCompiledModule* compiled_module = owner->compiled_module(); | 599 WasmCompiledModule* compiled_module = owner->compiled_module(); |
599 TRACE("Finalizing %d {\n", compiled_module->instance_id()); | 600 TRACE("Finalizing %d {\n", compiled_module->instance_id()); |
600 DCHECK(compiled_module->has_weak_wasm_module()); | 601 DCHECK(compiled_module->has_weak_wasm_module()); |
601 WeakCell* weak_wasm_module = compiled_module->ptr_to_weak_wasm_module(); | 602 WeakCell* weak_wasm_module = compiled_module->ptr_to_weak_wasm_module(); |
602 | 603 |
| 604 if (trap_handler::EnableTrapHandler()) { |
| 605 Handle<FixedArray> code_table = compiled_module->code_table(); |
| 606 for (int i = 0; i < code_table->length(); ++i) { |
| 607 Handle<Code> code = code_table->GetValueChecked<Code>(isolate, i); |
| 608 int index = code->trap_handler_index()->value(); |
| 609 if (index >= 0) { |
| 610 trap_handler::ReleaseHandlerData(index); |
| 611 } |
| 612 } |
| 613 } |
| 614 |
603 // weak_wasm_module may have been cleared, meaning the module object | 615 // weak_wasm_module may have been cleared, meaning the module object |
604 // was GC-ed. In that case, there won't be any new instances created, | 616 // was GC-ed. In that case, there won't be any new instances created, |
605 // and we don't need to maintain the links between instances. | 617 // and we don't need to maintain the links between instances. |
606 if (!weak_wasm_module->cleared()) { | 618 if (!weak_wasm_module->cleared()) { |
607 JSObject* wasm_module = JSObject::cast(weak_wasm_module->value()); | 619 JSObject* wasm_module = JSObject::cast(weak_wasm_module->value()); |
608 WasmCompiledModule* current_template = | 620 WasmCompiledModule* current_template = |
609 WasmCompiledModule::cast(wasm_module->GetInternalField(0)); | 621 WasmCompiledModule::cast(wasm_module->GetInternalField(0)); |
610 | 622 |
611 TRACE("chain before {\n"); | 623 TRACE("chain before {\n"); |
612 TRACE_CHAIN(current_template); | 624 TRACE_CHAIN(current_template); |
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 data.instr_offset = | 1343 data.instr_offset = |
1332 protected_instructions | 1344 protected_instructions |
1333 ->GetValueChecked<Smi>(isolate_, i + Code::kTrapCodeOffset) | 1345 ->GetValueChecked<Smi>(isolate_, i + Code::kTrapCodeOffset) |
1334 ->value(); | 1346 ->value(); |
1335 data.landing_offset = | 1347 data.landing_offset = |
1336 protected_instructions | 1348 protected_instructions |
1337 ->GetValueChecked<Smi>(isolate_, i + Code::kTrapLandingOffset) | 1349 ->GetValueChecked<Smi>(isolate_, i + Code::kTrapLandingOffset) |
1338 ->value(); | 1350 ->value(); |
1339 unpacked.emplace_back(data); | 1351 unpacked.emplace_back(data); |
1340 } | 1352 } |
1341 // TODO(eholk): Register the protected instruction information once the | 1353 if (unpacked.size() > 0) { |
1342 // trap handler is in place. | 1354 Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i); |
| 1355 byte* base = code->entry(); |
| 1356 int size = code->CodeSize(); |
| 1357 const int index = |
| 1358 RegisterHandlerData(reinterpret_cast<void*>(base), size, |
| 1359 unpacked.size(), &unpacked[0]); |
| 1360 // TODO(eholk): if index is negative, fail. |
| 1361 DCHECK(index >= 0); |
| 1362 code->set_trap_handler_index(Smi::FromInt(index)); |
| 1363 } |
1343 } | 1364 } |
1344 } | 1365 } |
1345 | 1366 |
1346 //-------------------------------------------------------------------------- | 1367 //-------------------------------------------------------------------------- |
1347 // Set up and link the new instance. | 1368 // Set up and link the new instance. |
1348 //-------------------------------------------------------------------------- | 1369 //-------------------------------------------------------------------------- |
1349 { | 1370 { |
1350 Handle<Object> global_handle = | 1371 Handle<Object> global_handle = |
1351 isolate_->global_handles()->Create(*instance); | 1372 isolate_->global_handles()->Create(*instance); |
1352 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_); | 1373 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_); |
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2457 | 2478 |
2458 JSObject::AddProperty(entry, name_string, export_name.ToHandleChecked(), | 2479 JSObject::AddProperty(entry, name_string, export_name.ToHandleChecked(), |
2459 NONE); | 2480 NONE); |
2460 JSObject::AddProperty(entry, kind_string, export_kind, NONE); | 2481 JSObject::AddProperty(entry, kind_string, export_kind, NONE); |
2461 | 2482 |
2462 storage->set(index, *entry); | 2483 storage->set(index, *entry); |
2463 } | 2484 } |
2464 | 2485 |
2465 return array_object; | 2486 return array_object; |
2466 } | 2487 } |
OLD | NEW |