2012-05-23 14:24:29 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2012-02-09 08:58:19 +00:00
|
|
|
// 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.
|
|
|
|
|
2014-07-18 07:17:21 +00:00
|
|
|
// Flags: --allow-natives-syntax
|
2017-04-28 13:33:43 +00:00
|
|
|
// Flags: --nostress-opt --opt
|
2012-02-09 08:58:19 +00:00
|
|
|
|
|
|
|
// Ensure that ElementsKind transitions in various situations are hoisted (or
|
|
|
|
// not hoisted) correctly, don't change the semantics programs and don't trigger
|
|
|
|
// deopt through hoisting in important situations.
|
|
|
|
|
2014-01-07 15:58:25 +00:00
|
|
|
function test_wrapper() {
|
2012-02-09 08:58:19 +00:00
|
|
|
// Make sure that a simple elements array transitions inside a loop before
|
|
|
|
// stores to an array gets hoisted in a way that doesn't generate a deopt in
|
|
|
|
// simple cases.}
|
|
|
|
function testDoubleConversion4(a) {
|
|
|
|
var object = new Object();
|
|
|
|
a[0] = 0;
|
|
|
|
var count = 3;
|
|
|
|
do {
|
|
|
|
a[0] = object;
|
|
|
|
} while (--count > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
testDoubleConversion4(new Array(5));
|
2012-06-08 13:06:24 +00:00
|
|
|
testDoubleConversion4(new Array(5)); // Call twice to make sure that second
|
|
|
|
// store is a transition and not
|
|
|
|
// optimistically MONOMORPHIC
|
2012-02-09 08:58:19 +00:00
|
|
|
%OptimizeFunctionOnNextCall(testDoubleConversion4);
|
|
|
|
testDoubleConversion4(new Array(5));
|
|
|
|
testDoubleConversion4(new Array(5));
|
2013-07-22 09:16:33 +00:00
|
|
|
assertOptimized(testDoubleConversion4);
|
2017-02-14 15:53:34 +00:00
|
|
|
%ClearFunctionFeedback(testDoubleConversion4);
|
2012-02-09 08:58:19 +00:00
|
|
|
|
|
|
|
// Make sure that non-element related map checks that are not preceded by
|
|
|
|
// transitions in a loop still get hoisted in a way that doesn't generate a
|
|
|
|
// deopt in simple cases.
|
|
|
|
function testExactMapHoisting(a) {
|
|
|
|
var object = new Object();
|
2013-04-26 15:30:41 +00:00
|
|
|
a.foo = {};
|
2012-02-09 08:58:19 +00:00
|
|
|
a[0] = 0;
|
|
|
|
a[1] = 1;
|
|
|
|
var count = 3;
|
|
|
|
do {
|
2012-06-08 13:06:24 +00:00
|
|
|
a.foo = object; // This map check should be hoistable
|
2012-02-09 08:58:19 +00:00
|
|
|
a[1] = object;
|
|
|
|
result = a.foo == object && a[1] == object;
|
|
|
|
} while (--count > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
testExactMapHoisting(new Array(5));
|
2012-06-08 13:06:24 +00:00
|
|
|
testExactMapHoisting(new Array(5)); // Call twice to make sure that second
|
|
|
|
// store is a transition and not
|
|
|
|
// optimistically MONOMORPHIC
|
2012-02-09 08:58:19 +00:00
|
|
|
%OptimizeFunctionOnNextCall(testExactMapHoisting);
|
|
|
|
testExactMapHoisting(new Array(5));
|
|
|
|
testExactMapHoisting(new Array(5));
|
2013-07-22 09:16:33 +00:00
|
|
|
assertOptimized(testExactMapHoisting);
|
2017-02-14 15:53:34 +00:00
|
|
|
%ClearFunctionFeedback(testExactMapHoisting);
|
2012-02-09 08:58:19 +00:00
|
|
|
|
|
|
|
// Make sure that non-element related map checks do NOT get hoisted if they
|
|
|
|
// depend on an elements transition before them and it's not possible to hoist
|
|
|
|
// that transition.
|
|
|
|
function testExactMapHoisting2(a) {
|
|
|
|
var object = new Object();
|
|
|
|
a.foo = 0;
|
|
|
|
a[0] = 0;
|
|
|
|
a[1] = 1;
|
|
|
|
var count = 3;
|
|
|
|
do {
|
|
|
|
if (a.bar === undefined) {
|
|
|
|
a[1] = 2.5;
|
|
|
|
}
|
2012-06-08 13:06:24 +00:00
|
|
|
a.foo = object; // This map check should NOT be hoistable because it
|
2017-06-30 11:26:14 +00:00
|
|
|
// includes a check for the PACKED_ELEMENTS map as well as
|
|
|
|
// the PACKED_DOUBLE_ELEMENTS map, which depends on the
|
2012-06-08 13:06:24 +00:00
|
|
|
// double transition above in the if, which cannot be
|
|
|
|
// hoisted.
|
2012-02-09 08:58:19 +00:00
|
|
|
} while (--count > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
testExactMapHoisting2(new Array(5));
|
2012-06-08 13:06:24 +00:00
|
|
|
testExactMapHoisting2(new Array(5)); // Call twice to make sure that second
|
|
|
|
// store is a transition and not
|
|
|
|
// optimistically MONOMORPHIC
|
2012-02-09 08:58:19 +00:00
|
|
|
%OptimizeFunctionOnNextCall(testExactMapHoisting2);
|
|
|
|
testExactMapHoisting2(new Array(5));
|
|
|
|
testExactMapHoisting2(new Array(5));
|
2012-06-12 15:44:12 +00:00
|
|
|
// Temporarily disabled - see bug 2176.
|
2013-07-22 09:16:33 +00:00
|
|
|
// assertOptimized(testExactMapHoisting2);
|
2017-02-14 15:53:34 +00:00
|
|
|
%ClearFunctionFeedback(testExactMapHoisting2);
|
2012-02-09 08:58:19 +00:00
|
|
|
|
|
|
|
// Make sure that non-element related map checks do get hoisted if they use
|
|
|
|
// the transitioned map for the check and all transitions that they depend
|
|
|
|
// upon can hoisted, too.
|
|
|
|
function testExactMapHoisting3(a) {
|
|
|
|
var object = new Object();
|
2013-05-10 17:17:50 +00:00
|
|
|
a.foo = null;
|
2012-02-09 08:58:19 +00:00
|
|
|
a[0] = 0;
|
|
|
|
a[1] = 1;
|
|
|
|
var count = 3;
|
|
|
|
do {
|
|
|
|
a[1] = 2.5;
|
2012-06-08 13:06:24 +00:00
|
|
|
a.foo = object; // This map check should be hoistable because all elements
|
|
|
|
// transitions in the loop can also be hoisted.
|
2012-02-09 08:58:19 +00:00
|
|
|
} while (--count > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
var add_transition = new Array(5);
|
|
|
|
add_transition.foo = 0;
|
2012-06-08 13:06:24 +00:00
|
|
|
add_transition[0] = new Object(); // For FAST_ELEMENT transition to be created
|
2012-02-09 08:58:19 +00:00
|
|
|
testExactMapHoisting3(new Array(5));
|
2012-06-08 13:06:24 +00:00
|
|
|
testExactMapHoisting3(new Array(5)); // Call twice to make sure that second
|
|
|
|
// store is a transition and not
|
|
|
|
// optimistically MONOMORPHIC
|
2012-02-09 08:58:19 +00:00
|
|
|
%OptimizeFunctionOnNextCall(testExactMapHoisting3);
|
|
|
|
testExactMapHoisting3(new Array(5));
|
|
|
|
testExactMapHoisting3(new Array(5));
|
2013-07-22 09:16:33 +00:00
|
|
|
assertOptimized(testExactMapHoisting3);
|
2017-02-14 15:53:34 +00:00
|
|
|
%ClearFunctionFeedback(testExactMapHoisting3);
|
2012-02-09 08:58:19 +00:00
|
|
|
|
|
|
|
function testDominatingTransitionHoisting1(a) {
|
|
|
|
var object = new Object();
|
|
|
|
a[0] = 0;
|
|
|
|
var count = 3;
|
|
|
|
do {
|
|
|
|
if (a.baz != true) {
|
|
|
|
a[1] = 2.5;
|
|
|
|
}
|
|
|
|
a[0] = object;
|
|
|
|
} while (--count > 3);
|
|
|
|
}
|
|
|
|
|
2012-10-01 16:22:43 +00:00
|
|
|
/*
|
2012-02-09 08:58:19 +00:00
|
|
|
testDominatingTransitionHoisting1(new Array(5));
|
2012-06-08 13:06:24 +00:00
|
|
|
testDominatingTransitionHoisting1(new Array(5)); // Call twice to make sure
|
|
|
|
// that second store is a
|
|
|
|
// transition and not
|
|
|
|
// optimistically MONOMORPHIC
|
2012-02-09 08:58:19 +00:00
|
|
|
%OptimizeFunctionOnNextCall(testDominatingTransitionHoisting1);
|
|
|
|
testDominatingTransitionHoisting1(new Array(5));
|
|
|
|
testDominatingTransitionHoisting1(new Array(5));
|
2012-10-01 16:22:43 +00:00
|
|
|
// TODO(verwaest) With current changes the elements transition gets hoisted
|
|
|
|
// above the access, causing a deopt. We should update the type of access
|
|
|
|
// rather than forbid hoisting the transition.
|
2013-07-22 09:16:33 +00:00
|
|
|
assertOptimized(testDominatingTransitionHoisting1);
|
2017-02-14 15:53:34 +00:00
|
|
|
%ClearFunctionFeedback(testDominatingTransitionHoisting1);
|
2012-10-01 16:22:43 +00:00
|
|
|
*/
|
2012-02-09 08:58:19 +00:00
|
|
|
|
|
|
|
function testHoistingWithSideEffect(a) {
|
|
|
|
var object = new Object();
|
|
|
|
a[0] = 0;
|
|
|
|
var count = 3;
|
|
|
|
do {
|
|
|
|
assertTrue(true);
|
|
|
|
a[0] = object;
|
|
|
|
} while (--count > 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
testHoistingWithSideEffect(new Array(5));
|
2012-06-08 13:06:24 +00:00
|
|
|
testHoistingWithSideEffect(new Array(5)); // Call twice to make sure that
|
|
|
|
// second store is a transition and
|
|
|
|
// not optimistically MONOMORPHIC
|
2012-02-09 08:58:19 +00:00
|
|
|
%OptimizeFunctionOnNextCall(testHoistingWithSideEffect);
|
|
|
|
testHoistingWithSideEffect(new Array(5));
|
|
|
|
testHoistingWithSideEffect(new Array(5));
|
2013-07-22 09:16:33 +00:00
|
|
|
assertOptimized(testHoistingWithSideEffect);
|
2017-02-14 15:53:34 +00:00
|
|
|
%ClearFunctionFeedback(testHoistingWithSideEffect);
|
2012-02-16 15:37:52 +00:00
|
|
|
|
2012-08-27 16:08:27 +00:00
|
|
|
function testStraightLineDupeElinination(a,b,c,d,e,f) {
|
2012-02-16 15:37:52 +00:00
|
|
|
var count = 3;
|
|
|
|
do {
|
|
|
|
assertTrue(true);
|
|
|
|
a[0] = b;
|
|
|
|
a[1] = c;
|
|
|
|
a[2] = d;
|
|
|
|
assertTrue(true);
|
2012-06-08 13:06:24 +00:00
|
|
|
a[3] = e; // TransitionElementsKind should be eliminated despite call.
|
2012-02-16 15:37:52 +00:00
|
|
|
a[4] = f;
|
|
|
|
} while (--count > 3);
|
|
|
|
}
|
|
|
|
|
2012-08-27 16:08:27 +00:00
|
|
|
testStraightLineDupeElinination(new Array(0, 0, 0, 0, 0),0,0,0,0,.5);
|
|
|
|
testStraightLineDupeElinination(new Array(0, 0, 0, 0, 0),0,0,0,.5,0);
|
|
|
|
testStraightLineDupeElinination(new Array(0, 0, 0, 0, 0),0,0,.5,0,0);
|
|
|
|
testStraightLineDupeElinination(new Array(0, 0, 0, 0, 0),0,.5,0,0,0);
|
|
|
|
testStraightLineDupeElinination(new Array(0, 0, 0, 0, 0),.5,0,0,0,0);
|
|
|
|
testStraightLineDupeElinination(new Array(.1,.1,.1,.1,.1),0,0,0,0,.5);
|
|
|
|
testStraightLineDupeElinination(new Array(.1,.1,.1,.1,.1),0,0,0,.5,0);
|
|
|
|
testStraightLineDupeElinination(new Array(.1,.1,.1,.1,.1),0,0,.5,0,0);
|
|
|
|
testStraightLineDupeElinination(new Array(.1,.1,.1,.1,.1),0,.5,0,0,0);
|
|
|
|
testStraightLineDupeElinination(new Array(.1,.1,.1,.1,.1),.5,0,0,0,0);
|
|
|
|
testStraightLineDupeElinination(new Array(5),.5,0,0,0,0);
|
|
|
|
testStraightLineDupeElinination(new Array(5),0,.5,0,0,0);
|
|
|
|
testStraightLineDupeElinination(new Array(5),0,0,.5,0,0);
|
|
|
|
testStraightLineDupeElinination(new Array(5),0,0,0,.5,0);
|
|
|
|
testStraightLineDupeElinination(new Array(5),0,0,0,0,.5);
|
|
|
|
testStraightLineDupeElinination(new Array(5),.5,0,0,0,0);
|
|
|
|
testStraightLineDupeElinination(new Array(5),0,.5,0,0,0);
|
|
|
|
testStraightLineDupeElinination(new Array(5),0,0,.5,0,0);
|
|
|
|
testStraightLineDupeElinination(new Array(5),0,0,0,.5,0);
|
|
|
|
testStraightLineDupeElinination(new Array(5),0,0,0,0,.5);
|
|
|
|
%OptimizeFunctionOnNextCall(testStraightLineDupeElinination);
|
2012-09-20 13:41:00 +00:00
|
|
|
testStraightLineDupeElinination(new Array(5),0,0,0,0,0);
|
|
|
|
testStraightLineDupeElinination(new Array(5),0,0,0,0,0);
|
2013-07-22 09:16:33 +00:00
|
|
|
assertOptimized(testStraightLineDupeElinination);
|
2017-02-14 15:53:34 +00:00
|
|
|
%ClearFunctionFeedback(testStraightLineDupeElinination);
|
2012-02-09 08:58:19 +00:00
|
|
|
}
|
2014-01-07 15:58:25 +00:00
|
|
|
|
2014-07-18 07:17:21 +00:00
|
|
|
// The test is called in a test wrapper that has type feedback cleared to
|
|
|
|
// prevent the influence of allocation-sites, which learn from transitions.
|
|
|
|
test_wrapper();
|
2017-02-14 15:53:34 +00:00
|
|
|
%ClearFunctionFeedback(test_wrapper);
|