blob: 9c37fe485f86f110637026f2255f02c825bab577 [file] [log] [blame]
Ben Murdochda12d292016-06-02 14:46:10 +01001// 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
3// found in the LICENSE file.
4
5// Flags: --expose-wasm --expose-gc
6
7load("test/mjsunit/wasm/wasm-constants.js");
8load("test/mjsunit/wasm/wasm-module-builder.js");
9
10function makeFFI(func, t) {
11 var builder = new WasmModuleBuilder();
12
Ben Murdoch61f157c2016-09-16 13:49:30 +010013 var sig_index = builder.addType(makeSig([t,t,t,t,t,t,t,t,t,t], [t]));
Ben Murdochda12d292016-06-02 14:46:10 +010014 builder.addImport("func", sig_index);
15 // Try to create a frame with lots of spilled values and parameters
16 // on the stack to try to catch GC bugs in the reference maps for
17 // the different parts of the stack.
18 builder.addFunction("main", sig_index)
19 .addBody([
Ben Murdochda12d292016-06-02 14:46:10 +010020 kExprGetLocal, 0, // --
21 kExprGetLocal, 1, // --
22 kExprGetLocal, 2, // --
23 kExprGetLocal, 3, // --
24 kExprGetLocal, 4, // --
25 kExprGetLocal, 5, // --
26 kExprGetLocal, 6, // --
27 kExprGetLocal, 7, // --
28 kExprGetLocal, 8, // --
29 kExprGetLocal, 9, // --
Ben Murdochc5610432016-08-08 18:44:38 +010030 kExprCallImport, 10, 0, // --
Ben Murdochda12d292016-06-02 14:46:10 +010031 kExprGetLocal, 0, // --
32 kExprGetLocal, 1, // --
33 kExprGetLocal, 2, // --
34 kExprGetLocal, 3, // --
35 kExprGetLocal, 4, // --
36 kExprGetLocal, 5, // --
37 kExprGetLocal, 6, // --
38 kExprGetLocal, 7, // --
39 kExprGetLocal, 8, // --
Ben Murdochc5610432016-08-08 18:44:38 +010040 kExprGetLocal, 9, // --
41 kExprCallImport, 10, 0 // --
Ben Murdochda12d292016-06-02 14:46:10 +010042 ]) // --
43 .exportFunc();
44
45 return builder.instantiate({func: func}).exports.main;
46}
47
48
49function print10(a, b, c, d, e, f, g, h, i) {
50 print(a + ",", b + ",", c + ",", d + ",", e + ",", f + ",", g + ",", h + ",", i);
51 gc();
52 print(a + ",", b + ",", c + ",", d + ",", e + ",", f + ",", g + ",", h + ",", i);
53}
54
55(function I32Test() {
56 var main = makeFFI(print10, kAstI32);
57 for (var i = 1; i < 0xFFFFFFF; i <<= 2) {
58 main(i - 1, i, i + 2, i + 3, i + 4, i + 5, i + 6, i + 7, i + 8);
59 }
60})();
61
62(function F32Test() {
63 var main = makeFFI(print10, kAstF32);
64 for (var i = 1; i < 2e+30; i *= -157) {
65 main(i - 1, i, i + 2, i + 3, i + 4, i + 5, i + 6, i + 7, i + 8);
66 }
67})();
68
Ben Murdoch61f157c2016-09-16 13:49:30 +010069(function F64Test() {
Ben Murdochda12d292016-06-02 14:46:10 +010070 var main = makeFFI(print10, kAstF64);
71 for (var i = 1; i < 2e+80; i *= -1137) {
72 main(i - 1, i, i + 2, i + 3, i + 4, i + 5, i + 6, i + 7, i + 8);
73 }
74})();
Ben Murdoch61f157c2016-09-16 13:49:30 +010075
76(function GCInJSToWasmTest() {
77 var builder = new WasmModuleBuilder();
78
79 var sig_index = builder.addType(kSig_i_i);
80 builder.addFunction("main", sig_index)
81 .addBody([
82 kExprGetLocal, 0, // --
83 ]) // --
84 .exportFunc();
85
86 var main = builder.instantiate({}).exports.main;
87
88 var gc_object = {
89 valueOf: function() {
90 // Call the GC in valueOf, which is called within the JSToWasm wrapper.
91 gc();
92 return {};
93 }
94 };
95
96 main(gc_object);
97})();