1// Copyright 2015 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// Flags: --allow-natives-syntax 6 7function literals_sharing_test(warmup, optimize) { 8 function closure() { 9 // Ensure small array literals start in specific element kind mode. 10 assertTrue(%HasFastSmiElements([])); 11 assertTrue(%HasFastSmiElements([1])); 12 assertTrue(%HasFastSmiElements([1,2])); 13 assertTrue(%HasFastDoubleElements([1.1])); 14 assertTrue(%HasFastDoubleElements([1.1,2])); 15 16 var a = [1, 2, 3]; 17 if (warmup) { 18 // Transition elements kind during warmup... 19 assertTrue(%HasFastSmiElements(a)); 20 assertEquals(4, a.push(1.3)); 21 } 22 // ... and ensure that the information about transitioning is 23 // propagated to the next closure. 24 assertTrue(%HasFastDoubleElements(a)); 25 }; 26 if (optimize) %OptimizeFunctionOnNextCall(closure); 27 closure(); 28} 29 30 31function test() { 32 var warmup = true; 33 for (var i = 0; i < 3; i++) { 34 print("iter: " + i + ", warmup: "+ warmup); 35 literals_sharing_test(warmup, false); 36 warmup = false; 37 } 38 print("iter: " + i + ", opt: true"); 39 literals_sharing_test(warmup, true); 40} 41 42 43function stress_opt_test() {} 44stress_opt_test(); 45if (%GetOptimizationStatus(stress_opt_test) == 2) { 46 // This test is not suitable for --always-opt mode. 47 test(); 48} 49