| 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" | |
| 18 #include "src/v8.h" | 17 #include "src/v8.h" |
| 19 | 18 |
| 20 #include "src/asmjs/asm-wasm-builder.h" | 19 #include "src/asmjs/asm-wasm-builder.h" |
| 21 #include "src/wasm/function-body-decoder.h" | 20 #include "src/wasm/function-body-decoder.h" |
| 22 #include "src/wasm/module-decoder.h" | 21 #include "src/wasm/module-decoder.h" |
| 23 #include "src/wasm/wasm-code-specialization.h" | 22 #include "src/wasm/wasm-code-specialization.h" |
| 24 #include "src/wasm/wasm-js.h" | 23 #include "src/wasm/wasm-js.h" |
| 25 #include "src/wasm/wasm-limits.h" | 24 #include "src/wasm/wasm-limits.h" |
| 26 #include "src/wasm/wasm-module.h" | 25 #include "src/wasm/wasm-module.h" |
| 27 #include "src/wasm/wasm-objects.h" | 26 #include "src/wasm/wasm-objects.h" |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 WasmInstanceObject* owner = reinterpret_cast<WasmInstanceObject*>(*p); | 664 WasmInstanceObject* owner = reinterpret_cast<WasmInstanceObject*>(*p); |
| 666 Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate()); | 665 Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate()); |
| 667 // If a link to shared memory instances exists, update the list of memory | 666 // If a link to shared memory instances exists, update the list of memory |
| 668 // instances before the instance is destroyed. | 667 // instances before the instance is destroyed. |
| 669 if (owner->has_instance_wrapper()) MemoryInstanceFinalizer(isolate, owner); | 668 if (owner->has_instance_wrapper()) MemoryInstanceFinalizer(isolate, owner); |
| 670 WasmCompiledModule* compiled_module = owner->compiled_module(); | 669 WasmCompiledModule* compiled_module = owner->compiled_module(); |
| 671 TRACE("Finalizing %d {\n", compiled_module->instance_id()); | 670 TRACE("Finalizing %d {\n", compiled_module->instance_id()); |
| 672 DCHECK(compiled_module->has_weak_wasm_module()); | 671 DCHECK(compiled_module->has_weak_wasm_module()); |
| 673 WeakCell* weak_wasm_module = compiled_module->ptr_to_weak_wasm_module(); | 672 WeakCell* weak_wasm_module = compiled_module->ptr_to_weak_wasm_module(); |
| 674 | 673 |
| 675 if (trap_handler::UseTrapHandler()) { | |
| 676 Handle<FixedArray> code_table = compiled_module->code_table(); | |
| 677 for (int i = 0; i < code_table->length(); ++i) { | |
| 678 Handle<Code> code = code_table->GetValueChecked<Code>(isolate, i); | |
| 679 int index = code->trap_handler_index()->value(); | |
| 680 if (index >= 0) { | |
| 681 trap_handler::ReleaseHandlerData(index); | |
| 682 code->set_trap_handler_index(Smi::FromInt(-1)); | |
| 683 } | |
| 684 } | |
| 685 } | |
| 686 | |
| 687 // weak_wasm_module may have been cleared, meaning the module object | 674 // weak_wasm_module may have been cleared, meaning the module object |
| 688 // 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, |
| 689 // and we don't need to maintain the links between instances. | 676 // and we don't need to maintain the links between instances. |
| 690 if (!weak_wasm_module->cleared()) { | 677 if (!weak_wasm_module->cleared()) { |
| 691 JSObject* wasm_module = JSObject::cast(weak_wasm_module->value()); | 678 JSObject* wasm_module = JSObject::cast(weak_wasm_module->value()); |
| 692 WasmCompiledModule* current_template = | 679 WasmCompiledModule* current_template = |
| 693 WasmCompiledModule::cast(wasm_module->GetInternalField(0)); | 680 WasmCompiledModule::cast(wasm_module->GetInternalField(0)); |
| 694 | 681 |
| 695 TRACE("chain before {\n"); | 682 TRACE("chain before {\n"); |
| 696 TRACE_CHAIN(current_template); | 683 TRACE_CHAIN(current_template); |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1236 { | 1223 { |
| 1237 code_specialization.RelocateDirectCalls(instance); | 1224 code_specialization.RelocateDirectCalls(instance); |
| 1238 code_specialization.ApplyToWholeInstance(*instance, SKIP_ICACHE_FLUSH); | 1225 code_specialization.ApplyToWholeInstance(*instance, SKIP_ICACHE_FLUSH); |
| 1239 } | 1226 } |
| 1240 | 1227 |
| 1241 FlushICache(isolate_, code_table); | 1228 FlushICache(isolate_, code_table); |
| 1242 | 1229 |
| 1243 //-------------------------------------------------------------------------- | 1230 //-------------------------------------------------------------------------- |
| 1244 // Unpack and notify signal handler of protected instructions. | 1231 // Unpack and notify signal handler of protected instructions. |
| 1245 //-------------------------------------------------------------------------- | 1232 //-------------------------------------------------------------------------- |
| 1246 if (trap_handler::UseTrapHandler()) { | 1233 if (FLAG_wasm_trap_handler) { |
| 1247 for (int i = 0; i < code_table->length(); ++i) { | 1234 for (int i = 0; i < code_table->length(); ++i) { |
| 1248 Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i); | 1235 Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i); |
| 1249 | 1236 |
| 1250 if (code->kind() != Code::WASM_FUNCTION) { | 1237 if (code->kind() != Code::WASM_FUNCTION) { |
| 1251 continue; | 1238 continue; |
| 1252 } | 1239 } |
| 1253 | 1240 |
| 1254 const intptr_t base = reinterpret_cast<intptr_t>(code->entry()); | 1241 const intptr_t base = reinterpret_cast<intptr_t>(code->entry()); |
| 1255 | 1242 |
| 1256 Zone zone(isolate_->allocator(), "Wasm Module"); | 1243 Zone zone(isolate_->allocator(), "Wasm Module"); |
| 1257 ZoneVector<trap_handler::ProtectedInstructionData> unpacked(&zone); | 1244 ZoneVector<trap_handler::ProtectedInstructionData> unpacked(&zone); |
| 1258 const int mode_mask = | 1245 const int mode_mask = |
| 1259 RelocInfo::ModeMask(RelocInfo::WASM_PROTECTED_INSTRUCTION_LANDING); | 1246 RelocInfo::ModeMask(RelocInfo::WASM_PROTECTED_INSTRUCTION_LANDING); |
| 1260 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { | 1247 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { |
| 1261 trap_handler::ProtectedInstructionData data; | 1248 trap_handler::ProtectedInstructionData data; |
| 1262 data.instr_offset = it.rinfo()->data(); | 1249 data.instr_offset = it.rinfo()->data(); |
| 1263 data.landing_offset = | 1250 data.landing_offset = |
| 1264 reinterpret_cast<intptr_t>(it.rinfo()->pc()) - base; | 1251 reinterpret_cast<intptr_t>(it.rinfo()->pc()) - base; |
| 1265 unpacked.emplace_back(data); | 1252 unpacked.emplace_back(data); |
| 1266 } | 1253 } |
| 1267 if (unpacked.size() > 0) { | 1254 // TODO(eholk): Register the protected instruction information once the |
| 1268 int size = code->CodeSize(); | 1255 // trap handler is in place. |
| 1269 const int index = | |
| 1270 RegisterHandlerData(reinterpret_cast<void*>(base), size, | |
| 1271 unpacked.size(), &unpacked[0]); | |
| 1272 // TODO(eholk): if index is negative, fail. | |
| 1273 DCHECK(index >= 0); | |
| 1274 code->set_trap_handler_index(Smi::FromInt(index)); | |
| 1275 } | |
| 1276 } | 1256 } |
| 1277 } | 1257 } |
| 1278 | 1258 |
| 1279 //-------------------------------------------------------------------------- | 1259 //-------------------------------------------------------------------------- |
| 1280 // Set up and link the new instance. | 1260 // Set up and link the new instance. |
| 1281 //-------------------------------------------------------------------------- | 1261 //-------------------------------------------------------------------------- |
| 1282 { | 1262 { |
| 1283 Handle<Object> global_handle = | 1263 Handle<Object> global_handle = |
| 1284 isolate_->global_handles()->Create(*instance); | 1264 isolate_->global_handles()->Create(*instance); |
| 1285 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_); | 1265 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_); |
| (...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2741 Handle<String> module_property_name = | 2721 Handle<String> module_property_name = |
| 2742 isolate->factory()->InternalizeUtf8String("module"); | 2722 isolate->factory()->InternalizeUtf8String("module"); |
| 2743 Handle<String> instance_property_name = | 2723 Handle<String> instance_property_name = |
| 2744 isolate->factory()->InternalizeUtf8String("instance"); | 2724 isolate->factory()->InternalizeUtf8String("instance"); |
| 2745 JSObject::AddProperty(ret, module_property_name, module, NONE); | 2725 JSObject::AddProperty(ret, module_property_name, module, NONE); |
| 2746 JSObject::AddProperty(ret, instance_property_name, | 2726 JSObject::AddProperty(ret, instance_property_name, |
| 2747 instance_object.ToHandleChecked(), NONE); | 2727 instance_object.ToHandleChecked(), NONE); |
| 2748 | 2728 |
| 2749 ResolvePromise(isolate, promise, ret); | 2729 ResolvePromise(isolate, promise, ret); |
| 2750 } | 2730 } |
| OLD | NEW |