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/asmjs/asm-wasm-builder.h" | 20 #include "src/asmjs/asm-wasm-builder.h" |
20 #include "src/wasm/function-body-decoder.h" | 21 #include "src/wasm/function-body-decoder.h" |
21 #include "src/wasm/module-decoder.h" | 22 #include "src/wasm/module-decoder.h" |
22 #include "src/wasm/wasm-js.h" | 23 #include "src/wasm/wasm-js.h" |
23 #include "src/wasm/wasm-limits.h" | 24 #include "src/wasm/wasm-limits.h" |
24 #include "src/wasm/wasm-module.h" | 25 #include "src/wasm/wasm-module.h" |
25 #include "src/wasm/wasm-objects.h" | 26 #include "src/wasm/wasm-objects.h" |
26 #include "src/wasm/wasm-result.h" | 27 #include "src/wasm/wasm-result.h" |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
651 WasmInstanceObject* owner = reinterpret_cast<WasmInstanceObject*>(*p); | 652 WasmInstanceObject* owner = reinterpret_cast<WasmInstanceObject*>(*p); |
652 Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate()); | 653 Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate()); |
653 // If a link to shared memory instances exists, update the list of memory | 654 // If a link to shared memory instances exists, update the list of memory |
654 // instances before the instance is destroyed. | 655 // instances before the instance is destroyed. |
655 if (owner->has_instance_wrapper()) MemoryInstanceFinalizer(isolate, owner); | 656 if (owner->has_instance_wrapper()) MemoryInstanceFinalizer(isolate, owner); |
656 WasmCompiledModule* compiled_module = owner->compiled_module(); | 657 WasmCompiledModule* compiled_module = owner->compiled_module(); |
657 TRACE("Finalizing %d {\n", compiled_module->instance_id()); | 658 TRACE("Finalizing %d {\n", compiled_module->instance_id()); |
658 DCHECK(compiled_module->has_weak_wasm_module()); | 659 DCHECK(compiled_module->has_weak_wasm_module()); |
659 WeakCell* weak_wasm_module = compiled_module->ptr_to_weak_wasm_module(); | 660 WeakCell* weak_wasm_module = compiled_module->ptr_to_weak_wasm_module(); |
660 | 661 |
662 if (trap_handler::ShouldEnableTrapHandler()) { | |
titzer
2017/02/20 09:50:08
Heads up that this code is going to move (see http
Eric Holk
2017/02/23 02:16:57
Acknowledged. (Interestingly, I didn't get any sig
| |
663 Handle<FixedArray> code_table = compiled_module->code_table(); | |
664 for (int i = 0; i < code_table->length(); ++i) { | |
665 Handle<Code> code = code_table->GetValueChecked<Code>(isolate, i); | |
666 int index = code->trap_handler_index()->value(); | |
667 if (index >= 0) { | |
668 trap_handler::ReleaseHandlerData(index); | |
669 code->set_trap_handler_index(Smi::FromInt(-1)); | |
670 } | |
671 } | |
672 } | |
673 | |
661 // weak_wasm_module may have been cleared, meaning the module object | 674 // weak_wasm_module may have been cleared, meaning the module object |
662 // was GC-ed. In that case, there won't be any new instances created, | 675 // was GC-ed. In that case, there won't be any new instances created, |
663 // and we don't need to maintain the links between instances. | 676 // and we don't need to maintain the links between instances. |
664 if (!weak_wasm_module->cleared()) { | 677 if (!weak_wasm_module->cleared()) { |
665 JSObject* wasm_module = JSObject::cast(weak_wasm_module->value()); | 678 JSObject* wasm_module = JSObject::cast(weak_wasm_module->value()); |
666 WasmCompiledModule* current_template = | 679 WasmCompiledModule* current_template = |
667 WasmCompiledModule::cast(wasm_module->GetInternalField(0)); | 680 WasmCompiledModule::cast(wasm_module->GetInternalField(0)); |
668 | 681 |
669 TRACE("chain before {\n"); | 682 TRACE("chain before {\n"); |
670 TRACE_CHAIN(current_template); | 683 TRACE_CHAIN(current_template); |
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1400 | 1413 |
1401 // Patch new call sites and the context. | 1414 // Patch new call sites and the context. |
1402 PatchDirectCallsAndContext(code_table, compiled_module_, module_, | 1415 PatchDirectCallsAndContext(code_table, compiled_module_, module_, |
1403 num_imported_functions); | 1416 num_imported_functions); |
1404 | 1417 |
1405 FlushICache(isolate_, code_table); | 1418 FlushICache(isolate_, code_table); |
1406 | 1419 |
1407 //-------------------------------------------------------------------------- | 1420 //-------------------------------------------------------------------------- |
1408 // Unpack and notify signal handler of protected instructions. | 1421 // Unpack and notify signal handler of protected instructions. |
1409 //-------------------------------------------------------------------------- | 1422 //-------------------------------------------------------------------------- |
1410 if (FLAG_wasm_trap_handler) { | 1423 if (trap_handler::ShouldEnableTrapHandler()) { |
1411 for (int i = 0; i < code_table->length(); ++i) { | 1424 for (int i = 0; i < code_table->length(); ++i) { |
1412 Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i); | 1425 Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i); |
1413 | 1426 |
1414 if (code->kind() != Code::WASM_FUNCTION) { | 1427 if (code->kind() != Code::WASM_FUNCTION) { |
1415 continue; | 1428 continue; |
1416 } | 1429 } |
1417 | 1430 |
1418 const intptr_t base = reinterpret_cast<intptr_t>(code->entry()); | 1431 const intptr_t base = reinterpret_cast<intptr_t>(code->entry()); |
1419 | 1432 |
1420 Zone zone(isolate_->allocator(), "Wasm Module"); | 1433 Zone zone(isolate_->allocator(), "Wasm Module"); |
1421 ZoneVector<trap_handler::ProtectedInstructionData> unpacked(&zone); | 1434 ZoneVector<trap_handler::ProtectedInstructionData> unpacked(&zone); |
1422 const int mode_mask = | 1435 const int mode_mask = |
1423 RelocInfo::ModeMask(RelocInfo::WASM_PROTECTED_INSTRUCTION_LANDING); | 1436 RelocInfo::ModeMask(RelocInfo::WASM_PROTECTED_INSTRUCTION_LANDING); |
1424 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { | 1437 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { |
1425 trap_handler::ProtectedInstructionData data; | 1438 trap_handler::ProtectedInstructionData data; |
1426 data.instr_offset = it.rinfo()->data(); | 1439 data.instr_offset = it.rinfo()->data(); |
1427 data.landing_offset = | 1440 data.landing_offset = |
1428 reinterpret_cast<intptr_t>(it.rinfo()->pc()) - base; | 1441 reinterpret_cast<intptr_t>(it.rinfo()->pc()) - base; |
1429 unpacked.emplace_back(data); | 1442 unpacked.emplace_back(data); |
1430 } | 1443 } |
1431 // TODO(eholk): Register the protected instruction information once the | 1444 if (unpacked.size() > 0) { |
1432 // trap handler is in place. | 1445 int size = code->CodeSize(); |
1446 const int index = | |
1447 RegisterHandlerData(reinterpret_cast<void*>(base), size, | |
1448 unpacked.size(), &unpacked[0]); | |
1449 // TODO(eholk): if index is negative, fail. | |
1450 DCHECK(index >= 0); | |
1451 code->set_trap_handler_index(Smi::FromInt(index)); | |
1452 } | |
1433 } | 1453 } |
1434 } | 1454 } |
1435 | 1455 |
1436 //-------------------------------------------------------------------------- | 1456 //-------------------------------------------------------------------------- |
1437 // Set up and link the new instance. | 1457 // Set up and link the new instance. |
1438 //-------------------------------------------------------------------------- | 1458 //-------------------------------------------------------------------------- |
1439 { | 1459 { |
1440 Handle<Object> global_handle = | 1460 Handle<Object> global_handle = |
1441 isolate_->global_handles()->Create(*instance); | 1461 isolate_->global_handles()->Create(*instance); |
1442 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_); | 1462 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_); |
(...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2818 Handle<FixedArray> storage = factory->NewFixedArray(num_custom_sections); | 2838 Handle<FixedArray> storage = factory->NewFixedArray(num_custom_sections); |
2819 JSArray::SetContent(array_object, storage); | 2839 JSArray::SetContent(array_object, storage); |
2820 array_object->set_length(Smi::FromInt(num_custom_sections)); | 2840 array_object->set_length(Smi::FromInt(num_custom_sections)); |
2821 | 2841 |
2822 for (int i = 0; i < num_custom_sections; i++) { | 2842 for (int i = 0; i < num_custom_sections; i++) { |
2823 storage->set(i, *matching_sections[i]); | 2843 storage->set(i, *matching_sections[i]); |
2824 } | 2844 } |
2825 | 2845 |
2826 return array_object; | 2846 return array_object; |
2827 } | 2847 } |
OLD | NEW |