Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: test/mjsunit/assert-opt-and-deopt.js

Issue 2654733004: [tests] Make assertOptimized()/assertUnoptimized() great again. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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,
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);
66 }; 69 };
67 70
68 OptTracker.prototype.AssertOptCount = function(func, optcount) { 71 OptTracker.prototype.AssertOptCount = function(func, optcount) {
69 if (this.DisableAsserts_(func)) { 72 if (this.DisableAsserts_(func)) {
70 return; 73 return;
71 } 74 }
72 assertEquals(optcount, this.GetOptCount_(func)); 75 assertEquals(optcount, this.GetOptCount_(func));
73 }; 76 };
74 77
75 OptTracker.prototype.AssertDeoptCount = function(func, deopt_count) { 78 OptTracker.prototype.AssertDeoptCount = function(func, deopt_count) {
76 if (this.DisableAsserts_(func)) { 79 if (this.DisableAsserts_(func)) {
77 return; 80 return;
78 } 81 }
79 assertEquals(deopt_count, this.GetDeoptCount_(func)); 82 assertEquals(deopt_count, this.GetDeoptCount_(func));
80 }; 83 };
81 84
82 OptTracker.prototype.AssertDeoptHappened = function(func, expect_deopt) { 85 OptTracker.prototype.AssertDeoptHappened =
86 function(func, expect_deopt) {
83 if (this.DisableAsserts_(func)) { 87 if (this.DisableAsserts_(func)) {
84 return; 88 return;
85 } 89 }
86 if (expect_deopt) { 90 if (expect_deopt) {
87 assertTrue(this.GetDeoptCount_(func) > 0); 91 assertTrue(this.GetDeoptCount_(func) > 0);
88 } else { 92 } else {
89 assertEquals(0, this.GetDeoptCount_(func)); 93 assertEquals(0, this.GetDeoptCount_(func));
90 } 94 }
91 } 95 }
92 96
93 OptTracker.prototype.AssertIsOptimized = function(func, expect_optimized) { 97 OptTracker.prototype.AssertIsOptimized = function(func, expect_optimized) {
94 if (this.DisableAsserts_(func)) { 98 if (this.DisableAsserts_(func)) {
95 return; 99 return;
96 } 100 }
97 var raw_optimized = %GetOptimizationStatus(func); 101 var opt_status = %GetOptimizationStatus(func);
98 if (expect_optimized) { 102 assertTrue((opt_status & OptTracker.OptimizationState.kIsFunction) !== 0);
99 assertEquals(OptTracker.OptimizationState.YES, raw_optimized); 103 assertEquals(
100 } else { 104 expect_optimized,
101 assertEquals(OptTracker.OptimizationState.NO, raw_optimized); 105 (opt_status & OptTracker.OptimizationState.kOptimized) !== 0);
102 }
103 } 106 }
104 107
105 /** 108 /**
106 * @private 109 * @private
107 */ 110 */
108 OptTracker.prototype.GetOptCount_ = function(func) { 111 OptTracker.prototype.GetOptCount_ = function(func) {
109 var raw_count = %GetOptimizationCount(func); 112 var raw_count = %GetOptimizationCount(func);
110 if (func in this.opt_counts_) { 113 if (func in this.opt_counts_) {
111 var checkpointed_count = this.opt_counts_[func]; 114 var checkpointed_count = this.opt_counts_[func];
112 return raw_count - checkpointed_count; 115 return raw_count - checkpointed_count;
113 } 116 }
114 return raw_count; 117 return raw_count;
115 } 118 }
116 119
117 /** 120 /**
118 * @private 121 * @private
119 */ 122 */
120 OptTracker.prototype.GetDeoptCount_ = function(func) { 123 OptTracker.prototype.GetDeoptCount_ = function(func) {
121 var count = this.GetOptCount_(func); 124 var count = this.GetOptCount_(func);
122 if (%GetOptimizationStatus(func) == OptTracker.OptimizationState.YES) { 125 var opt_status = %GetOptimizationStatus(func);
126 if ((opt_status & OptTracker.OptimizationState.kOptimized) !== 0) {
123 count -= 1; 127 count -= 1;
124 } 128 }
125 return count; 129 return count;
126 } 130 }
127 131
128 /** 132 /**
129 * @private 133 * @private
130 */ 134 */
131 OptTracker.prototype.DisableAsserts_ = function(func) { 135 OptTracker.prototype.DisableAsserts_ = function(func) {
132 switch(%GetOptimizationStatus(func)) { 136 var opt_status = %GetOptimizationStatus(func);
133 case OptTracker.OptimizationState.YES: 137 return (opt_status & OptTracker.OptimizationState.kAlwaysOptimize) !== 0 ||
134 case OptTracker.OptimizationState.NO: 138 (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 } 139 }
142 // (End of class OptTracker.) 140 // (End of class OptTracker.)
143 141
144 // Example function used by the test below. 142 // Example function used by the test below.
145 function f(a) { 143 function f(a) {
146 return a+1; 144 return a+1;
147 } 145 }
148 146
149 var tracker = new OptTracker(); 147 var tracker = new OptTracker();
150 tracker.CheckpointOptCount(f); 148 tracker.CheckpointOptCount(f);
(...skipping 23 matching lines...) Expand all
174 // Let's trigger optimization for another type. 172 // Let's trigger optimization for another type.
175 for (var i = 0; i < 5; i++) f("a"); 173 for (var i = 0; i < 5; i++) f("a");
176 174
177 %OptimizeFunctionOnNextCall(f); 175 %OptimizeFunctionOnNextCall(f);
178 f("b"); 176 f("b");
179 177
180 tracker.AssertOptCount(f, 2); 178 tracker.AssertOptCount(f, 2);
181 tracker.AssertIsOptimized(f, true); 179 tracker.AssertIsOptimized(f, true);
182 tracker.AssertDeoptHappened(f, true); 180 tracker.AssertDeoptHappened(f, true);
183 tracker.AssertDeoptCount(f, 1); 181 tracker.AssertDeoptCount(f, 1);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698