| 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_turbo_inlining = true; | |
| 40 FunctionTester T( | 39 FunctionTester T( |
| 41 "(function(){" | 40 "(function(){" |
| 42 "function foo(s) { AssertStackDepth(1); return s; };" | 41 "function foo(s) { AssertStackDepth(1); return s; };" |
| 43 "function bar(s, t) { return foo(s); };" | 42 "function bar(s, t) { return foo(s); };" |
| 44 "return bar;})();"); | 43 "return bar;})();", |
| 44 true, true); |
| 45 | 45 |
| 46 InstallAssertStackDepthHelper(CcTest::isolate()); | 46 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 47 T.CheckCall(T.Val(1), T.Val(1), T.Val(2)); | 47 T.CheckCall(T.Val(1), T.Val(1), T.Val(2)); |
| 48 } | 48 } |
| 49 | 49 |
| 50 | 50 |
| 51 TEST(SimpleInliningContext) { | 51 TEST(SimpleInliningContext) { |
| 52 FLAG_turbo_inlining = true; | |
| 53 FunctionTester T( | 52 FunctionTester T( |
| 54 "(function () {" | 53 "(function () {" |
| 55 "function foo(s) { AssertStackDepth(1); var x = 12; return s + x; };" | 54 "function foo(s) { AssertStackDepth(1); var x = 12; return s + x; };" |
| 56 "function bar(s, t) { return foo(s); };" | 55 "function bar(s, t) { return foo(s); };" |
| 57 "return bar;" | 56 "return bar;" |
| 58 "})();"); | 57 "})();", |
| 58 true, true); |
| 59 | 59 |
| 60 InstallAssertStackDepthHelper(CcTest::isolate()); | 60 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 61 T.CheckCall(T.Val(13), T.Val(1), T.Val(2)); | 61 T.CheckCall(T.Val(13), T.Val(1), T.Val(2)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 | 64 |
| 65 TEST(CaptureContext) { | 65 TEST(CaptureContext) { |
| 66 FLAG_turbo_inlining = true; | |
| 67 FunctionTester T( | 66 FunctionTester T( |
| 68 "var f = (function () {" | 67 "var f = (function () {" |
| 69 "var x = 42;" | 68 "var x = 42;" |
| 70 "function bar(s) { return x + s; };" | 69 "function bar(s) { return x + s; };" |
| 71 "return (function (s) { return bar(s); });" | 70 "return (function (s) { return bar(s); });" |
| 72 "})();" | 71 "})();" |
| 73 "(function (s) { return f(s)})"); | 72 "(function (s) { return f(s)})", |
| 73 true, true); |
| 74 | 74 |
| 75 InstallAssertStackDepthHelper(CcTest::isolate()); | 75 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 76 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); | 76 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); |
| 77 } | 77 } |
| 78 | 78 |
| 79 | 79 |
| 80 // 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 |
| 81 // some point, change this test. | 81 // some point, change this test. |
| 82 TEST(DontInlineEval) { | 82 TEST(DontInlineEval) { |
| 83 FLAG_turbo_inlining = true; | |
| 84 FunctionTester T( | 83 FunctionTester T( |
| 85 "var x = 42;" | 84 "var x = 42;" |
| 86 "(function () {" | 85 "(function () {" |
| 87 "function bar(s, t) { return eval(\"AssertStackDepth(2); x\") };" | 86 "function bar(s, t) { return eval(\"AssertStackDepth(2); x\") };" |
| 88 "return bar;" | 87 "return bar;" |
| 89 "})();"); | 88 "})();", |
| 89 true, true); |
| 90 | 90 |
| 91 InstallAssertStackDepthHelper(CcTest::isolate()); | 91 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 92 T.CheckCall(T.Val(42), T.Val("x"), T.undefined()); | 92 T.CheckCall(T.Val(42), T.Val("x"), T.undefined()); |
| 93 } | 93 } |
| 94 | 94 |
| 95 | 95 |
| 96 TEST(InlineOmitArguments) { | 96 TEST(InlineOmitArguments) { |
| 97 FLAG_turbo_inlining = true; | |
| 98 FunctionTester T( | 97 FunctionTester T( |
| 99 "(function () {" | 98 "(function () {" |
| 100 "var x = 42;" | 99 "var x = 42;" |
| 101 "function bar(s, t, u, v) { AssertStackDepth(1); return x + s; };" | 100 "function bar(s, t, u, v) { AssertStackDepth(1); return x + s; };" |
| 102 "return (function (s,t) { return bar(s); });" | 101 "return (function (s,t) { return bar(s); });" |
| 103 "})();"); | 102 "})();", |
| 103 true, true); |
| 104 | 104 |
| 105 InstallAssertStackDepthHelper(CcTest::isolate()); | 105 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 106 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); | 106 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); |
| 107 } | 107 } |
| 108 | 108 |
| 109 | 109 |
| 110 TEST(InlineSurplusArguments) { | 110 TEST(InlineSurplusArguments) { |
| 111 FLAG_turbo_inlining = true; | |
| 112 FunctionTester T( | 111 FunctionTester T( |
| 113 "(function () {" | 112 "(function () {" |
| 114 "var x = 42;" | 113 "var x = 42;" |
| 115 "function foo(s) { AssertStackDepth(1); return x + s; };" | 114 "function foo(s) { AssertStackDepth(1); return x + s; };" |
| 116 "function bar(s,t) { return foo(s,t,13); };" | 115 "function bar(s,t) { return foo(s,t,13); };" |
| 117 "return bar;" | 116 "return bar;" |
| 118 "})();"); | 117 "})();", |
| 118 true, true); |
| 119 | 119 |
| 120 InstallAssertStackDepthHelper(CcTest::isolate()); | 120 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 121 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); | 121 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); |
| 122 } | 122 } |
| 123 | 123 |
| 124 | 124 |
| 125 TEST(InlineTwice) { | 125 TEST(InlineTwice) { |
| 126 FLAG_turbo_inlining = true; | |
| 127 FunctionTester T( | 126 FunctionTester T( |
| 128 "(function () {" | 127 "(function () {" |
| 129 "var x = 42;" | 128 "var x = 42;" |
| 130 "function bar(s) { AssertStackDepth(1); return x + s; };" | 129 "function bar(s) { AssertStackDepth(1); return x + s; };" |
| 131 "return (function (s,t) { return bar(s) + bar(t); });" | 130 "return (function (s,t) { return bar(s) + bar(t); });" |
| 132 "})();"); | 131 "})();", |
| 132 true, true); |
| 133 | 133 |
| 134 InstallAssertStackDepthHelper(CcTest::isolate()); | 134 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 135 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)); |
| 136 } | 136 } |
| 137 | 137 |
| 138 | 138 |
| 139 TEST(InlineTwiceDependent) { | 139 TEST(InlineTwiceDependent) { |
| 140 FLAG_turbo_inlining = true; | |
| 141 FunctionTester T( | 140 FunctionTester T( |
| 142 "(function () {" | 141 "(function () {" |
| 143 "var x = 42;" | 142 "var x = 42;" |
| 144 "function foo(s) { AssertStackDepth(1); return x + s; };" | 143 "function foo(s) { AssertStackDepth(1); return x + s; };" |
| 145 "function bar(s,t) { return foo(foo(s)); };" | 144 "function bar(s,t) { return foo(foo(s)); };" |
| 146 "return bar;" | 145 "return bar;" |
| 147 "})();"); | 146 "})();", |
| 147 true, true); |
| 148 | 148 |
| 149 InstallAssertStackDepthHelper(CcTest::isolate()); | 149 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 150 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)); |
| 151 } | 151 } |
| 152 | 152 |
| 153 | 153 |
| 154 TEST(InlineTwiceDependentDiamond) { | 154 TEST(InlineTwiceDependentDiamond) { |
| 155 FLAG_turbo_inlining = true; | |
| 156 FunctionTester T( | 155 FunctionTester T( |
| 157 "(function () {" | 156 "(function () {" |
| 158 "function foo(s) { if (true) {" | 157 "function foo(s) { if (true) {" |
| 159 " return 12 } else { return 13; } };" | 158 " return 12 } else { return 13; } };" |
| 160 "function bar(s,t) { return foo(foo(1)); };" | 159 "function bar(s,t) { return foo(foo(1)); };" |
| 161 "return bar;" | 160 "return bar;" |
| 162 "})();"); | 161 "})();", |
| 162 true, true); |
| 163 | 163 |
| 164 InstallAssertStackDepthHelper(CcTest::isolate()); | 164 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 165 T.CheckCall(T.Val(12), T.undefined(), T.undefined()); | 165 T.CheckCall(T.Val(12), T.undefined(), T.undefined()); |
| 166 } | 166 } |
| 167 | 167 |
| 168 | 168 |
| 169 TEST(InlineTwiceDependentDiamondReal) { | 169 TEST(InlineTwiceDependentDiamondReal) { |
| 170 FLAG_turbo_inlining = true; | |
| 171 FunctionTester T( | 170 FunctionTester T( |
| 172 "(function () {" | 171 "(function () {" |
| 173 "var x = 41;" | 172 "var x = 41;" |
| 174 "function foo(s) { AssertStackDepth(1); if (s % 2 == 0) {" | 173 "function foo(s) { AssertStackDepth(1); if (s % 2 == 0) {" |
| 175 " return x - s } else { return x + s; } };" | 174 " return x - s } else { return x + s; } };" |
| 176 "function bar(s,t) { return foo(foo(s)); };" | 175 "function bar(s,t) { return foo(foo(s)); };" |
| 177 "return bar;" | 176 "return bar;" |
| 178 "})();"); | 177 "})();", |
| 178 true, true); |
| 179 | 179 |
| 180 InstallAssertStackDepthHelper(CcTest::isolate()); | 180 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 181 T.CheckCall(T.Val(-11), T.Val(11), T.Val(4)); | 181 T.CheckCall(T.Val(-11), T.Val(11), T.Val(4)); |
| 182 } | 182 } |
| 183 | 183 |
| 184 #endif // V8_TURBOFAN_TARGET | 184 #endif // V8_TURBOFAN_TARGET |
| OLD | NEW |