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

Side by Side Diff: test/mjsunit/wasm/module-memory.js

Issue 2345593003: [wasm] Master CL for Binary 0xC changes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: [wasm] Master CL for Binary 0xC changes. Created 4 years, 3 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
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 // Flags: --expose-wasm --expose-gc --stress-compaction 5 // Flags: --expose-wasm --expose-gc --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 kMemSize = 65536; 10 var kMemSize = 65536;
11 11
12 function genModule(memory) { 12 function genModule(memory) {
13 var builder = new WasmModuleBuilder(); 13 var builder = new WasmModuleBuilder();
14 14
15 builder.addMemory(1, 1, true); 15 builder.addMemory(1, 1, true);
16 builder.addFunction("main", kSig_i_i) 16 builder.addFunction("main", kSig_i_i)
17 .addBody([ 17 .addBody([
18 // main body: while(i) { if(mem[i]) return -1; i -= 4; } return 0; 18 // main body: while(i) { if(mem[i]) return -1; i -= 4; } return 0;
19 kExprLoop, 19 // TODO(titzer): this manual bytecode has a copy of test-run-wasm.cc
20 kExprGetLocal,0, 20 /**/ kExprLoop, kAstStmt, // --
21 kExprIf, 21 /* */ kExprGetLocal, 0, // --
22 kExprGetLocal,0, 22 /* */ kExprIf, kAstStmt, // --
23 kExprI32LoadMem,0,0, 23 /* */ kExprGetLocal, 0, // --
24 kExprIf, 24 /* */ kExprI32LoadMem, 0, 0, // --
25 kExprI8Const,255, 25 /* */ kExprIf, kAstStmt, // --
26 kExprReturn, kArity1, 26 /* */ kExprI8Const, 255, // --
27 kExprEnd, 27 /* */ kExprReturn, // --
28 kExprGetLocal,0, 28 /* */ kExprEnd, // --
29 kExprI8Const,4, 29 /* */ kExprGetLocal, 0, // --
30 kExprI32Sub, 30 /* */ kExprI8Const, 4, // --
31 kExprSetLocal,0, 31 /* */ kExprI32Sub, // --
32 kExprBr, kArity1, 1, 32 /* */ kExprSetLocal, 0, // --
33 kExprEnd, 33 /* */ kExprBr, 1, // --
34 kExprEnd, 34 /* */ kExprEnd, // --
35 kExprI8Const,0 35 /* */ kExprEnd, // --
36 /**/ kExprI8Const, 0 // --
36 ]) 37 ])
37 .exportFunc(); 38 .exportFunc();
38 39
39 return builder.instantiate(null, memory); 40 return builder.instantiate(null, memory);
40 } 41 }
41 42
42 function testPokeMemory() { 43 function testPokeMemory() {
43 var module = genModule(null); 44 var module = genModule(null);
44 var buffer = module.exports.memory; 45 var buffer = module.exports.memory;
45 var main = module.exports.main; 46 var main = module.exports.main;
(...skipping 13 matching lines...) Expand all
59 assertEquals(0, main(kMemSize/2 - 4)); 60 assertEquals(0, main(kMemSize/2 - 4));
60 assertEquals(-1, main(kMemSize - 4)); 61 assertEquals(-1, main(kMemSize - 4));
61 62
62 array[kMemSize/2 + i] = 0; 63 array[kMemSize/2 + i] = 0;
63 assertEquals(0, main(kMemSize - 4)); 64 assertEquals(0, main(kMemSize - 4));
64 } 65 }
65 } 66 }
66 67
67 testPokeMemory(); 68 testPokeMemory();
68 69
70 function genAndGetMain(buffer) {
71 return genModule(buffer).exports.main; // to prevent intermediates living
72 }
73
69 function testSurvivalAcrossGc() { 74 function testSurvivalAcrossGc() {
70 var checker = genModule(null).exports.main; 75 var checker = genAndGetMain(null);
71 for (var i = 0; i < 5; i++) { 76 for (var i = 0; i < 3; i++) {
72 print("gc run ", i); 77 print("gc run ", i);
73 assertEquals(0, checker(kMemSize - 4)); 78 assertEquals(0, checker(kMemSize - 4));
74 gc(); 79 gc();
75 } 80 }
76 } 81 }
77 82
78 testSurvivalAcrossGc(); 83 testSurvivalAcrossGc();
79 testSurvivalAcrossGc(); 84 testSurvivalAcrossGc();
80 testSurvivalAcrossGc(); 85 testSurvivalAcrossGc();
81 testSurvivalAcrossGc(); 86 testSurvivalAcrossGc();
(...skipping 21 matching lines...) Expand all
103 108
104 array[kMemSize/2 + i] = 0; 109 array[kMemSize/2 + i] = 0;
105 assertEquals(0, main(kMemSize - 4)); 110 assertEquals(0, main(kMemSize - 4));
106 } 111 }
107 } 112 }
108 113
109 testPokeOuterMemory(); 114 testPokeOuterMemory();
110 115
111 function testOuterMemorySurvivalAcrossGc() { 116 function testOuterMemorySurvivalAcrossGc() {
112 var buffer = new ArrayBuffer(kMemSize); 117 var buffer = new ArrayBuffer(kMemSize);
113 var checker = genModule(buffer).exports.main; 118 var checker = genAndGetMain(buffer);
114 for (var i = 0; i < 5; i++) { 119 for (var i = 0; i < 3; i++) {
115 print("gc run ", i); 120 print("gc run ", i);
116 assertEquals(0, checker(kMemSize - 4)); 121 assertEquals(0, checker(kMemSize - 4));
117 gc(); 122 gc();
118 } 123 }
119 } 124 }
120 125
121 testOuterMemorySurvivalAcrossGc(); 126 testOuterMemorySurvivalAcrossGc();
122 testOuterMemorySurvivalAcrossGc(); 127 testOuterMemorySurvivalAcrossGc();
123 testOuterMemorySurvivalAcrossGc(); 128 testOuterMemorySurvivalAcrossGc();
124 testOuterMemorySurvivalAcrossGc(); 129 testOuterMemorySurvivalAcrossGc();
125 130
126 131
127 function testOOBThrows() { 132 function testOOBThrows() {
128 var builder = new WasmModuleBuilder(); 133 var builder = new WasmModuleBuilder();
129 134
130 builder.addMemory(1, 1, true); 135 builder.addMemory(1, 1, true);
131 builder.addFunction("geti", kSig_i_ii) 136 builder.addFunction("geti", kSig_i_ii)
132 .addBody([ 137 .addBody([
133 kExprGetLocal, 0, 138 kExprGetLocal, 0,
134 kExprGetLocal, 1, 139 kExprGetLocal, 1,
135 kExprI32LoadMem, 0, 0, 140 kExprI32LoadMem, 0, 0,
136 kExprI32StoreMem, 0, 0 141 kExprI32StoreMem, 0, 0,
142 kExprGetLocal, 1,
143 kExprI32LoadMem, 0, 0,
137 ]) 144 ])
138 .exportFunc(); 145 .exportFunc();
139 146
140 var module = builder.instantiate(); 147 var module = builder.instantiate();
141 var offset; 148 var offset;
142 149
143 function read() { return module.exports.geti(0, offset); } 150 function read() { return module.exports.geti(0, offset); }
144 function write() { return module.exports.geti(offset, 0); } 151 function write() { return module.exports.geti(offset, 0); }
145 152
146 for (offset = 0; offset < 65533; offset++) { 153 for (offset = 0; offset < 65533; offset++) {
147 assertEquals(0, read()); 154 assertEquals(0, read());
148 assertEquals(0, write()); 155 assertEquals(0, write());
149 } 156 }
150 157
151 158
152 for (offset = 65534; offset < 66536; offset++) { 159 for (offset = 65534; offset < 66536; offset++) {
153 assertTraps(kTrapMemOutOfBounds, read); 160 assertTraps(kTrapMemOutOfBounds, read);
154 assertTraps(kTrapMemOutOfBounds, write); 161 assertTraps(kTrapMemOutOfBounds, write);
155 } 162 }
156 } 163 }
157 164
158 testOOBThrows(); 165 testOOBThrows();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698