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

Side by Side Diff: src/wasm/wasm-module.cc

Issue 2371833007: [wasm] Initial signal handler (Closed)
Patch Set: Feedback from mseaborn 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
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 <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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 WasmInstanceObject* owner = reinterpret_cast<WasmInstanceObject*>(*p); 648 WasmInstanceObject* owner = reinterpret_cast<WasmInstanceObject*>(*p);
648 Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate()); 649 Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate());
649 // If a link to shared memory instances exists, update the list of memory 650 // If a link to shared memory instances exists, update the list of memory
650 // instances before the instance is destroyed. 651 // instances before the instance is destroyed.
651 if (owner->has_instance_wrapper()) MemoryInstanceFinalizer(isolate, owner); 652 if (owner->has_instance_wrapper()) MemoryInstanceFinalizer(isolate, owner);
652 WasmCompiledModule* compiled_module = owner->compiled_module(); 653 WasmCompiledModule* compiled_module = owner->compiled_module();
653 TRACE("Finalizing %d {\n", compiled_module->instance_id()); 654 TRACE("Finalizing %d {\n", compiled_module->instance_id());
654 DCHECK(compiled_module->has_weak_wasm_module()); 655 DCHECK(compiled_module->has_weak_wasm_module());
655 WeakCell* weak_wasm_module = compiled_module->ptr_to_weak_wasm_module(); 656 WeakCell* weak_wasm_module = compiled_module->ptr_to_weak_wasm_module();
656 657
658 if (trap_handler::EnableTrapHandler()) {
659 Handle<FixedArray> code_table = compiled_module->code_table();
660 for (int i = 0; i < code_table->length(); ++i) {
661 Handle<Code> code = code_table->GetValueChecked<Code>(isolate, i);
662 int index = code->trap_handler_index()->value();
663 if (index >= 0) {
664 trap_handler::ReleaseHandlerData(index);
665 code->set_trap_handler_index(Smi::FromInt(-1));
666 }
667 }
668 }
669
657 // weak_wasm_module may have been cleared, meaning the module object 670 // weak_wasm_module may have been cleared, meaning the module object
658 // was GC-ed. In that case, there won't be any new instances created, 671 // was GC-ed. In that case, there won't be any new instances created,
659 // and we don't need to maintain the links between instances. 672 // and we don't need to maintain the links between instances.
660 if (!weak_wasm_module->cleared()) { 673 if (!weak_wasm_module->cleared()) {
661 JSObject* wasm_module = JSObject::cast(weak_wasm_module->value()); 674 JSObject* wasm_module = JSObject::cast(weak_wasm_module->value());
662 WasmCompiledModule* current_template = 675 WasmCompiledModule* current_template =
663 WasmCompiledModule::cast(wasm_module->GetInternalField(0)); 676 WasmCompiledModule::cast(wasm_module->GetInternalField(0));
664 677
665 TRACE("chain before {\n"); 678 TRACE("chain before {\n");
666 TRACE_CHAIN(current_template); 679 TRACE_CHAIN(current_template);
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 1403
1391 // Patch new call sites and the context. 1404 // Patch new call sites and the context.
1392 PatchDirectCallsAndContext(code_table, compiled_module_, module_, 1405 PatchDirectCallsAndContext(code_table, compiled_module_, module_,
1393 num_imported_functions); 1406 num_imported_functions);
1394 1407
1395 FlushICache(isolate_, code_table); 1408 FlushICache(isolate_, code_table);
1396 1409
1397 //-------------------------------------------------------------------------- 1410 //--------------------------------------------------------------------------
1398 // Unpack and notify signal handler of protected instructions. 1411 // Unpack and notify signal handler of protected instructions.
1399 //-------------------------------------------------------------------------- 1412 //--------------------------------------------------------------------------
1400 if (FLAG_wasm_trap_handler) { 1413 if (trap_handler::EnableTrapHandler()) {
1401 for (int i = 0; i < code_table->length(); ++i) { 1414 for (int i = 0; i < code_table->length(); ++i) {
1402 Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i); 1415 Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i);
1403 1416
1404 if (code->kind() != Code::WASM_FUNCTION) { 1417 if (code->kind() != Code::WASM_FUNCTION) {
1405 continue; 1418 continue;
1406 } 1419 }
1407 1420
1408 const intptr_t base = reinterpret_cast<intptr_t>(code->entry()); 1421 const intptr_t base = reinterpret_cast<intptr_t>(code->entry());
1409 1422
1410 Zone zone(isolate_->allocator(), "Wasm Module"); 1423 Zone zone(isolate_->allocator(), "Wasm Module");
1411 ZoneVector<trap_handler::ProtectedInstructionData> unpacked(&zone); 1424 ZoneVector<trap_handler::ProtectedInstructionData> unpacked(&zone);
1412 const int mode_mask = 1425 const int mode_mask =
1413 RelocInfo::ModeMask(RelocInfo::WASM_PROTECTED_INSTRUCTION_LANDING); 1426 RelocInfo::ModeMask(RelocInfo::WASM_PROTECTED_INSTRUCTION_LANDING);
1414 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { 1427 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) {
1415 trap_handler::ProtectedInstructionData data; 1428 trap_handler::ProtectedInstructionData data;
1416 data.instr_offset = it.rinfo()->data(); 1429 data.instr_offset = it.rinfo()->data();
1417 data.landing_offset = 1430 data.landing_offset =
1418 reinterpret_cast<intptr_t>(it.rinfo()->pc()) - base; 1431 reinterpret_cast<intptr_t>(it.rinfo()->pc()) - base;
1419 unpacked.emplace_back(data); 1432 unpacked.emplace_back(data);
1420 } 1433 }
1421 // TODO(eholk): Register the protected instruction information once the 1434 if (unpacked.size() > 0) {
1422 // trap handler is in place. 1435 int size = code->CodeSize();
1436 const int index =
1437 RegisterHandlerData(reinterpret_cast<void*>(base), size,
1438 unpacked.size(), &unpacked[0]);
1439 // TODO(eholk): if index is negative, fail.
1440 DCHECK(index >= 0);
1441 code->set_trap_handler_index(Smi::FromInt(index));
1442 }
1423 } 1443 }
1424 } 1444 }
1425 1445
1426 //-------------------------------------------------------------------------- 1446 //--------------------------------------------------------------------------
1427 // Set up and link the new instance. 1447 // Set up and link the new instance.
1428 //-------------------------------------------------------------------------- 1448 //--------------------------------------------------------------------------
1429 { 1449 {
1430 Handle<Object> global_handle = 1450 Handle<Object> global_handle =
1431 isolate_->global_handles()->Create(*instance); 1451 isolate_->global_handles()->Create(*instance);
1432 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_); 1452 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_);
(...skipping 1317 matching lines...) Expand 10 before | Expand all | Expand 10 after
2750 Handle<FixedArray> storage = factory->NewFixedArray(num_custom_sections); 2770 Handle<FixedArray> storage = factory->NewFixedArray(num_custom_sections);
2751 JSArray::SetContent(array_object, storage); 2771 JSArray::SetContent(array_object, storage);
2752 array_object->set_length(Smi::FromInt(num_custom_sections)); 2772 array_object->set_length(Smi::FromInt(num_custom_sections));
2753 2773
2754 for (int i = 0; i < num_custom_sections; i++) { 2774 for (int i = 0; i < num_custom_sections; i++) {
2755 storage->set(i, *matching_sections[i]); 2775 storage->set(i, *matching_sections[i]);
2756 } 2776 }
2757 2777
2758 return array_object; 2778 return array_object;
2759 } 2779 }
OLDNEW
« src/trap-handler/signal-handler.cc ('K') | « src/v8.gyp ('k') | test/cctest/cctest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698