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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 DCHECK(code_table->get(i)->IsCode()); | 140 DCHECK(code_table->get(i)->IsCode()); |
141 Handle<Code> code = Handle<Code>(Code::cast(code_table->get(i))); | 141 Handle<Code> code = Handle<Code>(Code::cast(code_table->get(i))); |
142 AllowDeferredHandleDereference embedding_raw_address; | 142 AllowDeferredHandleDereference embedding_raw_address; |
143 int mask = 1 << RelocInfo::WASM_GLOBAL_REFERENCE; | 143 int mask = 1 << RelocInfo::WASM_GLOBAL_REFERENCE; |
144 for (RelocIterator it(*code, mask); !it.done(); it.next()) { | 144 for (RelocIterator it(*code, mask); !it.done(); it.next()) { |
145 it.rinfo()->update_wasm_global_reference(old_start, globals_start); | 145 it.rinfo()->update_wasm_global_reference(old_start, globals_start); |
146 } | 146 } |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
| 150 void RelocateTableSizeReferences(Handle<FixedArray> code_table, |
| 151 uint32_t old_size, uint32_t new_size) { |
| 152 for (int i = 0; i < code_table->length(); ++i) { |
| 153 DCHECK(code_table->get(i)->IsCode()); |
| 154 Handle<Code> code = Handle<Code>(Code::cast(code_table->get(i))); |
| 155 AllowDeferredHandleDereference embedding_raw_address; |
| 156 int mask = 1 << RelocInfo::WASM_FUNCTION_TABLE_SIZE_REFERENCE; |
| 157 for (RelocIterator it(*code, mask); !it.done(); it.next()) { |
| 158 it.rinfo()->update_wasm_function_table_size_reference(old_size, new_size); |
| 159 } |
| 160 } |
| 161 } |
| 162 |
150 Handle<Code> CreatePlaceholder(Factory* factory, Code::Kind kind) { | 163 Handle<Code> CreatePlaceholder(Factory* factory, Code::Kind kind) { |
151 byte buffer[] = {0, 0, 0, 0}; // fake instructions. | 164 byte buffer[] = {0, 0, 0, 0}; // fake instructions. |
152 CodeDesc desc = { | 165 CodeDesc desc = { |
153 buffer, arraysize(buffer), arraysize(buffer), 0, 0, nullptr, 0, nullptr}; | 166 buffer, arraysize(buffer), arraysize(buffer), 0, 0, nullptr, 0, nullptr}; |
154 return factory->NewCode(desc, Code::KindField::encode(kind), | 167 return factory->NewCode(desc, Code::KindField::encode(kind), |
155 Handle<Object>::null()); | 168 Handle<Object>::null()); |
156 } | 169 } |
157 | 170 |
158 void FlushICache(Isolate* isolate, Handle<FixedArray> code_table) { | 171 void FlushICache(Isolate* isolate, Handle<FixedArray> code_table) { |
159 for (int i = 0; i < code_table->length(); ++i) { | 172 for (int i = 0; i < code_table->length(); ++i) { |
(...skipping 2176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2336 SetInstanceMemory(instance, *buffer); | 2349 SetInstanceMemory(instance, *buffer); |
2337 UncheckedUpdateInstanceMemory(isolate, instance, old_mem_start, old_size); | 2350 UncheckedUpdateInstanceMemory(isolate, instance, old_mem_start, old_size); |
2338 DCHECK(old_size % WasmModule::kPageSize == 0); | 2351 DCHECK(old_size % WasmModule::kPageSize == 0); |
2339 return (old_size / WasmModule::kPageSize); | 2352 return (old_size / WasmModule::kPageSize); |
2340 } else { | 2353 } else { |
2341 return GrowWebAssemblyMemory(isolate, handle(instance_obj->memory_object()), | 2354 return GrowWebAssemblyMemory(isolate, handle(instance_obj->memory_object()), |
2342 pages); | 2355 pages); |
2343 } | 2356 } |
2344 } | 2357 } |
2345 | 2358 |
| 2359 void wasm::GrowDispatchTables(Isolate* isolate, |
| 2360 Handle<FixedArray> dispatch_tables, |
| 2361 uint32_t old_size, uint32_t count) { |
| 2362 DCHECK_EQ(0, dispatch_tables->length() % 4); |
| 2363 for (int i = 0; i < dispatch_tables->length(); i += 4) { |
| 2364 Handle<FixedArray> old_function_table( |
| 2365 FixedArray::cast(dispatch_tables->get(i + 2))); |
| 2366 Handle<FixedArray> old_signature_table( |
| 2367 FixedArray::cast(dispatch_tables->get(i + 3))); |
| 2368 Handle<FixedArray> new_function_table = |
| 2369 isolate->factory()->CopyFixedArrayAndGrow(old_function_table, count); |
| 2370 Handle<FixedArray> new_signature_table = |
| 2371 isolate->factory()->CopyFixedArrayAndGrow(old_signature_table, count); |
| 2372 |
| 2373 // Get code table for the instance |
| 2374 Handle<WasmInstanceObject> instance( |
| 2375 WasmInstanceObject::cast(dispatch_tables->get(i))); |
| 2376 Handle<FixedArray> code_table(instance->compiled_module()->code_table()); |
| 2377 |
| 2378 // Relocate size references |
| 2379 RelocateTableSizeReferences(code_table, old_size, old_size + count); |
| 2380 |
| 2381 // Replace references of old tables with new tables. |
| 2382 for (int j = 0; j < code_table->length(); ++j) { |
| 2383 if (!code_table->get(j)->IsCode()) continue; |
| 2384 Handle<Code> code = Handle<Code>(Code::cast(code_table->get(j))); |
| 2385 ReplaceReferenceInCode(code, old_function_table, new_function_table); |
| 2386 ReplaceReferenceInCode(code, old_signature_table, new_signature_table); |
| 2387 } |
| 2388 |
| 2389 // Update dispatch tables with new function/signature tables |
| 2390 dispatch_tables->set(i + 2, *new_function_table); |
| 2391 dispatch_tables->set(i + 3, *new_signature_table); |
| 2392 } |
| 2393 } |
| 2394 |
2346 void testing::ValidateInstancesChain(Isolate* isolate, | 2395 void testing::ValidateInstancesChain(Isolate* isolate, |
2347 Handle<WasmModuleObject> module_obj, | 2396 Handle<WasmModuleObject> module_obj, |
2348 int instance_count) { | 2397 int instance_count) { |
2349 CHECK_GE(instance_count, 0); | 2398 CHECK_GE(instance_count, 0); |
2350 DisallowHeapAllocation no_gc; | 2399 DisallowHeapAllocation no_gc; |
2351 WasmCompiledModule* compiled_module = module_obj->compiled_module(); | 2400 WasmCompiledModule* compiled_module = module_obj->compiled_module(); |
2352 CHECK_EQ(JSObject::cast(compiled_module->ptr_to_weak_wasm_module()->value()), | 2401 CHECK_EQ(JSObject::cast(compiled_module->ptr_to_weak_wasm_module()->value()), |
2353 *module_obj); | 2402 *module_obj); |
2354 Object* prev = nullptr; | 2403 Object* prev = nullptr; |
2355 int found_instances = compiled_module->has_weak_owning_instance() ? 1 : 0; | 2404 int found_instances = compiled_module->has_weak_owning_instance() ? 1 : 0; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2515 | 2564 |
2516 JSObject::AddProperty(entry, name_string, export_name.ToHandleChecked(), | 2565 JSObject::AddProperty(entry, name_string, export_name.ToHandleChecked(), |
2517 NONE); | 2566 NONE); |
2518 JSObject::AddProperty(entry, kind_string, export_kind, NONE); | 2567 JSObject::AddProperty(entry, kind_string, export_kind, NONE); |
2519 | 2568 |
2520 storage->set(index, *entry); | 2569 storage->set(index, *entry); |
2521 } | 2570 } |
2522 | 2571 |
2523 return array_object; | 2572 return array_object; |
2524 } | 2573 } |
OLD | NEW |