| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 // Flags: --expose-wasm --expose-gc | 5 // Flags: --expose-wasm --expose-gc |
| 6 | 6 |
| 7 load("test/mjsunit/wasm/wasm-constants.js"); | 7 load("test/mjsunit/wasm/wasm-constants.js"); |
| 8 load("test/mjsunit/wasm/wasm-module-builder.js"); | 8 load("test/mjsunit/wasm/wasm-module-builder.js"); |
| 9 | 9 |
| 10 // This test verifies that when instances are exported, Gc'ed, the other | 10 // This test verifies that when instances are exported, Gc'ed, the other |
| 11 // instances in the chain still maintain a consistent view of the memory. | 11 // instances in the chain still maintain a consistent view of the memory. |
| 12 (function InstanceMemoryGcStress() { | 12 (function InstanceMemoryGcStress() { |
| 13 print("InstanceMemoryGcStress"); | 13 print("InstanceMemoryGcStress"); |
| 14 let memory = new WebAssembly.Memory({initial: 100, maximum: 1500}); | 14 let memory = new WebAssembly.Memory({initial: 100, maximum: 1500}); |
| 15 var builder = new WasmModuleBuilder(); | 15 var builder = new WasmModuleBuilder(); |
| 16 builder.addImportedMemory("imported_mem"); | 16 builder.addImportedMemory("mod", "imported_mem"); |
| 17 builder.addFunction("mem_size", kSig_i_v) | 17 builder.addFunction("mem_size", kSig_i_v) |
| 18 .addBody([kExprMemorySize, kMemoryZero]) | 18 .addBody([kExprMemorySize, kMemoryZero]) |
| 19 .exportFunc(); | 19 .exportFunc(); |
| 20 builder.addFunction("grow", kSig_i_i) | 20 builder.addFunction("grow", kSig_i_i) |
| 21 .addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero]) | 21 .addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero]) |
| 22 .exportFunc(); | 22 .exportFunc(); |
| 23 var instances = []; | 23 var instances = []; |
| 24 for (var i = 0; i < 5; i++) { | 24 for (var i = 0; i < 5; i++) { |
| 25 gc(); | 25 gc(); |
| 26 instances.push(builder.instantiate({imported_mem: memory})); | 26 instances.push(builder.instantiate({mod: {imported_mem: memory}})); |
| 27 } | 27 } |
| 28 function grow_instance_0(pages) { return instances[0].exports.grow(pages); } | 28 function grow_instance_0(pages) { return instances[0].exports.grow(pages); } |
| 29 function grow_instance_1(pages) { return instances[1].exports.grow(pages); } | 29 function grow_instance_1(pages) { return instances[1].exports.grow(pages); } |
| 30 function grow_instance_2(pages) { return instances[2].exports.grow(pages); } | 30 function grow_instance_2(pages) { return instances[2].exports.grow(pages); } |
| 31 function grow_instance_3(pages) { return instances[3].exports.grow(pages); } | 31 function grow_instance_3(pages) { return instances[3].exports.grow(pages); } |
| 32 function grow_instance_4(pages) { return instances[4].exports.grow(pages); } | 32 function grow_instance_4(pages) { return instances[4].exports.grow(pages); } |
| 33 | 33 |
| 34 var start_index = 0; | 34 var start_index = 0; |
| 35 var end_index = 5; | 35 var end_index = 5; |
| 36 function verify_mem_size(expected_pages) { | 36 function verify_mem_size(expected_pages) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 53 // i[0] - i[2] - i[3] - i[4] | 53 // i[0] - i[2] - i[3] - i[4] |
| 54 start_index = 2; | 54 start_index = 2; |
| 55 verify_mem_size(600); | 55 verify_mem_size(600); |
| 56 assertEquals(600, instances[0].exports.mem_size()); | 56 assertEquals(600, instances[0].exports.mem_size()); |
| 57 assertEquals(600, grow_instance_2(200)); | 57 assertEquals(600, grow_instance_2(200)); |
| 58 assertEquals(800*kPageSize, memory.buffer.byteLength); | 58 assertEquals(800*kPageSize, memory.buffer.byteLength); |
| 59 verify_mem_size(800); | 59 verify_mem_size(800); |
| 60 assertEquals(800, instances[0].exports.mem_size()); | 60 assertEquals(800, instances[0].exports.mem_size()); |
| 61 | 61 |
| 62 // Instantiate a new instance and verify that it can be grown correctly. | 62 // Instantiate a new instance and verify that it can be grown correctly. |
| 63 instances.push(builder.instantiate({imported_mem: memory})); | 63 instances.push(builder.instantiate({mod: {imported_mem: memory}})); |
| 64 function grow_instance_5(pages) { return instances[5].exports.grow(pages); } | 64 function grow_instance_5(pages) { return instances[5].exports.grow(pages); } |
| 65 gc(); | 65 gc(); |
| 66 gc(); | 66 gc(); |
| 67 | 67 |
| 68 // i[0] - i[2] - i[3] - i[4] - i[5] | 68 // i[0] - i[2] - i[3] - i[4] - i[5] |
| 69 start_index = 2; | 69 start_index = 2; |
| 70 end_index = 6; | 70 end_index = 6; |
| 71 verify_mem_size(800); | 71 verify_mem_size(800); |
| 72 assertEquals(800, instances[0].exports.mem_size()); | 72 assertEquals(800, instances[0].exports.mem_size()); |
| 73 assertEquals(800, grow_instance_2(100)); | 73 assertEquals(800, grow_instance_2(100)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 assertEquals(1100, instances[2].exports.mem_size()); | 115 assertEquals(1100, instances[2].exports.mem_size()); |
| 116 assertEquals(1100, instances[5].exports.mem_size()); | 116 assertEquals(1100, instances[5].exports.mem_size()); |
| 117 assertEquals(1100, grow_instance_5(1)); | 117 assertEquals(1100, grow_instance_5(1)); |
| 118 gc(); | 118 gc(); |
| 119 gc(); | 119 gc(); |
| 120 | 120 |
| 121 assertEquals(1101*kPageSize, memory.buffer.byteLength); | 121 assertEquals(1101*kPageSize, memory.buffer.byteLength); |
| 122 assertEquals(1101, instances[2].exports.mem_size()); | 122 assertEquals(1101, instances[2].exports.mem_size()); |
| 123 assertEquals(1101, instances[5].exports.mem_size()); | 123 assertEquals(1101, instances[5].exports.mem_size()); |
| 124 })(); | 124 })(); |
| OLD | NEW |