OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 #include "test/cctest/cctest.h" | 6 #include "test/cctest/cctest.h" |
7 | 7 |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/debug.h" | 9 #include "src/debug.h" |
10 #include "src/execution.h" | 10 #include "src/execution.h" |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 } | 378 } |
379 CHECK(number_map_found && o_map_found); | 379 CHECK(number_map_found && o_map_found); |
380 | 380 |
381 // The degree of polymorphism doesn't change. | 381 // The degree of polymorphism doesn't change. |
382 CompileRun("f(100)"); | 382 CompileRun("f(100)"); |
383 CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback()); | 383 CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback()); |
384 MapHandleList maps2; | 384 MapHandleList maps2; |
385 nexus.FindAllMaps(&maps2); | 385 nexus.FindAllMaps(&maps2); |
386 CHECK_EQ(2, maps2.length()); | 386 CHECK_EQ(2, maps2.length()); |
387 } | 387 } |
| 388 |
| 389 |
| 390 static Handle<JSFunction> GetFunction(const char* name) { |
| 391 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 392 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str(name)))); |
| 393 return f; |
388 } | 394 } |
| 395 |
| 396 |
| 397 TEST(ReferenceContextAllocatesNoSlots) { |
| 398 if (i::FLAG_always_opt) return; |
| 399 CcTest::InitializeVM(); |
| 400 LocalContext context; |
| 401 v8::HandleScope scope(context->GetIsolate()); |
| 402 Isolate* isolate = CcTest::i_isolate(); |
| 403 |
| 404 CompileRun( |
| 405 "function testvar(x) {" |
| 406 " y = x;" |
| 407 " y = a;" |
| 408 " return y;" |
| 409 "}" |
| 410 "a = 3;" |
| 411 "testvar({});"); |
| 412 |
| 413 Handle<JSFunction> f = GetFunction("testvar"); |
| 414 |
| 415 // There should be two LOAD_ICs, one for a and one for y at the end. |
| 416 Handle<TypeFeedbackVector> feedback_vector = |
| 417 handle(f->shared()->feedback_vector(), isolate); |
| 418 CHECK_EQ(2, feedback_vector->ICSlots()); |
| 419 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(0)) == Code::LOAD_IC); |
| 420 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(1)) == Code::LOAD_IC); |
| 421 |
| 422 CompileRun( |
| 423 "function testprop(x) {" |
| 424 " x.blue = a;" |
| 425 "}" |
| 426 "testprop({ blue: 3 });"); |
| 427 |
| 428 f = GetFunction("testprop"); |
| 429 |
| 430 // There should be one LOAD_IC, for the load of a. |
| 431 feedback_vector = handle(f->shared()->feedback_vector(), isolate); |
| 432 CHECK_EQ(1, feedback_vector->ICSlots()); |
| 433 |
| 434 CompileRun( |
| 435 "function testpropfunc(x) {" |
| 436 " x().blue = a;" |
| 437 " return x().blue;" |
| 438 "}" |
| 439 "function makeresult() { return { blue: 3 }; }" |
| 440 "testpropfunc(makeresult);"); |
| 441 |
| 442 f = GetFunction("testpropfunc"); |
| 443 |
| 444 // There should be 2 LOAD_ICs and 2 CALL_ICs. |
| 445 feedback_vector = handle(f->shared()->feedback_vector(), isolate); |
| 446 CHECK_EQ(4, feedback_vector->ICSlots()); |
| 447 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(0)) == Code::CALL_IC); |
| 448 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(1)) == Code::LOAD_IC); |
| 449 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(2)) == Code::CALL_IC); |
| 450 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(3)) == Code::LOAD_IC); |
| 451 |
| 452 CompileRun( |
| 453 "function testkeyedprop(x) {" |
| 454 " x[0] = a;" |
| 455 " return x[0];" |
| 456 "}" |
| 457 "testkeyedprop([0, 1, 2]);"); |
| 458 |
| 459 f = GetFunction("testkeyedprop"); |
| 460 |
| 461 // There should be 1 LOAD_ICs for the load of a, and one KEYED_LOAD_IC for the |
| 462 // load of x[0] in the return statement. |
| 463 feedback_vector = handle(f->shared()->feedback_vector(), isolate); |
| 464 CHECK_EQ(2, feedback_vector->ICSlots()); |
| 465 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(0)) == Code::LOAD_IC); |
| 466 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(1)) == |
| 467 Code::KEYED_LOAD_IC); |
| 468 |
| 469 CompileRun( |
| 470 "function testcompound(x) {" |
| 471 " x.old = x.young = x.in_between = a;" |
| 472 " return x.old + x.young;" |
| 473 "}" |
| 474 "testcompound({ old: 3, young: 3, in_between: 3 });"); |
| 475 |
| 476 f = GetFunction("testcompound"); |
| 477 |
| 478 // There should be 3 LOAD_ICs, for load of a and load of x.old and x.young. |
| 479 feedback_vector = handle(f->shared()->feedback_vector(), isolate); |
| 480 CHECK_EQ(3, feedback_vector->ICSlots()); |
| 481 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(0)) == Code::LOAD_IC); |
| 482 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(1)) == Code::LOAD_IC); |
| 483 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(2)) == Code::LOAD_IC); |
| 484 } |
| 485 } |
OLD | NEW |