| 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/base/atomic-utils.h" | 7 #include "src/base/atomic-utils.h" |
| 8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
| 9 | 9 |
| 10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
| (...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1215 seen = true; | 1215 seen = true; |
| 1216 it.rinfo()->set_target_address(new_target->instruction_start(), | 1216 it.rinfo()->set_target_address(new_target->instruction_start(), |
| 1217 UPDATE_WRITE_BARRIER, SKIP_ICACHE_FLUSH); | 1217 UPDATE_WRITE_BARRIER, SKIP_ICACHE_FLUSH); |
| 1218 } | 1218 } |
| 1219 } | 1219 } |
| 1220 CHECK(seen); | 1220 CHECK(seen); |
| 1221 Assembler::FlushICache(isolate, wrapper->instruction_start(), | 1221 Assembler::FlushICache(isolate, wrapper->instruction_start(), |
| 1222 wrapper->instruction_size()); | 1222 wrapper->instruction_size()); |
| 1223 } | 1223 } |
| 1224 | 1224 |
| 1225 Handle<FixedArray> SetupIndirectFunctionTable( |
| 1226 Isolate* isolate, Handle<FixedArray> wasm_functions, |
| 1227 Handle<FixedArray> indirect_table_template) { |
| 1228 Factory* factory = isolate->factory(); |
| 1229 Handle<FixedArray> cloned_indirect_tables = |
| 1230 factory->CopyFixedArray(indirect_table_template); |
| 1231 for (int i = 0; i < cloned_indirect_tables->length(); ++i) { |
| 1232 Handle<FixedArray> orig_metadata = |
| 1233 cloned_indirect_tables->GetValueChecked<FixedArray>(isolate, i); |
| 1234 Handle<FixedArray> cloned_metadata = factory->CopyFixedArray(orig_metadata); |
| 1235 cloned_indirect_tables->set(i, *cloned_metadata); |
| 1236 |
| 1237 Handle<FixedArray> orig_table = |
| 1238 cloned_metadata->GetValueChecked<FixedArray>(isolate, kTable); |
| 1239 Handle<FixedArray> cloned_table = factory->CopyFixedArray(orig_table); |
| 1240 cloned_metadata->set(kTable, *cloned_table); |
| 1241 // Patch the cloned code to refer to the cloned kTable. |
| 1242 for (int i = 0; i < wasm_functions->length(); ++i) { |
| 1243 Handle<Code> wasm_function = |
| 1244 wasm_functions->GetValueChecked<Code>(isolate, i); |
| 1245 PatchFunctionTable(wasm_function, orig_table, cloned_table); |
| 1246 } |
| 1247 } |
| 1248 return cloned_indirect_tables; |
| 1249 } |
| 1250 |
| 1225 Handle<FixedArray> CloneModuleForInstance(Isolate* isolate, | 1251 Handle<FixedArray> CloneModuleForInstance(Isolate* isolate, |
| 1226 Handle<FixedArray> original) { | 1252 Handle<FixedArray> original) { |
| 1227 Factory* factory = isolate->factory(); | 1253 Factory* factory = isolate->factory(); |
| 1228 Handle<FixedArray> clone = factory->CopyFixedArray(original); | 1254 Handle<FixedArray> clone = factory->CopyFixedArray(original); |
| 1229 | 1255 |
| 1230 // Clone each wasm code object. | 1256 // Clone each wasm code object. |
| 1231 Handle<FixedArray> orig_wasm_functions = | 1257 Handle<FixedArray> orig_wasm_functions = |
| 1232 original->GetValueChecked<FixedArray>(isolate, kFunctions); | 1258 original->GetValueChecked<FixedArray>(isolate, kFunctions); |
| 1233 Handle<FixedArray> clone_wasm_functions = | 1259 Handle<FixedArray> clone_wasm_functions = |
| 1234 factory->CopyFixedArray(orig_wasm_functions); | 1260 factory->CopyFixedArray(orig_wasm_functions); |
| 1235 clone->set(kFunctions, *clone_wasm_functions); | 1261 clone->set(kFunctions, *clone_wasm_functions); |
| 1236 for (int i = 0; i < clone_wasm_functions->length(); ++i) { | 1262 for (int i = 0; i < clone_wasm_functions->length(); ++i) { |
| 1237 Handle<Code> orig_code = | 1263 Handle<Code> orig_code = |
| 1238 clone_wasm_functions->GetValueChecked<Code>(isolate, i); | 1264 clone_wasm_functions->GetValueChecked<Code>(isolate, i); |
| 1239 Handle<Code> cloned_code = factory->CopyCode(orig_code); | 1265 Handle<Code> cloned_code = factory->CopyCode(orig_code); |
| 1240 clone_wasm_functions->set(i, *cloned_code); | 1266 clone_wasm_functions->set(i, *cloned_code); |
| 1241 } | 1267 } |
| 1242 | 1268 |
| 1243 // Copy the outer table, each WasmIndirectFunctionTableMetadata table, and the | |
| 1244 // inner kTable. | |
| 1245 MaybeHandle<FixedArray> maybe_indirect_tables = | |
| 1246 original->GetValue<FixedArray>(isolate, kTableOfIndirectFunctionTables); | |
| 1247 Handle<FixedArray> indirect_tables, clone_indirect_tables; | |
| 1248 if (maybe_indirect_tables.ToHandle(&indirect_tables)) { | |
| 1249 clone_indirect_tables = factory->CopyFixedArray(indirect_tables); | |
| 1250 clone->set(kTableOfIndirectFunctionTables, *clone_indirect_tables); | |
| 1251 for (int i = 0; i < clone_indirect_tables->length(); ++i) { | |
| 1252 Handle<FixedArray> orig_metadata = | |
| 1253 clone_indirect_tables->GetValueChecked<FixedArray>(isolate, i); | |
| 1254 Handle<FixedArray> clone_metadata = | |
| 1255 factory->CopyFixedArray(orig_metadata); | |
| 1256 clone_indirect_tables->set(i, *clone_metadata); | |
| 1257 | |
| 1258 Handle<FixedArray> orig_table = | |
| 1259 clone_metadata->GetValueChecked<FixedArray>(isolate, kTable); | |
| 1260 Handle<FixedArray> clone_table = factory->CopyFixedArray(orig_table); | |
| 1261 clone_metadata->set(kTable, *clone_table); | |
| 1262 // Patch the cloned code to refer to the cloned kTable. | |
| 1263 for (int i = 0; i < clone_wasm_functions->length(); ++i) { | |
| 1264 Handle<Code> cloned_code = | |
| 1265 clone_wasm_functions->GetValueChecked<Code>(isolate, i); | |
| 1266 PatchFunctionTable(cloned_code, orig_table, clone_table); | |
| 1267 } | |
| 1268 } | |
| 1269 } | |
| 1270 | |
| 1271 MaybeHandle<FixedArray> maybe_orig_exports = | 1269 MaybeHandle<FixedArray> maybe_orig_exports = |
| 1272 original->GetValue<FixedArray>(isolate, kExports); | 1270 original->GetValue<FixedArray>(isolate, kExports); |
| 1273 Handle<FixedArray> orig_exports; | 1271 Handle<FixedArray> orig_exports; |
| 1274 if (maybe_orig_exports.ToHandle(&orig_exports)) { | 1272 if (maybe_orig_exports.ToHandle(&orig_exports)) { |
| 1275 Handle<FixedArray> cloned_exports = factory->CopyFixedArray(orig_exports); | 1273 Handle<FixedArray> cloned_exports = factory->CopyFixedArray(orig_exports); |
| 1276 clone->set(kExports, *cloned_exports); | 1274 clone->set(kExports, *cloned_exports); |
| 1277 for (int i = 0; i < orig_exports->length(); ++i) { | 1275 for (int i = 0; i < orig_exports->length(); ++i) { |
| 1278 Handle<FixedArray> export_metadata = | 1276 Handle<FixedArray> export_metadata = |
| 1279 orig_exports->GetValueChecked<FixedArray>(isolate, i); | 1277 orig_exports->GetValueChecked<FixedArray>(isolate, i); |
| 1280 Handle<FixedArray> clone_metadata = | 1278 Handle<FixedArray> clone_metadata = |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1362 return nothing; | 1360 return nothing; |
| 1363 } | 1361 } |
| 1364 | 1362 |
| 1365 SetDebugSupport(factory, compiled_module, js_object); | 1363 SetDebugSupport(factory, compiled_module, js_object); |
| 1366 | 1364 |
| 1367 FlushAssemblyCache(isolate, code_table); | 1365 FlushAssemblyCache(isolate, code_table); |
| 1368 | 1366 |
| 1369 MaybeHandle<FixedArray> maybe_indirect_tables = | 1367 MaybeHandle<FixedArray> maybe_indirect_tables = |
| 1370 compiled_module->GetValue<FixedArray>(isolate, | 1368 compiled_module->GetValue<FixedArray>(isolate, |
| 1371 kTableOfIndirectFunctionTables); | 1369 kTableOfIndirectFunctionTables); |
| 1372 Handle<FixedArray> indirect_tables; | 1370 Handle<FixedArray> indirect_tables_template; |
| 1373 if (maybe_indirect_tables.ToHandle(&indirect_tables)) { | 1371 if (maybe_indirect_tables.ToHandle(&indirect_tables_template)) { |
| 1372 Handle<FixedArray> indirect_tables = SetupIndirectFunctionTable( |
| 1373 isolate, code_table, indirect_tables_template); |
| 1374 for (int i = 0; i < indirect_tables->length(); ++i) { | 1374 for (int i = 0; i < indirect_tables->length(); ++i) { |
| 1375 Handle<FixedArray> metadata = | 1375 Handle<FixedArray> metadata = |
| 1376 indirect_tables->GetValueChecked<FixedArray>(isolate, i); | 1376 indirect_tables->GetValueChecked<FixedArray>(isolate, i); |
| 1377 uint32_t size = Smi::cast(metadata->get(kSize))->value(); | 1377 uint32_t size = Smi::cast(metadata->get(kSize))->value(); |
| 1378 Handle<FixedArray> table = | 1378 Handle<FixedArray> table = |
| 1379 metadata->GetValueChecked<FixedArray>(isolate, kTable); | 1379 metadata->GetValueChecked<FixedArray>(isolate, kTable); |
| 1380 wasm::PopulateFunctionTable(table, size, &functions); | 1380 wasm::PopulateFunctionTable(table, size, &functions); |
| 1381 } | 1381 } |
| 1382 js_object->SetInternalField(kWasmModuleFunctionTable, *indirect_tables); | 1382 js_object->SetInternalField(kWasmModuleFunctionTable, *indirect_tables); |
| 1383 } | 1383 } |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1663 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); | 1663 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); |
| 1664 } | 1664 } |
| 1665 thrower->Error("WASM.compileRun() failed: Return value should be number"); | 1665 thrower->Error("WASM.compileRun() failed: Return value should be number"); |
| 1666 return -1; | 1666 return -1; |
| 1667 } | 1667 } |
| 1668 | 1668 |
| 1669 } // namespace testing | 1669 } // namespace testing |
| 1670 } // namespace wasm | 1670 } // namespace wasm |
| 1671 } // namespace internal | 1671 } // namespace internal |
| 1672 } // namespace v8 | 1672 } // namespace v8 |
| OLD | NEW |