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/cctest.h" |
7 #include "test/cctest/compiler/function-tester.h" | 8 #include "test/cctest/compiler/function-tester.h" |
8 | 9 |
| 10 using namespace v8; |
9 using namespace v8::internal; | 11 using namespace v8::internal; |
10 using namespace v8::internal::compiler; | 12 using namespace v8::internal::compiler; |
11 | 13 |
| 14 static void IsOptimized(const FunctionCallbackInfo<v8::Value>& args) { |
| 15 JavaScriptFrameIterator it(CcTest::i_isolate()); |
| 16 JavaScriptFrame* frame = it.frame(); |
| 17 return args.GetReturnValue().Set(frame->is_optimized()); |
| 18 } |
| 19 |
| 20 |
| 21 static void InstallIsOptimizedHelper(v8::Isolate* isolate) { |
| 22 Local<v8::Context> context = isolate->GetCurrentContext(); |
| 23 Local<v8::FunctionTemplate> t = FunctionTemplate::New(isolate, IsOptimized); |
| 24 context->Global()->Set(v8_str("IsOptimized"), t->GetFunction()); |
| 25 } |
| 26 |
12 #if V8_TURBOFAN_TARGET | 27 #if V8_TURBOFAN_TARGET |
13 | 28 |
14 TEST(TurboSimpleDeopt) { | 29 TEST(TurboSimpleDeopt) { |
15 FLAG_allow_natives_syntax = true; | 30 FLAG_allow_natives_syntax = true; |
16 FLAG_turbo_deoptimization = true; | 31 FLAG_turbo_deoptimization = true; |
17 | 32 |
18 FunctionTester T( | 33 FunctionTester T( |
19 "(function f(a) {" | 34 "(function f(a) {" |
20 "var b = 1;" | 35 "var b = 1;" |
21 "if (!%IsOptimized()) return 0;" | 36 "if (!IsOptimized()) return 0;" |
22 "%DeoptimizeFunction(f);" | 37 "%DeoptimizeFunction(f);" |
23 "if (%IsOptimized()) return 0;" | 38 "if (IsOptimized()) return 0;" |
24 "return a + b; })"); | 39 "return a + b; })"); |
25 | 40 |
| 41 InstallIsOptimizedHelper(CcTest::isolate()); |
26 T.CheckCall(T.Val(2), T.Val(1)); | 42 T.CheckCall(T.Val(2), T.Val(1)); |
27 } | 43 } |
28 | 44 |
29 | 45 |
30 TEST(TurboSimpleDeoptInExpr) { | 46 TEST(TurboSimpleDeoptInExpr) { |
31 FLAG_allow_natives_syntax = true; | 47 FLAG_allow_natives_syntax = true; |
32 FLAG_turbo_deoptimization = true; | 48 FLAG_turbo_deoptimization = true; |
33 | 49 |
34 FunctionTester T( | 50 FunctionTester T( |
35 "(function f(a) {" | 51 "(function f(a) {" |
36 "var b = 1;" | 52 "var b = 1;" |
37 "var c = 2;" | 53 "var c = 2;" |
38 "if (!%IsOptimized()) return 0;" | 54 "if (!IsOptimized()) return 0;" |
39 "var d = b + (%DeoptimizeFunction(f), c);" | 55 "var d = b + (%DeoptimizeFunction(f), c);" |
40 "if (%IsOptimized()) return 0;" | 56 "if (IsOptimized()) return 0;" |
41 "return d + a; })"); | 57 "return d + a; })"); |
42 | 58 |
| 59 InstallIsOptimizedHelper(CcTest::isolate()); |
43 T.CheckCall(T.Val(6), T.Val(3)); | 60 T.CheckCall(T.Val(6), T.Val(3)); |
44 } | 61 } |
45 | 62 |
46 #endif | 63 #endif |
47 | 64 |
48 TEST(TurboTrivialDeopt) { | 65 TEST(TurboTrivialDeopt) { |
49 FLAG_allow_natives_syntax = true; | 66 FLAG_allow_natives_syntax = true; |
50 FLAG_turbo_deoptimization = true; | 67 FLAG_turbo_deoptimization = true; |
51 | 68 |
52 FunctionTester T( | 69 FunctionTester T( |
53 "(function foo() {" | 70 "(function foo() {" |
54 "%DeoptimizeFunction(foo);" | 71 "%DeoptimizeFunction(foo);" |
55 "return 1; })"); | 72 "return 1; })"); |
56 | 73 |
57 T.CheckCall(T.Val(1)); | 74 T.CheckCall(T.Val(1)); |
58 } | 75 } |
OLD | NEW |