| OLD | NEW |
| 1 // Copyright 2007-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2010 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 12 matching lines...) Expand all Loading... |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include <stdlib.h> | 28 #include <stdlib.h> |
| 29 | 29 |
| 30 #include "v8.h" | 30 #include "v8.h" |
| 31 | 31 |
| 32 #include "api.h" | 32 #include "api.h" |
| 33 #include "cctest.h" |
| 33 #include "compilation-cache.h" | 34 #include "compilation-cache.h" |
| 34 #include "debug.h" | 35 #include "debug.h" |
| 35 #include "deoptimizer.h" | 36 #include "deoptimizer.h" |
| 37 #include "isolate.h" |
| 36 #include "platform.h" | 38 #include "platform.h" |
| 37 #include "stub-cache.h" | 39 #include "stub-cache.h" |
| 38 #include "cctest.h" | |
| 39 | 40 |
| 40 | |
| 41 using ::v8::internal::Handle; | |
| 42 using ::v8::internal::Object; | |
| 43 using ::v8::internal::JSFunction; | |
| 44 using ::v8::internal::Deoptimizer; | 41 using ::v8::internal::Deoptimizer; |
| 45 using ::v8::internal::EmbeddedVector; | 42 using ::v8::internal::EmbeddedVector; |
| 43 using ::v8::internal::Handle; |
| 44 using ::v8::internal::Isolate; |
| 45 using ::v8::internal::JSFunction; |
| 46 using ::v8::internal::OS; | 46 using ::v8::internal::OS; |
| 47 using ::v8::internal::Object; |
| 47 | 48 |
| 48 // Size of temp buffer for formatting small strings. | 49 // Size of temp buffer for formatting small strings. |
| 49 #define SMALL_STRING_BUFFER_SIZE 80 | 50 #define SMALL_STRING_BUFFER_SIZE 80 |
| 50 | 51 |
| 51 // Utility class to set --allow-natives-syntax --always-opt and --nouse-inlining | 52 // Utility class to set --allow-natives-syntax --always-opt and --nouse-inlining |
| 52 // when constructed and return to their default state when destroyed. | 53 // when constructed and return to their default state when destroyed. |
| 53 class AlwaysOptimizeAllowNativesSyntaxNoInlining { | 54 class AlwaysOptimizeAllowNativesSyntaxNoInlining { |
| 54 public: | 55 public: |
| 55 AlwaysOptimizeAllowNativesSyntaxNoInlining() | 56 AlwaysOptimizeAllowNativesSyntaxNoInlining() |
| 56 : always_opt_(i::FLAG_always_opt), | 57 : always_opt_(i::FLAG_always_opt), |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 "var count = 0;" | 118 "var count = 0;" |
| 118 "function h() { %DeoptimizeFunction(f); }" | 119 "function h() { %DeoptimizeFunction(f); }" |
| 119 "function g() { count++; h(); }" | 120 "function g() { count++; h(); }" |
| 120 "function f() { g(); };" | 121 "function f() { g(); };" |
| 121 "f();" | 122 "f();" |
| 122 "gc(); gc()"); | 123 "gc(); gc()"); |
| 123 } | 124 } |
| 124 | 125 |
| 125 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); | 126 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); |
| 126 CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized()); | 127 CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized()); |
| 127 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount()); | 128 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(Isolate::Current())); |
| 128 | 129 |
| 129 // Test lazy deoptimization of a simple function. Call the function after the | 130 // Test lazy deoptimization of a simple function. Call the function after the |
| 130 // deoptimization while it is still activated further down the stack. | 131 // deoptimization while it is still activated further down the stack. |
| 131 { | 132 { |
| 132 AlwaysOptimizeAllowNativesSyntaxNoInlining options; | 133 AlwaysOptimizeAllowNativesSyntaxNoInlining options; |
| 133 CompileRun( | 134 CompileRun( |
| 134 "var count = 0;" | 135 "var count = 0;" |
| 135 "function g() { count++; %DeoptimizeFunction(f); f(false); }" | 136 "function g() { count++; %DeoptimizeFunction(f); f(false); }" |
| 136 "function f(x) { if (x) { g(); } else { return } };" | 137 "function f(x) { if (x) { g(); } else { return } };" |
| 137 "f(true);" | 138 "f(true);" |
| 138 "gc(); gc()"); | 139 "gc(); gc()"); |
| 139 } | 140 } |
| 140 | 141 |
| 141 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); | 142 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); |
| 142 CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized()); | 143 CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized()); |
| 143 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount()); | 144 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(Isolate::Current())); |
| 144 } | 145 } |
| 145 | 146 |
| 146 | 147 |
| 147 TEST(DeoptimizeSimpleWithArguments) { | 148 TEST(DeoptimizeSimpleWithArguments) { |
| 148 v8::HandleScope scope; | 149 v8::HandleScope scope; |
| 149 const char* extension_list[] = { "v8/gc" }; | 150 const char* extension_list[] = { "v8/gc" }; |
| 150 v8::ExtensionConfiguration extensions(1, extension_list); | 151 v8::ExtensionConfiguration extensions(1, extension_list); |
| 151 LocalContext env(&extensions); | 152 LocalContext env(&extensions); |
| 152 | 153 |
| 153 // Test lazy deoptimization of a simple function with some arguments. | 154 // Test lazy deoptimization of a simple function with some arguments. |
| 154 { | 155 { |
| 155 AlwaysOptimizeAllowNativesSyntaxNoInlining options; | 156 AlwaysOptimizeAllowNativesSyntaxNoInlining options; |
| 156 CompileRun( | 157 CompileRun( |
| 157 "var count = 0;" | 158 "var count = 0;" |
| 158 "function h(x) { %DeoptimizeFunction(f); }" | 159 "function h(x) { %DeoptimizeFunction(f); }" |
| 159 "function g(x, y) { count++; h(x); }" | 160 "function g(x, y) { count++; h(x); }" |
| 160 "function f(x, y, z) { g(1,x); y+z; };" | 161 "function f(x, y, z) { g(1,x); y+z; };" |
| 161 "f(1, \"2\", false);" | 162 "f(1, \"2\", false);" |
| 162 "gc(); gc()"); | 163 "gc(); gc()"); |
| 163 } | 164 } |
| 164 | 165 |
| 165 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); | 166 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); |
| 166 CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized()); | 167 CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized()); |
| 167 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount()); | 168 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(Isolate::Current())); |
| 168 | 169 |
| 169 // Test lazy deoptimization of a simple function with some arguments. Call the | 170 // Test lazy deoptimization of a simple function with some arguments. Call the |
| 170 // function after the deoptimization while it is still activated further down | 171 // function after the deoptimization while it is still activated further down |
| 171 // the stack. | 172 // the stack. |
| 172 { | 173 { |
| 173 AlwaysOptimizeAllowNativesSyntaxNoInlining options; | 174 AlwaysOptimizeAllowNativesSyntaxNoInlining options; |
| 174 CompileRun( | 175 CompileRun( |
| 175 "var count = 0;" | 176 "var count = 0;" |
| 176 "function g(x, y) { count++; %DeoptimizeFunction(f); f(false, 1, y); }" | 177 "function g(x, y) { count++; %DeoptimizeFunction(f); f(false, 1, y); }" |
| 177 "function f(x, y, z) { if (x) { g(x, y); } else { return y + z; } };" | 178 "function f(x, y, z) { if (x) { g(x, y); } else { return y + z; } };" |
| 178 "f(true, 1, \"2\");" | 179 "f(true, 1, \"2\");" |
| 179 "gc(); gc()"); | 180 "gc(); gc()"); |
| 180 } | 181 } |
| 181 | 182 |
| 182 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); | 183 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); |
| 183 CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized()); | 184 CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized()); |
| 184 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount()); | 185 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(Isolate::Current())); |
| 185 } | 186 } |
| 186 | 187 |
| 187 | 188 |
| 188 TEST(DeoptimizeSimpleNested) { | 189 TEST(DeoptimizeSimpleNested) { |
| 189 v8::HandleScope scope; | 190 v8::HandleScope scope; |
| 190 const char* extension_list[] = { "v8/gc" }; | 191 const char* extension_list[] = { "v8/gc" }; |
| 191 v8::ExtensionConfiguration extensions(1, extension_list); | 192 v8::ExtensionConfiguration extensions(1, extension_list); |
| 192 LocalContext env(&extensions); | 193 LocalContext env(&extensions); |
| 193 | 194 |
| 194 // Test lazy deoptimization of a simple function. Have a nested function call | 195 // Test lazy deoptimization of a simple function. Have a nested function call |
| 195 // do the deoptimization. | 196 // do the deoptimization. |
| 196 { | 197 { |
| 197 AlwaysOptimizeAllowNativesSyntaxNoInlining options; | 198 AlwaysOptimizeAllowNativesSyntaxNoInlining options; |
| 198 CompileRun( | 199 CompileRun( |
| 199 "var count = 0;" | 200 "var count = 0;" |
| 200 "var result = 0;" | 201 "var result = 0;" |
| 201 "function h(x, y, z) { return x + y + z; }" | 202 "function h(x, y, z) { return x + y + z; }" |
| 202 "function g(z) { count++; %DeoptimizeFunction(f); return z;}" | 203 "function g(z) { count++; %DeoptimizeFunction(f); return z;}" |
| 203 "function f(x,y,z) { return h(x, y, g(z)); };" | 204 "function f(x,y,z) { return h(x, y, g(z)); };" |
| 204 "result = f(1, 2, 3);" | 205 "result = f(1, 2, 3);" |
| 205 "gc(); gc()"); | 206 "gc(); gc()"); |
| 206 | 207 |
| 207 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); | 208 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); |
| 208 CHECK_EQ(6, env->Global()->Get(v8_str("result"))->Int32Value()); | 209 CHECK_EQ(6, env->Global()->Get(v8_str("result"))->Int32Value()); |
| 209 CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized()); | 210 CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized()); |
| 210 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount()); | 211 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(Isolate::Current())); |
| 211 } | 212 } |
| 212 } | 213 } |
| 213 | 214 |
| 214 | 215 |
| 215 TEST(DeoptimizeRecursive) { | 216 TEST(DeoptimizeRecursive) { |
| 216 v8::HandleScope scope; | 217 v8::HandleScope scope; |
| 217 const char* extension_list[] = { "v8/gc" }; | 218 const char* extension_list[] = { "v8/gc" }; |
| 218 v8::ExtensionConfiguration extensions(1, extension_list); | 219 v8::ExtensionConfiguration extensions(1, extension_list); |
| 219 LocalContext env(&extensions); | 220 LocalContext env(&extensions); |
| 220 | 221 |
| 221 { | 222 { |
| 222 // Test lazy deoptimization of a simple function called recursively. Call | 223 // Test lazy deoptimization of a simple function called recursively. Call |
| 223 // the function recursively a number of times before deoptimizing it. | 224 // the function recursively a number of times before deoptimizing it. |
| 224 AlwaysOptimizeAllowNativesSyntaxNoInlining options; | 225 AlwaysOptimizeAllowNativesSyntaxNoInlining options; |
| 225 CompileRun( | 226 CompileRun( |
| 226 "var count = 0;" | 227 "var count = 0;" |
| 227 "var calls = 0;" | 228 "var calls = 0;" |
| 228 "function g() { count++; %DeoptimizeFunction(f); }" | 229 "function g() { count++; %DeoptimizeFunction(f); }" |
| 229 "function f(x) { calls++; if (x > 0) { f(x - 1); } else { g(); } };" | 230 "function f(x) { calls++; if (x > 0) { f(x - 1); } else { g(); } };" |
| 230 "f(10); gc(); gc()"); | 231 "f(10); gc(); gc()"); |
| 231 } | 232 } |
| 232 | 233 |
| 233 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); | 234 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); |
| 234 CHECK_EQ(11, env->Global()->Get(v8_str("calls"))->Int32Value()); | 235 CHECK_EQ(11, env->Global()->Get(v8_str("calls"))->Int32Value()); |
| 235 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount()); | 236 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(Isolate::Current())); |
| 236 | 237 |
| 237 v8::Local<v8::Function> fun = | 238 v8::Local<v8::Function> fun = |
| 238 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 239 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
| 239 Handle<v8::internal::JSFunction> f = v8::Utils::OpenHandle(*fun); | 240 Handle<v8::internal::JSFunction> f = v8::Utils::OpenHandle(*fun); |
| 240 } | 241 } |
| 241 | 242 |
| 242 | 243 |
| 243 TEST(DeoptimizeMultiple) { | 244 TEST(DeoptimizeMultiple) { |
| 244 v8::HandleScope scope; | 245 v8::HandleScope scope; |
| 245 const char* extension_list[] = { "v8/gc" }; | 246 const char* extension_list[] = { "v8/gc" }; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 259 "function f4(x) { g(); };" | 260 "function f4(x) { g(); };" |
| 260 "function f3(x, y, z) { f4(); return x + y + z; };" | 261 "function f3(x, y, z) { f4(); return x + y + z; };" |
| 261 "function f2(x, y) { return x + f3(y + 1, y + 1, y + 1) + y; };" | 262 "function f2(x, y) { return x + f3(y + 1, y + 1, y + 1) + y; };" |
| 262 "function f1(x) { return f2(x + 1, x + 1) + x; };" | 263 "function f1(x) { return f2(x + 1, x + 1) + x; };" |
| 263 "result = f1(1);" | 264 "result = f1(1);" |
| 264 "gc(); gc()"); | 265 "gc(); gc()"); |
| 265 } | 266 } |
| 266 | 267 |
| 267 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); | 268 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); |
| 268 CHECK_EQ(14, env->Global()->Get(v8_str("result"))->Int32Value()); | 269 CHECK_EQ(14, env->Global()->Get(v8_str("result"))->Int32Value()); |
| 269 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount()); | 270 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(Isolate::Current())); |
| 270 } | 271 } |
| 271 | 272 |
| 272 | 273 |
| 273 TEST(DeoptimizeConstructor) { | 274 TEST(DeoptimizeConstructor) { |
| 274 v8::HandleScope scope; | 275 v8::HandleScope scope; |
| 275 const char* extension_list[] = { "v8/gc" }; | 276 const char* extension_list[] = { "v8/gc" }; |
| 276 v8::ExtensionConfiguration extensions(1, extension_list); | 277 v8::ExtensionConfiguration extensions(1, extension_list); |
| 277 LocalContext env(&extensions); | 278 LocalContext env(&extensions); |
| 278 | 279 |
| 279 { | 280 { |
| 280 AlwaysOptimizeAllowNativesSyntaxNoInlining options; | 281 AlwaysOptimizeAllowNativesSyntaxNoInlining options; |
| 281 CompileRun( | 282 CompileRun( |
| 282 "var count = 0;" | 283 "var count = 0;" |
| 283 "function g() { count++;" | 284 "function g() { count++;" |
| 284 " %DeoptimizeFunction(f); }" | 285 " %DeoptimizeFunction(f); }" |
| 285 "function f() { g(); };" | 286 "function f() { g(); };" |
| 286 "result = new f() instanceof f;" | 287 "result = new f() instanceof f;" |
| 287 "gc(); gc()"); | 288 "gc(); gc()"); |
| 288 } | 289 } |
| 289 | 290 |
| 290 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); | 291 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); |
| 291 CHECK(env->Global()->Get(v8_str("result"))->IsTrue()); | 292 CHECK(env->Global()->Get(v8_str("result"))->IsTrue()); |
| 292 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount()); | 293 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(Isolate::Current())); |
| 293 | 294 |
| 294 { | 295 { |
| 295 AlwaysOptimizeAllowNativesSyntaxNoInlining options; | 296 AlwaysOptimizeAllowNativesSyntaxNoInlining options; |
| 296 CompileRun( | 297 CompileRun( |
| 297 "var count = 0;" | 298 "var count = 0;" |
| 298 "var result = 0;" | 299 "var result = 0;" |
| 299 "function g() { count++;" | 300 "function g() { count++;" |
| 300 " %DeoptimizeFunction(f); }" | 301 " %DeoptimizeFunction(f); }" |
| 301 "function f(x, y) { this.x = x; g(); this.y = y; };" | 302 "function f(x, y) { this.x = x; g(); this.y = y; };" |
| 302 "result = new f(1, 2);" | 303 "result = new f(1, 2);" |
| 303 "result = result.x + result.y;" | 304 "result = result.x + result.y;" |
| 304 "gc(); gc()"); | 305 "gc(); gc()"); |
| 305 } | 306 } |
| 306 | 307 |
| 307 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); | 308 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); |
| 308 CHECK_EQ(3, env->Global()->Get(v8_str("result"))->Int32Value()); | 309 CHECK_EQ(3, env->Global()->Get(v8_str("result"))->Int32Value()); |
| 309 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount()); | 310 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(Isolate::Current())); |
| 310 } | 311 } |
| 311 | 312 |
| 312 | 313 |
| 313 TEST(DeoptimizeConstructorMultiple) { | 314 TEST(DeoptimizeConstructorMultiple) { |
| 314 v8::HandleScope scope; | 315 v8::HandleScope scope; |
| 315 const char* extension_list[] = { "v8/gc" }; | 316 const char* extension_list[] = { "v8/gc" }; |
| 316 v8::ExtensionConfiguration extensions(1, extension_list); | 317 v8::ExtensionConfiguration extensions(1, extension_list); |
| 317 LocalContext env(&extensions); | 318 LocalContext env(&extensions); |
| 318 | 319 |
| 319 { | 320 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 330 "function f3(x, y, z) { this.result = new f4(x + y + z).result; };" | 331 "function f3(x, y, z) { this.result = new f4(x + y + z).result; };" |
| 331 "function f2(x, y) {" | 332 "function f2(x, y) {" |
| 332 " this.result = x + new f3(y + 1, y + 1, y + 1).result + y; };" | 333 " this.result = x + new f3(y + 1, y + 1, y + 1).result + y; };" |
| 333 "function f1(x) { this.result = new f2(x + 1, x + 1).result + x; };" | 334 "function f1(x) { this.result = new f2(x + 1, x + 1).result + x; };" |
| 334 "result = new f1(1).result;" | 335 "result = new f1(1).result;" |
| 335 "gc(); gc()"); | 336 "gc(); gc()"); |
| 336 } | 337 } |
| 337 | 338 |
| 338 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); | 339 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); |
| 339 CHECK_EQ(14, env->Global()->Get(v8_str("result"))->Int32Value()); | 340 CHECK_EQ(14, env->Global()->Get(v8_str("result"))->Int32Value()); |
| 340 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount()); | 341 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(Isolate::Current())); |
| 341 } | 342 } |
| 342 | 343 |
| 343 | 344 |
| 344 TEST(DeoptimizeBinaryOperationADDString) { | 345 TEST(DeoptimizeBinaryOperationADDString) { |
| 345 v8::HandleScope scope; | 346 v8::HandleScope scope; |
| 346 const char* extension_list[] = { "v8/gc" }; | 347 const char* extension_list[] = { "v8/gc" }; |
| 347 v8::ExtensionConfiguration extensions(1, extension_list); | 348 v8::ExtensionConfiguration extensions(1, extension_list); |
| 348 LocalContext env(&extensions); | 349 LocalContext env(&extensions); |
| 349 | 350 |
| 350 const char* f_source = "function f(x, y) { return x + y; };"; | 351 const char* f_source = "function f(x, y) { return x + y; };"; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 378 "var result = f('a+', new X());" | 379 "var result = f('a+', new X());" |
| 379 "gc(); gc();"); | 380 "gc(); gc();"); |
| 380 } | 381 } |
| 381 | 382 |
| 382 CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized()); | 383 CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized()); |
| 383 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); | 384 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); |
| 384 v8::Handle<v8::Value> result = env->Global()->Get(v8_str("result")); | 385 v8::Handle<v8::Value> result = env->Global()->Get(v8_str("result")); |
| 385 CHECK(result->IsString()); | 386 CHECK(result->IsString()); |
| 386 v8::String::AsciiValue ascii(result); | 387 v8::String::AsciiValue ascii(result); |
| 387 CHECK_EQ("a+an X", *ascii); | 388 CHECK_EQ("a+an X", *ascii); |
| 388 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount()); | 389 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(Isolate::Current())); |
| 389 } | 390 } |
| 390 | 391 |
| 391 | 392 |
| 392 static void CompileConstructorWithDeoptimizingValueOf() { | 393 static void CompileConstructorWithDeoptimizingValueOf() { |
| 393 CompileRun("var count = 0;" | 394 CompileRun("var count = 0;" |
| 394 "var result = 0;" | 395 "var result = 0;" |
| 395 "var deopt = false;" | 396 "var deopt = false;" |
| 396 "function X() { };" | 397 "function X() { };" |
| 397 "X.prototype.valueOf = function () {" | 398 "X.prototype.valueOf = function () {" |
| 398 " if (deopt) { count++; %DeoptimizeFunction(f); } return 8" | 399 " if (deopt) { count++; %DeoptimizeFunction(f); } return 8" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 TEST(DeoptimizeBinaryOperationADD) { | 438 TEST(DeoptimizeBinaryOperationADD) { |
| 438 v8::HandleScope scope; | 439 v8::HandleScope scope; |
| 439 const char* extension_list[] = { "v8/gc" }; | 440 const char* extension_list[] = { "v8/gc" }; |
| 440 v8::ExtensionConfiguration extensions(1, extension_list); | 441 v8::ExtensionConfiguration extensions(1, extension_list); |
| 441 LocalContext env(&extensions); | 442 LocalContext env(&extensions); |
| 442 | 443 |
| 443 TestDeoptimizeBinaryOpHelper(&env, "+"); | 444 TestDeoptimizeBinaryOpHelper(&env, "+"); |
| 444 | 445 |
| 445 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); | 446 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); |
| 446 CHECK_EQ(15, env->Global()->Get(v8_str("result"))->Int32Value()); | 447 CHECK_EQ(15, env->Global()->Get(v8_str("result"))->Int32Value()); |
| 447 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount()); | 448 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(Isolate::Current())); |
| 448 } | 449 } |
| 449 | 450 |
| 450 | 451 |
| 451 TEST(DeoptimizeBinaryOperationSUB) { | 452 TEST(DeoptimizeBinaryOperationSUB) { |
| 452 v8::HandleScope scope; | 453 v8::HandleScope scope; |
| 453 const char* extension_list[] = { "v8/gc" }; | 454 const char* extension_list[] = { "v8/gc" }; |
| 454 v8::ExtensionConfiguration extensions(1, extension_list); | 455 v8::ExtensionConfiguration extensions(1, extension_list); |
| 455 LocalContext env(&extensions); | 456 LocalContext env(&extensions); |
| 456 | 457 |
| 457 TestDeoptimizeBinaryOpHelper(&env, "-"); | 458 TestDeoptimizeBinaryOpHelper(&env, "-"); |
| 458 | 459 |
| 459 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); | 460 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); |
| 460 CHECK_EQ(-1, env->Global()->Get(v8_str("result"))->Int32Value()); | 461 CHECK_EQ(-1, env->Global()->Get(v8_str("result"))->Int32Value()); |
| 461 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount()); | 462 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(Isolate::Current())); |
| 462 } | 463 } |
| 463 | 464 |
| 464 | 465 |
| 465 TEST(DeoptimizeBinaryOperationMUL) { | 466 TEST(DeoptimizeBinaryOperationMUL) { |
| 466 v8::HandleScope scope; | 467 v8::HandleScope scope; |
| 467 const char* extension_list[] = { "v8/gc" }; | 468 const char* extension_list[] = { "v8/gc" }; |
| 468 v8::ExtensionConfiguration extensions(1, extension_list); | 469 v8::ExtensionConfiguration extensions(1, extension_list); |
| 469 LocalContext env(&extensions); | 470 LocalContext env(&extensions); |
| 470 | 471 |
| 471 TestDeoptimizeBinaryOpHelper(&env, "*"); | 472 TestDeoptimizeBinaryOpHelper(&env, "*"); |
| 472 | 473 |
| 473 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); | 474 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); |
| 474 CHECK_EQ(56, env->Global()->Get(v8_str("result"))->Int32Value()); | 475 CHECK_EQ(56, env->Global()->Get(v8_str("result"))->Int32Value()); |
| 475 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount()); | 476 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(Isolate::Current())); |
| 476 } | 477 } |
| 477 | 478 |
| 478 | 479 |
| 479 TEST(DeoptimizeBinaryOperationDIV) { | 480 TEST(DeoptimizeBinaryOperationDIV) { |
| 480 v8::HandleScope scope; | 481 v8::HandleScope scope; |
| 481 const char* extension_list[] = { "v8/gc" }; | 482 const char* extension_list[] = { "v8/gc" }; |
| 482 v8::ExtensionConfiguration extensions(1, extension_list); | 483 v8::ExtensionConfiguration extensions(1, extension_list); |
| 483 LocalContext env(&extensions); | 484 LocalContext env(&extensions); |
| 484 | 485 |
| 485 TestDeoptimizeBinaryOpHelper(&env, "/"); | 486 TestDeoptimizeBinaryOpHelper(&env, "/"); |
| 486 | 487 |
| 487 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); | 488 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); |
| 488 CHECK_EQ(0, env->Global()->Get(v8_str("result"))->Int32Value()); | 489 CHECK_EQ(0, env->Global()->Get(v8_str("result"))->Int32Value()); |
| 489 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount()); | 490 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(Isolate::Current())); |
| 490 } | 491 } |
| 491 | 492 |
| 492 | 493 |
| 493 TEST(DeoptimizeBinaryOperationMOD) { | 494 TEST(DeoptimizeBinaryOperationMOD) { |
| 494 v8::HandleScope scope; | 495 v8::HandleScope scope; |
| 495 const char* extension_list[] = { "v8/gc" }; | 496 const char* extension_list[] = { "v8/gc" }; |
| 496 v8::ExtensionConfiguration extensions(1, extension_list); | 497 v8::ExtensionConfiguration extensions(1, extension_list); |
| 497 LocalContext env(&extensions); | 498 LocalContext env(&extensions); |
| 498 | 499 |
| 499 TestDeoptimizeBinaryOpHelper(&env, "%"); | 500 TestDeoptimizeBinaryOpHelper(&env, "%"); |
| 500 | 501 |
| 501 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); | 502 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); |
| 502 CHECK_EQ(7, env->Global()->Get(v8_str("result"))->Int32Value()); | 503 CHECK_EQ(7, env->Global()->Get(v8_str("result"))->Int32Value()); |
| 503 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount()); | 504 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(Isolate::Current())); |
| 504 } | 505 } |
| 505 | 506 |
| 506 | 507 |
| 507 TEST(DeoptimizeCompare) { | 508 TEST(DeoptimizeCompare) { |
| 508 v8::HandleScope scope; | 509 v8::HandleScope scope; |
| 509 const char* extension_list[] = { "v8/gc" }; | 510 const char* extension_list[] = { "v8/gc" }; |
| 510 v8::ExtensionConfiguration extensions(1, extension_list); | 511 v8::ExtensionConfiguration extensions(1, extension_list); |
| 511 LocalContext env(&extensions); | 512 LocalContext env(&extensions); |
| 512 | 513 |
| 513 const char* f_source = "function f(x, y) { return x < y; };"; | 514 const char* f_source = "function f(x, y) { return x < y; };"; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 538 | 539 |
| 539 // Call f and force deoptimization while processing the comparison. | 540 // Call f and force deoptimization while processing the comparison. |
| 540 CompileRun("deopt = true;" | 541 CompileRun("deopt = true;" |
| 541 "var result = f('a', new X());" | 542 "var result = f('a', new X());" |
| 542 "gc(); gc();"); | 543 "gc(); gc();"); |
| 543 } | 544 } |
| 544 | 545 |
| 545 CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized()); | 546 CHECK(!GetJSFunction(env->Global(), "f")->IsOptimized()); |
| 546 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); | 547 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); |
| 547 CHECK_EQ(true, env->Global()->Get(v8_str("result"))->BooleanValue()); | 548 CHECK_EQ(true, env->Global()->Get(v8_str("result"))->BooleanValue()); |
| 548 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount()); | 549 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(Isolate::Current())); |
| 549 } | 550 } |
| 550 | 551 |
| 551 | 552 |
| 552 TEST(DeoptimizeLoadICStoreIC) { | 553 TEST(DeoptimizeLoadICStoreIC) { |
| 553 v8::HandleScope scope; | 554 v8::HandleScope scope; |
| 554 const char* extension_list[] = { "v8/gc" }; | 555 const char* extension_list[] = { "v8/gc" }; |
| 555 v8::ExtensionConfiguration extensions(1, extension_list); | 556 v8::ExtensionConfiguration extensions(1, extension_list); |
| 556 LocalContext env(&extensions); | 557 LocalContext env(&extensions); |
| 557 | 558 |
| 558 // Functions to generate load/store/keyed load/keyed store IC calls. | 559 // Functions to generate load/store/keyed load/keyed store IC calls. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 "g2(new X(), 'z');" | 621 "g2(new X(), 'z');" |
| 621 "gc(); gc();"); | 622 "gc(); gc();"); |
| 622 } | 623 } |
| 623 | 624 |
| 624 CHECK(!GetJSFunction(env->Global(), "f1")->IsOptimized()); | 625 CHECK(!GetJSFunction(env->Global(), "f1")->IsOptimized()); |
| 625 CHECK(!GetJSFunction(env->Global(), "g1")->IsOptimized()); | 626 CHECK(!GetJSFunction(env->Global(), "g1")->IsOptimized()); |
| 626 CHECK(!GetJSFunction(env->Global(), "f2")->IsOptimized()); | 627 CHECK(!GetJSFunction(env->Global(), "f2")->IsOptimized()); |
| 627 CHECK(!GetJSFunction(env->Global(), "g2")->IsOptimized()); | 628 CHECK(!GetJSFunction(env->Global(), "g2")->IsOptimized()); |
| 628 CHECK_EQ(4, env->Global()->Get(v8_str("count"))->Int32Value()); | 629 CHECK_EQ(4, env->Global()->Get(v8_str("count"))->Int32Value()); |
| 629 CHECK_EQ(13, env->Global()->Get(v8_str("result"))->Int32Value()); | 630 CHECK_EQ(13, env->Global()->Get(v8_str("result"))->Int32Value()); |
| 630 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount()); | 631 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(Isolate::Current())); |
| 631 } | 632 } |
| 632 | 633 |
| 633 | 634 |
| 634 TEST(DeoptimizeLoadICStoreICNested) { | 635 TEST(DeoptimizeLoadICStoreICNested) { |
| 635 v8::HandleScope scope; | 636 v8::HandleScope scope; |
| 636 const char* extension_list[] = { "v8/gc" }; | 637 const char* extension_list[] = { "v8/gc" }; |
| 637 v8::ExtensionConfiguration extensions(1, extension_list); | 638 v8::ExtensionConfiguration extensions(1, extension_list); |
| 638 LocalContext env(&extensions); | 639 LocalContext env(&extensions); |
| 639 | 640 |
| 640 // Functions to generate load/store/keyed load/keyed store IC calls. | 641 // Functions to generate load/store/keyed load/keyed store IC calls. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 "var result = f1(new X());" | 704 "var result = f1(new X());" |
| 704 "gc(); gc();"); | 705 "gc(); gc();"); |
| 705 } | 706 } |
| 706 | 707 |
| 707 CHECK(!GetJSFunction(env->Global(), "f1")->IsOptimized()); | 708 CHECK(!GetJSFunction(env->Global(), "f1")->IsOptimized()); |
| 708 CHECK(!GetJSFunction(env->Global(), "g1")->IsOptimized()); | 709 CHECK(!GetJSFunction(env->Global(), "g1")->IsOptimized()); |
| 709 CHECK(!GetJSFunction(env->Global(), "f2")->IsOptimized()); | 710 CHECK(!GetJSFunction(env->Global(), "f2")->IsOptimized()); |
| 710 CHECK(!GetJSFunction(env->Global(), "g2")->IsOptimized()); | 711 CHECK(!GetJSFunction(env->Global(), "g2")->IsOptimized()); |
| 711 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); | 712 CHECK_EQ(1, env->Global()->Get(v8_str("count"))->Int32Value()); |
| 712 CHECK_EQ(13, env->Global()->Get(v8_str("result"))->Int32Value()); | 713 CHECK_EQ(13, env->Global()->Get(v8_str("result"))->Int32Value()); |
| 713 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount()); | 714 CHECK_EQ(0, Deoptimizer::GetDeoptimizedCodeCount(Isolate::Current())); |
| 714 } | 715 } |
| OLD | NEW |