OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 function OptTracker() { | 42 function OptTracker() { |
43 this.opt_counts_ = {}; | 43 this.opt_counts_ = {}; |
44 } | 44 } |
45 | 45 |
46 /** | 46 /** |
47 * The possible optimization states of a function. Must be in sync with the | 47 * The possible optimization states of a function. Must be in sync with the |
48 * return values of Runtime_GetOptimizationStatus() in runtime.cc! | 48 * return values of Runtime_GetOptimizationStatus() in runtime.cc! |
49 * @enum {int} | 49 * @enum {int} |
50 */ | 50 */ |
51 OptTracker.OptimizationState = { | 51 OptTracker.OptimizationState = { |
52 YES: 1, | 52 kIsFunction: 1 << 0, |
Michael Starzinger
2017/01/26 12:24:52
suggestion: Could we map these to the existing con
Igor Sheludko
2017/01/26 14:12:31
Given that this file already uses stuff from mjsun
| |
53 NO: 2, | 53 kNeverOptimize: 1 << 1, |
54 ALWAYS: 3, | 54 kAlwaysOptimize: 1 << 2, |
55 NEVER: 4 | 55 kMaybeDeopted: 1 << 3, |
56 kOptimized: 1 << 4, | |
57 kTurboFanned: 1 << 5, | |
58 kInterpreted: 1 << 6 | |
56 }; | 59 }; |
57 | 60 |
58 /** | 61 /** |
59 * Always call this at the beginning of your test, once for each function | 62 * Always call this at the beginning of your test, once for each function |
60 * that you later want to track de/optimizations for. It is necessary because | 63 * that you later want to track de/optimizations for. It is necessary because |
61 * tests are sometimes executed several times in a row, and you want to | 64 * tests are sometimes executed several times in a row, and you want to |
62 * disregard counts from previous runs. | 65 * disregard counts from previous runs. |
63 */ | 66 */ |
64 OptTracker.prototype.CheckpointOptCount = function(func) { | 67 OptTracker.prototype.CheckpointOptCount = function(func) { |
65 this.opt_counts_[func] = %GetOptimizationCount(func); | 68 this.opt_counts_[func] = %GetOptimizationCount(func); |
(...skipping 21 matching lines...) Expand all Loading... | |
87 assertTrue(this.GetDeoptCount_(func) > 0); | 90 assertTrue(this.GetDeoptCount_(func) > 0); |
88 } else { | 91 } else { |
89 assertEquals(0, this.GetDeoptCount_(func)); | 92 assertEquals(0, this.GetDeoptCount_(func)); |
90 } | 93 } |
91 } | 94 } |
92 | 95 |
93 OptTracker.prototype.AssertIsOptimized = function(func, expect_optimized) { | 96 OptTracker.prototype.AssertIsOptimized = function(func, expect_optimized) { |
94 if (this.DisableAsserts_(func)) { | 97 if (this.DisableAsserts_(func)) { |
95 return; | 98 return; |
96 } | 99 } |
97 var raw_optimized = %GetOptimizationStatus(func); | 100 var opt_status = %GetOptimizationStatus(func); |
98 if (expect_optimized) { | 101 assertTrue((opt_status & OptTracker.OptimizationState.kIsFunction) !== 0); |
99 assertEquals(OptTracker.OptimizationState.YES, raw_optimized); | 102 assertEquals( |
100 } else { | 103 expect_optimized, |
101 assertEquals(OptTracker.OptimizationState.NO, raw_optimized); | 104 (opt_status & OptTracker.OptimizationState.kOptimized) !== 0); |
102 } | |
103 } | 105 } |
104 | 106 |
105 /** | 107 /** |
106 * @private | 108 * @private |
107 */ | 109 */ |
108 OptTracker.prototype.GetOptCount_ = function(func) { | 110 OptTracker.prototype.GetOptCount_ = function(func) { |
109 var raw_count = %GetOptimizationCount(func); | 111 var raw_count = %GetOptimizationCount(func); |
110 if (func in this.opt_counts_) { | 112 if (func in this.opt_counts_) { |
111 var checkpointed_count = this.opt_counts_[func]; | 113 var checkpointed_count = this.opt_counts_[func]; |
112 return raw_count - checkpointed_count; | 114 return raw_count - checkpointed_count; |
113 } | 115 } |
114 return raw_count; | 116 return raw_count; |
115 } | 117 } |
116 | 118 |
117 /** | 119 /** |
118 * @private | 120 * @private |
119 */ | 121 */ |
120 OptTracker.prototype.GetDeoptCount_ = function(func) { | 122 OptTracker.prototype.GetDeoptCount_ = function(func) { |
121 var count = this.GetOptCount_(func); | 123 var count = this.GetOptCount_(func); |
122 if (%GetOptimizationStatus(func) == OptTracker.OptimizationState.YES) { | 124 var opt_status = %GetOptimizationStatus(func); |
125 if ((opt_status & OptTracker.OptimizationState.kOptimized) !== 0) { | |
123 count -= 1; | 126 count -= 1; |
124 } | 127 } |
125 return count; | 128 return count; |
126 } | 129 } |
127 | 130 |
128 /** | 131 /** |
129 * @private | 132 * @private |
130 */ | 133 */ |
131 OptTracker.prototype.DisableAsserts_ = function(func) { | 134 OptTracker.prototype.DisableAsserts_ = function(func) { |
132 switch(%GetOptimizationStatus(func)) { | 135 var opt_status = %GetOptimizationStatus(func); |
133 case OptTracker.OptimizationState.YES: | 136 return (opt_status & OptTracker.OptimizationState.kAlwaysOptimize) !== 0 || |
134 case OptTracker.OptimizationState.NO: | 137 (opt_status & OptTracker.OptimizationState.kNeverOptimize) !== 0; |
135 return false; | |
136 case OptTracker.OptimizationState.ALWAYS: | |
137 case OptTracker.OptimizationState.NEVER: | |
138 return true; | |
139 } | |
140 return true; | |
141 } | 138 } |
142 // (End of class OptTracker.) | 139 // (End of class OptTracker.) |
143 | 140 |
144 // Example function used by the test below. | 141 // Example function used by the test below. |
145 function f(a) { | 142 function f(a) { |
146 return a+1; | 143 return a+1; |
147 } | 144 } |
148 | 145 |
149 var tracker = new OptTracker(); | 146 var tracker = new OptTracker(); |
150 tracker.CheckpointOptCount(f); | 147 tracker.CheckpointOptCount(f); |
(...skipping 23 matching lines...) Expand all Loading... | |
174 // Let's trigger optimization for another type. | 171 // Let's trigger optimization for another type. |
175 for (var i = 0; i < 5; i++) f("a"); | 172 for (var i = 0; i < 5; i++) f("a"); |
176 | 173 |
177 %OptimizeFunctionOnNextCall(f); | 174 %OptimizeFunctionOnNextCall(f); |
178 f("b"); | 175 f("b"); |
179 | 176 |
180 tracker.AssertOptCount(f, 2); | 177 tracker.AssertOptCount(f, 2); |
181 tracker.AssertIsOptimized(f, true); | 178 tracker.AssertIsOptimized(f, true); |
182 tracker.AssertDeoptHappened(f, true); | 179 tracker.AssertDeoptHappened(f, true); |
183 tracker.AssertDeoptCount(f, 1); | 180 tracker.AssertDeoptCount(f, 1); |
OLD | NEW |