| 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 3609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3620 | 3620 |
| 3621 // Prepare function f that contains type feedback for the two closures. | 3621 // Prepare function f that contains type feedback for the two closures. |
| 3622 CHECK(CcTest::global()->Set(ctx, v8_str("fun1"), fun1).FromJust()); | 3622 CHECK(CcTest::global()->Set(ctx, v8_str("fun1"), fun1).FromJust()); |
| 3623 CHECK(CcTest::global()->Set(ctx, v8_str("fun2"), fun2).FromJust()); | 3623 CHECK(CcTest::global()->Set(ctx, v8_str("fun2"), fun2).FromJust()); |
| 3624 CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);"); | 3624 CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);"); |
| 3625 | 3625 |
| 3626 Handle<JSFunction> f = Handle<JSFunction>::cast( | 3626 Handle<JSFunction> f = Handle<JSFunction>::cast( |
| 3627 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 3627 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 3628 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked()))); | 3628 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked()))); |
| 3629 | 3629 |
| 3630 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector()); | 3630 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); |
| 3631 FeedbackVectorHelper feedback_helper(feedback_vector); | 3631 FeedbackVectorHelper feedback_helper(feedback_vector); |
| 3632 | 3632 |
| 3633 int expected_slots = 2; | 3633 int expected_slots = 2; |
| 3634 CHECK_EQ(expected_slots, feedback_helper.slot_count()); | 3634 CHECK_EQ(expected_slots, feedback_helper.slot_count()); |
| 3635 int slot1 = 0; | 3635 int slot1 = 0; |
| 3636 int slot2 = 1; | 3636 int slot2 = 1; |
| 3637 CHECK(feedback_vector->Get(feedback_helper.slot(slot1))->IsWeakCell()); | 3637 CHECK(feedback_vector->Get(feedback_helper.slot(slot1))->IsWeakCell()); |
| 3638 CHECK(feedback_vector->Get(feedback_helper.slot(slot2))->IsWeakCell()); | 3638 CHECK(feedback_vector->Get(feedback_helper.slot(slot2))->IsWeakCell()); |
| 3639 | 3639 |
| 3640 SimulateIncrementalMarking(CcTest::heap()); | 3640 SimulateIncrementalMarking(CcTest::heap()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3657 return target; | 3657 return target; |
| 3658 } | 3658 } |
| 3659 } | 3659 } |
| 3660 return NULL; | 3660 return NULL; |
| 3661 } | 3661 } |
| 3662 | 3662 |
| 3663 | 3663 |
| 3664 static void CheckVectorIC(Handle<JSFunction> f, int slot_index, | 3664 static void CheckVectorIC(Handle<JSFunction> f, int slot_index, |
| 3665 InlineCacheState desired_state) { | 3665 InlineCacheState desired_state) { |
| 3666 Handle<TypeFeedbackVector> vector = | 3666 Handle<TypeFeedbackVector> vector = |
| 3667 Handle<TypeFeedbackVector>(f->feedback_vector()); | 3667 Handle<TypeFeedbackVector>(f->shared()->feedback_vector()); |
| 3668 FeedbackVectorHelper helper(vector); | 3668 FeedbackVectorHelper helper(vector); |
| 3669 FeedbackVectorSlot slot = helper.slot(slot_index); | 3669 FeedbackVectorSlot slot = helper.slot(slot_index); |
| 3670 if (vector->GetKind(slot) == FeedbackVectorSlotKind::LOAD_IC) { | 3670 if (vector->GetKind(slot) == FeedbackVectorSlotKind::LOAD_IC) { |
| 3671 LoadICNexus nexus(vector, slot); | 3671 LoadICNexus nexus(vector, slot); |
| 3672 CHECK(nexus.StateFromFeedback() == desired_state); | 3672 CHECK(nexus.StateFromFeedback() == desired_state); |
| 3673 } else { | 3673 } else { |
| 3674 CHECK_EQ(FeedbackVectorSlotKind::KEYED_LOAD_IC, vector->GetKind(slot)); | 3674 CHECK_EQ(FeedbackVectorSlotKind::KEYED_LOAD_IC, vector->GetKind(slot)); |
| 3675 KeyedLoadICNexus nexus(vector, slot); | 3675 KeyedLoadICNexus nexus(vector, slot); |
| 3676 CHECK(nexus.StateFromFeedback() == desired_state); | 3676 CHECK(nexus.StateFromFeedback() == desired_state); |
| 3677 } | 3677 } |
| 3678 } | 3678 } |
| 3679 | 3679 |
| 3680 | 3680 |
| 3681 static void CheckVectorICCleared(Handle<JSFunction> f, int slot_index) { |
| 3682 Handle<TypeFeedbackVector> vector = |
| 3683 Handle<TypeFeedbackVector>(f->shared()->feedback_vector()); |
| 3684 FeedbackVectorSlot slot(slot_index); |
| 3685 LoadICNexus nexus(vector, slot); |
| 3686 CHECK(IC::IsCleared(&nexus)); |
| 3687 } |
| 3688 |
| 3689 |
| 3681 TEST(IncrementalMarkingPreservesMonomorphicConstructor) { | 3690 TEST(IncrementalMarkingPreservesMonomorphicConstructor) { |
| 3682 if (i::FLAG_always_opt) return; | 3691 if (i::FLAG_always_opt) return; |
| 3683 CcTest::InitializeVM(); | 3692 CcTest::InitializeVM(); |
| 3684 v8::HandleScope scope(CcTest::isolate()); | 3693 v8::HandleScope scope(CcTest::isolate()); |
| 3685 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext(); | 3694 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext(); |
| 3686 // Prepare function f that contains a monomorphic IC for object | 3695 // Prepare function f that contains a monomorphic IC for object |
| 3687 // originating from the same native context. | 3696 // originating from the same native context. |
| 3688 CompileRun( | 3697 CompileRun( |
| 3689 "function fun() { this.x = 1; };" | 3698 "function fun() { this.x = 1; };" |
| 3690 "function f(o) { return new o(); } f(fun); f(fun);"); | 3699 "function f(o) { return new o(); } f(fun); f(fun);"); |
| 3691 Handle<JSFunction> f = Handle<JSFunction>::cast( | 3700 Handle<JSFunction> f = Handle<JSFunction>::cast( |
| 3692 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 3701 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 3693 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked()))); | 3702 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked()))); |
| 3694 | 3703 |
| 3695 Handle<TypeFeedbackVector> vector(f->feedback_vector()); | 3704 Handle<TypeFeedbackVector> vector(f->shared()->feedback_vector()); |
| 3696 CHECK(vector->Get(FeedbackVectorSlot(0))->IsWeakCell()); | 3705 CHECK(vector->Get(FeedbackVectorSlot(0))->IsWeakCell()); |
| 3697 | 3706 |
| 3698 SimulateIncrementalMarking(CcTest::heap()); | 3707 SimulateIncrementalMarking(CcTest::heap()); |
| 3699 CcTest::heap()->CollectAllGarbage(); | 3708 CcTest::heap()->CollectAllGarbage(); |
| 3700 | 3709 |
| 3701 CHECK(vector->Get(FeedbackVectorSlot(0))->IsWeakCell()); | 3710 CHECK(vector->Get(FeedbackVectorSlot(0))->IsWeakCell()); |
| 3702 } | 3711 } |
| 3703 | 3712 |
| 3704 | 3713 |
| 3714 TEST(IncrementalMarkingClearsMonomorphicConstructor) { |
| 3715 if (i::FLAG_always_opt) return; |
| 3716 CcTest::InitializeVM(); |
| 3717 Isolate* isolate = CcTest::i_isolate(); |
| 3718 v8::HandleScope scope(CcTest::isolate()); |
| 3719 v8::Local<v8::Value> fun1; |
| 3720 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext(); |
| 3721 |
| 3722 { |
| 3723 LocalContext env; |
| 3724 CompileRun("function fun() { this.x = 1; };"); |
| 3725 fun1 = env->Global()->Get(env.local(), v8_str("fun")).ToLocalChecked(); |
| 3726 } |
| 3727 |
| 3728 // Prepare function f that contains a monomorphic constructor for object |
| 3729 // originating from a different native context. |
| 3730 CHECK(CcTest::global()->Set(ctx, v8_str("fun1"), fun1).FromJust()); |
| 3731 CompileRun( |
| 3732 "function fun() { this.x = 1; };" |
| 3733 "function f(o) { return new o(); } f(fun1); f(fun1);"); |
| 3734 Handle<JSFunction> f = Handle<JSFunction>::cast( |
| 3735 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 3736 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked()))); |
| 3737 |
| 3738 |
| 3739 Handle<TypeFeedbackVector> vector(f->shared()->feedback_vector()); |
| 3740 CHECK(vector->Get(FeedbackVectorSlot(0))->IsWeakCell()); |
| 3741 |
| 3742 // Fire context dispose notification. |
| 3743 CcTest::isolate()->ContextDisposedNotification(); |
| 3744 SimulateIncrementalMarking(CcTest::heap()); |
| 3745 CcTest::heap()->CollectAllGarbage(); |
| 3746 |
| 3747 CHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(isolate), |
| 3748 vector->Get(FeedbackVectorSlot(0))); |
| 3749 } |
| 3750 |
| 3751 |
| 3705 TEST(IncrementalMarkingPreservesMonomorphicIC) { | 3752 TEST(IncrementalMarkingPreservesMonomorphicIC) { |
| 3706 if (i::FLAG_always_opt) return; | 3753 if (i::FLAG_always_opt) return; |
| 3707 CcTest::InitializeVM(); | 3754 CcTest::InitializeVM(); |
| 3708 v8::HandleScope scope(CcTest::isolate()); | 3755 v8::HandleScope scope(CcTest::isolate()); |
| 3709 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext(); | 3756 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext(); |
| 3710 // Prepare function f that contains a monomorphic IC for object | 3757 // Prepare function f that contains a monomorphic IC for object |
| 3711 // originating from the same native context. | 3758 // originating from the same native context. |
| 3712 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" | 3759 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" |
| 3713 "function f(o) { return o.x; } f(obj); f(obj);"); | 3760 "function f(o) { return o.x; } f(obj); f(obj);"); |
| 3714 Handle<JSFunction> f = Handle<JSFunction>::cast( | 3761 Handle<JSFunction> f = Handle<JSFunction>::cast( |
| 3715 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 3762 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 3716 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked()))); | 3763 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked()))); |
| 3717 | 3764 |
| 3718 CheckVectorIC(f, 0, MONOMORPHIC); | 3765 CheckVectorIC(f, 0, MONOMORPHIC); |
| 3719 | 3766 |
| 3720 SimulateIncrementalMarking(CcTest::heap()); | 3767 SimulateIncrementalMarking(CcTest::heap()); |
| 3721 CcTest::heap()->CollectAllGarbage(); | 3768 CcTest::heap()->CollectAllGarbage(); |
| 3722 | 3769 |
| 3723 CheckVectorIC(f, 0, MONOMORPHIC); | 3770 CheckVectorIC(f, 0, MONOMORPHIC); |
| 3724 } | 3771 } |
| 3725 | 3772 |
| 3726 | 3773 |
| 3774 TEST(IncrementalMarkingClearsMonomorphicIC) { |
| 3775 if (i::FLAG_always_opt) return; |
| 3776 CcTest::InitializeVM(); |
| 3777 v8::HandleScope scope(CcTest::isolate()); |
| 3778 v8::Local<v8::Value> obj1; |
| 3779 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext(); |
| 3780 |
| 3781 { |
| 3782 LocalContext env; |
| 3783 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); |
| 3784 obj1 = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); |
| 3785 } |
| 3786 |
| 3787 // Prepare function f that contains a monomorphic IC for object |
| 3788 // originating from a different native context. |
| 3789 CHECK(CcTest::global()->Set(ctx, v8_str("obj1"), obj1).FromJust()); |
| 3790 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1);"); |
| 3791 Handle<JSFunction> f = Handle<JSFunction>::cast( |
| 3792 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 3793 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked()))); |
| 3794 |
| 3795 CheckVectorIC(f, 0, MONOMORPHIC); |
| 3796 |
| 3797 // Fire context dispose notification. |
| 3798 CcTest::isolate()->ContextDisposedNotification(); |
| 3799 SimulateIncrementalMarking(CcTest::heap()); |
| 3800 CcTest::heap()->CollectAllGarbage(); |
| 3801 |
| 3802 CheckVectorICCleared(f, 0); |
| 3803 } |
| 3804 |
| 3805 |
| 3727 TEST(IncrementalMarkingPreservesPolymorphicIC) { | 3806 TEST(IncrementalMarkingPreservesPolymorphicIC) { |
| 3728 if (i::FLAG_always_opt) return; | 3807 if (i::FLAG_always_opt) return; |
| 3729 CcTest::InitializeVM(); | 3808 CcTest::InitializeVM(); |
| 3730 v8::HandleScope scope(CcTest::isolate()); | 3809 v8::HandleScope scope(CcTest::isolate()); |
| 3731 v8::Local<v8::Value> obj1, obj2; | 3810 v8::Local<v8::Value> obj1, obj2; |
| 3732 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext(); | 3811 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext(); |
| 3733 | 3812 |
| 3734 { | 3813 { |
| 3735 LocalContext env; | 3814 LocalContext env; |
| 3736 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); | 3815 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3754 | 3833 |
| 3755 CheckVectorIC(f, 0, POLYMORPHIC); | 3834 CheckVectorIC(f, 0, POLYMORPHIC); |
| 3756 | 3835 |
| 3757 // Fire context dispose notification. | 3836 // Fire context dispose notification. |
| 3758 SimulateIncrementalMarking(CcTest::heap()); | 3837 SimulateIncrementalMarking(CcTest::heap()); |
| 3759 CcTest::heap()->CollectAllGarbage(); | 3838 CcTest::heap()->CollectAllGarbage(); |
| 3760 | 3839 |
| 3761 CheckVectorIC(f, 0, POLYMORPHIC); | 3840 CheckVectorIC(f, 0, POLYMORPHIC); |
| 3762 } | 3841 } |
| 3763 | 3842 |
| 3764 TEST(ContextDisposeDoesntClearPolymorphicIC) { | 3843 |
| 3844 TEST(IncrementalMarkingClearsPolymorphicIC) { |
| 3765 if (i::FLAG_always_opt) return; | 3845 if (i::FLAG_always_opt) return; |
| 3766 CcTest::InitializeVM(); | 3846 CcTest::InitializeVM(); |
| 3767 v8::HandleScope scope(CcTest::isolate()); | 3847 v8::HandleScope scope(CcTest::isolate()); |
| 3768 v8::Local<v8::Value> obj1, obj2; | 3848 v8::Local<v8::Value> obj1, obj2; |
| 3769 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext(); | 3849 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext(); |
| 3770 | 3850 |
| 3771 { | 3851 { |
| 3772 LocalContext env; | 3852 LocalContext env; |
| 3773 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); | 3853 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); |
| 3774 obj1 = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); | 3854 obj1 = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3789 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 3869 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 3790 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked()))); | 3870 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked()))); |
| 3791 | 3871 |
| 3792 CheckVectorIC(f, 0, POLYMORPHIC); | 3872 CheckVectorIC(f, 0, POLYMORPHIC); |
| 3793 | 3873 |
| 3794 // Fire context dispose notification. | 3874 // Fire context dispose notification. |
| 3795 CcTest::isolate()->ContextDisposedNotification(); | 3875 CcTest::isolate()->ContextDisposedNotification(); |
| 3796 SimulateIncrementalMarking(CcTest::heap()); | 3876 SimulateIncrementalMarking(CcTest::heap()); |
| 3797 CcTest::heap()->CollectAllGarbage(); | 3877 CcTest::heap()->CollectAllGarbage(); |
| 3798 | 3878 |
| 3799 CheckVectorIC(f, 0, POLYMORPHIC); | 3879 CheckVectorICCleared(f, 0); |
| 3800 } | 3880 } |
| 3801 | 3881 |
| 3802 | 3882 |
| 3803 class SourceResource : public v8::String::ExternalOneByteStringResource { | 3883 class SourceResource : public v8::String::ExternalOneByteStringResource { |
| 3804 public: | 3884 public: |
| 3805 explicit SourceResource(const char* data) | 3885 explicit SourceResource(const char* data) |
| 3806 : data_(data), length_(strlen(data)) { } | 3886 : data_(data), length_(strlen(data)) { } |
| 3807 | 3887 |
| 3808 virtual void Dispose() { | 3888 virtual void Dispose() { |
| 3809 i::DeleteArray(data_); | 3889 i::DeleteArray(data_); |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4205 CompileRun("function g() { return 2 }" | 4285 CompileRun("function g() { return 2 }" |
| 4206 "g(); %OptimizeFunctionOnNextCall(g); g();"); | 4286 "g(); %OptimizeFunctionOnNextCall(g); g();"); |
| 4207 | 4287 |
| 4208 Handle<JSFunction> g = Handle<JSFunction>::cast( | 4288 Handle<JSFunction> g = Handle<JSFunction>::cast( |
| 4209 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 4289 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 4210 CcTest::global()->Get(env.local(), v8_str("g")).ToLocalChecked()))); | 4290 CcTest::global()->Get(env.local(), v8_str("g")).ToLocalChecked()))); |
| 4211 code = inner_scope.CloseAndEscape(handle(g->code(), isolate)); | 4291 code = inner_scope.CloseAndEscape(handle(g->code(), isolate)); |
| 4212 if (!code->is_optimized_code()) return; | 4292 if (!code->is_optimized_code()) return; |
| 4213 } | 4293 } |
| 4214 | 4294 |
| 4215 Handle<TypeFeedbackVector> vector = | 4295 Handle<TypeFeedbackVector> vector = handle(shared->feedback_vector()); |
| 4216 TypeFeedbackVector::New(isolate, handle(shared->feedback_metadata())); | |
| 4217 Handle<LiteralsArray> lit = | 4296 Handle<LiteralsArray> lit = |
| 4218 LiteralsArray::New(isolate, vector, shared->num_literals(), TENURED); | 4297 LiteralsArray::New(isolate, vector, shared->num_literals(), TENURED); |
| 4219 Handle<Context> context(isolate->context()); | 4298 Handle<Context> context(isolate->context()); |
| 4220 | 4299 |
| 4221 // Add the new code several times to the optimized code map and also set an | 4300 // Add the new code several times to the optimized code map and also set an |
| 4222 // allocation timeout so that expanding the code map will trigger a GC. | 4301 // allocation timeout so that expanding the code map will trigger a GC. |
| 4223 heap->set_allocation_timeout(5); | 4302 heap->set_allocation_timeout(5); |
| 4224 FLAG_gc_interval = 1000; | 4303 FLAG_gc_interval = 1000; |
| 4225 for (int i = 0; i < 10; ++i) { | 4304 for (int i = 0; i < 10; ++i) { |
| 4226 BailoutId id = BailoutId(i); | 4305 BailoutId id = BailoutId(i); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4263 CompileRun("function g() { return 2 }" | 4342 CompileRun("function g() { return 2 }" |
| 4264 "g(); %OptimizeFunctionOnNextCall(g); g();"); | 4343 "g(); %OptimizeFunctionOnNextCall(g); g();"); |
| 4265 | 4344 |
| 4266 Handle<JSFunction> g = Handle<JSFunction>::cast( | 4345 Handle<JSFunction> g = Handle<JSFunction>::cast( |
| 4267 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 4346 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 4268 CcTest::global()->Get(env.local(), v8_str("g")).ToLocalChecked()))); | 4347 CcTest::global()->Get(env.local(), v8_str("g")).ToLocalChecked()))); |
| 4269 code = inner_scope.CloseAndEscape(handle(g->code(), isolate)); | 4348 code = inner_scope.CloseAndEscape(handle(g->code(), isolate)); |
| 4270 if (!code->is_optimized_code()) return; | 4349 if (!code->is_optimized_code()) return; |
| 4271 } | 4350 } |
| 4272 | 4351 |
| 4273 Handle<TypeFeedbackVector> vector = | 4352 Handle<TypeFeedbackVector> vector = handle(shared->feedback_vector()); |
| 4274 TypeFeedbackVector::New(isolate, handle(shared->feedback_metadata())); | |
| 4275 Handle<LiteralsArray> lit = | 4353 Handle<LiteralsArray> lit = |
| 4276 LiteralsArray::New(isolate, vector, shared->num_literals(), TENURED); | 4354 LiteralsArray::New(isolate, vector, shared->num_literals(), TENURED); |
| 4277 Handle<Context> context(isolate->context()); | 4355 Handle<Context> context(isolate->context()); |
| 4278 | 4356 |
| 4279 // Add the code several times to the optimized code map. | 4357 // Add the code several times to the optimized code map. |
| 4280 for (int i = 0; i < 3; ++i) { | 4358 for (int i = 0; i < 3; ++i) { |
| 4281 HandleScope inner_scope(isolate); | 4359 HandleScope inner_scope(isolate); |
| 4282 BailoutId id = BailoutId(i); | 4360 BailoutId id = BailoutId(i); |
| 4283 SharedFunctionInfo::AddToOptimizedCodeMap(shared, context, code, lit, id); | 4361 SharedFunctionInfo::AddToOptimizedCodeMap(shared, context, code, lit, id); |
| 4284 } | 4362 } |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4968 weak_ic_cleared = false; | 5046 weak_ic_cleared = false; |
| 4969 garbage.SetWeak(&garbage, &ClearWeakIC, v8::WeakCallbackType::kParameter); | 5047 garbage.SetWeak(&garbage, &ClearWeakIC, v8::WeakCallbackType::kParameter); |
| 4970 Heap* heap = CcTest::i_isolate()->heap(); | 5048 Heap* heap = CcTest::i_isolate()->heap(); |
| 4971 heap->CollectAllGarbage(); | 5049 heap->CollectAllGarbage(); |
| 4972 CHECK(weak_ic_cleared); | 5050 CHECK(weak_ic_cleared); |
| 4973 | 5051 |
| 4974 // We've determined the constructor in createObj has had it's weak cell | 5052 // We've determined the constructor in createObj has had it's weak cell |
| 4975 // cleared. Now, verify that one additional call with a new function | 5053 // cleared. Now, verify that one additional call with a new function |
| 4976 // allows monomorphicity. | 5054 // allows monomorphicity. |
| 4977 Handle<TypeFeedbackVector> feedback_vector = Handle<TypeFeedbackVector>( | 5055 Handle<TypeFeedbackVector> feedback_vector = Handle<TypeFeedbackVector>( |
| 4978 createObj->feedback_vector(), CcTest::i_isolate()); | 5056 createObj->shared()->feedback_vector(), CcTest::i_isolate()); |
| 4979 for (int i = 0; i < 20; i++) { | 5057 for (int i = 0; i < 20; i++) { |
| 4980 Object* slot_value = feedback_vector->Get(FeedbackVectorSlot(0)); | 5058 Object* slot_value = feedback_vector->Get(FeedbackVectorSlot(0)); |
| 4981 CHECK(slot_value->IsWeakCell()); | 5059 CHECK(slot_value->IsWeakCell()); |
| 4982 if (WeakCell::cast(slot_value)->cleared()) break; | 5060 if (WeakCell::cast(slot_value)->cleared()) break; |
| 4983 heap->CollectAllGarbage(); | 5061 heap->CollectAllGarbage(); |
| 4984 } | 5062 } |
| 4985 | 5063 |
| 4986 Object* slot_value = feedback_vector->Get(FeedbackVectorSlot(0)); | 5064 Object* slot_value = feedback_vector->Get(FeedbackVectorSlot(0)); |
| 4987 CHECK(slot_value->IsWeakCell() && WeakCell::cast(slot_value)->cleared()); | 5065 CHECK(slot_value->IsWeakCell() && WeakCell::cast(slot_value)->cleared()); |
| 4988 CompileRun( | 5066 CompileRun( |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5169 } | 5247 } |
| 5170 | 5248 |
| 5171 | 5249 |
| 5172 Handle<JSFunction> GetFunctionByName(Isolate* isolate, const char* name) { | 5250 Handle<JSFunction> GetFunctionByName(Isolate* isolate, const char* name) { |
| 5173 Handle<String> str = isolate->factory()->InternalizeUtf8String(name); | 5251 Handle<String> str = isolate->factory()->InternalizeUtf8String(name); |
| 5174 Handle<Object> obj = | 5252 Handle<Object> obj = |
| 5175 Object::GetProperty(isolate->global_object(), str).ToHandleChecked(); | 5253 Object::GetProperty(isolate->global_object(), str).ToHandleChecked(); |
| 5176 return Handle<JSFunction>::cast(obj); | 5254 return Handle<JSFunction>::cast(obj); |
| 5177 } | 5255 } |
| 5178 | 5256 |
| 5179 void CheckIC(Handle<JSFunction> function, Code::Kind kind, int slot_index, | 5257 |
| 5180 InlineCacheState state) { | 5258 void CheckIC(Code* code, Code::Kind kind, SharedFunctionInfo* shared, |
| 5259 int slot_index, InlineCacheState state) { |
| 5181 if (kind == Code::LOAD_IC || kind == Code::KEYED_LOAD_IC || | 5260 if (kind == Code::LOAD_IC || kind == Code::KEYED_LOAD_IC || |
| 5182 kind == Code::CALL_IC) { | 5261 kind == Code::CALL_IC) { |
| 5183 TypeFeedbackVector* vector = function->feedback_vector(); | 5262 TypeFeedbackVector* vector = shared->feedback_vector(); |
| 5184 FeedbackVectorSlot slot(slot_index); | 5263 FeedbackVectorSlot slot(slot_index); |
| 5185 if (kind == Code::LOAD_IC) { | 5264 if (kind == Code::LOAD_IC) { |
| 5186 LoadICNexus nexus(vector, slot); | 5265 LoadICNexus nexus(vector, slot); |
| 5187 CHECK_EQ(nexus.StateFromFeedback(), state); | 5266 CHECK_EQ(nexus.StateFromFeedback(), state); |
| 5188 } else if (kind == Code::KEYED_LOAD_IC) { | 5267 } else if (kind == Code::KEYED_LOAD_IC) { |
| 5189 KeyedLoadICNexus nexus(vector, slot); | 5268 KeyedLoadICNexus nexus(vector, slot); |
| 5190 CHECK_EQ(nexus.StateFromFeedback(), state); | 5269 CHECK_EQ(nexus.StateFromFeedback(), state); |
| 5191 } else if (kind == Code::CALL_IC) { | 5270 } else if (kind == Code::CALL_IC) { |
| 5192 CallICNexus nexus(vector, slot); | 5271 CallICNexus nexus(vector, slot); |
| 5193 CHECK_EQ(nexus.StateFromFeedback(), state); | 5272 CHECK_EQ(nexus.StateFromFeedback(), state); |
| 5194 } | 5273 } |
| 5195 } else { | 5274 } else { |
| 5196 Code* ic = FindFirstIC(function->code(), kind); | 5275 Code* ic = FindFirstIC(code, kind); |
| 5197 CHECK(ic->is_inline_cache_stub()); | 5276 CHECK(ic->is_inline_cache_stub()); |
| 5198 CHECK(ic->ic_state() == state); | 5277 CHECK(ic->ic_state() == state); |
| 5199 } | 5278 } |
| 5200 } | 5279 } |
| 5201 | 5280 |
| 5202 | 5281 |
| 5203 TEST(MonomorphicStaysMonomorphicAfterGC) { | 5282 TEST(MonomorphicStaysMonomorphicAfterGC) { |
| 5204 if (FLAG_always_opt) return; | 5283 if (FLAG_always_opt) return; |
| 5205 CcTest::InitializeVM(); | 5284 CcTest::InitializeVM(); |
| 5206 Isolate* isolate = CcTest::i_isolate(); | 5285 Isolate* isolate = CcTest::i_isolate(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 5217 " loadIC(obj);" | 5296 " loadIC(obj);" |
| 5218 " loadIC(obj);" | 5297 " loadIC(obj);" |
| 5219 " return proto;" | 5298 " return proto;" |
| 5220 "};"); | 5299 "};"); |
| 5221 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); | 5300 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); |
| 5222 { | 5301 { |
| 5223 v8::HandleScope scope(CcTest::isolate()); | 5302 v8::HandleScope scope(CcTest::isolate()); |
| 5224 CompileRun("(testIC())"); | 5303 CompileRun("(testIC())"); |
| 5225 } | 5304 } |
| 5226 heap->CollectAllGarbage(); | 5305 heap->CollectAllGarbage(); |
| 5227 CheckIC(loadIC, Code::LOAD_IC, 0, MONOMORPHIC); | 5306 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, MONOMORPHIC); |
| 5228 { | 5307 { |
| 5229 v8::HandleScope scope(CcTest::isolate()); | 5308 v8::HandleScope scope(CcTest::isolate()); |
| 5230 CompileRun("(testIC())"); | 5309 CompileRun("(testIC())"); |
| 5231 } | 5310 } |
| 5232 CheckIC(loadIC, Code::LOAD_IC, 0, MONOMORPHIC); | 5311 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, MONOMORPHIC); |
| 5233 } | 5312 } |
| 5234 | 5313 |
| 5235 | 5314 |
| 5236 TEST(PolymorphicStaysPolymorphicAfterGC) { | 5315 TEST(PolymorphicStaysPolymorphicAfterGC) { |
| 5237 if (FLAG_always_opt) return; | 5316 if (FLAG_always_opt) return; |
| 5238 CcTest::InitializeVM(); | 5317 CcTest::InitializeVM(); |
| 5239 Isolate* isolate = CcTest::i_isolate(); | 5318 Isolate* isolate = CcTest::i_isolate(); |
| 5240 Heap* heap = isolate->heap(); | 5319 Heap* heap = isolate->heap(); |
| 5241 v8::HandleScope scope(CcTest::isolate()); | 5320 v8::HandleScope scope(CcTest::isolate()); |
| 5242 CompileRun( | 5321 CompileRun( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 5253 " poly.x = true;" | 5332 " poly.x = true;" |
| 5254 " loadIC(poly);" | 5333 " loadIC(poly);" |
| 5255 " return proto;" | 5334 " return proto;" |
| 5256 "};"); | 5335 "};"); |
| 5257 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); | 5336 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); |
| 5258 { | 5337 { |
| 5259 v8::HandleScope scope(CcTest::isolate()); | 5338 v8::HandleScope scope(CcTest::isolate()); |
| 5260 CompileRun("(testIC())"); | 5339 CompileRun("(testIC())"); |
| 5261 } | 5340 } |
| 5262 heap->CollectAllGarbage(); | 5341 heap->CollectAllGarbage(); |
| 5263 CheckIC(loadIC, Code::LOAD_IC, 0, POLYMORPHIC); | 5342 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, POLYMORPHIC); |
| 5264 { | 5343 { |
| 5265 v8::HandleScope scope(CcTest::isolate()); | 5344 v8::HandleScope scope(CcTest::isolate()); |
| 5266 CompileRun("(testIC())"); | 5345 CompileRun("(testIC())"); |
| 5267 } | 5346 } |
| 5268 CheckIC(loadIC, Code::LOAD_IC, 0, POLYMORPHIC); | 5347 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, POLYMORPHIC); |
| 5269 } | 5348 } |
| 5270 | 5349 |
| 5271 | 5350 |
| 5272 TEST(WeakCell) { | 5351 TEST(WeakCell) { |
| 5273 CcTest::InitializeVM(); | 5352 CcTest::InitializeVM(); |
| 5274 Isolate* isolate = CcTest::i_isolate(); | 5353 Isolate* isolate = CcTest::i_isolate(); |
| 5275 v8::internal::Heap* heap = CcTest::heap(); | 5354 v8::internal::Heap* heap = CcTest::heap(); |
| 5276 v8::internal::Factory* factory = isolate->factory(); | 5355 v8::internal::Factory* factory = isolate->factory(); |
| 5277 | 5356 |
| 5278 HandleScope outer_scope(isolate); | 5357 HandleScope outer_scope(isolate); |
| (...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6360 isolate->IncrementJsCallsFromApiCounter(); | 6439 isolate->IncrementJsCallsFromApiCounter(); |
| 6361 isolate->IncrementJsCallsFromApiCounter(); | 6440 isolate->IncrementJsCallsFromApiCounter(); |
| 6362 isolate->IncrementJsCallsFromApiCounter(); | 6441 isolate->IncrementJsCallsFromApiCounter(); |
| 6363 calls_per_ms = memory_reducer->SampleAndGetJsCallsPerMs(4); | 6442 calls_per_ms = memory_reducer->SampleAndGetJsCallsPerMs(4); |
| 6364 CheckDoubleEquals(2, calls_per_ms); | 6443 CheckDoubleEquals(2, calls_per_ms); |
| 6365 } | 6444 } |
| 6366 | 6445 |
| 6367 | 6446 |
| 6368 } // namespace internal | 6447 } // namespace internal |
| 6369 } // namespace v8 | 6448 } // namespace v8 |
| OLD | NEW |