OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "test/cctest/compiler/function-tester.h" | 7 #include "test/cctest/compiler/function-tester.h" |
8 | 8 |
9 #if V8_TURBOFAN_TARGET | 9 #if V8_TURBOFAN_TARGET |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 static void InstallAssertStackDepthHelper(v8::Isolate* isolate) { | 30 static void InstallAssertStackDepthHelper(v8::Isolate* isolate) { |
31 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 31 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
32 v8::Local<v8::FunctionTemplate> t = | 32 v8::Local<v8::FunctionTemplate> t = |
33 v8::FunctionTemplate::New(isolate, AssertStackDepth); | 33 v8::FunctionTemplate::New(isolate, AssertStackDepth); |
34 context->Global()->Set(v8_str("AssertStackDepth"), t->GetFunction()); | 34 context->Global()->Set(v8_str("AssertStackDepth"), t->GetFunction()); |
35 } | 35 } |
36 | 36 |
37 | 37 |
38 TEST(SimpleInlining) { | 38 TEST(SimpleInlining) { |
39 FLAG_context_specialization = true; | |
40 FLAG_turbo_inlining = true; | |
41 FunctionTester T( | 39 FunctionTester T( |
42 "(function(){" | 40 "(function(){" |
43 "function foo(s) { AssertStackDepth(1); return s; };" | 41 "function foo(s) { AssertStackDepth(1); return s; };" |
44 "function bar(s, t) { return foo(s); };" | 42 "function bar(s, t) { return foo(s); };" |
45 "return bar;})();"); | 43 "return bar;})();", |
| 44 FunctionTester::kInliningEnabled | FunctionTester::kContextSpecializing); |
46 | 45 |
47 InstallAssertStackDepthHelper(CcTest::isolate()); | 46 InstallAssertStackDepthHelper(CcTest::isolate()); |
48 T.CheckCall(T.Val(1), T.Val(1), T.Val(2)); | 47 T.CheckCall(T.Val(1), T.Val(1), T.Val(2)); |
49 } | 48 } |
50 | 49 |
51 | 50 |
52 TEST(SimpleInliningContext) { | 51 TEST(SimpleInliningContext) { |
53 FLAG_context_specialization = true; | |
54 FLAG_turbo_inlining = true; | |
55 FunctionTester T( | 52 FunctionTester T( |
56 "(function () {" | 53 "(function () {" |
57 "function foo(s) { AssertStackDepth(1); var x = 12; return s + x; };" | 54 "function foo(s) { AssertStackDepth(1); var x = 12; return s + x; };" |
58 "function bar(s, t) { return foo(s); };" | 55 "function bar(s, t) { return foo(s); };" |
59 "return bar;" | 56 "return bar;" |
60 "})();"); | 57 "})();", |
| 58 FunctionTester::kInliningEnabled | FunctionTester::kContextSpecializing); |
61 | 59 |
62 InstallAssertStackDepthHelper(CcTest::isolate()); | 60 InstallAssertStackDepthHelper(CcTest::isolate()); |
63 T.CheckCall(T.Val(13), T.Val(1), T.Val(2)); | 61 T.CheckCall(T.Val(13), T.Val(1), T.Val(2)); |
64 } | 62 } |
65 | 63 |
66 | 64 |
67 TEST(CaptureContext) { | 65 TEST(CaptureContext) { |
68 FLAG_context_specialization = true; | |
69 FLAG_turbo_inlining = true; | |
70 FunctionTester T( | 66 FunctionTester T( |
71 "var f = (function () {" | 67 "var f = (function () {" |
72 "var x = 42;" | 68 "var x = 42;" |
73 "function bar(s) { return x + s; };" | 69 "function bar(s) { return x + s; };" |
74 "return (function (s) { return bar(s); });" | 70 "return (function (s) { return bar(s); });" |
75 "})();" | 71 "})();" |
76 "(function (s) { return f(s)})"); | 72 "(function (s) { return f(s)})", |
| 73 FunctionTester::kInliningEnabled | FunctionTester::kContextSpecializing); |
77 | 74 |
78 InstallAssertStackDepthHelper(CcTest::isolate()); | 75 InstallAssertStackDepthHelper(CcTest::isolate()); |
79 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); | 76 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); |
80 } | 77 } |
81 | 78 |
82 | 79 |
83 // TODO(sigurds) For now we do not inline any native functions. If we do at | 80 // TODO(sigurds) For now we do not inline any native functions. If we do at |
84 // some point, change this test. | 81 // some point, change this test. |
85 TEST(DontInlineEval) { | 82 TEST(DontInlineEval) { |
86 FLAG_context_specialization = true; | |
87 FLAG_turbo_inlining = true; | |
88 FunctionTester T( | 83 FunctionTester T( |
89 "var x = 42;" | 84 "var x = 42;" |
90 "(function () {" | 85 "(function () {" |
91 "function bar(s, t) { return eval(\"AssertStackDepth(2); x\") };" | 86 "function bar(s, t) { return eval(\"AssertStackDepth(2); x\") };" |
92 "return bar;" | 87 "return bar;" |
93 "})();"); | 88 "})();", |
| 89 FunctionTester::kInliningEnabled | FunctionTester::kContextSpecializing); |
94 | 90 |
95 InstallAssertStackDepthHelper(CcTest::isolate()); | 91 InstallAssertStackDepthHelper(CcTest::isolate()); |
96 T.CheckCall(T.Val(42), T.Val("x"), T.undefined()); | 92 T.CheckCall(T.Val(42), T.Val("x"), T.undefined()); |
97 } | 93 } |
98 | 94 |
99 | 95 |
100 TEST(InlineOmitArguments) { | 96 TEST(InlineOmitArguments) { |
101 FLAG_context_specialization = true; | |
102 FLAG_turbo_inlining = true; | |
103 FunctionTester T( | 97 FunctionTester T( |
104 "(function () {" | 98 "(function () {" |
105 "var x = 42;" | 99 "var x = 42;" |
106 "function bar(s, t, u, v) { AssertStackDepth(1); return x + s; };" | 100 "function bar(s, t, u, v) { AssertStackDepth(1); return x + s; };" |
107 "return (function (s,t) { return bar(s); });" | 101 "return (function (s,t) { return bar(s); });" |
108 "})();"); | 102 "})();", |
| 103 FunctionTester::kInliningEnabled | FunctionTester::kContextSpecializing); |
109 | 104 |
110 InstallAssertStackDepthHelper(CcTest::isolate()); | 105 InstallAssertStackDepthHelper(CcTest::isolate()); |
111 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); | 106 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); |
112 } | 107 } |
113 | 108 |
114 | 109 |
115 TEST(InlineSurplusArguments) { | 110 TEST(InlineSurplusArguments) { |
116 FLAG_context_specialization = true; | |
117 FLAG_turbo_inlining = true; | |
118 FunctionTester T( | 111 FunctionTester T( |
119 "(function () {" | 112 "(function () {" |
120 "var x = 42;" | 113 "var x = 42;" |
121 "function foo(s) { AssertStackDepth(1); return x + s; };" | 114 "function foo(s) { AssertStackDepth(1); return x + s; };" |
122 "function bar(s,t) { return foo(s,t,13); };" | 115 "function bar(s,t) { return foo(s,t,13); };" |
123 "return bar;" | 116 "return bar;" |
124 "})();"); | 117 "})();", |
| 118 FunctionTester::kInliningEnabled | FunctionTester::kContextSpecializing); |
125 | 119 |
126 InstallAssertStackDepthHelper(CcTest::isolate()); | 120 InstallAssertStackDepthHelper(CcTest::isolate()); |
127 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); | 121 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); |
128 } | 122 } |
129 | 123 |
130 | 124 |
131 TEST(InlineTwice) { | 125 TEST(InlineTwice) { |
132 FLAG_context_specialization = true; | |
133 FLAG_turbo_inlining = true; | |
134 FunctionTester T( | 126 FunctionTester T( |
135 "(function () {" | 127 "(function () {" |
136 "var x = 42;" | 128 "var x = 42;" |
137 "function bar(s) { AssertStackDepth(1); return x + s; };" | 129 "function bar(s) { AssertStackDepth(1); return x + s; };" |
138 "return (function (s,t) { return bar(s) + bar(t); });" | 130 "return (function (s,t) { return bar(s) + bar(t); });" |
139 "})();"); | 131 "})();", |
| 132 FunctionTester::kInliningEnabled | FunctionTester::kContextSpecializing); |
140 | 133 |
141 InstallAssertStackDepthHelper(CcTest::isolate()); | 134 InstallAssertStackDepthHelper(CcTest::isolate()); |
142 T.CheckCall(T.Val(2 * 42 + 12 + 4), T.Val(12), T.Val(4)); | 135 T.CheckCall(T.Val(2 * 42 + 12 + 4), T.Val(12), T.Val(4)); |
143 } | 136 } |
144 | 137 |
145 | 138 |
146 TEST(InlineTwiceDependent) { | 139 TEST(InlineTwiceDependent) { |
147 FLAG_context_specialization = true; | |
148 FLAG_turbo_inlining = true; | |
149 FunctionTester T( | 140 FunctionTester T( |
150 "(function () {" | 141 "(function () {" |
151 "var x = 42;" | 142 "var x = 42;" |
152 "function foo(s) { AssertStackDepth(1); return x + s; };" | 143 "function foo(s) { AssertStackDepth(1); return x + s; };" |
153 "function bar(s,t) { return foo(foo(s)); };" | 144 "function bar(s,t) { return foo(foo(s)); };" |
154 "return bar;" | 145 "return bar;" |
155 "})();"); | 146 "})();", |
| 147 FunctionTester::kInliningEnabled | FunctionTester::kContextSpecializing); |
156 | 148 |
157 InstallAssertStackDepthHelper(CcTest::isolate()); | 149 InstallAssertStackDepthHelper(CcTest::isolate()); |
158 T.CheckCall(T.Val(42 + 42 + 12), T.Val(12), T.Val(4)); | 150 T.CheckCall(T.Val(42 + 42 + 12), T.Val(12), T.Val(4)); |
159 } | 151 } |
160 | 152 |
161 | 153 |
162 TEST(InlineTwiceDependentDiamond) { | 154 TEST(InlineTwiceDependentDiamond) { |
163 FLAG_context_specialization = true; | |
164 FLAG_turbo_inlining = true; | |
165 FunctionTester T( | 155 FunctionTester T( |
166 "(function () {" | 156 "(function () {" |
167 "function foo(s) { if (true) {" | 157 "function foo(s) { if (true) {" |
168 " return 12 } else { return 13; } };" | 158 " return 12 } else { return 13; } };" |
169 "function bar(s,t) { return foo(foo(1)); };" | 159 "function bar(s,t) { return foo(foo(1)); };" |
170 "return bar;" | 160 "return bar;" |
171 "})();"); | 161 "})();", |
| 162 FunctionTester::kInliningEnabled | FunctionTester::kContextSpecializing); |
172 | 163 |
173 InstallAssertStackDepthHelper(CcTest::isolate()); | 164 InstallAssertStackDepthHelper(CcTest::isolate()); |
174 T.CheckCall(T.Val(12), T.undefined(), T.undefined()); | 165 T.CheckCall(T.Val(12), T.undefined(), T.undefined()); |
175 } | 166 } |
176 | 167 |
177 | 168 |
178 TEST(InlineTwiceDependentDiamondReal) { | 169 TEST(InlineTwiceDependentDiamondReal) { |
179 FLAG_context_specialization = true; | |
180 FLAG_turbo_inlining = true; | |
181 FunctionTester T( | 170 FunctionTester T( |
182 "(function () {" | 171 "(function () {" |
183 "var x = 41;" | 172 "var x = 41;" |
184 "function foo(s) { AssertStackDepth(1); if (s % 2 == 0) {" | 173 "function foo(s) { AssertStackDepth(1); if (s % 2 == 0) {" |
185 " return x - s } else { return x + s; } };" | 174 " return x - s } else { return x + s; } };" |
186 "function bar(s,t) { return foo(foo(s)); };" | 175 "function bar(s,t) { return foo(foo(s)); };" |
187 "return bar;" | 176 "return bar;" |
188 "})();"); | 177 "})();", |
| 178 FunctionTester::kInliningEnabled | FunctionTester::kContextSpecializing); |
189 | 179 |
190 InstallAssertStackDepthHelper(CcTest::isolate()); | 180 InstallAssertStackDepthHelper(CcTest::isolate()); |
191 T.CheckCall(T.Val(-11), T.Val(11), T.Val(4)); | 181 T.CheckCall(T.Val(-11), T.Val(11), T.Val(4)); |
192 } | 182 } |
193 | 183 |
194 #endif // V8_TURBOFAN_TARGET | 184 #endif // V8_TURBOFAN_TARGET |
OLD | NEW |