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