| 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 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 /** | 40 /** |
| 41 * The possible optimization states of a function. Must be in sync with the | 41 * The possible optimization states of a function. Must be in sync with the |
| 42 * return values of Runtime_GetOptimizationStatus() in runtime.cc! | 42 * return values of Runtime_GetOptimizationStatus() in runtime.cc! |
| 43 * @enum {int} | 43 * @enum {int} |
| 44 */ | 44 */ |
| 45 OptTracker.OptimizationState = { | 45 OptTracker.OptimizationState = { |
| 46 YES: 1, | 46 YES: 1, |
| 47 NO: 2, | 47 NO: 2, |
| 48 ALWAYS: 3, | 48 ALWAYS: 3, |
| 49 NEVER: 4 | 49 NEVER: 4, |
| 50 CONCURRENT: 5 |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 /** | 53 /** |
| 53 * Always call this at the beginning of your test, once for each function | 54 * Always call this at the beginning of your test, once for each function |
| 54 * that you later want to track de/optimizations for. It is necessary because | 55 * that you later want to track de/optimizations for. It is necessary because |
| 55 * tests are sometimes executed several times in a row, and you want to | 56 * tests are sometimes executed several times in a row, and you want to |
| 56 * disregard counts from previous runs. | 57 * disregard counts from previous runs. |
| 57 */ | 58 */ |
| 58 OptTracker.prototype.CheckpointOptCount = function(func) { | 59 OptTracker.prototype.CheckpointOptCount = function(func) { |
| 59 this.opt_counts_[func] = %GetOptimizationCount(func); | 60 this.opt_counts_[func] = %GetOptimizationCount(func); |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 OptTracker.prototype.AssertOptCount = function(func, optcount) { | 63 OptTracker.prototype.AssertOptCount = function(func, optcount) { |
| 63 if (this.DisableAsserts_(func)) { | 64 if (this.DisableAsserts_(func) || |
| 65 %GetOptimizationStatus(func) == OptTracker.OptimizationState.CONCURRENT) { |
| 64 return; | 66 return; |
| 65 } | 67 } |
| 66 assertEquals(optcount, this.GetOptCount_(func)); | 68 assertEquals(optcount, this.GetOptCount_(func)); |
| 67 }; | 69 }; |
| 68 | 70 |
| 69 OptTracker.prototype.AssertDeoptCount = function(func, deopt_count) { | 71 OptTracker.prototype.AssertDeoptCount = function(func, deopt_count) { |
| 70 if (this.DisableAsserts_(func)) { | 72 if (this.DisableAsserts_(func)) { |
| 71 return; | 73 return; |
| 72 } | 74 } |
| 75 |
| 76 // We can't assert much about a functions opt and deopt behavior if |
| 77 // it is being optimized on a separate thread. |
| 78 if (%GetOptimizationStatus(func) == |
| 79 OptTracker.OptimizationState.CONCURRENT) |
| 80 return; |
| 73 assertEquals(deopt_count, this.GetDeoptCount_(func)); | 81 assertEquals(deopt_count, this.GetDeoptCount_(func)); |
| 74 }; | 82 }; |
| 75 | 83 |
| 76 OptTracker.prototype.AssertDeoptHappened = function(func, expect_deopt) { | 84 OptTracker.prototype.AssertDeoptHappened = function(func, expect_deopt) { |
| 77 if (this.DisableAsserts_(func)) { | 85 if (this.DisableAsserts_(func) || |
| 86 %GetOptimizationStatus(func) == OptTracker.OptimizationState.CONCURRENT) { |
| 78 return; | 87 return; |
| 79 } | 88 } |
| 80 if (expect_deopt) { | 89 if (expect_deopt) { |
| 81 assertTrue(this.GetDeoptCount_(func) > 0); | 90 assertTrue(this.GetDeoptCount_(func) > 0); |
| 82 } else { | 91 } else { |
| 83 assertEquals(0, this.GetDeoptCount_(func)); | 92 assertEquals(0, this.GetDeoptCount_(func)); |
| 84 } | 93 } |
| 85 } | 94 } |
| 86 | 95 |
| 87 OptTracker.prototype.AssertIsOptimized = function(func, expect_optimized) { | 96 OptTracker.prototype.AssertIsOptimized = function(func, expect_optimized) { |
| 88 if (this.DisableAsserts_(func)) { | 97 if (this.DisableAsserts_(func)) { |
| 89 return; | 98 return; |
| 90 } | 99 } |
| 91 var raw_optimized = %GetOptimizationStatus(func); | 100 var raw_optimized = %GetOptimizationStatus(func); |
| 92 if (expect_optimized) { | 101 if (expect_optimized) { |
| 93 assertEquals(OptTracker.OptimizationState.YES, raw_optimized); | 102 assertTrue(OptTracker.OptimizationState.YES == raw_optimized || |
| 103 OptTracker.OptimizationState.CONCURRENT == raw_optimized); |
| 94 } else { | 104 } else { |
| 95 assertEquals(OptTracker.OptimizationState.NO, raw_optimized); | 105 assertTrue(OptTracker.OptimizationState.NO == raw_optimized || |
| 106 OptTracker.OptimizationState.CONCURRENT == raw_optimized); |
| 96 } | 107 } |
| 97 } | 108 } |
| 98 | 109 |
| 99 /** | 110 /** |
| 100 * @private | 111 * @private |
| 101 */ | 112 */ |
| 102 OptTracker.prototype.GetOptCount_ = function(func) { | 113 OptTracker.prototype.GetOptCount_ = function(func) { |
| 103 var raw_count = %GetOptimizationCount(func); | 114 var raw_count = %GetOptimizationCount(func); |
| 104 if (func in this.opt_counts_) { | 115 if (func in this.opt_counts_) { |
| 105 var checkpointed_count = this.opt_counts_[func]; | 116 var checkpointed_count = this.opt_counts_[func]; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 // Let's trigger optimization for another type. | 179 // Let's trigger optimization for another type. |
| 169 for (var i = 0; i < 5; i++) f("a"); | 180 for (var i = 0; i < 5; i++) f("a"); |
| 170 | 181 |
| 171 %OptimizeFunctionOnNextCall(f); | 182 %OptimizeFunctionOnNextCall(f); |
| 172 f("b"); | 183 f("b"); |
| 173 | 184 |
| 174 tracker.AssertOptCount(f, 2); | 185 tracker.AssertOptCount(f, 2); |
| 175 tracker.AssertIsOptimized(f, true); | 186 tracker.AssertIsOptimized(f, true); |
| 176 tracker.AssertDeoptHappened(f, true); | 187 tracker.AssertDeoptHappened(f, true); |
| 177 tracker.AssertDeoptCount(f, 1); | 188 tracker.AssertDeoptCount(f, 1); |
| OLD | NEW |