Home | History | Annotate | Download | only in mjsunit
      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 --noalways-opt
      6 
      7 // We disable vector store ICs because slot indices change when this option
      8 // is enabled.
      9 
     10 // Locations in the type feedback vector where call counts are maintained for
     11 // the two calls made from bar();
     12 
     13 (function() {
     14   const kFooCallExtraIndex = 5;
     15   const kArrayCallExtraIndex = 7;
     16 
     17   function GetCallCount(func, slot) {
     18     var vector = %GetTypeFeedbackVector(func);
     19     // Call counts are recorded doubled.
     20     var value = %FixedArrayGet(vector, slot);
     21     return Math.floor(value / 2);
     22   }
     23 
     24   function foo(a) { return a[3] * 16; }
     25 
     26   function bar(a) {
     27     var result = 0;
     28     for (var i = 0; i < 10; i++) {
     29       result = foo(a);
     30       if (i % 2 === 0) {
     31         var r = Array();
     32         r[0] = 1;
     33         result += r[0];
     34       }
     35     }
     36     return result;
     37   }
     38 
     39   var a = [1, 2, 3];
     40   bar(a);
     41   assertEquals(10, GetCallCount(bar, kFooCallExtraIndex));
     42   assertEquals(5, GetCallCount(bar, kArrayCallExtraIndex));
     43 
     44   %OptimizeFunctionOnNextCall(bar);
     45   bar(a);
     46 })();
     47