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" |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 } | 673 } |
674 } | 674 } |
675 } | 675 } |
676 | 676 |
677 // weak_wasm_module may have been cleared, meaning the module object | 677 // weak_wasm_module may have been cleared, meaning the module object |
678 // was GC-ed. In that case, there won't be any new instances created, | 678 // was GC-ed. In that case, there won't be any new instances created, |
679 // and we don't need to maintain the links between instances. | 679 // and we don't need to maintain the links between instances. |
680 if (!weak_wasm_module->cleared()) { | 680 if (!weak_wasm_module->cleared()) { |
681 JSObject* wasm_module = JSObject::cast(weak_wasm_module->value()); | 681 JSObject* wasm_module = JSObject::cast(weak_wasm_module->value()); |
682 WasmCompiledModule* current_template = | 682 WasmCompiledModule* current_template = |
683 WasmCompiledModule::cast(wasm_module->GetInternalField(0)); | 683 WasmCompiledModule::cast(wasm_module->GetEmbedderField(0)); |
684 | 684 |
685 TRACE("chain before {\n"); | 685 TRACE("chain before {\n"); |
686 TRACE_CHAIN(current_template); | 686 TRACE_CHAIN(current_template); |
687 TRACE("}\n"); | 687 TRACE("}\n"); |
688 | 688 |
689 DCHECK(!current_template->has_weak_prev_instance()); | 689 DCHECK(!current_template->has_weak_prev_instance()); |
690 WeakCell* next = compiled_module->maybe_ptr_to_weak_next_instance(); | 690 WeakCell* next = compiled_module->maybe_ptr_to_weak_next_instance(); |
691 WeakCell* prev = compiled_module->maybe_ptr_to_weak_prev_instance(); | 691 WeakCell* prev = compiled_module->maybe_ptr_to_weak_prev_instance(); |
692 | 692 |
693 if (current_template == compiled_module) { | 693 if (current_template == compiled_module) { |
694 if (next == nullptr) { | 694 if (next == nullptr) { |
695 ResetCompiledModule(isolate, owner, compiled_module); | 695 ResetCompiledModule(isolate, owner, compiled_module); |
696 } else { | 696 } else { |
697 DCHECK(next->value()->IsFixedArray()); | 697 DCHECK(next->value()->IsFixedArray()); |
698 wasm_module->SetInternalField(0, next->value()); | 698 wasm_module->SetEmbedderField(0, next->value()); |
699 DCHECK_NULL(prev); | 699 DCHECK_NULL(prev); |
700 WasmCompiledModule::cast(next->value())->reset_weak_prev_instance(); | 700 WasmCompiledModule::cast(next->value())->reset_weak_prev_instance(); |
701 } | 701 } |
702 } else { | 702 } else { |
703 DCHECK(!(prev == nullptr && next == nullptr)); | 703 DCHECK(!(prev == nullptr && next == nullptr)); |
704 // the only reason prev or next would be cleared is if the | 704 // the only reason prev or next would be cleared is if the |
705 // respective objects got collected, but if that happened, | 705 // respective objects got collected, but if that happened, |
706 // we would have relinked the list. | 706 // we would have relinked the list. |
707 if (prev != nullptr) { | 707 if (prev != nullptr) { |
708 DCHECK(!prev->cleared()); | 708 DCHECK(!prev->cleared()); |
709 if (next == nullptr) { | 709 if (next == nullptr) { |
710 WasmCompiledModule::cast(prev->value())->reset_weak_next_instance(); | 710 WasmCompiledModule::cast(prev->value())->reset_weak_next_instance(); |
711 } else { | 711 } else { |
712 WasmCompiledModule::cast(prev->value()) | 712 WasmCompiledModule::cast(prev->value()) |
713 ->set_ptr_to_weak_next_instance(next); | 713 ->set_ptr_to_weak_next_instance(next); |
714 } | 714 } |
715 } | 715 } |
716 if (next != nullptr) { | 716 if (next != nullptr) { |
717 DCHECK(!next->cleared()); | 717 DCHECK(!next->cleared()); |
718 if (prev == nullptr) { | 718 if (prev == nullptr) { |
719 WasmCompiledModule::cast(next->value())->reset_weak_prev_instance(); | 719 WasmCompiledModule::cast(next->value())->reset_weak_prev_instance(); |
720 } else { | 720 } else { |
721 WasmCompiledModule::cast(next->value()) | 721 WasmCompiledModule::cast(next->value()) |
722 ->set_ptr_to_weak_prev_instance(prev); | 722 ->set_ptr_to_weak_prev_instance(prev); |
723 } | 723 } |
724 } | 724 } |
725 } | 725 } |
726 TRACE("chain after {\n"); | 726 TRACE("chain after {\n"); |
727 TRACE_CHAIN(WasmCompiledModule::cast(wasm_module->GetInternalField(0))); | 727 TRACE_CHAIN(WasmCompiledModule::cast(wasm_module->GetEmbedderField(0))); |
728 TRACE("}\n"); | 728 TRACE("}\n"); |
729 } | 729 } |
730 compiled_module->reset_weak_owning_instance(); | 730 compiled_module->reset_weak_owning_instance(); |
731 GlobalHandles::Destroy(reinterpret_cast<Object**>(p)); | 731 GlobalHandles::Destroy(reinterpret_cast<Object**>(p)); |
732 TRACE("}\n"); | 732 TRACE("}\n"); |
733 } | 733 } |
734 | 734 |
735 std::pair<int, int> GetFunctionOffsetAndLength( | 735 std::pair<int, int> GetFunctionOffsetAndLength( |
736 Handle<WasmCompiledModule> compiled_module, int func_index) { | 736 Handle<WasmCompiledModule> compiled_module, int func_index) { |
737 WasmModule* module = compiled_module->module(); | 737 WasmModule* module = compiled_module->module(); |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1295 // Publish the new instance to the instances chain. | 1295 // Publish the new instance to the instances chain. |
1296 { | 1296 { |
1297 DisallowHeapAllocation no_gc; | 1297 DisallowHeapAllocation no_gc; |
1298 if (!link_to_original.is_null()) { | 1298 if (!link_to_original.is_null()) { |
1299 compiled_module_->set_weak_next_instance( | 1299 compiled_module_->set_weak_next_instance( |
1300 link_to_original.ToHandleChecked()); | 1300 link_to_original.ToHandleChecked()); |
1301 original.ToHandleChecked()->set_weak_prev_instance(link_to_clone); | 1301 original.ToHandleChecked()->set_weak_prev_instance(link_to_clone); |
1302 compiled_module_->set_weak_wasm_module( | 1302 compiled_module_->set_weak_wasm_module( |
1303 original.ToHandleChecked()->weak_wasm_module()); | 1303 original.ToHandleChecked()->weak_wasm_module()); |
1304 } | 1304 } |
1305 module_object_->SetInternalField(0, *compiled_module_); | 1305 module_object_->SetEmbedderField(0, *compiled_module_); |
1306 compiled_module_->set_weak_owning_instance(link_to_owning_instance); | 1306 compiled_module_->set_weak_owning_instance(link_to_owning_instance); |
1307 GlobalHandles::MakeWeak(global_handle.location(), | 1307 GlobalHandles::MakeWeak(global_handle.location(), |
1308 global_handle.location(), &InstanceFinalizer, | 1308 global_handle.location(), &InstanceFinalizer, |
1309 v8::WeakCallbackType::kFinalizer); | 1309 v8::WeakCallbackType::kFinalizer); |
1310 } | 1310 } |
1311 } | 1311 } |
1312 | 1312 |
1313 //-------------------------------------------------------------------------- | 1313 //-------------------------------------------------------------------------- |
1314 // Debugging support. | 1314 // Debugging support. |
1315 //-------------------------------------------------------------------------- | 1315 //-------------------------------------------------------------------------- |
(...skipping 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2750 Handle<String> module_property_name = | 2750 Handle<String> module_property_name = |
2751 isolate->factory()->InternalizeUtf8String("module"); | 2751 isolate->factory()->InternalizeUtf8String("module"); |
2752 Handle<String> instance_property_name = | 2752 Handle<String> instance_property_name = |
2753 isolate->factory()->InternalizeUtf8String("instance"); | 2753 isolate->factory()->InternalizeUtf8String("instance"); |
2754 JSObject::AddProperty(ret, module_property_name, module, NONE); | 2754 JSObject::AddProperty(ret, module_property_name, module, NONE); |
2755 JSObject::AddProperty(ret, instance_property_name, | 2755 JSObject::AddProperty(ret, instance_property_name, |
2756 instance_object.ToHandleChecked(), NONE); | 2756 instance_object.ToHandleChecked(), NONE); |
2757 | 2757 |
2758 ResolvePromise(isolate, promise, ret); | 2758 ResolvePromise(isolate, promise, ret); |
2759 } | 2759 } |
OLD | NEW |