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

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

Issue 2548223002: [wasm] Update WasmMemoryObject correctly when module memory is exported. (Closed)
Patch Set: Rebase Created 4 years 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 | « no previous file | test/mjsunit/regress/wasm/regression-670683.js » ('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/base/atomic-utils.h" 7 #include "src/base/atomic-utils.h"
8 #include "src/code-stubs.h" 8 #include "src/code-stubs.h"
9 #include "src/compiler/wasm-compiler.h" 9 #include "src/compiler/wasm-compiler.h"
10 #include "src/debug/interface-types.h" 10 #include "src/debug/interface-types.h"
(...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 ? static_cast<Address>( 1212 ? static_cast<Address>(
1213 compiled_module_->memory()->backing_store()) 1213 compiled_module_->memory()->backing_store())
1214 : nullptr; 1214 : nullptr;
1215 RelocateMemoryReferencesInCode(code_table, old_mem_start, mem_start, 1215 RelocateMemoryReferencesInCode(code_table, old_mem_start, mem_start,
1216 old_mem_size, mem_size); 1216 old_mem_size, mem_size);
1217 compiled_module_->set_memory(memory_); 1217 compiled_module_->set_memory(memory_);
1218 } else { 1218 } else {
1219 LoadDataSegments(nullptr, 0); 1219 LoadDataSegments(nullptr, 0);
1220 } 1220 }
1221 1221
1222 DCHECK(wasm::IsWasmInstance(*instance));
1223 if (instance->has_memory_object()) {
1224 instance->get_memory_object()->AddInstance(isolate_, instance);
1225 }
1226
1227 //-------------------------------------------------------------------------- 1222 //--------------------------------------------------------------------------
1228 // Set up the runtime support for the new instance. 1223 // Set up the runtime support for the new instance.
1229 //-------------------------------------------------------------------------- 1224 //--------------------------------------------------------------------------
1230 Handle<WeakCell> weak_link = factory->NewWeakCell(instance); 1225 Handle<WeakCell> weak_link = factory->NewWeakCell(instance);
1231 1226
1232 for (int i = num_imported_functions + FLAG_skip_compiling_wasm_funcs; 1227 for (int i = num_imported_functions + FLAG_skip_compiling_wasm_funcs;
1233 i < code_table->length(); ++i) { 1228 i < code_table->length(); ++i) {
1234 Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i); 1229 Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i);
1235 if (code->kind() == Code::WASM_FUNCTION) { 1230 if (code->kind() == Code::WASM_FUNCTION) {
1236 Handle<FixedArray> deopt_data = factory->NewFixedArray(2, TENURED); 1231 Handle<FixedArray> deopt_data = factory->NewFixedArray(2, TENURED);
1237 deopt_data->set(0, *weak_link); 1232 deopt_data->set(0, *weak_link);
1238 deopt_data->set(1, Smi::FromInt(static_cast<int>(i))); 1233 deopt_data->set(1, Smi::FromInt(static_cast<int>(i)));
1239 deopt_data->set_length(2); 1234 deopt_data->set_length(2);
1240 code->set_deoptimization_data(*deopt_data); 1235 code->set_deoptimization_data(*deopt_data);
1241 } 1236 }
1242 } 1237 }
1243 1238
1244 //-------------------------------------------------------------------------- 1239 //--------------------------------------------------------------------------
1245 // Set up the exports object for the new instance. 1240 // Set up the exports object for the new instance.
1246 //-------------------------------------------------------------------------- 1241 //--------------------------------------------------------------------------
1247 ProcessExports(code_table, instance); 1242 ProcessExports(code_table, instance);
1248 1243
1249 //-------------------------------------------------------------------------- 1244 //--------------------------------------------------------------------------
1245 // Add instance to Memory object
1246 //--------------------------------------------------------------------------
1247 DCHECK(wasm::IsWasmInstance(*instance));
1248 if (instance->has_memory_object()) {
1249 instance->get_memory_object()->AddInstance(isolate_, instance);
1250 }
1251
1252 //--------------------------------------------------------------------------
1250 // Set up the indirect function tables for the new instance. 1253 // Set up the indirect function tables for the new instance.
1251 //-------------------------------------------------------------------------- 1254 //--------------------------------------------------------------------------
1252 if (function_table_count > 0) InitializeTables(code_table, instance); 1255 if (function_table_count > 0) InitializeTables(code_table, instance);
1253 1256
1254 if (num_imported_functions > 0 || !owner.is_null()) { 1257 if (num_imported_functions > 0 || !owner.is_null()) {
1255 // If the code was cloned, or new imports were compiled, patch. 1258 // If the code was cloned, or new imports were compiled, patch.
1256 PatchDirectCalls(old_code_table, code_table, num_imported_functions); 1259 PatchDirectCalls(old_code_table, code_table, num_imported_functions);
1257 } 1260 }
1258 1261
1259 FlushICache(isolate_, code_table); 1262 FlushICache(isolate_, code_table);
(...skipping 24 matching lines...) Expand all
1284 protected_instructions 1287 protected_instructions
1285 ->GetValueChecked<Smi>(isolate_, i + Code::kTrapLandingOffset) 1288 ->GetValueChecked<Smi>(isolate_, i + Code::kTrapLandingOffset)
1286 ->value(); 1289 ->value();
1287 unpacked.emplace_back(data); 1290 unpacked.emplace_back(data);
1288 } 1291 }
1289 // TODO(eholk): Register the protected instruction information once the 1292 // TODO(eholk): Register the protected instruction information once the
1290 // trap handler is in place. 1293 // trap handler is in place.
1291 } 1294 }
1292 } 1295 }
1293 1296
1297 //--------------------------------------------------------------------------
1294 // Set up and link the new instance. 1298 // Set up and link the new instance.
1295 //-------------------------------------------------------------------------- 1299 //--------------------------------------------------------------------------
1296 { 1300 {
1297 Handle<Object> global_handle = 1301 Handle<Object> global_handle =
1298 isolate_->global_handles()->Create(*instance); 1302 isolate_->global_handles()->Create(*instance);
1299 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_); 1303 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_);
1300 Handle<WeakCell> link_to_owning_instance = factory->NewWeakCell(instance); 1304 Handle<WeakCell> link_to_owning_instance = factory->NewWeakCell(instance);
1301 MaybeHandle<WeakCell> link_to_original; 1305 MaybeHandle<WeakCell> link_to_original;
1302 MaybeHandle<WasmCompiledModule> original; 1306 MaybeHandle<WasmCompiledModule> original;
1303 if (!owner.is_null()) { 1307 if (!owner.is_null()) {
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after
2371 MaybeHandle<String> WasmCompiledModule::GetFunctionName( 2375 MaybeHandle<String> WasmCompiledModule::GetFunctionName(
2372 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { 2376 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) {
2373 DCHECK_LT(func_index, compiled_module->module()->functions.size()); 2377 DCHECK_LT(func_index, compiled_module->module()->functions.size());
2374 WasmFunction& function = compiled_module->module()->functions[func_index]; 2378 WasmFunction& function = compiled_module->module()->functions[func_index];
2375 Isolate* isolate = compiled_module->GetIsolate(); 2379 Isolate* isolate = compiled_module->GetIsolate();
2376 MaybeHandle<String> string = ExtractStringFromModuleBytes( 2380 MaybeHandle<String> string = ExtractStringFromModuleBytes(
2377 isolate, compiled_module, function.name_offset, function.name_length); 2381 isolate, compiled_module, function.name_offset, function.name_length);
2378 if (!string.is_null()) return string.ToHandleChecked(); 2382 if (!string.is_null()) return string.ToHandleChecked();
2379 return {}; 2383 return {};
2380 } 2384 }
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/wasm/regression-670683.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698