Chromium Code Reviews| 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 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1325 data.instr_offset = | 1337 data.instr_offset = |
| 1326 protected_instructions | 1338 protected_instructions |
| 1327 ->GetValueChecked<Smi>(isolate_, i + Code::kTrapCodeOffset) | 1339 ->GetValueChecked<Smi>(isolate_, i + Code::kTrapCodeOffset) |
| 1328 ->value(); | 1340 ->value(); |
| 1329 data.landing_offset = | 1341 data.landing_offset = |
| 1330 protected_instructions | 1342 protected_instructions |
| 1331 ->GetValueChecked<Smi>(isolate_, i + Code::kTrapLandingOffset) | 1343 ->GetValueChecked<Smi>(isolate_, i + Code::kTrapLandingOffset) |
| 1332 ->value(); | 1344 ->value(); |
| 1333 unpacked.emplace_back(data); | 1345 unpacked.emplace_back(data); |
| 1334 } | 1346 } |
| 1335 // TODO(eholk): Register the protected instruction information once the | 1347 if (unpacked.size() > 0) { |
| 1336 // trap handler is in place. | 1348 Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i); |
| 1349 byte* base = code->entry(); | |
| 1350 int size = code->CodeSize(); | |
| 1351 trap_handler::CodeObjectData* handler_data = | |
|
titzer
2017/01/09 09:26:56
Is it possible to hide this data structure altoget
Eric Holk
2017/01/10 23:10:48
Yes. Originally I was thinking keeping them separa
| |
| 1352 CreateHandlerData(reinterpret_cast<void*>(base), size, | |
| 1353 unpacked.size(), &unpacked[0]); | |
| 1354 const int index = RegisterHandlerData(handler_data); | |
| 1355 // TODO(eholk): if index is negative, fail. | |
| 1356 DCHECK(index >= 0); | |
| 1357 code->set_trap_handler_index(Smi::FromInt(index)); | |
| 1358 } | |
| 1337 } | 1359 } |
| 1338 } | 1360 } |
| 1339 | 1361 |
| 1340 //-------------------------------------------------------------------------- | 1362 //-------------------------------------------------------------------------- |
| 1341 // Set up and link the new instance. | 1363 // Set up and link the new instance. |
| 1342 //-------------------------------------------------------------------------- | 1364 //-------------------------------------------------------------------------- |
| 1343 { | 1365 { |
| 1344 Handle<Object> global_handle = | 1366 Handle<Object> global_handle = |
| 1345 isolate_->global_handles()->Create(*instance); | 1367 isolate_->global_handles()->Create(*instance); |
| 1346 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_); | 1368 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_); |
| (...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2298 CHECK(!compiled_module->has_weak_owning_instance()); | 2320 CHECK(!compiled_module->has_weak_owning_instance()); |
| 2299 } | 2321 } |
| 2300 | 2322 |
| 2301 void testing::ValidateOrphanedInstance(Isolate* isolate, | 2323 void testing::ValidateOrphanedInstance(Isolate* isolate, |
| 2302 Handle<WasmInstanceObject> instance) { | 2324 Handle<WasmInstanceObject> instance) { |
| 2303 DisallowHeapAllocation no_gc; | 2325 DisallowHeapAllocation no_gc; |
| 2304 WasmCompiledModule* compiled_module = instance->compiled_module(); | 2326 WasmCompiledModule* compiled_module = instance->compiled_module(); |
| 2305 CHECK(compiled_module->has_weak_wasm_module()); | 2327 CHECK(compiled_module->has_weak_wasm_module()); |
| 2306 CHECK(compiled_module->ptr_to_weak_wasm_module()->cleared()); | 2328 CHECK(compiled_module->ptr_to_weak_wasm_module()->cleared()); |
| 2307 } | 2329 } |
| OLD | NEW |