| 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 <functional> | 5 #include <functional> |
| 6 #include <memory> | 6 #include <memory> |
| 7 | 7 |
| 8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
| 9 #include "src/debug/interface-types.h" | 9 #include "src/debug/interface-types.h" |
| 10 #include "src/frames-inl.h" | 10 #include "src/frames-inl.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 trap_handler::ReleaseHandlerData(index); | 152 trap_handler::ReleaseHandlerData(index); |
| 153 code->set_trap_handler_index(Smi::FromInt(-1)); | 153 code->set_trap_handler_index(Smi::FromInt(-1)); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| 158 // weak_wasm_module may have been cleared, meaning the module object | 158 // weak_wasm_module may have been cleared, meaning the module object |
| 159 // was GC-ed. In that case, there won't be any new instances created, | 159 // was GC-ed. In that case, there won't be any new instances created, |
| 160 // and we don't need to maintain the links between instances. | 160 // and we don't need to maintain the links between instances. |
| 161 if (!weak_wasm_module->cleared()) { | 161 if (!weak_wasm_module->cleared()) { |
| 162 JSObject* wasm_module = JSObject::cast(weak_wasm_module->value()); | 162 WasmModuleObject* wasm_module = |
| 163 WasmCompiledModule* current_template = | 163 WasmModuleObject::cast(weak_wasm_module->value()); |
| 164 WasmCompiledModule::cast(wasm_module->GetEmbedderField(0)); | 164 WasmCompiledModule* current_template = wasm_module->compiled_module(); |
| 165 | 165 |
| 166 TRACE("chain before {\n"); | 166 TRACE("chain before {\n"); |
| 167 TRACE_CHAIN(current_template); | 167 TRACE_CHAIN(current_template); |
| 168 TRACE("}\n"); | 168 TRACE("}\n"); |
| 169 | 169 |
| 170 DCHECK(!current_template->has_weak_prev_instance()); | 170 DCHECK(!current_template->has_weak_prev_instance()); |
| 171 WeakCell* next = compiled_module->maybe_ptr_to_weak_next_instance(); | 171 WeakCell* next = compiled_module->maybe_ptr_to_weak_next_instance(); |
| 172 WeakCell* prev = compiled_module->maybe_ptr_to_weak_prev_instance(); | 172 WeakCell* prev = compiled_module->maybe_ptr_to_weak_prev_instance(); |
| 173 | 173 |
| 174 if (current_template == compiled_module) { | 174 if (current_template == compiled_module) { |
| 175 if (next == nullptr) { | 175 if (next == nullptr) { |
| 176 WasmCompiledModule::Reset(isolate, compiled_module); | 176 WasmCompiledModule::Reset(isolate, compiled_module); |
| 177 } else { | 177 } else { |
| 178 DCHECK(next->value()->IsFixedArray()); | 178 WasmCompiledModule* next_compiled_module = |
| 179 wasm_module->SetEmbedderField(0, next->value()); | 179 WasmCompiledModule::cast(next->value()); |
| 180 WasmModuleObject::cast(wasm_module) |
| 181 ->set_compiled_module(next_compiled_module); |
| 180 DCHECK_NULL(prev); | 182 DCHECK_NULL(prev); |
| 181 WasmCompiledModule::cast(next->value())->reset_weak_prev_instance(); | 183 next_compiled_module->reset_weak_prev_instance(); |
| 182 } | 184 } |
| 183 } else { | 185 } else { |
| 184 DCHECK(!(prev == nullptr && next == nullptr)); | 186 DCHECK(!(prev == nullptr && next == nullptr)); |
| 185 // the only reason prev or next would be cleared is if the | 187 // the only reason prev or next would be cleared is if the |
| 186 // respective objects got collected, but if that happened, | 188 // respective objects got collected, but if that happened, |
| 187 // we would have relinked the list. | 189 // we would have relinked the list. |
| 188 if (prev != nullptr) { | 190 if (prev != nullptr) { |
| 189 DCHECK(!prev->cleared()); | 191 DCHECK(!prev->cleared()); |
| 190 if (next == nullptr) { | 192 if (next == nullptr) { |
| 191 WasmCompiledModule::cast(prev->value())->reset_weak_next_instance(); | 193 WasmCompiledModule::cast(prev->value())->reset_weak_next_instance(); |
| 192 } else { | 194 } else { |
| 193 WasmCompiledModule::cast(prev->value()) | 195 WasmCompiledModule::cast(prev->value()) |
| 194 ->set_ptr_to_weak_next_instance(next); | 196 ->set_ptr_to_weak_next_instance(next); |
| 195 } | 197 } |
| 196 } | 198 } |
| 197 if (next != nullptr) { | 199 if (next != nullptr) { |
| 198 DCHECK(!next->cleared()); | 200 DCHECK(!next->cleared()); |
| 199 if (prev == nullptr) { | 201 if (prev == nullptr) { |
| 200 WasmCompiledModule::cast(next->value())->reset_weak_prev_instance(); | 202 WasmCompiledModule::cast(next->value())->reset_weak_prev_instance(); |
| 201 } else { | 203 } else { |
| 202 WasmCompiledModule::cast(next->value()) | 204 WasmCompiledModule::cast(next->value()) |
| 203 ->set_ptr_to_weak_prev_instance(prev); | 205 ->set_ptr_to_weak_prev_instance(prev); |
| 204 } | 206 } |
| 205 } | 207 } |
| 206 } | 208 } |
| 207 TRACE("chain after {\n"); | 209 TRACE("chain after {\n"); |
| 208 TRACE_CHAIN(WasmCompiledModule::cast(wasm_module->GetEmbedderField(0))); | 210 TRACE_CHAIN(wasm_module->compiled_module()); |
| 209 TRACE("}\n"); | 211 TRACE("}\n"); |
| 210 } | 212 } |
| 211 compiled_module->reset_weak_owning_instance(); | 213 compiled_module->reset_weak_owning_instance(); |
| 212 GlobalHandles::Destroy(reinterpret_cast<Object**>(p)); | 214 GlobalHandles::Destroy(reinterpret_cast<Object**>(p)); |
| 213 TRACE("}\n"); | 215 TRACE("}\n"); |
| 214 } | 216 } |
| 215 | 217 |
| 216 int AdvanceSourcePositionTableIterator(SourcePositionTableIterator& iterator, | 218 int AdvanceSourcePositionTableIterator(SourcePositionTableIterator& iterator, |
| 217 int offset) { | 219 int offset) { |
| 218 DCHECK(!iterator.done()); | 220 DCHECK(!iterator.done()); |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 if (!function.is_null()) { | 447 if (!function.is_null()) { |
| 446 wasm_function = GetWasmFunctionForImportWrapper(isolate, function); | 448 wasm_function = GetWasmFunctionForImportWrapper(isolate, function); |
| 447 code = UnwrapImportWrapper(function); | 449 code = UnwrapImportWrapper(function); |
| 448 value = Handle<Object>::cast(function); | 450 value = Handle<Object>::cast(function); |
| 449 } | 451 } |
| 450 | 452 |
| 451 UpdateDispatchTables(isolate, dispatch_tables, index, wasm_function, code); | 453 UpdateDispatchTables(isolate, dispatch_tables, index, wasm_function, code); |
| 452 array->set(index, *value); | 454 array->set(index, *value); |
| 453 } | 455 } |
| 454 | 456 |
| 455 bool wasm::IsWasmInstance(Object* object) { | |
| 456 return WasmInstanceObject::IsWasmInstanceObject(object); | |
| 457 } | |
| 458 | |
| 459 Handle<Script> wasm::GetScript(Handle<JSObject> instance) { | 457 Handle<Script> wasm::GetScript(Handle<JSObject> instance) { |
| 460 WasmCompiledModule* compiled_module = | 458 WasmCompiledModule* compiled_module = |
| 461 WasmInstanceObject::cast(*instance)->compiled_module(); | 459 WasmInstanceObject::cast(*instance)->compiled_module(); |
| 462 return handle(compiled_module->script()); | 460 return handle(compiled_module->script()); |
| 463 } | 461 } |
| 464 | 462 |
| 465 bool wasm::IsWasmCodegenAllowed(Isolate* isolate, Handle<Context> context) { | 463 bool wasm::IsWasmCodegenAllowed(Isolate* isolate, Handle<Context> context) { |
| 466 // TODO(wasm): Once wasm has its own CSP policy, we should introduce a | 464 // TODO(wasm): Once wasm has its own CSP policy, we should introduce a |
| 467 // separate callback that includes information about the module about to be | 465 // separate callback that includes information about the module about to be |
| 468 // compiled. For the time being, pass an empty string as placeholder for the | 466 // compiled. For the time being, pass an empty string as placeholder for the |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 WasmCompiledModule* compiled_module = module_obj->compiled_module(); | 505 WasmCompiledModule* compiled_module = module_obj->compiled_module(); |
| 508 CHECK_EQ(JSObject::cast(compiled_module->ptr_to_weak_wasm_module()->value()), | 506 CHECK_EQ(JSObject::cast(compiled_module->ptr_to_weak_wasm_module()->value()), |
| 509 *module_obj); | 507 *module_obj); |
| 510 Object* prev = nullptr; | 508 Object* prev = nullptr; |
| 511 int found_instances = compiled_module->has_weak_owning_instance() ? 1 : 0; | 509 int found_instances = compiled_module->has_weak_owning_instance() ? 1 : 0; |
| 512 WasmCompiledModule* current_instance = compiled_module; | 510 WasmCompiledModule* current_instance = compiled_module; |
| 513 while (current_instance->has_weak_next_instance()) { | 511 while (current_instance->has_weak_next_instance()) { |
| 514 CHECK((prev == nullptr && !current_instance->has_weak_prev_instance()) || | 512 CHECK((prev == nullptr && !current_instance->has_weak_prev_instance()) || |
| 515 current_instance->ptr_to_weak_prev_instance()->value() == prev); | 513 current_instance->ptr_to_weak_prev_instance()->value() == prev); |
| 516 CHECK_EQ(current_instance->ptr_to_weak_wasm_module()->value(), *module_obj); | 514 CHECK_EQ(current_instance->ptr_to_weak_wasm_module()->value(), *module_obj); |
| 517 CHECK(IsWasmInstance( | 515 CHECK(current_instance->ptr_to_weak_owning_instance() |
| 518 current_instance->ptr_to_weak_owning_instance()->value())); | 516 ->value() |
| 517 ->IsWasmInstanceObject()); |
| 519 prev = current_instance; | 518 prev = current_instance; |
| 520 current_instance = WasmCompiledModule::cast( | 519 current_instance = WasmCompiledModule::cast( |
| 521 current_instance->ptr_to_weak_next_instance()->value()); | 520 current_instance->ptr_to_weak_next_instance()->value()); |
| 522 ++found_instances; | 521 ++found_instances; |
| 523 CHECK_LE(found_instances, instance_count); | 522 CHECK_LE(found_instances, instance_count); |
| 524 } | 523 } |
| 525 CHECK_EQ(found_instances, instance_count); | 524 CHECK_EQ(found_instances, instance_count); |
| 526 } | 525 } |
| 527 | 526 |
| 528 void testing::ValidateModuleState(Isolate* isolate, | 527 void testing::ValidateModuleState(Isolate* isolate, |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 callee_compiled->instruction_start()); | 1151 callee_compiled->instruction_start()); |
| 1153 } | 1152 } |
| 1154 DCHECK_EQ(non_compiled_functions.size(), idx); | 1153 DCHECK_EQ(non_compiled_functions.size(), idx); |
| 1155 } | 1154 } |
| 1156 | 1155 |
| 1157 Code* ret = | 1156 Code* ret = |
| 1158 Code::cast(compiled_module->code_table()->get(func_to_return_idx)); | 1157 Code::cast(compiled_module->code_table()->get(func_to_return_idx)); |
| 1159 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind()); | 1158 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind()); |
| 1160 return handle(ret, isolate); | 1159 return handle(ret, isolate); |
| 1161 } | 1160 } |
| OLD | NEW |