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

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

Issue 2201663003: Heap::CopyCode handling of references into NEW_SPACE (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Just wasm-module changes. Created 4 years, 4 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 | « no previous file | no next file » | 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/macro-assembler.h" 8 #include "src/macro-assembler.h"
9 #include "src/objects.h" 9 #include "src/objects.h"
10 #include "src/property-descriptor.h" 10 #include "src/property-descriptor.h"
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 MaybeHandle<FixedArray> nothing; 1001 MaybeHandle<FixedArray> nothing;
1002 1002
1003 WasmModuleInstance temp_instance_for_compilation(this); 1003 WasmModuleInstance temp_instance_for_compilation(this);
1004 temp_instance_for_compilation.context = isolate->native_context(); 1004 temp_instance_for_compilation.context = isolate->native_context();
1005 temp_instance_for_compilation.mem_size = GetMinModuleMemSize(this); 1005 temp_instance_for_compilation.mem_size = GetMinModuleMemSize(this);
1006 temp_instance_for_compilation.mem_start = nullptr; 1006 temp_instance_for_compilation.mem_start = nullptr;
1007 temp_instance_for_compilation.globals_start = nullptr; 1007 temp_instance_for_compilation.globals_start = nullptr;
1008 1008
1009 MaybeHandle<FixedArray> indirect_table = 1009 MaybeHandle<FixedArray> indirect_table =
1010 function_tables.size() 1010 function_tables.size()
1011 ? factory->NewFixedArray(static_cast<int>(function_tables.size())) 1011 ? factory->NewFixedArray(static_cast<int>(function_tables.size()),
1012 TENURED)
1012 : MaybeHandle<FixedArray>(); 1013 : MaybeHandle<FixedArray>();
1013 for (uint32_t i = 0; i < function_tables.size(); ++i) { 1014 for (uint32_t i = 0; i < function_tables.size(); ++i) {
1014 Handle<FixedArray> values = wasm::BuildFunctionTable(isolate, i, this); 1015 Handle<FixedArray> values = wasm::BuildFunctionTable(isolate, i, this);
1015 temp_instance_for_compilation.function_tables[i] = values; 1016 temp_instance_for_compilation.function_tables[i] = values;
1016 1017
1017 Handle<FixedArray> metadata = isolate->factory()->NewFixedArray( 1018 Handle<FixedArray> metadata = isolate->factory()->NewFixedArray(
1018 kWasmIndirectFunctionTableMetadataSize); 1019 kWasmIndirectFunctionTableMetadataSize, TENURED);
1019 metadata->set(kSize, Smi::FromInt(function_tables[i].size)); 1020 metadata->set(kSize, Smi::FromInt(function_tables[i].size));
1020 metadata->set(kTable, *values); 1021 metadata->set(kTable, *values);
1021 indirect_table.ToHandleChecked()->set(i, *metadata); 1022 indirect_table.ToHandleChecked()->set(i, *metadata);
1022 } 1023 }
1023 1024
1024 HistogramTimerScope wasm_compile_module_time_scope( 1025 HistogramTimerScope wasm_compile_module_time_scope(
1025 isolate->counters()->wasm_compile_module_time()); 1026 isolate->counters()->wasm_compile_module_time());
1026 1027
1027 ModuleEnv module_env; 1028 ModuleEnv module_env;
1028 module_env.module = this; 1029 module_env.module = this;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 CHECK(seen); 1162 CHECK(seen);
1162 Assembler::FlushICache(isolate, wrapper->instruction_start(), 1163 Assembler::FlushICache(isolate, wrapper->instruction_start(),
1163 wrapper->instruction_size()); 1164 wrapper->instruction_size());
1164 } 1165 }
1165 1166
1166 Handle<FixedArray> CloneModuleForInstance(Isolate* isolate, 1167 Handle<FixedArray> CloneModuleForInstance(Isolate* isolate,
1167 Handle<FixedArray> original) { 1168 Handle<FixedArray> original) {
1168 Factory* factory = isolate->factory(); 1169 Factory* factory = isolate->factory();
1169 Handle<FixedArray> clone = factory->CopyFixedArray(original); 1170 Handle<FixedArray> clone = factory->CopyFixedArray(original);
1170 1171
1172 // Clone each wasm code object.
1173 Handle<FixedArray> orig_wasm_functions =
1174 original->GetValueChecked<FixedArray>(isolate, kFunctions);
1175 Handle<FixedArray> clone_wasm_functions =
1176 factory->CopyFixedArray(orig_wasm_functions);
1177 clone->set(kFunctions, *clone_wasm_functions);
1178 for (int i = 0; i < clone_wasm_functions->length(); ++i) {
1179 Handle<Code> orig_code =
1180 clone_wasm_functions->GetValueChecked<Code>(isolate, i);
1181 Handle<Code> cloned_code = factory->CopyCode(orig_code);
1182 clone_wasm_functions->set(i, *cloned_code);
1183 }
1184
1171 // Copy the outer table, each WasmIndirectFunctionTableMetadata table, and the 1185 // Copy the outer table, each WasmIndirectFunctionTableMetadata table, and the
1172 // inner kTable. 1186 // inner kTable.
1173 MaybeHandle<FixedArray> maybe_indirect_tables = 1187 MaybeHandle<FixedArray> maybe_indirect_tables =
1174 original->GetValue<FixedArray>(isolate, kTableOfIndirectFunctionTables); 1188 original->GetValue<FixedArray>(isolate, kTableOfIndirectFunctionTables);
1175 Handle<FixedArray> indirect_tables, clone_indirect_tables; 1189 Handle<FixedArray> indirect_tables, clone_indirect_tables;
1176 if (maybe_indirect_tables.ToHandle(&indirect_tables)) { 1190 if (maybe_indirect_tables.ToHandle(&indirect_tables)) {
1177 clone_indirect_tables = factory->CopyFixedArray(indirect_tables); 1191 clone_indirect_tables = factory->CopyFixedArray(indirect_tables);
1178 clone->set(kTableOfIndirectFunctionTables, *clone_indirect_tables); 1192 clone->set(kTableOfIndirectFunctionTables, *clone_indirect_tables);
1179 for (int i = 0; i < clone_indirect_tables->length(); ++i) { 1193 for (int i = 0; i < clone_indirect_tables->length(); ++i) {
1180 Handle<FixedArray> orig_metadata = 1194 Handle<FixedArray> orig_metadata =
1181 clone_indirect_tables->GetValueChecked<FixedArray>(isolate, i); 1195 clone_indirect_tables->GetValueChecked<FixedArray>(isolate, i);
1182 Handle<FixedArray> clone_metadata = 1196 Handle<FixedArray> clone_metadata =
1183 factory->CopyFixedArray(orig_metadata); 1197 factory->CopyFixedArray(orig_metadata);
1184 clone_indirect_tables->set(i, *clone_metadata); 1198 clone_indirect_tables->set(i, *clone_metadata);
1185 1199
1186 Handle<FixedArray> orig_table = 1200 Handle<FixedArray> orig_table =
1187 clone_metadata->GetValueChecked<FixedArray>(isolate, kTable); 1201 clone_metadata->GetValueChecked<FixedArray>(isolate, kTable);
1188 Handle<FixedArray> clone_table = factory->CopyFixedArray(orig_table); 1202 Handle<FixedArray> clone_table = factory->CopyFixedArray(orig_table);
1189 clone_metadata->set(kTable, *clone_table); 1203 clone_metadata->set(kTable, *clone_table);
1190 } 1204 // Patch the cloned code to refer to the cloned kTable.
1191 } 1205 for (int i = 0; i < clone_wasm_functions->length(); ++i) {
1192 1206 Handle<Code> cloned_code =
1193 // Clone each code, then if indirect tables are used, patch the cloned code to 1207 clone_wasm_functions->GetValueChecked<Code>(isolate, i);
1194 // refer to the cloned kTable.
1195 Handle<FixedArray> orig_wasm_functions =
1196 original->GetValueChecked<FixedArray>(isolate, kFunctions);
1197 Handle<FixedArray> clone_wasm_functions =
1198 factory->CopyFixedArray(orig_wasm_functions);
1199 clone->set(kFunctions, *clone_wasm_functions);
1200 for (int i = 0; i < clone_wasm_functions->length(); ++i) {
1201 Handle<Code> orig_code =
1202 clone_wasm_functions->GetValueChecked<Code>(isolate, i);
1203 Handle<Code> cloned_code = factory->CopyCode(orig_code);
1204 clone_wasm_functions->set(i, *cloned_code);
1205
1206 if (!clone_indirect_tables.is_null()) {
1207 for (int j = 0; j < clone_indirect_tables->length(); ++j) {
bradnelson 2016/08/02 22:47:14 I think you want to keep this.
bradnelson 2016/08/02 22:48:54 Nm, this got pulled into the loop above.
1208 Handle<FixedArray> orig_metadata =
1209 indirect_tables->GetValueChecked<FixedArray>(isolate, j);
1210 Handle<FixedArray> orig_table =
1211 orig_metadata->GetValueChecked<FixedArray>(isolate, kTable);
1212
1213 Handle<FixedArray> clone_metadata =
1214 clone_indirect_tables->GetValueChecked<FixedArray>(isolate, j);
1215 Handle<FixedArray> clone_table =
1216 clone_metadata->GetValueChecked<FixedArray>(isolate, kTable);
1217
1218 PatchFunctionTable(cloned_code, orig_table, clone_table); 1208 PatchFunctionTable(cloned_code, orig_table, clone_table);
1219 } 1209 }
1220 } 1210 }
1221 } 1211 }
1222 1212
1223 MaybeHandle<FixedArray> maybe_orig_exports = 1213 MaybeHandle<FixedArray> maybe_orig_exports =
1224 original->GetValue<FixedArray>(isolate, kExports); 1214 original->GetValue<FixedArray>(isolate, kExports);
1225 Handle<FixedArray> orig_exports; 1215 Handle<FixedArray> orig_exports;
1226 if (maybe_orig_exports.ToHandle(&orig_exports)) { 1216 if (maybe_orig_exports.ToHandle(&orig_exports)) {
1227 Handle<FixedArray> cloned_exports = factory->CopyFixedArray(orig_exports); 1217 Handle<FixedArray> cloned_exports = factory->CopyFixedArray(orig_exports);
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1486 } 1476 }
1487 return true; 1477 return true;
1488 } 1478 }
1489 1479
1490 Handle<FixedArray> BuildFunctionTable(Isolate* isolate, uint32_t index, 1480 Handle<FixedArray> BuildFunctionTable(Isolate* isolate, uint32_t index,
1491 const WasmModule* module) { 1481 const WasmModule* module) {
1492 const WasmIndirectFunctionTable* table = &module->function_tables[index]; 1482 const WasmIndirectFunctionTable* table = &module->function_tables[index];
1493 DCHECK_EQ(table->size, table->values.size()); 1483 DCHECK_EQ(table->size, table->values.size());
1494 DCHECK_GE(table->max_size, table->size); 1484 DCHECK_GE(table->max_size, table->size);
1495 Handle<FixedArray> values = 1485 Handle<FixedArray> values =
1496 isolate->factory()->NewFixedArray(2 * table->max_size); 1486 isolate->factory()->NewFixedArray(2 * table->max_size, TENURED);
1497 for (uint32_t i = 0; i < table->size; ++i) { 1487 for (uint32_t i = 0; i < table->size; ++i) {
1498 const WasmFunction* function = &module->functions[table->values[i]]; 1488 const WasmFunction* function = &module->functions[table->values[i]];
1499 values->set(i, Smi::FromInt(function->sig_index)); 1489 values->set(i, Smi::FromInt(function->sig_index));
1500 values->set(i + table->max_size, Smi::FromInt(table->values[i])); 1490 values->set(i + table->max_size, Smi::FromInt(table->values[i]));
1501 } 1491 }
1502 // Set the remaining elements to -1 (instead of "undefined"). These 1492 // Set the remaining elements to -1 (instead of "undefined"). These
1503 // elements are accessed directly as SMIs (without a check). On 64-bit 1493 // elements are accessed directly as SMIs (without a check). On 64-bit
1504 // platforms, it is possible to have the top bits of "undefined" take 1494 // platforms, it is possible to have the top bits of "undefined" take
1505 // small integer values (or zero), which are more likely to be equal to 1495 // small integer values (or zero), which are more likely to be equal to
1506 // the signature index we check against. 1496 // the signature index we check against.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); 1586 return static_cast<int32_t>(HeapNumber::cast(*result)->value());
1597 } 1587 }
1598 thrower.Error("WASM.compileRun() failed: Return value should be number"); 1588 thrower.Error("WASM.compileRun() failed: Return value should be number");
1599 return -1; 1589 return -1;
1600 } 1590 }
1601 1591
1602 } // namespace testing 1592 } // namespace testing
1603 } // namespace wasm 1593 } // namespace wasm
1604 } // namespace internal 1594 } // namespace internal
1605 } // namespace v8 1595 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698