| 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/cctest.h" |
| 8 #include "test/cctest/compiler/function-tester.h" | 8 #include "test/cctest/compiler/function-tester.h" |
| 9 | 9 |
| 10 using namespace v8::internal; | 10 using namespace v8::internal; |
| 11 using namespace v8::internal::compiler; | 11 using namespace v8::internal::compiler; |
| 12 | 12 |
| 13 #if V8_TURBOFAN_TARGET | 13 #if V8_TURBOFAN_TARGET |
| 14 | 14 |
| 15 static void IsOptimized(const v8::FunctionCallbackInfo<v8::Value>& args) { | 15 static void IsOptimized(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 16 JavaScriptFrameIterator it(CcTest::i_isolate()); | 16 JavaScriptFrameIterator it(CcTest::i_isolate()); |
| 17 JavaScriptFrame* frame = it.frame(); | 17 JavaScriptFrame* frame = it.frame(); |
| 18 return args.GetReturnValue().Set(frame->is_optimized()); | 18 return args.GetReturnValue().Set(frame->is_optimized()); |
| 19 } | 19 } |
| 20 | 20 |
| 21 | 21 |
| 22 static void InstallIsOptimizedHelper(v8::Isolate* isolate) { | 22 static void InstallIsOptimizedHelper(v8::Isolate* isolate) { |
| 23 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 23 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 24 v8::Local<v8::FunctionTemplate> t = | 24 v8::Local<v8::FunctionTemplate> t = |
| 25 v8::FunctionTemplate::New(isolate, IsOptimized); | 25 v8::FunctionTemplate::New(isolate, IsOptimized); |
| 26 context->Global()->Set(v8_str("IsOptimized"), t->GetFunction()); | 26 context->Global()->Set(v8_str("IsOptimized"), t->GetFunction()); |
| 27 } | 27 } |
| 28 | 28 |
| 29 | 29 |
| 30 TEST(TurboSimpleDeopt) { | 30 TEST(DeoptSimple) { |
| 31 FLAG_allow_natives_syntax = true; | 31 FLAG_allow_natives_syntax = true; |
| 32 | 32 |
| 33 FunctionTester T( | 33 FunctionTester T( |
| 34 "(function f(a) {" | 34 "(function f(a) {" |
| 35 "var b = 1;" | 35 " var b = 1;" |
| 36 "if (!IsOptimized()) return 0;" | 36 " if (!IsOptimized()) return 0;" |
| 37 "%DeoptimizeFunction(f);" | 37 " %DeoptimizeFunction(f);" |
| 38 "if (IsOptimized()) return 0;" | 38 " if (IsOptimized()) return 0;" |
| 39 "return a + b; })"); | 39 " return a + b;" |
| 40 "})"); |
| 40 | 41 |
| 41 InstallIsOptimizedHelper(CcTest::isolate()); | 42 InstallIsOptimizedHelper(CcTest::isolate()); |
| 42 T.CheckCall(T.Val(2), T.Val(1)); | 43 T.CheckCall(T.Val(2), T.Val(1)); |
| 43 } | 44 } |
| 44 | 45 |
| 45 | 46 |
| 46 TEST(TurboSimpleDeoptInExpr) { | 47 TEST(DeoptSimpleInExpr) { |
| 47 FLAG_allow_natives_syntax = true; | 48 FLAG_allow_natives_syntax = true; |
| 48 | 49 |
| 49 FunctionTester T( | 50 FunctionTester T( |
| 50 "(function f(a) {" | 51 "(function f(a) {" |
| 51 "var b = 1;" | 52 " var b = 1;" |
| 52 "var c = 2;" | 53 " var c = 2;" |
| 53 "if (!IsOptimized()) return 0;" | 54 " if (!IsOptimized()) return 0;" |
| 54 "var d = b + (%DeoptimizeFunction(f), c);" | 55 " var d = b + (%DeoptimizeFunction(f), c);" |
| 55 "if (IsOptimized()) return 0;" | 56 " if (IsOptimized()) return 0;" |
| 56 "return d + a; })"); | 57 " return d + a;" |
| 58 "})"); |
| 57 | 59 |
| 58 InstallIsOptimizedHelper(CcTest::isolate()); | 60 InstallIsOptimizedHelper(CcTest::isolate()); |
| 59 T.CheckCall(T.Val(6), T.Val(3)); | 61 T.CheckCall(T.Val(6), T.Val(3)); |
| 60 } | 62 } |
| 61 | 63 |
| 64 |
| 65 TEST(DeoptExceptionHandlerCatch) { |
| 66 FLAG_allow_natives_syntax = true; |
| 67 FLAG_turbo_try_catch = true; |
| 68 |
| 69 FunctionTester T( |
| 70 "(function f() {" |
| 71 " var is_opt = IsOptimized;" |
| 72 " try {" |
| 73 " DeoptAndThrow(f);" |
| 74 " } catch (e) {" |
| 75 " return is_opt();" |
| 76 " }" |
| 77 "})"); |
| 78 |
| 79 CompileRun("function DeoptAndThrow(f) { %DeoptimizeFunction(f); throw 0; }"); |
| 80 InstallIsOptimizedHelper(CcTest::isolate()); |
| 81 T.CheckCall(T.false_value()); |
| 82 } |
| 83 |
| 84 |
| 85 TEST(DeoptExceptionHandlerFinally) { |
| 86 FLAG_allow_natives_syntax = true; |
| 87 FLAG_turbo_try_finally = true; |
| 88 |
| 89 FunctionTester T( |
| 90 "(function f() {" |
| 91 " var is_opt = IsOptimized;" |
| 92 " try {" |
| 93 " DeoptAndThrow(f);" |
| 94 " } finally {" |
| 95 " return is_opt();" |
| 96 " }" |
| 97 "})"); |
| 98 |
| 99 CompileRun("function DeoptAndThrow(f) { %DeoptimizeFunction(f); throw 0; }"); |
| 100 InstallIsOptimizedHelper(CcTest::isolate()); |
| 101 T.CheckCall(T.false_value()); |
| 102 } |
| 103 |
| 62 #endif | 104 #endif |
| 63 | 105 |
| 64 TEST(TurboTrivialDeopt) { | 106 TEST(DeoptTrivial) { |
| 65 FLAG_allow_natives_syntax = true; | 107 FLAG_allow_natives_syntax = true; |
| 66 | 108 |
| 67 FunctionTester T( | 109 FunctionTester T( |
| 68 "(function foo() {" | 110 "(function foo() {" |
| 69 "%DeoptimizeFunction(foo);" | 111 " %DeoptimizeFunction(foo);" |
| 70 "return 1; })"); | 112 " return 1;" |
| 113 "})"); |
| 71 | 114 |
| 72 T.CheckCall(T.Val(1)); | 115 T.CheckCall(T.Val(1)); |
| 73 } | 116 } |
| OLD | NEW |