OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --allow-natives-syntax --noalways-opt | 5 // Flags: --allow-natives-syntax --noalways-opt |
6 | 6 |
7 // Locations in the type feedback vector where call counts are maintained for | 7 // Locations in the type feedback vector where call counts are maintained for |
8 // the two calls made from bar(); | 8 // the two calls made from bar(); |
9 const kFooCallExtraIndex = 5; | |
10 const kArrayCallExtraIndex = 9; | |
11 | 9 |
12 function GetCallCount(func, slot) { | 10 (function() { |
13 var vector = %GetTypeFeedbackVector(func); | 11 const kFooCallExtraIndex = 5; |
14 // Call counts are recorded doubled. | 12 const kArrayCallExtraIndex = 7; |
15 var value = %FixedArrayGet(vector, slot); | |
16 return Math.floor(value / 2); | |
17 } | |
18 | 13 |
19 function foo(a) { return a[3] * 16; } | 14 function GetCallCount(func, slot) { |
| 15 var vector = %GetTypeFeedbackVector(func); |
| 16 // Call counts are recorded doubled. |
| 17 var value = %FixedArrayGet(vector, slot); |
| 18 return Math.floor(value / 2); |
| 19 } |
20 | 20 |
21 function bar(a) { | 21 function foo(a) { return a[3] * 16; } |
22 var result = 0; | 22 |
23 for (var i = 0; i < 10; i++) { | 23 function bar(a) { |
24 result = foo(a); | 24 var result = 0; |
25 if (i % 2 === 0) { | 25 for (var i = 0; i < 10; i++) { |
26 var r = Array(); | 26 result = foo(a); |
27 r[0] = 1; | 27 if (i % 2 === 0) { |
28 result += r[0]; | 28 var r = Array(); |
| 29 r[0] = 1; |
| 30 result += r[0]; |
| 31 } |
29 } | 32 } |
| 33 return result; |
30 } | 34 } |
31 return result; | |
32 } | |
33 | 35 |
34 var a = [1, 2, 3]; | 36 var a = [1, 2, 3]; |
35 bar(a); | 37 bar(a); |
36 assertEquals(10, GetCallCount(bar, kFooCallExtraIndex)); | 38 assertEquals(10, GetCallCount(bar, kFooCallExtraIndex)); |
37 assertEquals(5, GetCallCount(bar, kArrayCallExtraIndex)); | 39 assertEquals(5, GetCallCount(bar, kArrayCallExtraIndex)); |
38 | 40 |
39 %OptimizeFunctionOnNextCall(bar); | 41 %OptimizeFunctionOnNextCall(bar); |
40 bar(a); | 42 bar(a); |
| 43 })(); |
OLD | NEW |