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

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

Issue 2654733004: [tests] Make assertOptimized()/assertUnoptimized() great again. (Closed)
Patch Set: Rebasing for relanding 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 26 matching lines...) Expand all
37 * This class shows how to use %GetOptimizationCount() and 37 * This class shows how to use %GetOptimizationCount() and
38 * %GetOptimizationStatus() to infer information about opts and deopts. 38 * %GetOptimizationStatus() to infer information about opts and deopts.
39 * Might be nice to put this into mjsunit.js, but that doesn't depend on 39 * Might be nice to put this into mjsunit.js, but that doesn't depend on
40 * the --allow-natives-syntax flag so far. 40 * the --allow-natives-syntax flag so far.
41 */ 41 */
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
48 * return values of Runtime_GetOptimizationStatus() in runtime.cc!
49 * @enum {int}
50 */
51 OptTracker.OptimizationState = {
52 YES: 1,
53 NO: 2,
54 ALWAYS: 3,
55 NEVER: 4
56 };
57
58 /**
59 * Always call this at the beginning of your test, once for each function 47 * 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 48 * 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 49 * tests are sometimes executed several times in a row, and you want to
62 * disregard counts from previous runs. 50 * disregard counts from previous runs.
63 */ 51 */
64 OptTracker.prototype.CheckpointOptCount = function(func) { 52 OptTracker.prototype.CheckpointOptCount = function(func) {
65 this.opt_counts_[func] = %GetOptimizationCount(func); 53 this.opt_counts_[func] = %GetOptimizationCount(func);
66 }; 54 };
67 55
68 OptTracker.prototype.AssertOptCount = function(func, optcount) { 56 OptTracker.prototype.AssertOptCount = function(func, optcount) {
(...skipping 18 matching lines...) Expand all
87 assertTrue(this.GetDeoptCount_(func) > 0); 75 assertTrue(this.GetDeoptCount_(func) > 0);
88 } else { 76 } else {
89 assertEquals(0, this.GetDeoptCount_(func)); 77 assertEquals(0, this.GetDeoptCount_(func));
90 } 78 }
91 } 79 }
92 80
93 OptTracker.prototype.AssertIsOptimized = function(func, expect_optimized) { 81 OptTracker.prototype.AssertIsOptimized = function(func, expect_optimized) {
94 if (this.DisableAsserts_(func)) { 82 if (this.DisableAsserts_(func)) {
95 return; 83 return;
96 } 84 }
97 var raw_optimized = %GetOptimizationStatus(func); 85 var opt_status = %GetOptimizationStatus(func);
98 if (expect_optimized) { 86 assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0);
99 assertEquals(OptTracker.OptimizationState.YES, raw_optimized); 87 assertEquals(expect_optimized,
100 } else { 88 (opt_status & V8OptimizationStatus.kOptimized) !== 0);
101 assertEquals(OptTracker.OptimizationState.NO, raw_optimized);
102 }
103 } 89 }
104 90
105 /** 91 /**
106 * @private 92 * @private
107 */ 93 */
108 OptTracker.prototype.GetOptCount_ = function(func) { 94 OptTracker.prototype.GetOptCount_ = function(func) {
109 var raw_count = %GetOptimizationCount(func); 95 var raw_count = %GetOptimizationCount(func);
110 if (func in this.opt_counts_) { 96 if (func in this.opt_counts_) {
111 var checkpointed_count = this.opt_counts_[func]; 97 var checkpointed_count = this.opt_counts_[func];
112 return raw_count - checkpointed_count; 98 return raw_count - checkpointed_count;
113 } 99 }
114 return raw_count; 100 return raw_count;
115 } 101 }
116 102
117 /** 103 /**
118 * @private 104 * @private
119 */ 105 */
120 OptTracker.prototype.GetDeoptCount_ = function(func) { 106 OptTracker.prototype.GetDeoptCount_ = function(func) {
121 var count = this.GetOptCount_(func); 107 var count = this.GetOptCount_(func);
122 if (%GetOptimizationStatus(func) == OptTracker.OptimizationState.YES) { 108 var opt_status = %GetOptimizationStatus(func);
109 if ((opt_status & V8OptimizationStatus.kOptimized) !== 0) {
123 count -= 1; 110 count -= 1;
124 } 111 }
125 return count; 112 return count;
126 } 113 }
127 114
128 /** 115 /**
129 * @private 116 * @private
130 */ 117 */
131 OptTracker.prototype.DisableAsserts_ = function(func) { 118 OptTracker.prototype.DisableAsserts_ = function(func) {
132 switch(%GetOptimizationStatus(func)) { 119 var opt_status = %GetOptimizationStatus(func);
133 case OptTracker.OptimizationState.YES: 120 return (opt_status & V8OptimizationStatus.kAlwaysOptimize) !== 0 ||
134 case OptTracker.OptimizationState.NO: 121 (opt_status & V8OptimizationStatus.kNeverOptimize) !== 0;
135 return false;
136 case OptTracker.OptimizationState.ALWAYS:
137 case OptTracker.OptimizationState.NEVER:
138 return true;
139 }
140 return true;
141 } 122 }
142 // (End of class OptTracker.) 123 // (End of class OptTracker.)
143 124
144 // Example function used by the test below. 125 // Example function used by the test below.
145 function f(a) { 126 function f(a) {
146 return a+1; 127 return a+1;
147 } 128 }
148 129
149 var tracker = new OptTracker(); 130 var tracker = new OptTracker();
150 tracker.CheckpointOptCount(f); 131 tracker.CheckpointOptCount(f);
(...skipping 23 matching lines...) Expand all
174 // Let's trigger optimization for another type. 155 // Let's trigger optimization for another type.
175 for (var i = 0; i < 5; i++) f("a"); 156 for (var i = 0; i < 5; i++) f("a");
176 157
177 %OptimizeFunctionOnNextCall(f); 158 %OptimizeFunctionOnNextCall(f);
178 f("b"); 159 f("b");
179 160
180 tracker.AssertOptCount(f, 2); 161 tracker.AssertOptCount(f, 2);
181 tracker.AssertIsOptimized(f, true); 162 tracker.AssertIsOptimized(f, true);
182 tracker.AssertDeoptHappened(f, true); 163 tracker.AssertDeoptHappened(f, true);
183 tracker.AssertDeoptCount(f, 1); 164 tracker.AssertDeoptCount(f, 1);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698