Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: src/wasm/wasm-module.cc

Issue 2844163006: [wasm] Move Table.Grow implementation to wasm-objects.cc, cleanup (Closed)
Patch Set: Cleanup Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/wasm-module.h ('k') | src/wasm/wasm-objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/atomic-utils.h" 8 #include "src/base/atomic-utils.h"
9 #include "src/code-stubs.h" 9 #include "src/code-stubs.h"
10 #include "src/compiler/wasm-compiler.h" 10 #include "src/compiler/wasm-compiler.h"
(...skipping 2065 matching lines...) Expand 10 before | Expand all | Expand 10 after
2076 Handle<WasmInstanceObject> instance) { 2076 Handle<WasmInstanceObject> instance) {
2077 int function_table_count = 2077 int function_table_count =
2078 static_cast<int>(module_->function_tables.size()); 2078 static_cast<int>(module_->function_tables.size());
2079 for (int index = 0; index < function_table_count; ++index) { 2079 for (int index = 0; index < function_table_count; ++index) {
2080 WasmIndirectFunctionTable& table = module_->function_tables[index]; 2080 WasmIndirectFunctionTable& table = module_->function_tables[index];
2081 TableInstance& table_instance = table_instances_[index]; 2081 TableInstance& table_instance = table_instances_[index];
2082 2082
2083 Handle<FixedArray> all_dispatch_tables; 2083 Handle<FixedArray> all_dispatch_tables;
2084 if (!table_instance.table_object.is_null()) { 2084 if (!table_instance.table_object.is_null()) {
2085 // Get the existing dispatch table(s) with the WebAssembly.Table object. 2085 // Get the existing dispatch table(s) with the WebAssembly.Table object.
2086 all_dispatch_tables = WasmTableObject::AddDispatchTable( 2086 all_dispatch_tables =
2087 isolate_, table_instance.table_object, 2087 handle(table_instance.table_object->dispatch_tables());
2088 Handle<WasmInstanceObject>::null(), index,
2089 Handle<FixedArray>::null(), Handle<FixedArray>::null());
2090 } 2088 }
2091 2089
2092 // Count the number of table exports for each function (needed for lazy 2090 // Count the number of table exports for each function (needed for lazy
2093 // compilation). 2091 // compilation).
2094 std::unordered_map<uint32_t, uint32_t> num_table_exports; 2092 std::unordered_map<uint32_t, uint32_t> num_table_exports;
2095 if (compile_lazy(module_)) { 2093 if (compile_lazy(module_)) {
2096 for (auto table_init : module_->table_inits) { 2094 for (auto table_init : module_->table_inits) {
2097 for (uint32_t func_index : table_init.entries) { 2095 for (uint32_t func_index : table_init.entries) {
2098 Code* code = 2096 Code* code =
2099 Code::cast(code_table->get(static_cast<int>(func_index))); 2097 Code::cast(code_table->get(static_cast<int>(func_index)));
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
2217 if (has_guard_regions) { 2215 if (has_guard_regions) {
2218 base::OS::Free(backing_store, RoundUp(i::wasm::kWasmMaxHeapOffset, 2216 base::OS::Free(backing_store, RoundUp(i::wasm::kWasmMaxHeapOffset,
2219 base::OS::CommitPageSize())); 2217 base::OS::CommitPageSize()));
2220 reinterpret_cast<v8::Isolate*>(isolate) 2218 reinterpret_cast<v8::Isolate*>(isolate)
2221 ->AdjustAmountOfExternalAllocatedMemory(-byte_length); 2219 ->AdjustAmountOfExternalAllocatedMemory(-byte_length);
2222 } else if (!has_guard_regions && !is_external) { 2220 } else if (!has_guard_regions && !is_external) {
2223 isolate->array_buffer_allocator()->Free(backing_store, byte_length); 2221 isolate->array_buffer_allocator()->Free(backing_store, byte_length);
2224 } 2222 }
2225 } 2223 }
2226 2224
2227 void wasm::GrowDispatchTables(Isolate* isolate,
2228 Handle<FixedArray> dispatch_tables,
2229 uint32_t old_size, uint32_t count) {
2230 DCHECK_EQ(0, dispatch_tables->length() % 4);
2231
2232 Zone specialization_zone(isolate->allocator(), ZONE_NAME);
2233 for (int i = 0; i < dispatch_tables->length(); i += 4) {
2234 Handle<FixedArray> old_function_table(
2235 FixedArray::cast(dispatch_tables->get(i + 2)));
2236 Handle<FixedArray> old_signature_table(
2237 FixedArray::cast(dispatch_tables->get(i + 3)));
2238 Handle<FixedArray> new_function_table =
2239 isolate->factory()->CopyFixedArrayAndGrow(old_function_table, count);
2240 Handle<FixedArray> new_signature_table =
2241 isolate->factory()->CopyFixedArrayAndGrow(old_signature_table, count);
2242
2243 // Update dispatch tables with new function/signature tables
2244 dispatch_tables->set(i + 2, *new_function_table);
2245 dispatch_tables->set(i + 3, *new_signature_table);
2246
2247 // Patch the code of the respective instance.
2248 CodeSpecialization code_specialization(isolate, &specialization_zone);
2249 code_specialization.PatchTableSize(old_size, old_size + count);
2250 code_specialization.RelocateObject(old_function_table, new_function_table);
2251 code_specialization.RelocateObject(old_signature_table,
2252 new_signature_table);
2253 code_specialization.ApplyToWholeInstance(
2254 WasmInstanceObject::cast(dispatch_tables->get(i)));
2255 }
2256 }
2257
2258 void testing::ValidateInstancesChain(Isolate* isolate, 2225 void testing::ValidateInstancesChain(Isolate* isolate,
2259 Handle<WasmModuleObject> module_obj, 2226 Handle<WasmModuleObject> module_obj,
2260 int instance_count) { 2227 int instance_count) {
2261 CHECK_GE(instance_count, 0); 2228 CHECK_GE(instance_count, 0);
2262 DisallowHeapAllocation no_gc; 2229 DisallowHeapAllocation no_gc;
2263 WasmCompiledModule* compiled_module = module_obj->compiled_module(); 2230 WasmCompiledModule* compiled_module = module_obj->compiled_module();
2264 CHECK_EQ(JSObject::cast(compiled_module->ptr_to_weak_wasm_module()->value()), 2231 CHECK_EQ(JSObject::cast(compiled_module->ptr_to_weak_wasm_module()->value()),
2265 *module_obj); 2232 *module_obj);
2266 Object* prev = nullptr; 2233 Object* prev = nullptr;
2267 int found_instances = compiled_module->has_weak_owning_instance() ? 1 : 0; 2234 int found_instances = compiled_module->has_weak_owning_instance() ? 1 : 0;
(...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after
3310 callee_compiled->instruction_start()); 3277 callee_compiled->instruction_start());
3311 } 3278 }
3312 DCHECK_EQ(non_compiled_functions.size(), idx); 3279 DCHECK_EQ(non_compiled_functions.size(), idx);
3313 } 3280 }
3314 3281
3315 Code* ret = 3282 Code* ret =
3316 Code::cast(compiled_module->code_table()->get(func_to_return_idx)); 3283 Code::cast(compiled_module->code_table()->get(func_to_return_idx));
3317 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind()); 3284 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind());
3318 return handle(ret, isolate); 3285 return handle(ret, isolate);
3319 } 3286 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.h ('k') | src/wasm/wasm-objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698