| 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 3339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3350 CcTest::global()->Set(v8_str("fun2"), fun2); | 3350 CcTest::global()->Set(v8_str("fun2"), fun2); |
| 3351 CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);"); | 3351 CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);"); |
| 3352 | 3352 |
| 3353 Handle<JSFunction> f = | 3353 Handle<JSFunction> f = |
| 3354 v8::Utils::OpenHandle( | 3354 v8::Utils::OpenHandle( |
| 3355 *v8::Handle<v8::Function>::Cast( | 3355 *v8::Handle<v8::Function>::Cast( |
| 3356 CcTest::global()->Get(v8_str("f")))); | 3356 CcTest::global()->Get(v8_str("f")))); |
| 3357 | 3357 |
| 3358 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); | 3358 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); |
| 3359 | 3359 |
| 3360 int expected_slots = 2; | 3360 int expected_slots = 3; |
| 3361 CHECK_EQ(expected_slots, feedback_vector->ICSlots()); | 3361 CHECK_EQ(expected_slots, feedback_vector->ICSlots()); |
| 3362 int slot1 = 0; | 3362 int slot1 = 1; |
| 3363 int slot2 = 1; | 3363 int slot2 = 2; |
| 3364 CHECK(feedback_vector->Get(FeedbackVectorICSlot(slot1))->IsWeakCell()); | 3364 CHECK(feedback_vector->Get(FeedbackVectorICSlot(slot1))->IsWeakCell()); |
| 3365 CHECK(feedback_vector->Get(FeedbackVectorICSlot(slot2))->IsWeakCell()); | 3365 CHECK(feedback_vector->Get(FeedbackVectorICSlot(slot2))->IsWeakCell()); |
| 3366 | 3366 |
| 3367 SimulateIncrementalMarking(CcTest::heap()); | 3367 SimulateIncrementalMarking(CcTest::heap()); |
| 3368 CcTest::heap()->CollectAllGarbage(); | 3368 CcTest::heap()->CollectAllGarbage(); |
| 3369 | 3369 |
| 3370 CHECK(!WeakCell::cast(feedback_vector->Get(FeedbackVectorICSlot(slot1))) | 3370 CHECK(!WeakCell::cast(feedback_vector->Get(FeedbackVectorICSlot(slot1))) |
| 3371 ->cleared()); | 3371 ->cleared()); |
| 3372 CHECK(!WeakCell::cast(feedback_vector->Get(FeedbackVectorICSlot(slot2))) | 3372 CHECK(!WeakCell::cast(feedback_vector->Get(FeedbackVectorICSlot(slot2))) |
| 3373 ->cleared()); | 3373 ->cleared()); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3476 // Prepare function f that contains a monomorphic IC for object | 3476 // Prepare function f that contains a monomorphic IC for object |
| 3477 // originating from the same native context. | 3477 // originating from the same native context. |
| 3478 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" | 3478 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" |
| 3479 "function f(o) { return o.x; } f(obj); f(obj);"); | 3479 "function f(o) { return o.x; } f(obj); f(obj);"); |
| 3480 Handle<JSFunction> f = | 3480 Handle<JSFunction> f = |
| 3481 v8::Utils::OpenHandle( | 3481 v8::Utils::OpenHandle( |
| 3482 *v8::Handle<v8::Function>::Cast( | 3482 *v8::Handle<v8::Function>::Cast( |
| 3483 CcTest::global()->Get(v8_str("f")))); | 3483 CcTest::global()->Get(v8_str("f")))); |
| 3484 | 3484 |
| 3485 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3485 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3486 CheckVectorIC(f, 0, MONOMORPHIC); | 3486 CheckVectorIC(f, 1, MONOMORPHIC); |
| 3487 CHECK(ic_before->ic_state() == DEFAULT); | 3487 CHECK(ic_before->ic_state() == DEFAULT); |
| 3488 | 3488 |
| 3489 SimulateIncrementalMarking(CcTest::heap()); | 3489 SimulateIncrementalMarking(CcTest::heap()); |
| 3490 CcTest::heap()->CollectAllGarbage(); | 3490 CcTest::heap()->CollectAllGarbage(); |
| 3491 | 3491 |
| 3492 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3492 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3493 CheckVectorIC(f, 0, MONOMORPHIC); | 3493 CheckVectorIC(f, 1, MONOMORPHIC); |
| 3494 CHECK(ic_after->ic_state() == DEFAULT); | 3494 CHECK(ic_after->ic_state() == DEFAULT); |
| 3495 } | 3495 } |
| 3496 | 3496 |
| 3497 | 3497 |
| 3498 TEST(IncrementalMarkingClearsMonomorphicIC) { | 3498 TEST(IncrementalMarkingClearsMonomorphicIC) { |
| 3499 if (i::FLAG_always_opt) return; | 3499 if (i::FLAG_always_opt) return; |
| 3500 CcTest::InitializeVM(); | 3500 CcTest::InitializeVM(); |
| 3501 v8::HandleScope scope(CcTest::isolate()); | 3501 v8::HandleScope scope(CcTest::isolate()); |
| 3502 v8::Local<v8::Value> obj1; | 3502 v8::Local<v8::Value> obj1; |
| 3503 | 3503 |
| 3504 { | 3504 { |
| 3505 LocalContext env; | 3505 LocalContext env; |
| 3506 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); | 3506 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); |
| 3507 obj1 = env->Global()->Get(v8_str("obj")); | 3507 obj1 = env->Global()->Get(v8_str("obj")); |
| 3508 } | 3508 } |
| 3509 | 3509 |
| 3510 // Prepare function f that contains a monomorphic IC for object | 3510 // Prepare function f that contains a monomorphic IC for object |
| 3511 // originating from a different native context. | 3511 // originating from a different native context. |
| 3512 CcTest::global()->Set(v8_str("obj1"), obj1); | 3512 CcTest::global()->Set(v8_str("obj1"), obj1); |
| 3513 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1);"); | 3513 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1);"); |
| 3514 Handle<JSFunction> f = v8::Utils::OpenHandle( | 3514 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 3515 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 3515 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 3516 | 3516 |
| 3517 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3517 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3518 CheckVectorIC(f, 0, MONOMORPHIC); | 3518 CheckVectorIC(f, 1, MONOMORPHIC); |
| 3519 CHECK(ic_before->ic_state() == DEFAULT); | 3519 CHECK(ic_before->ic_state() == DEFAULT); |
| 3520 | 3520 |
| 3521 // Fire context dispose notification. | 3521 // Fire context dispose notification. |
| 3522 CcTest::isolate()->ContextDisposedNotification(); | 3522 CcTest::isolate()->ContextDisposedNotification(); |
| 3523 SimulateIncrementalMarking(CcTest::heap()); | 3523 SimulateIncrementalMarking(CcTest::heap()); |
| 3524 CcTest::heap()->CollectAllGarbage(); | 3524 CcTest::heap()->CollectAllGarbage(); |
| 3525 | 3525 |
| 3526 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3526 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3527 CheckVectorICCleared(f, 0); | 3527 CheckVectorICCleared(f, 1); |
| 3528 CHECK(ic_after->ic_state() == DEFAULT); | 3528 CHECK(ic_after->ic_state() == DEFAULT); |
| 3529 } | 3529 } |
| 3530 | 3530 |
| 3531 | 3531 |
| 3532 TEST(IncrementalMarkingPreservesPolymorphicIC) { | 3532 TEST(IncrementalMarkingPreservesPolymorphicIC) { |
| 3533 if (i::FLAG_always_opt) return; | 3533 if (i::FLAG_always_opt) return; |
| 3534 CcTest::InitializeVM(); | 3534 CcTest::InitializeVM(); |
| 3535 v8::HandleScope scope(CcTest::isolate()); | 3535 v8::HandleScope scope(CcTest::isolate()); |
| 3536 v8::Local<v8::Value> obj1, obj2; | 3536 v8::Local<v8::Value> obj1, obj2; |
| 3537 | 3537 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3549 | 3549 |
| 3550 // Prepare function f that contains a polymorphic IC for objects | 3550 // Prepare function f that contains a polymorphic IC for objects |
| 3551 // originating from two different native contexts. | 3551 // originating from two different native contexts. |
| 3552 CcTest::global()->Set(v8_str("obj1"), obj1); | 3552 CcTest::global()->Set(v8_str("obj1"), obj1); |
| 3553 CcTest::global()->Set(v8_str("obj2"), obj2); | 3553 CcTest::global()->Set(v8_str("obj2"), obj2); |
| 3554 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); | 3554 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); |
| 3555 Handle<JSFunction> f = v8::Utils::OpenHandle( | 3555 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 3556 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 3556 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 3557 | 3557 |
| 3558 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3558 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3559 CheckVectorIC(f, 0, POLYMORPHIC); | 3559 CheckVectorIC(f, 1, POLYMORPHIC); |
| 3560 CHECK(ic_before->ic_state() == DEFAULT); | 3560 CHECK(ic_before->ic_state() == DEFAULT); |
| 3561 | 3561 |
| 3562 // Fire context dispose notification. | 3562 // Fire context dispose notification. |
| 3563 SimulateIncrementalMarking(CcTest::heap()); | 3563 SimulateIncrementalMarking(CcTest::heap()); |
| 3564 CcTest::heap()->CollectAllGarbage(); | 3564 CcTest::heap()->CollectAllGarbage(); |
| 3565 | 3565 |
| 3566 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3566 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3567 CheckVectorIC(f, 0, POLYMORPHIC); | 3567 CheckVectorIC(f, 1, POLYMORPHIC); |
| 3568 CHECK(ic_after->ic_state() == DEFAULT); | 3568 CHECK(ic_after->ic_state() == DEFAULT); |
| 3569 } | 3569 } |
| 3570 | 3570 |
| 3571 | 3571 |
| 3572 TEST(IncrementalMarkingClearsPolymorphicIC) { | 3572 TEST(IncrementalMarkingClearsPolymorphicIC) { |
| 3573 if (i::FLAG_always_opt) return; | 3573 if (i::FLAG_always_opt) return; |
| 3574 CcTest::InitializeVM(); | 3574 CcTest::InitializeVM(); |
| 3575 v8::HandleScope scope(CcTest::isolate()); | 3575 v8::HandleScope scope(CcTest::isolate()); |
| 3576 v8::Local<v8::Value> obj1, obj2; | 3576 v8::Local<v8::Value> obj1, obj2; |
| 3577 | 3577 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3589 | 3589 |
| 3590 // Prepare function f that contains a polymorphic IC for objects | 3590 // Prepare function f that contains a polymorphic IC for objects |
| 3591 // originating from two different native contexts. | 3591 // originating from two different native contexts. |
| 3592 CcTest::global()->Set(v8_str("obj1"), obj1); | 3592 CcTest::global()->Set(v8_str("obj1"), obj1); |
| 3593 CcTest::global()->Set(v8_str("obj2"), obj2); | 3593 CcTest::global()->Set(v8_str("obj2"), obj2); |
| 3594 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); | 3594 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); |
| 3595 Handle<JSFunction> f = v8::Utils::OpenHandle( | 3595 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 3596 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 3596 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 3597 | 3597 |
| 3598 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3598 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3599 CheckVectorIC(f, 0, POLYMORPHIC); | 3599 CheckVectorIC(f, 1, POLYMORPHIC); |
| 3600 CHECK(ic_before->ic_state() == DEFAULT); | 3600 CHECK(ic_before->ic_state() == DEFAULT); |
| 3601 | 3601 |
| 3602 // Fire context dispose notification. | 3602 // Fire context dispose notification. |
| 3603 CcTest::isolate()->ContextDisposedNotification(); | 3603 CcTest::isolate()->ContextDisposedNotification(); |
| 3604 SimulateIncrementalMarking(CcTest::heap()); | 3604 SimulateIncrementalMarking(CcTest::heap()); |
| 3605 CcTest::heap()->CollectAllGarbage(); | 3605 CcTest::heap()->CollectAllGarbage(); |
| 3606 | 3606 |
| 3607 CheckVectorICCleared(f, 0); | 3607 CheckVectorICCleared(f, 1); |
| 3608 CHECK(ic_before->ic_state() == DEFAULT); | 3608 CHECK(ic_before->ic_state() == DEFAULT); |
| 3609 } | 3609 } |
| 3610 | 3610 |
| 3611 | 3611 |
| 3612 class SourceResource : public v8::String::ExternalOneByteStringResource { | 3612 class SourceResource : public v8::String::ExternalOneByteStringResource { |
| 3613 public: | 3613 public: |
| 3614 explicit SourceResource(const char* data) | 3614 explicit SourceResource(const char* data) |
| 3615 : data_(data), length_(strlen(data)) { } | 3615 : data_(data), length_(strlen(data)) { } |
| 3616 | 3616 |
| 3617 virtual void Dispose() { | 3617 virtual void Dispose() { |
| (...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4748 " loadIC(obj);" | 4748 " loadIC(obj);" |
| 4749 " loadIC(obj);" | 4749 " loadIC(obj);" |
| 4750 " return proto;" | 4750 " return proto;" |
| 4751 "};"); | 4751 "};"); |
| 4752 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); | 4752 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); |
| 4753 { | 4753 { |
| 4754 v8::HandleScope scope(CcTest::isolate()); | 4754 v8::HandleScope scope(CcTest::isolate()); |
| 4755 CompileRun("(testIC())"); | 4755 CompileRun("(testIC())"); |
| 4756 } | 4756 } |
| 4757 heap->CollectAllGarbage(); | 4757 heap->CollectAllGarbage(); |
| 4758 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, MONOMORPHIC); | 4758 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 1, MONOMORPHIC); |
| 4759 { | 4759 { |
| 4760 v8::HandleScope scope(CcTest::isolate()); | 4760 v8::HandleScope scope(CcTest::isolate()); |
| 4761 CompileRun("(testIC())"); | 4761 CompileRun("(testIC())"); |
| 4762 } | 4762 } |
| 4763 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, MONOMORPHIC); | 4763 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 1, MONOMORPHIC); |
| 4764 } | 4764 } |
| 4765 | 4765 |
| 4766 | 4766 |
| 4767 TEST(PolymorphicStaysPolymorphicAfterGC) { | 4767 TEST(PolymorphicStaysPolymorphicAfterGC) { |
| 4768 if (FLAG_always_opt) return; | 4768 if (FLAG_always_opt) return; |
| 4769 CcTest::InitializeVM(); | 4769 CcTest::InitializeVM(); |
| 4770 Isolate* isolate = CcTest::i_isolate(); | 4770 Isolate* isolate = CcTest::i_isolate(); |
| 4771 Heap* heap = isolate->heap(); | 4771 Heap* heap = isolate->heap(); |
| 4772 v8::HandleScope scope(CcTest::isolate()); | 4772 v8::HandleScope scope(CcTest::isolate()); |
| 4773 CompileRun( | 4773 CompileRun( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4784 " poly.x = true;" | 4784 " poly.x = true;" |
| 4785 " loadIC(poly);" | 4785 " loadIC(poly);" |
| 4786 " return proto;" | 4786 " return proto;" |
| 4787 "};"); | 4787 "};"); |
| 4788 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); | 4788 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); |
| 4789 { | 4789 { |
| 4790 v8::HandleScope scope(CcTest::isolate()); | 4790 v8::HandleScope scope(CcTest::isolate()); |
| 4791 CompileRun("(testIC())"); | 4791 CompileRun("(testIC())"); |
| 4792 } | 4792 } |
| 4793 heap->CollectAllGarbage(); | 4793 heap->CollectAllGarbage(); |
| 4794 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, POLYMORPHIC); | 4794 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 1, POLYMORPHIC); |
| 4795 { | 4795 { |
| 4796 v8::HandleScope scope(CcTest::isolate()); | 4796 v8::HandleScope scope(CcTest::isolate()); |
| 4797 CompileRun("(testIC())"); | 4797 CompileRun("(testIC())"); |
| 4798 } | 4798 } |
| 4799 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, POLYMORPHIC); | 4799 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 1, POLYMORPHIC); |
| 4800 } | 4800 } |
| 4801 | 4801 |
| 4802 | 4802 |
| 4803 TEST(WeakCell) { | 4803 TEST(WeakCell) { |
| 4804 CcTest::InitializeVM(); | 4804 CcTest::InitializeVM(); |
| 4805 Isolate* isolate = CcTest::i_isolate(); | 4805 Isolate* isolate = CcTest::i_isolate(); |
| 4806 v8::internal::Heap* heap = CcTest::heap(); | 4806 v8::internal::Heap* heap = CcTest::heap(); |
| 4807 v8::internal::Factory* factory = isolate->factory(); | 4807 v8::internal::Factory* factory = isolate->factory(); |
| 4808 | 4808 |
| 4809 HandleScope outer_scope(isolate); | 4809 HandleScope outer_scope(isolate); |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5454 shared.SetWeak(&shared, SharedHasBeenCollected, | 5454 shared.SetWeak(&shared, SharedHasBeenCollected, |
| 5455 v8::WeakCallbackType::kParameter); | 5455 v8::WeakCallbackType::kParameter); |
| 5456 builtin_exports.SetWeak(&builtin_exports, BuiltinExportsHasBeenCollected, | 5456 builtin_exports.SetWeak(&builtin_exports, BuiltinExportsHasBeenCollected, |
| 5457 v8::WeakCallbackType::kParameter); | 5457 v8::WeakCallbackType::kParameter); |
| 5458 | 5458 |
| 5459 CcTest::heap()->CollectAllAvailableGarbage("fire weak callbacks"); | 5459 CcTest::heap()->CollectAllAvailableGarbage("fire weak callbacks"); |
| 5460 | 5460 |
| 5461 CHECK(shared_has_been_collected); | 5461 CHECK(shared_has_been_collected); |
| 5462 CHECK(builtin_exports_has_been_collected); | 5462 CHECK(builtin_exports_has_been_collected); |
| 5463 } | 5463 } |
| OLD | NEW |