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

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

Issue 2371833007: [wasm] Initial signal handler (Closed)
Patch Set: Avoid signed/unsigned comparisons for windows 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/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-code-specialization.h" 23 #include "src/wasm/wasm-code-specialization.h"
23 #include "src/wasm/wasm-js.h" 24 #include "src/wasm/wasm-js.h"
24 #include "src/wasm/wasm-limits.h" 25 #include "src/wasm/wasm-limits.h"
25 #include "src/wasm/wasm-module.h" 26 #include "src/wasm/wasm-module.h"
26 #include "src/wasm/wasm-objects.h" 27 #include "src/wasm/wasm-objects.h"
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 WasmInstanceObject* owner = reinterpret_cast<WasmInstanceObject*>(*p); 469 WasmInstanceObject* owner = reinterpret_cast<WasmInstanceObject*>(*p);
469 Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate()); 470 Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate());
470 // If a link to shared memory instances exists, update the list of memory 471 // If a link to shared memory instances exists, update the list of memory
471 // instances before the instance is destroyed. 472 // instances before the instance is destroyed.
472 if (owner->has_instance_wrapper()) MemoryInstanceFinalizer(isolate, owner); 473 if (owner->has_instance_wrapper()) MemoryInstanceFinalizer(isolate, owner);
473 WasmCompiledModule* compiled_module = owner->compiled_module(); 474 WasmCompiledModule* compiled_module = owner->compiled_module();
474 TRACE("Finalizing %d {\n", compiled_module->instance_id()); 475 TRACE("Finalizing %d {\n", compiled_module->instance_id());
475 DCHECK(compiled_module->has_weak_wasm_module()); 476 DCHECK(compiled_module->has_weak_wasm_module());
476 WeakCell* weak_wasm_module = compiled_module->ptr_to_weak_wasm_module(); 477 WeakCell* weak_wasm_module = compiled_module->ptr_to_weak_wasm_module();
477 478
479 if (trap_handler::UseTrapHandler()) {
480 Handle<FixedArray> code_table = compiled_module->code_table();
481 for (int i = 0; i < code_table->length(); ++i) {
482 Handle<Code> code = code_table->GetValueChecked<Code>(isolate, i);
483 int index = code->trap_handler_index()->value();
484 if (index >= 0) {
485 trap_handler::ReleaseHandlerData(index);
486 code->set_trap_handler_index(Smi::FromInt(-1));
487 }
488 }
489 }
490
478 // weak_wasm_module may have been cleared, meaning the module object 491 // weak_wasm_module may have been cleared, meaning the module object
479 // was GC-ed. In that case, there won't be any new instances created, 492 // was GC-ed. In that case, there won't be any new instances created,
480 // and we don't need to maintain the links between instances. 493 // and we don't need to maintain the links between instances.
481 if (!weak_wasm_module->cleared()) { 494 if (!weak_wasm_module->cleared()) {
482 JSObject* wasm_module = JSObject::cast(weak_wasm_module->value()); 495 JSObject* wasm_module = JSObject::cast(weak_wasm_module->value());
483 WasmCompiledModule* current_template = 496 WasmCompiledModule* current_template =
484 WasmCompiledModule::cast(wasm_module->GetInternalField(0)); 497 WasmCompiledModule::cast(wasm_module->GetInternalField(0));
485 498
486 TRACE("chain before {\n"); 499 TRACE("chain before {\n");
487 TRACE_CHAIN(current_template); 500 TRACE_CHAIN(current_template);
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 { 1249 {
1237 code_specialization.RelocateDirectCalls(instance); 1250 code_specialization.RelocateDirectCalls(instance);
1238 code_specialization.ApplyToWholeInstance(*instance, SKIP_ICACHE_FLUSH); 1251 code_specialization.ApplyToWholeInstance(*instance, SKIP_ICACHE_FLUSH);
1239 } 1252 }
1240 1253
1241 FlushICache(isolate_, code_table); 1254 FlushICache(isolate_, code_table);
1242 1255
1243 //-------------------------------------------------------------------------- 1256 //--------------------------------------------------------------------------
1244 // Unpack and notify signal handler of protected instructions. 1257 // Unpack and notify signal handler of protected instructions.
1245 //-------------------------------------------------------------------------- 1258 //--------------------------------------------------------------------------
1246 if (FLAG_wasm_trap_handler) { 1259 if (trap_handler::UseTrapHandler()) {
1247 for (int i = 0; i < code_table->length(); ++i) { 1260 for (int i = 0; i < code_table->length(); ++i) {
1248 Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i); 1261 Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i);
1249 1262
1250 if (code->kind() != Code::WASM_FUNCTION) { 1263 if (code->kind() != Code::WASM_FUNCTION) {
1251 continue; 1264 continue;
1252 } 1265 }
1253 1266
1254 const intptr_t base = reinterpret_cast<intptr_t>(code->entry()); 1267 const intptr_t base = reinterpret_cast<intptr_t>(code->entry());
1255 1268
1256 Zone zone(isolate_->allocator(), "Wasm Module"); 1269 Zone zone(isolate_->allocator(), "Wasm Module");
1257 ZoneVector<trap_handler::ProtectedInstructionData> unpacked(&zone); 1270 ZoneVector<trap_handler::ProtectedInstructionData> unpacked(&zone);
1258 const int mode_mask = 1271 const int mode_mask =
1259 RelocInfo::ModeMask(RelocInfo::WASM_PROTECTED_INSTRUCTION_LANDING); 1272 RelocInfo::ModeMask(RelocInfo::WASM_PROTECTED_INSTRUCTION_LANDING);
1260 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { 1273 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) {
1261 trap_handler::ProtectedInstructionData data; 1274 trap_handler::ProtectedInstructionData data;
1262 data.instr_offset = it.rinfo()->data(); 1275 data.instr_offset = it.rinfo()->data();
1263 data.landing_offset = 1276 data.landing_offset =
1264 reinterpret_cast<intptr_t>(it.rinfo()->pc()) - base; 1277 reinterpret_cast<intptr_t>(it.rinfo()->pc()) - base;
1265 unpacked.emplace_back(data); 1278 unpacked.emplace_back(data);
1266 } 1279 }
1267 // TODO(eholk): Register the protected instruction information once the 1280 if (unpacked.size() > 0) {
1268 // trap handler is in place. 1281 int size = code->CodeSize();
1282 const int index =
1283 RegisterHandlerData(reinterpret_cast<void*>(base), size,
1284 unpacked.size(), &unpacked[0]);
1285 // TODO(eholk): if index is negative, fail.
1286 DCHECK(index >= 0);
1287 code->set_trap_handler_index(Smi::FromInt(index));
1288 }
1269 } 1289 }
1270 } 1290 }
1271 1291
1272 //-------------------------------------------------------------------------- 1292 //--------------------------------------------------------------------------
1273 // Set up and link the new instance. 1293 // Set up and link the new instance.
1274 //-------------------------------------------------------------------------- 1294 //--------------------------------------------------------------------------
1275 { 1295 {
1276 Handle<Object> global_handle = 1296 Handle<Object> global_handle =
1277 isolate_->global_handles()->Create(*instance); 1297 isolate_->global_handles()->Create(*instance);
1278 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_); 1298 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_);
(...skipping 1453 matching lines...) Expand 10 before | Expand all | Expand 10 after
2732 Handle<String> module_property_name = 2752 Handle<String> module_property_name =
2733 isolate->factory()->InternalizeUtf8String("module"); 2753 isolate->factory()->InternalizeUtf8String("module");
2734 Handle<String> instance_property_name = 2754 Handle<String> instance_property_name =
2735 isolate->factory()->InternalizeUtf8String("instance"); 2755 isolate->factory()->InternalizeUtf8String("instance");
2736 JSObject::AddProperty(ret, module_property_name, module, NONE); 2756 JSObject::AddProperty(ret, module_property_name, module, NONE);
2737 JSObject::AddProperty(ret, instance_property_name, 2757 JSObject::AddProperty(ret, instance_property_name,
2738 instance_object.ToHandleChecked(), NONE); 2758 instance_object.ToHandleChecked(), NONE);
2739 2759
2740 ResolvePromise(isolate, promise, ret); 2760 ResolvePromise(isolate, promise, ret);
2741 } 2761 }
OLDNEW
« src/isolate.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