regress-2618.js 3.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
//       copyright notice, this list of conditions and the following
//       disclaimer in the documentation and/or other materials provided
//       with the distribution.
//     * Neither the name of Google Inc. nor the names of its
//       contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

28 29
// Flags: --use-osr --allow-natives-syntax --turbofan
// Flags: --no-always-turbofan
30

31
// Can't OSR with always-turbofan or in Lite mode.
32 33
if (isNeverOptimizeLiteMode()) {
  print("Warning: skipping test that requires optimization in Lite mode.");
34
  testRunner.quit(0);
35
}
36
assertFalse(isAlwaysOptimize());
37

38
function f(disable_asserts) {
39 40
  do {
    do {
41
      for (var i = 0; i < 10; i++) {
42
        %OptimizeOsr();
43 44
        %PrepareFunctionForOptimization(f);
      }
45 46 47 48 49
      // Note: this check can't be wrapped in a function, because
      // calling that function causes a deopt from lack of call
      // feedback.
      var opt_status = %GetOptimizationStatus(f);
      assertTrue(
50
        disable_asserts ||
51
        (opt_status & V8OptimizationStatus.kMaybeDeopted) !== 0 ||
52
        (opt_status & V8OptimizationStatus.kTopmostFrameIsTurboFanned) !== 0);
53 54 55 56
    } while (false);
  } while (false);
}

57
%PrepareFunctionForOptimization(f);
58 59
f(true);  // Gather feedback first.
f(false);
60 61 62 63 64 65

function g() {
  for (var i = 0; i < 1; i++) { }

  do {
    do {
66
      for (var i = 0; i < 1; i++) { }
67 68 69 70 71 72 73 74 75 76 77
    } while (false);
  } while (false);

  do {
    do {
      do {
        do {
          do {
            do {
              do {
                do {
78
                  for (var i = 0; i < 10; i++) {
79
                    %OptimizeOsr();
80 81
                    %PrepareFunctionForOptimization(g);
                  }
82
                  var opt_status = %GetOptimizationStatus(g);
83 84 85 86
                  assertTrue(
                    (opt_status & V8OptimizationStatus.kMaybeDeopted) !== 0 ||
                    (opt_status &
                        V8OptimizationStatus.kTopmostFrameIsTurboFanned) !== 0);
87 88 89 90 91 92 93 94 95 96
                } while (false);
              } while (false);
            } while (false);
          } while (false);
        } while (false);
      } while (false);
    } while (false);
  } while (false);
}

97
%PrepareFunctionForOptimization(g);
98
g();