OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 3328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3339 CcTest::global()->Set(v8_str("fun2"), fun2); | 3339 CcTest::global()->Set(v8_str("fun2"), fun2); |
3340 CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);"); | 3340 CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);"); |
3341 | 3341 |
3342 Handle<JSFunction> f = | 3342 Handle<JSFunction> f = |
3343 v8::Utils::OpenHandle( | 3343 v8::Utils::OpenHandle( |
3344 *v8::Handle<v8::Function>::Cast( | 3344 *v8::Handle<v8::Function>::Cast( |
3345 CcTest::global()->Get(v8_str("f")))); | 3345 CcTest::global()->Get(v8_str("f")))); |
3346 | 3346 |
3347 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); | 3347 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); |
3348 | 3348 |
3349 int expected_slots = 2; | 3349 int expected_slots = 3; |
3350 CHECK_EQ(expected_slots, feedback_vector->ICSlots()); | 3350 CHECK_EQ(expected_slots, feedback_vector->ICSlots()); |
3351 int slot1 = 0; | 3351 int slot1 = 1; |
3352 int slot2 = 1; | 3352 int slot2 = 2; |
3353 CHECK(feedback_vector->Get(FeedbackVectorICSlot(slot1))->IsWeakCell()); | 3353 CHECK(feedback_vector->Get(FeedbackVectorICSlot(slot1))->IsWeakCell()); |
3354 CHECK(feedback_vector->Get(FeedbackVectorICSlot(slot2))->IsWeakCell()); | 3354 CHECK(feedback_vector->Get(FeedbackVectorICSlot(slot2))->IsWeakCell()); |
3355 | 3355 |
3356 SimulateIncrementalMarking(CcTest::heap()); | 3356 SimulateIncrementalMarking(CcTest::heap()); |
3357 CcTest::heap()->CollectAllGarbage(); | 3357 CcTest::heap()->CollectAllGarbage(); |
3358 | 3358 |
3359 CHECK(!WeakCell::cast(feedback_vector->Get(FeedbackVectorICSlot(slot1))) | 3359 CHECK(!WeakCell::cast(feedback_vector->Get(FeedbackVectorICSlot(slot1))) |
3360 ->cleared()); | 3360 ->cleared()); |
3361 CHECK(!WeakCell::cast(feedback_vector->Get(FeedbackVectorICSlot(slot2))) | 3361 CHECK(!WeakCell::cast(feedback_vector->Get(FeedbackVectorICSlot(slot2))) |
3362 ->cleared()); | 3362 ->cleared()); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3466 // originating from the same native context. | 3466 // originating from the same native context. |
3467 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" | 3467 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" |
3468 "function f(o) { return o.x; } f(obj); f(obj);"); | 3468 "function f(o) { return o.x; } f(obj); f(obj);"); |
3469 Handle<JSFunction> f = | 3469 Handle<JSFunction> f = |
3470 v8::Utils::OpenHandle( | 3470 v8::Utils::OpenHandle( |
3471 *v8::Handle<v8::Function>::Cast( | 3471 *v8::Handle<v8::Function>::Cast( |
3472 CcTest::global()->Get(v8_str("f")))); | 3472 CcTest::global()->Get(v8_str("f")))); |
3473 | 3473 |
3474 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3474 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
3475 if (FLAG_vector_ics) { | 3475 if (FLAG_vector_ics) { |
3476 CheckVectorIC(f, 0, MONOMORPHIC); | 3476 CheckVectorIC(f, 1, MONOMORPHIC); |
3477 CHECK(ic_before->ic_state() == DEFAULT); | 3477 CHECK(ic_before->ic_state() == DEFAULT); |
3478 } else { | 3478 } else { |
3479 CHECK(ic_before->ic_state() == MONOMORPHIC); | 3479 CHECK(ic_before->ic_state() == MONOMORPHIC); |
3480 } | 3480 } |
3481 | 3481 |
3482 SimulateIncrementalMarking(CcTest::heap()); | 3482 SimulateIncrementalMarking(CcTest::heap()); |
3483 CcTest::heap()->CollectAllGarbage(); | 3483 CcTest::heap()->CollectAllGarbage(); |
3484 | 3484 |
3485 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3485 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
3486 if (FLAG_vector_ics) { | 3486 if (FLAG_vector_ics) { |
3487 CheckVectorIC(f, 0, MONOMORPHIC); | 3487 CheckVectorIC(f, 1, MONOMORPHIC); |
3488 CHECK(ic_after->ic_state() == DEFAULT); | 3488 CHECK(ic_after->ic_state() == DEFAULT); |
3489 } else { | 3489 } else { |
3490 CHECK(ic_after->ic_state() == MONOMORPHIC); | 3490 CHECK(ic_after->ic_state() == MONOMORPHIC); |
3491 } | 3491 } |
3492 } | 3492 } |
3493 | 3493 |
3494 | 3494 |
3495 TEST(IncrementalMarkingClearsMonomorphicIC) { | 3495 TEST(IncrementalMarkingClearsMonomorphicIC) { |
3496 if (i::FLAG_always_opt) return; | 3496 if (i::FLAG_always_opt) return; |
3497 CcTest::InitializeVM(); | 3497 CcTest::InitializeVM(); |
3498 v8::HandleScope scope(CcTest::isolate()); | 3498 v8::HandleScope scope(CcTest::isolate()); |
3499 v8::Local<v8::Value> obj1; | 3499 v8::Local<v8::Value> obj1; |
3500 | 3500 |
3501 { | 3501 { |
3502 LocalContext env; | 3502 LocalContext env; |
3503 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); | 3503 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); |
3504 obj1 = env->Global()->Get(v8_str("obj")); | 3504 obj1 = env->Global()->Get(v8_str("obj")); |
3505 } | 3505 } |
3506 | 3506 |
3507 // Prepare function f that contains a monomorphic IC for object | 3507 // Prepare function f that contains a monomorphic IC for object |
3508 // originating from a different native context. | 3508 // originating from a different native context. |
3509 CcTest::global()->Set(v8_str("obj1"), obj1); | 3509 CcTest::global()->Set(v8_str("obj1"), obj1); |
3510 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1);"); | 3510 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1);"); |
3511 Handle<JSFunction> f = v8::Utils::OpenHandle( | 3511 Handle<JSFunction> f = v8::Utils::OpenHandle( |
3512 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 3512 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
3513 | 3513 |
3514 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3514 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
3515 if (FLAG_vector_ics) { | 3515 if (FLAG_vector_ics) { |
3516 CheckVectorIC(f, 0, MONOMORPHIC); | 3516 CheckVectorIC(f, 1, MONOMORPHIC); |
3517 CHECK(ic_before->ic_state() == DEFAULT); | 3517 CHECK(ic_before->ic_state() == DEFAULT); |
3518 } else { | 3518 } else { |
3519 CHECK(ic_before->ic_state() == MONOMORPHIC); | 3519 CHECK(ic_before->ic_state() == MONOMORPHIC); |
3520 } | 3520 } |
3521 | 3521 |
3522 // Fire context dispose notification. | 3522 // Fire context dispose notification. |
3523 CcTest::isolate()->ContextDisposedNotification(); | 3523 CcTest::isolate()->ContextDisposedNotification(); |
3524 SimulateIncrementalMarking(CcTest::heap()); | 3524 SimulateIncrementalMarking(CcTest::heap()); |
3525 CcTest::heap()->CollectAllGarbage(); | 3525 CcTest::heap()->CollectAllGarbage(); |
3526 | 3526 |
3527 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3527 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
3528 if (FLAG_vector_ics) { | 3528 if (FLAG_vector_ics) { |
3529 CheckVectorICCleared(f, 0); | 3529 CheckVectorICCleared(f, 1); |
3530 CHECK(ic_after->ic_state() == DEFAULT); | 3530 CHECK(ic_after->ic_state() == DEFAULT); |
3531 } else { | 3531 } else { |
3532 CHECK(IC::IsCleared(ic_after)); | 3532 CHECK(IC::IsCleared(ic_after)); |
3533 } | 3533 } |
3534 } | 3534 } |
3535 | 3535 |
3536 | 3536 |
3537 TEST(IncrementalMarkingPreservesPolymorphicIC) { | 3537 TEST(IncrementalMarkingPreservesPolymorphicIC) { |
3538 if (i::FLAG_always_opt) return; | 3538 if (i::FLAG_always_opt) return; |
3539 CcTest::InitializeVM(); | 3539 CcTest::InitializeVM(); |
(...skipping 15 matching lines...) Expand all Loading... |
3555 // Prepare function f that contains a polymorphic IC for objects | 3555 // Prepare function f that contains a polymorphic IC for objects |
3556 // originating from two different native contexts. | 3556 // originating from two different native contexts. |
3557 CcTest::global()->Set(v8_str("obj1"), obj1); | 3557 CcTest::global()->Set(v8_str("obj1"), obj1); |
3558 CcTest::global()->Set(v8_str("obj2"), obj2); | 3558 CcTest::global()->Set(v8_str("obj2"), obj2); |
3559 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); | 3559 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); |
3560 Handle<JSFunction> f = v8::Utils::OpenHandle( | 3560 Handle<JSFunction> f = v8::Utils::OpenHandle( |
3561 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 3561 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
3562 | 3562 |
3563 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3563 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
3564 if (FLAG_vector_ics) { | 3564 if (FLAG_vector_ics) { |
3565 CheckVectorIC(f, 0, POLYMORPHIC); | 3565 CheckVectorIC(f, 1, POLYMORPHIC); |
3566 CHECK(ic_before->ic_state() == DEFAULT); | 3566 CHECK(ic_before->ic_state() == DEFAULT); |
3567 } else { | 3567 } else { |
3568 CHECK(ic_before->ic_state() == POLYMORPHIC); | 3568 CHECK(ic_before->ic_state() == POLYMORPHIC); |
3569 } | 3569 } |
3570 | 3570 |
3571 // Fire context dispose notification. | 3571 // Fire context dispose notification. |
3572 SimulateIncrementalMarking(CcTest::heap()); | 3572 SimulateIncrementalMarking(CcTest::heap()); |
3573 CcTest::heap()->CollectAllGarbage(); | 3573 CcTest::heap()->CollectAllGarbage(); |
3574 | 3574 |
3575 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3575 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
3576 if (FLAG_vector_ics) { | 3576 if (FLAG_vector_ics) { |
3577 CheckVectorIC(f, 0, POLYMORPHIC); | 3577 CheckVectorIC(f, 1, POLYMORPHIC); |
3578 CHECK(ic_after->ic_state() == DEFAULT); | 3578 CHECK(ic_after->ic_state() == DEFAULT); |
3579 } else { | 3579 } else { |
3580 CHECK(ic_after->ic_state() == POLYMORPHIC); | 3580 CHECK(ic_after->ic_state() == POLYMORPHIC); |
3581 } | 3581 } |
3582 } | 3582 } |
3583 | 3583 |
3584 | 3584 |
3585 TEST(IncrementalMarkingClearsPolymorphicIC) { | 3585 TEST(IncrementalMarkingClearsPolymorphicIC) { |
3586 if (i::FLAG_always_opt) return; | 3586 if (i::FLAG_always_opt) return; |
3587 CcTest::InitializeVM(); | 3587 CcTest::InitializeVM(); |
(...skipping 15 matching lines...) Expand all Loading... |
3603 // Prepare function f that contains a polymorphic IC for objects | 3603 // Prepare function f that contains a polymorphic IC for objects |
3604 // originating from two different native contexts. | 3604 // originating from two different native contexts. |
3605 CcTest::global()->Set(v8_str("obj1"), obj1); | 3605 CcTest::global()->Set(v8_str("obj1"), obj1); |
3606 CcTest::global()->Set(v8_str("obj2"), obj2); | 3606 CcTest::global()->Set(v8_str("obj2"), obj2); |
3607 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); | 3607 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); |
3608 Handle<JSFunction> f = v8::Utils::OpenHandle( | 3608 Handle<JSFunction> f = v8::Utils::OpenHandle( |
3609 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 3609 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
3610 | 3610 |
3611 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3611 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
3612 if (FLAG_vector_ics) { | 3612 if (FLAG_vector_ics) { |
3613 CheckVectorIC(f, 0, POLYMORPHIC); | 3613 CheckVectorIC(f, 1, POLYMORPHIC); |
3614 CHECK(ic_before->ic_state() == DEFAULT); | 3614 CHECK(ic_before->ic_state() == DEFAULT); |
3615 } else { | 3615 } else { |
3616 CHECK(ic_before->ic_state() == POLYMORPHIC); | 3616 CHECK(ic_before->ic_state() == POLYMORPHIC); |
3617 } | 3617 } |
3618 | 3618 |
3619 // Fire context dispose notification. | 3619 // Fire context dispose notification. |
3620 CcTest::isolate()->ContextDisposedNotification(); | 3620 CcTest::isolate()->ContextDisposedNotification(); |
3621 SimulateIncrementalMarking(CcTest::heap()); | 3621 SimulateIncrementalMarking(CcTest::heap()); |
3622 CcTest::heap()->CollectAllGarbage(); | 3622 CcTest::heap()->CollectAllGarbage(); |
3623 | 3623 |
3624 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3624 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
3625 if (FLAG_vector_ics) { | 3625 if (FLAG_vector_ics) { |
3626 CheckVectorICCleared(f, 0); | 3626 CheckVectorICCleared(f, 1); |
3627 CHECK(ic_before->ic_state() == DEFAULT); | 3627 CHECK(ic_before->ic_state() == DEFAULT); |
3628 } else { | 3628 } else { |
3629 CHECK(IC::IsCleared(ic_after)); | 3629 CHECK(IC::IsCleared(ic_after)); |
3630 } | 3630 } |
3631 } | 3631 } |
3632 | 3632 |
3633 | 3633 |
3634 class SourceResource : public v8::String::ExternalOneByteStringResource { | 3634 class SourceResource : public v8::String::ExternalOneByteStringResource { |
3635 public: | 3635 public: |
3636 explicit SourceResource(const char* data) | 3636 explicit SourceResource(const char* data) |
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4770 " loadIC(obj);" | 4770 " loadIC(obj);" |
4771 " loadIC(obj);" | 4771 " loadIC(obj);" |
4772 " return proto;" | 4772 " return proto;" |
4773 "};"); | 4773 "};"); |
4774 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); | 4774 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); |
4775 { | 4775 { |
4776 v8::HandleScope scope(CcTest::isolate()); | 4776 v8::HandleScope scope(CcTest::isolate()); |
4777 CompileRun("(testIC())"); | 4777 CompileRun("(testIC())"); |
4778 } | 4778 } |
4779 heap->CollectAllGarbage(); | 4779 heap->CollectAllGarbage(); |
4780 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, MONOMORPHIC); | 4780 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 1, MONOMORPHIC); |
4781 { | 4781 { |
4782 v8::HandleScope scope(CcTest::isolate()); | 4782 v8::HandleScope scope(CcTest::isolate()); |
4783 CompileRun("(testIC())"); | 4783 CompileRun("(testIC())"); |
4784 } | 4784 } |
4785 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, MONOMORPHIC); | 4785 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 1, MONOMORPHIC); |
4786 } | 4786 } |
4787 | 4787 |
4788 | 4788 |
4789 TEST(PolymorphicStaysPolymorphicAfterGC) { | 4789 TEST(PolymorphicStaysPolymorphicAfterGC) { |
4790 if (FLAG_always_opt) return; | 4790 if (FLAG_always_opt) return; |
4791 CcTest::InitializeVM(); | 4791 CcTest::InitializeVM(); |
4792 Isolate* isolate = CcTest::i_isolate(); | 4792 Isolate* isolate = CcTest::i_isolate(); |
4793 Heap* heap = isolate->heap(); | 4793 Heap* heap = isolate->heap(); |
4794 v8::HandleScope scope(CcTest::isolate()); | 4794 v8::HandleScope scope(CcTest::isolate()); |
4795 CompileRun( | 4795 CompileRun( |
(...skipping 10 matching lines...) Expand all Loading... |
4806 " poly.x = true;" | 4806 " poly.x = true;" |
4807 " loadIC(poly);" | 4807 " loadIC(poly);" |
4808 " return proto;" | 4808 " return proto;" |
4809 "};"); | 4809 "};"); |
4810 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); | 4810 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); |
4811 { | 4811 { |
4812 v8::HandleScope scope(CcTest::isolate()); | 4812 v8::HandleScope scope(CcTest::isolate()); |
4813 CompileRun("(testIC())"); | 4813 CompileRun("(testIC())"); |
4814 } | 4814 } |
4815 heap->CollectAllGarbage(); | 4815 heap->CollectAllGarbage(); |
4816 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, POLYMORPHIC); | 4816 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 1, POLYMORPHIC); |
4817 { | 4817 { |
4818 v8::HandleScope scope(CcTest::isolate()); | 4818 v8::HandleScope scope(CcTest::isolate()); |
4819 CompileRun("(testIC())"); | 4819 CompileRun("(testIC())"); |
4820 } | 4820 } |
4821 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, POLYMORPHIC); | 4821 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 1, POLYMORPHIC); |
4822 } | 4822 } |
4823 | 4823 |
4824 | 4824 |
4825 TEST(WeakCell) { | 4825 TEST(WeakCell) { |
4826 CcTest::InitializeVM(); | 4826 CcTest::InitializeVM(); |
4827 Isolate* isolate = CcTest::i_isolate(); | 4827 Isolate* isolate = CcTest::i_isolate(); |
4828 v8::internal::Heap* heap = CcTest::heap(); | 4828 v8::internal::Heap* heap = CcTest::heap(); |
4829 v8::internal::Factory* factory = isolate->factory(); | 4829 v8::internal::Factory* factory = isolate->factory(); |
4830 | 4830 |
4831 HandleScope outer_scope(isolate); | 4831 HandleScope outer_scope(isolate); |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5423 CHECK(pos->IsSmi()); | 5423 CHECK(pos->IsSmi()); |
5424 | 5424 |
5425 Handle<JSArray> stack_trace_array = Handle<JSArray>::cast(stack_trace); | 5425 Handle<JSArray> stack_trace_array = Handle<JSArray>::cast(stack_trace); |
5426 int array_length = Smi::cast(stack_trace_array->length())->value(); | 5426 int array_length = Smi::cast(stack_trace_array->length())->value(); |
5427 for (int i = 0; i < array_length; i++) { | 5427 for (int i = 0; i < array_length; i++) { |
5428 Handle<Object> element = | 5428 Handle<Object> element = |
5429 Object::GetElement(isolate, stack_trace, i).ToHandleChecked(); | 5429 Object::GetElement(isolate, stack_trace, i).ToHandleChecked(); |
5430 CHECK(!element->IsCode()); | 5430 CHECK(!element->IsCode()); |
5431 } | 5431 } |
5432 } | 5432 } |
OLD | NEW |