LCOV - code coverage report
Current view: top level - test/cctest/compiler - test-run-deopt.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 38 38 100.0 %
Date: 2019-04-17 Functions: 9 9 100.0 %

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

Generated by: LCOV version 1.10