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 --stress-compaction | 5 // Flags: --expose-wasm --stress-compaction |
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 var kPageSize = 0x10000; | 10 var kPageSize = 0x10000; |
11 var kV8MaxPages = 32767; | 11 var kV8MaxPages = 16384; |
12 | 12 |
13 function genGrowMemoryBuilder() { | 13 function genGrowMemoryBuilder() { |
14 var builder = new WasmModuleBuilder(); | 14 var builder = new WasmModuleBuilder(); |
15 builder.addFunction("grow_memory", kSig_i_i) | 15 builder.addFunction("grow_memory", kSig_i_i) |
16 .addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero]) | 16 .addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero]) |
17 .exportFunc(); | 17 .exportFunc(); |
18 builder.addFunction("load", kSig_i_i) | 18 builder.addFunction("load", kSig_i_i) |
19 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) | 19 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) |
20 .exportFunc(); | 20 .exportFunc(); |
21 builder.addFunction("store", kSig_i_ii) | 21 builder.addFunction("store", kSig_i_ii) |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 assertTraps(kTrapMemOutOfBounds, peek); | 291 assertTraps(kTrapMemOutOfBounds, peek); |
292 } | 292 } |
293 } | 293 } |
294 | 294 |
295 testGrowMemoryZeroInitialSize8(); | 295 testGrowMemoryZeroInitialSize8(); |
296 | 296 |
297 function testGrowMemoryTrapMaxPagesZeroInitialMemory() { | 297 function testGrowMemoryTrapMaxPagesZeroInitialMemory() { |
298 var builder = genGrowMemoryBuilder(); | 298 var builder = genGrowMemoryBuilder(); |
299 builder.addMemory(0, kV8MaxPages, false); | 299 builder.addMemory(0, kV8MaxPages, false); |
300 var module = builder.instantiate(); | 300 var module = builder.instantiate(); |
| 301 var maxPages = 16385; |
301 function growMem(pages) { return module.exports.grow_memory(pages); } | 302 function growMem(pages) { return module.exports.grow_memory(pages); } |
302 assertEquals(-1, growMem(kV8MaxPages + 1)); | 303 assertEquals(-1, growMem(maxPages)); |
303 } | 304 } |
304 | 305 |
305 testGrowMemoryTrapMaxPagesZeroInitialMemory(); | 306 testGrowMemoryTrapMaxPagesZeroInitialMemory(); |
306 | 307 |
307 function testGrowMemoryTrapMaxPages() { | 308 function testGrowMemoryTrapMaxPages() { |
308 var builder = genGrowMemoryBuilder(); | 309 var builder = genGrowMemoryBuilder(); |
309 builder.addMemory(1, 1, false); | 310 builder.addMemory(1, 1, false); |
310 var module = builder.instantiate(); | 311 var module = builder.instantiate(); |
| 312 var maxPages = 16384; |
311 function growMem(pages) { return module.exports.grow_memory(pages); } | 313 function growMem(pages) { return module.exports.grow_memory(pages); } |
312 assertEquals(-1, growMem(kV8MaxPages)); | 314 assertEquals(-1, growMem(maxPages)); |
313 } | 315 } |
314 | 316 |
315 testGrowMemoryTrapMaxPages(); | 317 testGrowMemoryTrapMaxPages(); |
316 | 318 |
317 function testGrowMemoryTrapsWithNonSmiInput() { | 319 function testGrowMemoryTrapsWithNonSmiInput() { |
318 var builder = genGrowMemoryBuilder(); | 320 var builder = genGrowMemoryBuilder(); |
319 builder.addMemory(0, kV8MaxPages, false); | 321 builder.addMemory(0, kV8MaxPages, false); |
320 var module = builder.instantiate(); | 322 var module = builder.instantiate(); |
321 function growMem(pages) { return module.exports.grow_memory(pages); } | 323 function growMem(pages) { return module.exports.grow_memory(pages); } |
322 // The parameter of grow_memory is unsigned. Therefore -1 stands for | 324 // The parameter of grow_memory is unsigned. Therefore -1 stands for |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 var kSpecMaxPages = 65535; | 486 var kSpecMaxPages = 65535; |
485 builder.addMemory(1, kSpecMaxPages, false); | 487 builder.addMemory(1, kSpecMaxPages, false); |
486 var module = builder.instantiate(); | 488 var module = builder.instantiate(); |
487 function poke(value) { return module.exports.store(offset, value); } | 489 function poke(value) { return module.exports.store(offset, value); } |
488 function growMem(pages) { return module.exports.grow_memory(pages); } | 490 function growMem(pages) { return module.exports.grow_memory(pages); } |
489 assertEquals(1, growMem(20)); | 491 assertEquals(1, growMem(20)); |
490 assertEquals(-1, growMem(kV8MaxPages - 20)); | 492 assertEquals(-1, growMem(kV8MaxPages - 20)); |
491 } | 493 } |
492 | 494 |
493 testGrowMemoryDeclaredSpecMaxTraps(); | 495 testGrowMemoryDeclaredSpecMaxTraps(); |
494 | |
495 function testGrowMemory2Gb() { | |
496 print("testGrowMemory2Gb"); | |
497 var builder = genGrowMemoryBuilder(); | |
498 builder.addMemory(1, kV8MaxPages, false); | |
499 var module = builder.instantiate(); | |
500 var offset, val; | |
501 function peek() { return module.exports.load(offset); } | |
502 function poke(value) { return module.exports.store(offset, value); } | |
503 function growMem(pages) { return module.exports.grow_memory(pages); } | |
504 | |
505 for(offset = 0; offset <= (kPageSize - 4); offset+=4) { | |
506 poke(100000 - offset); | |
507 assertEquals(100000 - offset, peek()); | |
508 } | |
509 | |
510 let result = growMem(kV8MaxPages - 1); | |
511 if (result == 1 ){ | |
512 for(offset = 0; offset <= (kPageSize - 4); offset+=4) { | |
513 assertEquals(100000 - offset, peek()); | |
514 } | |
515 | |
516 // Bounds check for large mem size | |
517 for(offset = (kV8MaxPages - 1) * kPageSize; | |
518 offset <= (kV8MaxPages * kPageSize - 4); offset+=4) { | |
519 poke(0xaced); | |
520 assertEquals(0xaced, peek()); | |
521 } | |
522 | |
523 for (offset = kV8MaxPages * kPageSize - 3; | |
524 offset <= kV8MaxPages * kPageSize + 4; offset++) { | |
525 assertTraps(kTrapMemOutOfBounds, poke); | |
526 } | |
527 | |
528 // Check traps around 3GB/4GB boundaries | |
529 let offset_3gb = 49152 * kPageSize; | |
530 let offset_4gb = 2 * kV8MaxPages * kPageSize; | |
531 for (offset = offset_3gb - 5; offset < offset_3gb + 4; offset++) { | |
532 assertTraps(kTrapMemOutOfBounds, poke); | |
533 } | |
534 for (offset = offset_4gb - 5; offset < offset_4gb; offset++) { | |
535 assertTraps(kTrapMemOutOfBounds, poke); | |
536 } | |
537 } else { | |
538 // Allocating big chunks of memory can fail on gc_stress, especially on 32 | |
539 // bit platforms. When grow_memory fails, expected result is -1. | |
540 assertEquals(-1, result); | |
541 } | |
542 } | |
543 | |
544 testGrowMemory2Gb(); | |
OLD | NEW |