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 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 static_cast<int>(module_->functions.size() + func_index); | 642 static_cast<int>(module_->functions.size() + func_index); |
643 code_table->set(export_index, *wrapper_code); | 643 code_table->set(export_index, *wrapper_code); |
644 RecordStats(isolate_, *wrapper_code); | 644 RecordStats(isolate_, *wrapper_code); |
645 func_index++; | 645 func_index++; |
646 } | 646 } |
647 | 647 |
648 return WasmModuleObject::New(isolate_, compiled_module); | 648 return WasmModuleObject::New(isolate_, compiled_module); |
649 } | 649 } |
650 }; | 650 }; |
651 | 651 |
652 static void ResetCompiledModule(Isolate* isolate, WasmInstanceObject* owner, | |
653 WasmCompiledModule* compiled_module) { | |
654 TRACE("Resetting %d\n", compiled_module->instance_id()); | |
655 Object* undefined = *isolate->factory()->undefined_value(); | |
656 Object* fct_obj = compiled_module->ptr_to_code_table(); | |
657 if (fct_obj != nullptr && fct_obj != undefined) { | |
658 uint32_t old_mem_size = compiled_module->mem_size(); | |
659 uint32_t default_mem_size = compiled_module->default_mem_size(); | |
660 Object* mem_start = compiled_module->maybe_ptr_to_memory(); | |
661 | |
662 // Patch code to update memory references, global references, and function | |
663 // table references. | |
664 Zone specialization_zone(isolate->allocator(), ZONE_NAME); | |
665 CodeSpecialization code_specialization(isolate, &specialization_zone); | |
666 | |
667 if (old_mem_size > 0) { | |
668 CHECK_NE(mem_start, undefined); | |
669 Address old_mem_address = | |
670 static_cast<Address>(JSArrayBuffer::cast(mem_start)->backing_store()); | |
671 code_specialization.RelocateMemoryReferences( | |
672 old_mem_address, old_mem_size, nullptr, default_mem_size); | |
673 } | |
674 | |
675 if (owner->has_globals_buffer()) { | |
676 Address globals_start = | |
677 static_cast<Address>(owner->globals_buffer()->backing_store()); | |
678 code_specialization.RelocateGlobals(globals_start, nullptr); | |
679 } | |
680 | |
681 // Reset function tables. | |
682 if (compiled_module->has_function_tables()) { | |
683 FixedArray* function_tables = compiled_module->ptr_to_function_tables(); | |
684 FixedArray* empty_function_tables = | |
685 compiled_module->ptr_to_empty_function_tables(); | |
686 DCHECK_EQ(function_tables->length(), empty_function_tables->length()); | |
687 for (int i = 0, e = function_tables->length(); i < e; ++i) { | |
688 code_specialization.RelocateObject( | |
689 handle(function_tables->get(i), isolate), | |
690 handle(empty_function_tables->get(i), isolate)); | |
691 } | |
692 compiled_module->set_ptr_to_function_tables(empty_function_tables); | |
693 } | |
694 | |
695 FixedArray* functions = FixedArray::cast(fct_obj); | |
696 for (int i = compiled_module->num_imported_functions(), | |
697 end = functions->length(); | |
698 i < end; ++i) { | |
699 Code* code = Code::cast(functions->get(i)); | |
700 // Skip lazy compile stubs. | |
701 if (code->builtin_index() == Builtins::kWasmCompileLazy) continue; | |
702 if (code->kind() != Code::WASM_FUNCTION) { | |
703 // From here on, there should only be wrappers for exported functions. | |
704 for (; i < end; ++i) { | |
705 DCHECK_EQ(Code::JS_TO_WASM_FUNCTION, | |
706 Code::cast(functions->get(i))->kind()); | |
707 } | |
708 break; | |
709 } | |
710 bool changed = | |
711 code_specialization.ApplyToWasmCode(code, SKIP_ICACHE_FLUSH); | |
712 // TODO(wasm): Check if this is faster than passing FLUSH_ICACHE_IF_NEEDED | |
713 // above. | |
714 if (changed) { | |
715 Assembler::FlushICache(isolate, code->instruction_start(), | |
716 code->instruction_size()); | |
717 } | |
718 } | |
719 } | |
720 compiled_module->reset_memory(); | |
721 } | |
722 | |
723 static void MemoryInstanceFinalizer(Isolate* isolate, | 652 static void MemoryInstanceFinalizer(Isolate* isolate, |
724 WasmInstanceObject* instance) { | 653 WasmInstanceObject* instance) { |
725 DisallowHeapAllocation no_gc; | 654 DisallowHeapAllocation no_gc; |
726 // If the memory object is destroyed, nothing needs to be done here. | 655 // If the memory object is destroyed, nothing needs to be done here. |
727 if (!instance->has_memory_object()) return; | 656 if (!instance->has_memory_object()) return; |
728 Handle<WasmInstanceWrapper> instance_wrapper = | 657 Handle<WasmInstanceWrapper> instance_wrapper = |
729 handle(instance->instance_wrapper()); | 658 handle(instance->instance_wrapper()); |
730 DCHECK(WasmInstanceWrapper::IsWasmInstanceWrapper(*instance_wrapper)); | 659 DCHECK(WasmInstanceWrapper::IsWasmInstanceWrapper(*instance_wrapper)); |
731 DCHECK(instance_wrapper->has_instance()); | 660 DCHECK(instance_wrapper->has_instance()); |
732 bool has_prev = instance_wrapper->has_previous(); | 661 bool has_prev = instance_wrapper->has_previous(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 TRACE("chain before {\n"); | 727 TRACE("chain before {\n"); |
799 TRACE_CHAIN(current_template); | 728 TRACE_CHAIN(current_template); |
800 TRACE("}\n"); | 729 TRACE("}\n"); |
801 | 730 |
802 DCHECK(!current_template->has_weak_prev_instance()); | 731 DCHECK(!current_template->has_weak_prev_instance()); |
803 WeakCell* next = compiled_module->maybe_ptr_to_weak_next_instance(); | 732 WeakCell* next = compiled_module->maybe_ptr_to_weak_next_instance(); |
804 WeakCell* prev = compiled_module->maybe_ptr_to_weak_prev_instance(); | 733 WeakCell* prev = compiled_module->maybe_ptr_to_weak_prev_instance(); |
805 | 734 |
806 if (current_template == compiled_module) { | 735 if (current_template == compiled_module) { |
807 if (next == nullptr) { | 736 if (next == nullptr) { |
808 ResetCompiledModule(isolate, owner, compiled_module); | 737 WasmCompiledModule::Reset(isolate, compiled_module); |
809 } else { | 738 } else { |
810 DCHECK(next->value()->IsFixedArray()); | 739 DCHECK(next->value()->IsFixedArray()); |
811 wasm_module->SetEmbedderField(0, next->value()); | 740 wasm_module->SetEmbedderField(0, next->value()); |
812 DCHECK_NULL(prev); | 741 DCHECK_NULL(prev); |
813 WasmCompiledModule::cast(next->value())->reset_weak_prev_instance(); | 742 WasmCompiledModule::cast(next->value())->reset_weak_prev_instance(); |
814 } | 743 } |
815 } else { | 744 } else { |
816 DCHECK(!(prev == nullptr && next == nullptr)); | 745 DCHECK(!(prev == nullptr && next == nullptr)); |
817 // the only reason prev or next would be cleared is if the | 746 // the only reason prev or next would be cleared is if the |
818 // respective objects got collected, but if that happened, | 747 // respective objects got collected, but if that happened, |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 uint32_t globals_size = module_->globals_size; | 1190 uint32_t globals_size = module_->globals_size; |
1262 if (globals_size > 0) { | 1191 if (globals_size > 0) { |
1263 const bool enable_guard_regions = false; | 1192 const bool enable_guard_regions = false; |
1264 Handle<JSArrayBuffer> global_buffer = | 1193 Handle<JSArrayBuffer> global_buffer = |
1265 NewArrayBuffer(isolate_, globals_size, enable_guard_regions); | 1194 NewArrayBuffer(isolate_, globals_size, enable_guard_regions); |
1266 globals_ = global_buffer; | 1195 globals_ = global_buffer; |
1267 if (globals_.is_null()) { | 1196 if (globals_.is_null()) { |
1268 thrower_->RangeError("Out of memory: wasm globals"); | 1197 thrower_->RangeError("Out of memory: wasm globals"); |
1269 return {}; | 1198 return {}; |
1270 } | 1199 } |
1271 Address old_globals_start = nullptr; | 1200 Address old_globals_start = compiled_module_->GetGlobalsStartOrNull(); |
1272 if (!owner.is_null()) { | |
1273 DCHECK(owner.ToHandleChecked()->has_globals_buffer()); | |
1274 old_globals_start = static_cast<Address>( | |
1275 owner.ToHandleChecked()->globals_buffer()->backing_store()); | |
1276 } | |
1277 Address new_globals_start = | 1201 Address new_globals_start = |
1278 static_cast<Address>(global_buffer->backing_store()); | 1202 static_cast<Address>(global_buffer->backing_store()); |
1279 code_specialization.RelocateGlobals(old_globals_start, new_globals_start); | 1203 code_specialization.RelocateGlobals(old_globals_start, new_globals_start); |
| 1204 // The address of the backing buffer for the golbals is in native memory |
| 1205 // and, thus, not moving. We need it saved for |
| 1206 // serialization/deserialization purposes - so that the other end |
| 1207 // understands how to relocate the references. We still need to save the |
| 1208 // JSArrayBuffer on the instance, to keep it all alive. |
| 1209 WasmCompiledModule::SetGlobalsStartAddressFrom(factory, compiled_module_, |
| 1210 global_buffer); |
1280 instance->set_globals_buffer(*global_buffer); | 1211 instance->set_globals_buffer(*global_buffer); |
1281 } | 1212 } |
1282 | 1213 |
1283 //-------------------------------------------------------------------------- | 1214 //-------------------------------------------------------------------------- |
1284 // Prepare for initialization of function tables. | 1215 // Prepare for initialization of function tables. |
1285 //-------------------------------------------------------------------------- | 1216 //-------------------------------------------------------------------------- |
1286 int function_table_count = | 1217 int function_table_count = |
1287 static_cast<int>(module_->function_tables.size()); | 1218 static_cast<int>(module_->function_tables.size()); |
1288 table_instances_.reserve(module_->function_tables.size()); | 1219 table_instances_.reserve(module_->function_tables.size()); |
1289 for (int index = 0; index < function_table_count; ++index) { | 1220 for (int index = 0; index < function_table_count; ++index) { |
(...skipping 15 matching lines...) Expand all Loading... |
1305 | 1236 |
1306 //-------------------------------------------------------------------------- | 1237 //-------------------------------------------------------------------------- |
1307 // Set up the indirect function tables for the new instance. | 1238 // Set up the indirect function tables for the new instance. |
1308 //-------------------------------------------------------------------------- | 1239 //-------------------------------------------------------------------------- |
1309 if (function_table_count > 0) | 1240 if (function_table_count > 0) |
1310 InitializeTables(code_table, instance, &code_specialization); | 1241 InitializeTables(code_table, instance, &code_specialization); |
1311 | 1242 |
1312 //-------------------------------------------------------------------------- | 1243 //-------------------------------------------------------------------------- |
1313 // Set up the memory for the new instance. | 1244 // Set up the memory for the new instance. |
1314 //-------------------------------------------------------------------------- | 1245 //-------------------------------------------------------------------------- |
1315 MaybeHandle<JSArrayBuffer> old_memory; | |
1316 | |
1317 uint32_t min_mem_pages = module_->min_mem_pages; | 1246 uint32_t min_mem_pages = module_->min_mem_pages; |
1318 (module_->is_wasm() ? isolate_->counters()->wasm_wasm_min_mem_pages_count() | 1247 (module_->is_wasm() ? isolate_->counters()->wasm_wasm_min_mem_pages_count() |
1319 : isolate_->counters()->wasm_asm_min_mem_pages_count()) | 1248 : isolate_->counters()->wasm_asm_min_mem_pages_count()) |
1320 ->AddSample(min_mem_pages); | 1249 ->AddSample(min_mem_pages); |
1321 | 1250 |
1322 if (!memory_.is_null()) { | 1251 if (!memory_.is_null()) { |
1323 // Set externally passed ArrayBuffer non neuterable. | 1252 // Set externally passed ArrayBuffer non neuterable. |
1324 memory_->set_is_neuterable(false); | 1253 memory_->set_is_neuterable(false); |
1325 | 1254 |
1326 DCHECK_IMPLIES(EnableGuardRegions(), | 1255 DCHECK_IMPLIES(EnableGuardRegions(), |
(...skipping 28 matching lines...) Expand all Loading... |
1355 if (!in_bounds(base, seg.source_size, mem_size)) { | 1284 if (!in_bounds(base, seg.source_size, mem_size)) { |
1356 thrower_->LinkError("data segment is out of bounds"); | 1285 thrower_->LinkError("data segment is out of bounds"); |
1357 return {}; | 1286 return {}; |
1358 } | 1287 } |
1359 } | 1288 } |
1360 | 1289 |
1361 //-------------------------------------------------------------------------- | 1290 //-------------------------------------------------------------------------- |
1362 // Initialize memory. | 1291 // Initialize memory. |
1363 //-------------------------------------------------------------------------- | 1292 //-------------------------------------------------------------------------- |
1364 if (!memory_.is_null()) { | 1293 if (!memory_.is_null()) { |
1365 instance->set_memory_buffer(*memory_); | |
1366 Address mem_start = static_cast<Address>(memory_->backing_store()); | 1294 Address mem_start = static_cast<Address>(memory_->backing_store()); |
1367 uint32_t mem_size = | 1295 uint32_t mem_size = |
1368 static_cast<uint32_t>(memory_->byte_length()->Number()); | 1296 static_cast<uint32_t>(memory_->byte_length()->Number()); |
1369 LoadDataSegments(mem_start, mem_size); | 1297 LoadDataSegments(mem_start, mem_size); |
1370 | 1298 |
1371 uint32_t old_mem_size = compiled_module_->mem_size(); | 1299 uint32_t old_mem_size = compiled_module_->mem_size(); |
1372 Address old_mem_start = | 1300 Address old_mem_start = compiled_module_->GetEmbeddedMemStartOrNull(); |
1373 compiled_module_->has_memory() | |
1374 ? static_cast<Address>( | |
1375 compiled_module_->memory()->backing_store()) | |
1376 : nullptr; | |
1377 // We might get instantiated again with the same memory. No patching | 1301 // We might get instantiated again with the same memory. No patching |
1378 // needed in this case. | 1302 // needed in this case. |
1379 if (old_mem_start != mem_start || old_mem_size != mem_size) { | 1303 if (old_mem_start != mem_start || old_mem_size != mem_size) { |
1380 code_specialization.RelocateMemoryReferences( | 1304 code_specialization.RelocateMemoryReferences( |
1381 old_mem_start, old_mem_size, mem_start, mem_size); | 1305 old_mem_start, old_mem_size, mem_start, mem_size); |
1382 } | 1306 } |
1383 compiled_module_->set_memory(memory_); | 1307 // Just like with globals, we need to keep both the JSArrayBuffer |
| 1308 // and save the start pointer. |
| 1309 instance->set_memory_buffer(*memory_); |
| 1310 WasmCompiledModule::SetSpecializationMemInfoFrom( |
| 1311 factory, compiled_module_, memory_); |
1384 } | 1312 } |
1385 | 1313 |
1386 //-------------------------------------------------------------------------- | 1314 //-------------------------------------------------------------------------- |
1387 // Set up the runtime support for the new instance. | 1315 // Set up the runtime support for the new instance. |
1388 //-------------------------------------------------------------------------- | 1316 //-------------------------------------------------------------------------- |
1389 Handle<WeakCell> weak_link = factory->NewWeakCell(instance); | 1317 Handle<WeakCell> weak_link = factory->NewWeakCell(instance); |
1390 | 1318 |
1391 for (int i = num_imported_functions + FLAG_skip_compiling_wasm_funcs, | 1319 for (int i = num_imported_functions + FLAG_skip_compiling_wasm_funcs, |
1392 num_functions = static_cast<int>(module_->functions.size()); | 1320 num_functions = static_cast<int>(module_->functions.size()); |
1393 i < num_functions; ++i) { | 1321 i < num_functions; ++i) { |
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2311 | 2239 |
2312 MaybeHandle<JSArrayBuffer> wasm::GetInstanceMemory( | 2240 MaybeHandle<JSArrayBuffer> wasm::GetInstanceMemory( |
2313 Isolate* isolate, Handle<WasmInstanceObject> object) { | 2241 Isolate* isolate, Handle<WasmInstanceObject> object) { |
2314 auto instance = Handle<WasmInstanceObject>::cast(object); | 2242 auto instance = Handle<WasmInstanceObject>::cast(object); |
2315 if (instance->has_memory_buffer()) { | 2243 if (instance->has_memory_buffer()) { |
2316 return Handle<JSArrayBuffer>(instance->memory_buffer(), isolate); | 2244 return Handle<JSArrayBuffer>(instance->memory_buffer(), isolate); |
2317 } | 2245 } |
2318 return MaybeHandle<JSArrayBuffer>(); | 2246 return MaybeHandle<JSArrayBuffer>(); |
2319 } | 2247 } |
2320 | 2248 |
2321 void SetInstanceMemory(Handle<WasmInstanceObject> instance, | 2249 // May GC, because SetSpecializationMemInfoFrom may GC |
2322 JSArrayBuffer* buffer) { | 2250 void SetInstanceMemory(Isolate* isolate, Handle<WasmInstanceObject> instance, |
2323 DisallowHeapAllocation no_gc; | 2251 Handle<JSArrayBuffer> buffer) { |
2324 instance->set_memory_buffer(buffer); | 2252 instance->set_memory_buffer(*buffer); |
2325 instance->compiled_module()->set_ptr_to_memory(buffer); | 2253 WasmCompiledModule::SetSpecializationMemInfoFrom( |
| 2254 isolate->factory(), handle(instance->compiled_module()), buffer); |
2326 } | 2255 } |
2327 | 2256 |
2328 int32_t wasm::GetInstanceMemorySize(Isolate* isolate, | 2257 int32_t wasm::GetInstanceMemorySize(Isolate* isolate, |
2329 Handle<WasmInstanceObject> instance) { | 2258 Handle<WasmInstanceObject> instance) { |
2330 DCHECK(IsWasmInstance(*instance)); | 2259 DCHECK(IsWasmInstance(*instance)); |
2331 MaybeHandle<JSArrayBuffer> maybe_mem_buffer = | 2260 MaybeHandle<JSArrayBuffer> maybe_mem_buffer = |
2332 GetInstanceMemory(isolate, instance); | 2261 GetInstanceMemory(isolate, instance); |
2333 Handle<JSArrayBuffer> buffer; | 2262 Handle<JSArrayBuffer> buffer; |
2334 if (!maybe_mem_buffer.ToHandle(&buffer)) { | 2263 if (!maybe_mem_buffer.ToHandle(&buffer)) { |
2335 return 0; | 2264 return 0; |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2488 DCHECK(WasmInstanceWrapper::IsWasmInstanceWrapper(*instance_wrapper)); | 2417 DCHECK(WasmInstanceWrapper::IsWasmInstanceWrapper(*instance_wrapper)); |
2489 DCHECK(instance_wrapper->has_instance()); | 2418 DCHECK(instance_wrapper->has_instance()); |
2490 Handle<WasmInstanceObject> instance = instance_wrapper->instance_object(); | 2419 Handle<WasmInstanceObject> instance = instance_wrapper->instance_object(); |
2491 DCHECK(IsWasmInstance(*instance)); | 2420 DCHECK(IsWasmInstance(*instance)); |
2492 uint32_t max_pages = GetMaxInstanceMemoryPages(isolate, instance); | 2421 uint32_t max_pages = GetMaxInstanceMemoryPages(isolate, instance); |
2493 | 2422 |
2494 // Grow memory object buffer and update instances associated with it. | 2423 // Grow memory object buffer and update instances associated with it. |
2495 new_buffer = GrowMemoryBuffer(isolate, memory_buffer, pages, max_pages); | 2424 new_buffer = GrowMemoryBuffer(isolate, memory_buffer, pages, max_pages); |
2496 if (new_buffer.is_null()) return -1; | 2425 if (new_buffer.is_null()) return -1; |
2497 DCHECK(!instance_wrapper->has_previous()); | 2426 DCHECK(!instance_wrapper->has_previous()); |
2498 SetInstanceMemory(instance, *new_buffer); | 2427 SetInstanceMemory(isolate, instance, new_buffer); |
2499 UncheckedUpdateInstanceMemory(isolate, instance, old_mem_start, old_size); | 2428 UncheckedUpdateInstanceMemory(isolate, instance, old_mem_start, old_size); |
2500 while (instance_wrapper->has_next()) { | 2429 while (instance_wrapper->has_next()) { |
2501 instance_wrapper = instance_wrapper->next_wrapper(); | 2430 instance_wrapper = instance_wrapper->next_wrapper(); |
2502 DCHECK(WasmInstanceWrapper::IsWasmInstanceWrapper(*instance_wrapper)); | 2431 DCHECK(WasmInstanceWrapper::IsWasmInstanceWrapper(*instance_wrapper)); |
2503 Handle<WasmInstanceObject> instance = instance_wrapper->instance_object(); | 2432 Handle<WasmInstanceObject> instance = instance_wrapper->instance_object(); |
2504 DCHECK(IsWasmInstance(*instance)); | 2433 DCHECK(IsWasmInstance(*instance)); |
2505 SetInstanceMemory(instance, *new_buffer); | 2434 SetInstanceMemory(isolate, instance, new_buffer); |
2506 UncheckedUpdateInstanceMemory(isolate, instance, old_mem_start, old_size); | 2435 UncheckedUpdateInstanceMemory(isolate, instance, old_mem_start, old_size); |
2507 } | 2436 } |
2508 } | 2437 } |
2509 memory_object->set_buffer(*new_buffer); | 2438 memory_object->set_buffer(*new_buffer); |
2510 DCHECK(old_size % WasmModule::kPageSize == 0); | 2439 DCHECK(old_size % WasmModule::kPageSize == 0); |
2511 return (old_size / WasmModule::kPageSize); | 2440 return (old_size / WasmModule::kPageSize); |
2512 } | 2441 } |
2513 | 2442 |
2514 int32_t wasm::GrowMemory(Isolate* isolate, Handle<WasmInstanceObject> instance, | 2443 int32_t wasm::GrowMemory(Isolate* isolate, Handle<WasmInstanceObject> instance, |
2515 uint32_t pages) { | 2444 uint32_t pages) { |
2516 if (!IsWasmInstance(*instance)) return -1; | 2445 if (!IsWasmInstance(*instance)) return -1; |
2517 if (pages == 0) return GetInstanceMemorySize(isolate, instance); | 2446 if (pages == 0) return GetInstanceMemorySize(isolate, instance); |
2518 Handle<WasmInstanceObject> instance_obj(WasmInstanceObject::cast(*instance)); | 2447 Handle<WasmInstanceObject> instance_obj(WasmInstanceObject::cast(*instance)); |
2519 if (!instance_obj->has_memory_object()) { | 2448 if (!instance_obj->has_memory_object()) { |
2520 // No other instances to grow, grow just the one. | 2449 // No other instances to grow, grow just the one. |
2521 MaybeHandle<JSArrayBuffer> instance_buffer = | 2450 MaybeHandle<JSArrayBuffer> instance_buffer = |
2522 GetInstanceMemory(isolate, instance); | 2451 GetInstanceMemory(isolate, instance); |
2523 Handle<JSArrayBuffer> old_buffer; | 2452 Handle<JSArrayBuffer> old_buffer; |
2524 uint32_t old_size = 0; | 2453 uint32_t old_size = 0; |
2525 Address old_mem_start = nullptr; | 2454 Address old_mem_start = nullptr; |
2526 if (instance_buffer.ToHandle(&old_buffer) && | 2455 if (instance_buffer.ToHandle(&old_buffer) && |
2527 old_buffer->backing_store() != nullptr) { | 2456 old_buffer->backing_store() != nullptr) { |
2528 old_size = old_buffer->byte_length()->Number(); | 2457 old_size = old_buffer->byte_length()->Number(); |
2529 old_mem_start = static_cast<Address>(old_buffer->backing_store()); | 2458 old_mem_start = static_cast<Address>(old_buffer->backing_store()); |
2530 } | 2459 } |
2531 uint32_t max_pages = GetMaxInstanceMemoryPages(isolate, instance_obj); | 2460 uint32_t max_pages = GetMaxInstanceMemoryPages(isolate, instance_obj); |
2532 Handle<JSArrayBuffer> buffer = | 2461 Handle<JSArrayBuffer> buffer = |
2533 GrowMemoryBuffer(isolate, instance_buffer, pages, max_pages); | 2462 GrowMemoryBuffer(isolate, instance_buffer, pages, max_pages); |
2534 if (buffer.is_null()) return -1; | 2463 if (buffer.is_null()) return -1; |
2535 SetInstanceMemory(instance, *buffer); | 2464 SetInstanceMemory(isolate, instance, buffer); |
2536 UncheckedUpdateInstanceMemory(isolate, instance, old_mem_start, old_size); | 2465 UncheckedUpdateInstanceMemory(isolate, instance, old_mem_start, old_size); |
2537 DCHECK(old_size % WasmModule::kPageSize == 0); | 2466 DCHECK(old_size % WasmModule::kPageSize == 0); |
2538 return (old_size / WasmModule::kPageSize); | 2467 return (old_size / WasmModule::kPageSize); |
2539 } else { | 2468 } else { |
2540 return GrowWebAssemblyMemory(isolate, handle(instance_obj->memory_object()), | 2469 return GrowWebAssemblyMemory(isolate, handle(instance_obj->memory_object()), |
2541 pages); | 2470 pages); |
2542 } | 2471 } |
2543 } | 2472 } |
2544 | 2473 |
2545 void wasm::GrowDispatchTables(Isolate* isolate, | 2474 void wasm::GrowDispatchTables(Isolate* isolate, |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3103 DCHECK_EQ(Builtins::kWasmCompileLazy, | 3032 DCHECK_EQ(Builtins::kWasmCompileLazy, |
3104 Code::cast(compiled_module->code_table()->get(func_index)) | 3033 Code::cast(compiled_module->code_table()->get(func_index)) |
3105 ->builtin_index()); | 3034 ->builtin_index()); |
3106 compiled_module->code_table()->set(func_index, *code); | 3035 compiled_module->code_table()->set(func_index, *code); |
3107 | 3036 |
3108 // Now specialize the generated code for this instance. | 3037 // Now specialize the generated code for this instance. |
3109 Zone specialization_zone(isolate->allocator(), ZONE_NAME); | 3038 Zone specialization_zone(isolate->allocator(), ZONE_NAME); |
3110 CodeSpecialization code_specialization(isolate, &specialization_zone); | 3039 CodeSpecialization code_specialization(isolate, &specialization_zone); |
3111 if (module_env.module->globals_size) { | 3040 if (module_env.module->globals_size) { |
3112 Address globals_start = | 3041 Address globals_start = |
3113 reinterpret_cast<Address>(instance->globals_buffer()->backing_store()); | 3042 reinterpret_cast<Address>(compiled_module->globals_start()); |
3114 code_specialization.RelocateGlobals(nullptr, globals_start); | 3043 code_specialization.RelocateGlobals(nullptr, globals_start); |
3115 } | 3044 } |
3116 if (instance->has_memory_buffer()) { | 3045 if (instance->has_memory_buffer()) { |
3117 Address mem_start = | 3046 Address mem_start = |
3118 reinterpret_cast<Address>(instance->memory_buffer()->backing_store()); | 3047 reinterpret_cast<Address>(instance->memory_buffer()->backing_store()); |
3119 int mem_size = instance->memory_buffer()->byte_length()->Number(); | 3048 int mem_size = instance->memory_buffer()->byte_length()->Number(); |
3120 DCHECK_IMPLIES(mem_size == 0, mem_start == nullptr); | 3049 DCHECK_IMPLIES(mem_size == 0, mem_start == nullptr); |
3121 if (mem_size > 0) { | 3050 if (mem_size > 0) { |
3122 code_specialization.RelocateMemoryReferences(nullptr, 0, mem_start, | 3051 code_specialization.RelocateMemoryReferences(nullptr, 0, mem_start, |
3123 mem_size); | 3052 mem_size); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3220 callee_compiled->instruction_start()); | 3149 callee_compiled->instruction_start()); |
3221 } | 3150 } |
3222 DCHECK_EQ(non_compiled_functions.size(), idx); | 3151 DCHECK_EQ(non_compiled_functions.size(), idx); |
3223 } | 3152 } |
3224 | 3153 |
3225 Code* ret = | 3154 Code* ret = |
3226 Code::cast(compiled_module->code_table()->get(func_to_return_idx)); | 3155 Code::cast(compiled_module->code_table()->get(func_to_return_idx)); |
3227 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind()); | 3156 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind()); |
3228 return handle(ret, isolate); | 3157 return handle(ret, isolate); |
3229 } | 3158 } |
OLD | NEW |