Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: test/cctest/heap/test-heap.cc

Issue 1906823002: Move of the type feedback vector to the closure. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: REBASE. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/compiler/test-run-jscalls.cc ('k') | test/cctest/interpreter/interpreter-tester.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 3623 matching lines...) Expand 10 before | Expand all | Expand 10 after
3634 3634
3635 // Prepare function f that contains type feedback for the two closures. 3635 // Prepare function f that contains type feedback for the two closures.
3636 CHECK(CcTest::global()->Set(ctx, v8_str("fun1"), fun1).FromJust()); 3636 CHECK(CcTest::global()->Set(ctx, v8_str("fun1"), fun1).FromJust());
3637 CHECK(CcTest::global()->Set(ctx, v8_str("fun2"), fun2).FromJust()); 3637 CHECK(CcTest::global()->Set(ctx, v8_str("fun2"), fun2).FromJust());
3638 CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);"); 3638 CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);");
3639 3639
3640 Handle<JSFunction> f = Handle<JSFunction>::cast( 3640 Handle<JSFunction> f = Handle<JSFunction>::cast(
3641 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( 3641 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
3642 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked()))); 3642 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked())));
3643 3643
3644 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); 3644 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector());
3645 FeedbackVectorHelper feedback_helper(feedback_vector); 3645 FeedbackVectorHelper feedback_helper(feedback_vector);
3646 3646
3647 int expected_slots = 2; 3647 int expected_slots = 2;
3648 CHECK_EQ(expected_slots, feedback_helper.slot_count()); 3648 CHECK_EQ(expected_slots, feedback_helper.slot_count());
3649 int slot1 = 0; 3649 int slot1 = 0;
3650 int slot2 = 1; 3650 int slot2 = 1;
3651 CHECK(feedback_vector->Get(feedback_helper.slot(slot1))->IsWeakCell()); 3651 CHECK(feedback_vector->Get(feedback_helper.slot(slot1))->IsWeakCell());
3652 CHECK(feedback_vector->Get(feedback_helper.slot(slot2))->IsWeakCell()); 3652 CHECK(feedback_vector->Get(feedback_helper.slot(slot2))->IsWeakCell());
3653 3653
3654 heap::SimulateIncrementalMarking(CcTest::heap()); 3654 heap::SimulateIncrementalMarking(CcTest::heap());
(...skipping 16 matching lines...) Expand all
3671 return target; 3671 return target;
3672 } 3672 }
3673 } 3673 }
3674 return NULL; 3674 return NULL;
3675 } 3675 }
3676 3676
3677 3677
3678 static void CheckVectorIC(Handle<JSFunction> f, int slot_index, 3678 static void CheckVectorIC(Handle<JSFunction> f, int slot_index,
3679 InlineCacheState desired_state) { 3679 InlineCacheState desired_state) {
3680 Handle<TypeFeedbackVector> vector = 3680 Handle<TypeFeedbackVector> vector =
3681 Handle<TypeFeedbackVector>(f->shared()->feedback_vector()); 3681 Handle<TypeFeedbackVector>(f->feedback_vector());
3682 FeedbackVectorHelper helper(vector); 3682 FeedbackVectorHelper helper(vector);
3683 FeedbackVectorSlot slot = helper.slot(slot_index); 3683 FeedbackVectorSlot slot = helper.slot(slot_index);
3684 if (vector->GetKind(slot) == FeedbackVectorSlotKind::LOAD_IC) { 3684 if (vector->GetKind(slot) == FeedbackVectorSlotKind::LOAD_IC) {
3685 LoadICNexus nexus(vector, slot); 3685 LoadICNexus nexus(vector, slot);
3686 CHECK(nexus.StateFromFeedback() == desired_state); 3686 CHECK(nexus.StateFromFeedback() == desired_state);
3687 } else { 3687 } else {
3688 CHECK_EQ(FeedbackVectorSlotKind::KEYED_LOAD_IC, vector->GetKind(slot)); 3688 CHECK_EQ(FeedbackVectorSlotKind::KEYED_LOAD_IC, vector->GetKind(slot));
3689 KeyedLoadICNexus nexus(vector, slot); 3689 KeyedLoadICNexus nexus(vector, slot);
3690 CHECK(nexus.StateFromFeedback() == desired_state); 3690 CHECK(nexus.StateFromFeedback() == desired_state);
3691 } 3691 }
3692 } 3692 }
3693 3693
3694
3695 static void CheckVectorICCleared(Handle<JSFunction> f, int slot_index) {
3696 Handle<TypeFeedbackVector> vector =
3697 Handle<TypeFeedbackVector>(f->shared()->feedback_vector());
3698 FeedbackVectorSlot slot(slot_index);
3699 LoadICNexus nexus(vector, slot);
3700 CHECK(IC::IsCleared(&nexus));
3701 }
3702
3703
3704 TEST(IncrementalMarkingPreservesMonomorphicConstructor) { 3694 TEST(IncrementalMarkingPreservesMonomorphicConstructor) {
3705 if (i::FLAG_always_opt) return; 3695 if (i::FLAG_always_opt) return;
3706 CcTest::InitializeVM(); 3696 CcTest::InitializeVM();
3707 v8::HandleScope scope(CcTest::isolate()); 3697 v8::HandleScope scope(CcTest::isolate());
3708 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext(); 3698 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
3709 // Prepare function f that contains a monomorphic IC for object 3699 // Prepare function f that contains a monomorphic IC for object
3710 // originating from the same native context. 3700 // originating from the same native context.
3711 CompileRun( 3701 CompileRun(
3712 "function fun() { this.x = 1; };" 3702 "function fun() { this.x = 1; };"
3713 "function f(o) { return new o(); } f(fun); f(fun);"); 3703 "function f(o) { return new o(); } f(fun); f(fun);");
3714 Handle<JSFunction> f = Handle<JSFunction>::cast( 3704 Handle<JSFunction> f = Handle<JSFunction>::cast(
3715 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( 3705 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
3716 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked()))); 3706 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked())));
3717 3707
3718 Handle<TypeFeedbackVector> vector(f->shared()->feedback_vector()); 3708 Handle<TypeFeedbackVector> vector(f->feedback_vector());
3719 CHECK(vector->Get(FeedbackVectorSlot(0))->IsWeakCell()); 3709 CHECK(vector->Get(FeedbackVectorSlot(0))->IsWeakCell());
3720 3710
3721 heap::SimulateIncrementalMarking(CcTest::heap()); 3711 heap::SimulateIncrementalMarking(CcTest::heap());
3722 CcTest::heap()->CollectAllGarbage(); 3712 CcTest::heap()->CollectAllGarbage();
3723 3713
3724 CHECK(vector->Get(FeedbackVectorSlot(0))->IsWeakCell()); 3714 CHECK(vector->Get(FeedbackVectorSlot(0))->IsWeakCell());
3725 } 3715 }
3726 3716
3727
3728 TEST(IncrementalMarkingClearsMonomorphicConstructor) {
3729 if (i::FLAG_always_opt) return;
3730 CcTest::InitializeVM();
3731 Isolate* isolate = CcTest::i_isolate();
3732 v8::HandleScope scope(CcTest::isolate());
3733 v8::Local<v8::Value> fun1;
3734 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
3735
3736 {
3737 LocalContext env;
3738 CompileRun("function fun() { this.x = 1; };");
3739 fun1 = env->Global()->Get(env.local(), v8_str("fun")).ToLocalChecked();
3740 }
3741
3742 // Prepare function f that contains a monomorphic constructor for object
3743 // originating from a different native context.
3744 CHECK(CcTest::global()->Set(ctx, v8_str("fun1"), fun1).FromJust());
3745 CompileRun(
3746 "function fun() { this.x = 1; };"
3747 "function f(o) { return new o(); } f(fun1); f(fun1);");
3748 Handle<JSFunction> f = Handle<JSFunction>::cast(
3749 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
3750 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked())));
3751
3752
3753 Handle<TypeFeedbackVector> vector(f->shared()->feedback_vector());
3754 CHECK(vector->Get(FeedbackVectorSlot(0))->IsWeakCell());
3755
3756 // Fire context dispose notification.
3757 CcTest::isolate()->ContextDisposedNotification();
3758 heap::SimulateIncrementalMarking(CcTest::heap());
3759 CcTest::heap()->CollectAllGarbage();
3760
3761 CHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(isolate),
3762 vector->Get(FeedbackVectorSlot(0)));
3763 }
3764
3765
3766 TEST(IncrementalMarkingPreservesMonomorphicIC) { 3717 TEST(IncrementalMarkingPreservesMonomorphicIC) {
3767 if (i::FLAG_always_opt) return; 3718 if (i::FLAG_always_opt) return;
3768 CcTest::InitializeVM(); 3719 CcTest::InitializeVM();
3769 v8::HandleScope scope(CcTest::isolate()); 3720 v8::HandleScope scope(CcTest::isolate());
3770 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext(); 3721 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
3771 // Prepare function f that contains a monomorphic IC for object 3722 // Prepare function f that contains a monomorphic IC for object
3772 // originating from the same native context. 3723 // originating from the same native context.
3773 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" 3724 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"
3774 "function f(o) { return o.x; } f(obj); f(obj);"); 3725 "function f(o) { return o.x; } f(obj); f(obj);");
3775 Handle<JSFunction> f = Handle<JSFunction>::cast( 3726 Handle<JSFunction> f = Handle<JSFunction>::cast(
3776 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( 3727 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
3777 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked()))); 3728 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked())));
3778 3729
3779 CheckVectorIC(f, 0, MONOMORPHIC); 3730 CheckVectorIC(f, 0, MONOMORPHIC);
3780 3731
3781 heap::SimulateIncrementalMarking(CcTest::heap()); 3732 heap::SimulateIncrementalMarking(CcTest::heap());
3782 CcTest::heap()->CollectAllGarbage(); 3733 CcTest::heap()->CollectAllGarbage();
3783 3734
3784 CheckVectorIC(f, 0, MONOMORPHIC); 3735 CheckVectorIC(f, 0, MONOMORPHIC);
3785 } 3736 }
3786 3737
3787
3788 TEST(IncrementalMarkingClearsMonomorphicIC) {
3789 if (i::FLAG_always_opt) return;
3790 CcTest::InitializeVM();
3791 v8::HandleScope scope(CcTest::isolate());
3792 v8::Local<v8::Value> obj1;
3793 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
3794
3795 {
3796 LocalContext env;
3797 CompileRun("function fun() { this.x = 1; }; var obj = new fun();");
3798 obj1 = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
3799 }
3800
3801 // Prepare function f that contains a monomorphic IC for object
3802 // originating from a different native context.
3803 CHECK(CcTest::global()->Set(ctx, v8_str("obj1"), obj1).FromJust());
3804 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1);");
3805 Handle<JSFunction> f = Handle<JSFunction>::cast(
3806 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
3807 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked())));
3808
3809 CheckVectorIC(f, 0, MONOMORPHIC);
3810
3811 // Fire context dispose notification.
3812 CcTest::isolate()->ContextDisposedNotification();
3813 heap::SimulateIncrementalMarking(CcTest::heap());
3814 CcTest::heap()->CollectAllGarbage();
3815
3816 CheckVectorICCleared(f, 0);
3817 }
3818
3819
3820 TEST(IncrementalMarkingPreservesPolymorphicIC) { 3738 TEST(IncrementalMarkingPreservesPolymorphicIC) {
3821 if (i::FLAG_always_opt) return; 3739 if (i::FLAG_always_opt) return;
3822 CcTest::InitializeVM(); 3740 CcTest::InitializeVM();
3823 v8::HandleScope scope(CcTest::isolate()); 3741 v8::HandleScope scope(CcTest::isolate());
3824 v8::Local<v8::Value> obj1, obj2; 3742 v8::Local<v8::Value> obj1, obj2;
3825 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext(); 3743 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
3826 3744
3827 { 3745 {
3828 LocalContext env; 3746 LocalContext env;
3829 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); 3747 CompileRun("function fun() { this.x = 1; }; var obj = new fun();");
(...skipping 17 matching lines...) Expand all
3847 3765
3848 CheckVectorIC(f, 0, POLYMORPHIC); 3766 CheckVectorIC(f, 0, POLYMORPHIC);
3849 3767
3850 // Fire context dispose notification. 3768 // Fire context dispose notification.
3851 heap::SimulateIncrementalMarking(CcTest::heap()); 3769 heap::SimulateIncrementalMarking(CcTest::heap());
3852 CcTest::heap()->CollectAllGarbage(); 3770 CcTest::heap()->CollectAllGarbage();
3853 3771
3854 CheckVectorIC(f, 0, POLYMORPHIC); 3772 CheckVectorIC(f, 0, POLYMORPHIC);
3855 } 3773 }
3856 3774
3857 3775 TEST(ContextDisposeDoesntClearPolymorphicIC) {
3858 TEST(IncrementalMarkingClearsPolymorphicIC) {
3859 if (i::FLAG_always_opt) return; 3776 if (i::FLAG_always_opt) return;
3860 CcTest::InitializeVM(); 3777 CcTest::InitializeVM();
3861 v8::HandleScope scope(CcTest::isolate()); 3778 v8::HandleScope scope(CcTest::isolate());
3862 v8::Local<v8::Value> obj1, obj2; 3779 v8::Local<v8::Value> obj1, obj2;
3863 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext(); 3780 v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
3864 3781
3865 { 3782 {
3866 LocalContext env; 3783 LocalContext env;
3867 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); 3784 CompileRun("function fun() { this.x = 1; }; var obj = new fun();");
3868 obj1 = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); 3785 obj1 = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
(...skipping 14 matching lines...) Expand all
3883 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( 3800 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
3884 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked()))); 3801 CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked())));
3885 3802
3886 CheckVectorIC(f, 0, POLYMORPHIC); 3803 CheckVectorIC(f, 0, POLYMORPHIC);
3887 3804
3888 // Fire context dispose notification. 3805 // Fire context dispose notification.
3889 CcTest::isolate()->ContextDisposedNotification(); 3806 CcTest::isolate()->ContextDisposedNotification();
3890 heap::SimulateIncrementalMarking(CcTest::heap()); 3807 heap::SimulateIncrementalMarking(CcTest::heap());
3891 CcTest::heap()->CollectAllGarbage(); 3808 CcTest::heap()->CollectAllGarbage();
3892 3809
3893 CheckVectorICCleared(f, 0); 3810 CheckVectorIC(f, 0, POLYMORPHIC);
3894 } 3811 }
3895 3812
3896 3813
3897 class SourceResource : public v8::String::ExternalOneByteStringResource { 3814 class SourceResource : public v8::String::ExternalOneByteStringResource {
3898 public: 3815 public:
3899 explicit SourceResource(const char* data) 3816 explicit SourceResource(const char* data)
3900 : data_(data), length_(strlen(data)) { } 3817 : data_(data), length_(strlen(data)) { }
3901 3818
3902 virtual void Dispose() { 3819 virtual void Dispose() {
3903 i::DeleteArray(data_); 3820 i::DeleteArray(data_);
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
4297 CompileRun("function g() { return 2 }" 4214 CompileRun("function g() { return 2 }"
4298 "g(); %OptimizeFunctionOnNextCall(g); g();"); 4215 "g(); %OptimizeFunctionOnNextCall(g); g();");
4299 4216
4300 Handle<JSFunction> g = Handle<JSFunction>::cast( 4217 Handle<JSFunction> g = Handle<JSFunction>::cast(
4301 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( 4218 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
4302 CcTest::global()->Get(env.local(), v8_str("g")).ToLocalChecked()))); 4219 CcTest::global()->Get(env.local(), v8_str("g")).ToLocalChecked())));
4303 code = inner_scope.CloseAndEscape(handle(g->code(), isolate)); 4220 code = inner_scope.CloseAndEscape(handle(g->code(), isolate));
4304 if (!code->is_optimized_code()) return; 4221 if (!code->is_optimized_code()) return;
4305 } 4222 }
4306 4223
4307 Handle<TypeFeedbackVector> vector = handle(shared->feedback_vector()); 4224 Handle<TypeFeedbackVector> vector =
4225 TypeFeedbackVector::New(isolate, handle(shared->feedback_metadata()));
4308 Handle<LiteralsArray> lit = 4226 Handle<LiteralsArray> lit =
4309 LiteralsArray::New(isolate, vector, shared->num_literals(), TENURED); 4227 LiteralsArray::New(isolate, vector, shared->num_literals(), TENURED);
4310 Handle<Context> context(isolate->context()); 4228 Handle<Context> context(isolate->context());
4311 4229
4312 // Add the new code several times to the optimized code map and also set an 4230 // Add the new code several times to the optimized code map and also set an
4313 // allocation timeout so that expanding the code map will trigger a GC. 4231 // allocation timeout so that expanding the code map will trigger a GC.
4314 heap->set_allocation_timeout(5); 4232 heap->set_allocation_timeout(5);
4315 FLAG_gc_interval = 1000; 4233 FLAG_gc_interval = 1000;
4316 for (int i = 0; i < 10; ++i) { 4234 for (int i = 0; i < 10; ++i) {
4317 BailoutId id = BailoutId(i); 4235 BailoutId id = BailoutId(i);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
4354 CompileRun("function g() { return 2 }" 4272 CompileRun("function g() { return 2 }"
4355 "g(); %OptimizeFunctionOnNextCall(g); g();"); 4273 "g(); %OptimizeFunctionOnNextCall(g); g();");
4356 4274
4357 Handle<JSFunction> g = Handle<JSFunction>::cast( 4275 Handle<JSFunction> g = Handle<JSFunction>::cast(
4358 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( 4276 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
4359 CcTest::global()->Get(env.local(), v8_str("g")).ToLocalChecked()))); 4277 CcTest::global()->Get(env.local(), v8_str("g")).ToLocalChecked())));
4360 code = inner_scope.CloseAndEscape(handle(g->code(), isolate)); 4278 code = inner_scope.CloseAndEscape(handle(g->code(), isolate));
4361 if (!code->is_optimized_code()) return; 4279 if (!code->is_optimized_code()) return;
4362 } 4280 }
4363 4281
4364 Handle<TypeFeedbackVector> vector = handle(shared->feedback_vector()); 4282 Handle<TypeFeedbackVector> vector =
4283 TypeFeedbackVector::New(isolate, handle(shared->feedback_metadata()));
4365 Handle<LiteralsArray> lit = 4284 Handle<LiteralsArray> lit =
4366 LiteralsArray::New(isolate, vector, shared->num_literals(), TENURED); 4285 LiteralsArray::New(isolate, vector, shared->num_literals(), TENURED);
4367 Handle<Context> context(isolate->context()); 4286 Handle<Context> context(isolate->context());
4368 4287
4369 // Add the code several times to the optimized code map. 4288 // Add the code several times to the optimized code map.
4370 for (int i = 0; i < 3; ++i) { 4289 for (int i = 0; i < 3; ++i) {
4371 HandleScope inner_scope(isolate); 4290 HandleScope inner_scope(isolate);
4372 BailoutId id = BailoutId(i); 4291 BailoutId id = BailoutId(i);
4373 SharedFunctionInfo::AddToOptimizedCodeMap(shared, context, code, lit, id); 4292 SharedFunctionInfo::AddToOptimizedCodeMap(shared, context, code, lit, id);
4374 } 4293 }
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
5059 weak_ic_cleared = false; 4978 weak_ic_cleared = false;
5060 garbage.SetWeak(&garbage, &ClearWeakIC, v8::WeakCallbackType::kParameter); 4979 garbage.SetWeak(&garbage, &ClearWeakIC, v8::WeakCallbackType::kParameter);
5061 Heap* heap = CcTest::i_isolate()->heap(); 4980 Heap* heap = CcTest::i_isolate()->heap();
5062 heap->CollectAllGarbage(); 4981 heap->CollectAllGarbage();
5063 CHECK(weak_ic_cleared); 4982 CHECK(weak_ic_cleared);
5064 4983
5065 // We've determined the constructor in createObj has had it's weak cell 4984 // We've determined the constructor in createObj has had it's weak cell
5066 // cleared. Now, verify that one additional call with a new function 4985 // cleared. Now, verify that one additional call with a new function
5067 // allows monomorphicity. 4986 // allows monomorphicity.
5068 Handle<TypeFeedbackVector> feedback_vector = Handle<TypeFeedbackVector>( 4987 Handle<TypeFeedbackVector> feedback_vector = Handle<TypeFeedbackVector>(
5069 createObj->shared()->feedback_vector(), CcTest::i_isolate()); 4988 createObj->feedback_vector(), CcTest::i_isolate());
5070 for (int i = 0; i < 20; i++) { 4989 for (int i = 0; i < 20; i++) {
5071 Object* slot_value = feedback_vector->Get(FeedbackVectorSlot(0)); 4990 Object* slot_value = feedback_vector->Get(FeedbackVectorSlot(0));
5072 CHECK(slot_value->IsWeakCell()); 4991 CHECK(slot_value->IsWeakCell());
5073 if (WeakCell::cast(slot_value)->cleared()) break; 4992 if (WeakCell::cast(slot_value)->cleared()) break;
5074 heap->CollectAllGarbage(); 4993 heap->CollectAllGarbage();
5075 } 4994 }
5076 4995
5077 Object* slot_value = feedback_vector->Get(FeedbackVectorSlot(0)); 4996 Object* slot_value = feedback_vector->Get(FeedbackVectorSlot(0));
5078 CHECK(slot_value->IsWeakCell() && WeakCell::cast(slot_value)->cleared()); 4997 CHECK(slot_value->IsWeakCell() && WeakCell::cast(slot_value)->cleared());
5079 CompileRun( 4998 CompileRun(
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
5260 } 5179 }
5261 5180
5262 5181
5263 Handle<JSFunction> GetFunctionByName(Isolate* isolate, const char* name) { 5182 Handle<JSFunction> GetFunctionByName(Isolate* isolate, const char* name) {
5264 Handle<String> str = isolate->factory()->InternalizeUtf8String(name); 5183 Handle<String> str = isolate->factory()->InternalizeUtf8String(name);
5265 Handle<Object> obj = 5184 Handle<Object> obj =
5266 Object::GetProperty(isolate->global_object(), str).ToHandleChecked(); 5185 Object::GetProperty(isolate->global_object(), str).ToHandleChecked();
5267 return Handle<JSFunction>::cast(obj); 5186 return Handle<JSFunction>::cast(obj);
5268 } 5187 }
5269 5188
5270 5189 void CheckIC(Handle<JSFunction> function, Code::Kind kind, int slot_index,
5271 void CheckIC(Code* code, Code::Kind kind, SharedFunctionInfo* shared, 5190 InlineCacheState state) {
5272 int slot_index, InlineCacheState state) {
5273 if (kind == Code::LOAD_IC || kind == Code::KEYED_LOAD_IC || 5191 if (kind == Code::LOAD_IC || kind == Code::KEYED_LOAD_IC ||
5274 kind == Code::CALL_IC) { 5192 kind == Code::CALL_IC) {
5275 TypeFeedbackVector* vector = shared->feedback_vector(); 5193 TypeFeedbackVector* vector = function->feedback_vector();
5276 FeedbackVectorSlot slot(slot_index); 5194 FeedbackVectorSlot slot(slot_index);
5277 if (kind == Code::LOAD_IC) { 5195 if (kind == Code::LOAD_IC) {
5278 LoadICNexus nexus(vector, slot); 5196 LoadICNexus nexus(vector, slot);
5279 CHECK_EQ(nexus.StateFromFeedback(), state); 5197 CHECK_EQ(nexus.StateFromFeedback(), state);
5280 } else if (kind == Code::KEYED_LOAD_IC) { 5198 } else if (kind == Code::KEYED_LOAD_IC) {
5281 KeyedLoadICNexus nexus(vector, slot); 5199 KeyedLoadICNexus nexus(vector, slot);
5282 CHECK_EQ(nexus.StateFromFeedback(), state); 5200 CHECK_EQ(nexus.StateFromFeedback(), state);
5283 } else if (kind == Code::CALL_IC) { 5201 } else if (kind == Code::CALL_IC) {
5284 CallICNexus nexus(vector, slot); 5202 CallICNexus nexus(vector, slot);
5285 CHECK_EQ(nexus.StateFromFeedback(), state); 5203 CHECK_EQ(nexus.StateFromFeedback(), state);
5286 } 5204 }
5287 } else { 5205 } else {
5288 Code* ic = FindFirstIC(code, kind); 5206 Code* ic = FindFirstIC(function->code(), kind);
5289 CHECK(ic->is_inline_cache_stub()); 5207 CHECK(ic->is_inline_cache_stub());
5290 CHECK(ic->ic_state() == state); 5208 CHECK(ic->ic_state() == state);
5291 } 5209 }
5292 } 5210 }
5293 5211
5294 5212
5295 TEST(MonomorphicStaysMonomorphicAfterGC) { 5213 TEST(MonomorphicStaysMonomorphicAfterGC) {
5296 if (FLAG_always_opt) return; 5214 if (FLAG_always_opt) return;
5297 CcTest::InitializeVM(); 5215 CcTest::InitializeVM();
5298 Isolate* isolate = CcTest::i_isolate(); 5216 Isolate* isolate = CcTest::i_isolate();
(...skipping 10 matching lines...) Expand all
5309 " loadIC(obj);" 5227 " loadIC(obj);"
5310 " loadIC(obj);" 5228 " loadIC(obj);"
5311 " return proto;" 5229 " return proto;"
5312 "};"); 5230 "};");
5313 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); 5231 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC");
5314 { 5232 {
5315 v8::HandleScope scope(CcTest::isolate()); 5233 v8::HandleScope scope(CcTest::isolate());
5316 CompileRun("(testIC())"); 5234 CompileRun("(testIC())");
5317 } 5235 }
5318 heap->CollectAllGarbage(); 5236 heap->CollectAllGarbage();
5319 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, MONOMORPHIC); 5237 CheckIC(loadIC, Code::LOAD_IC, 0, MONOMORPHIC);
5320 { 5238 {
5321 v8::HandleScope scope(CcTest::isolate()); 5239 v8::HandleScope scope(CcTest::isolate());
5322 CompileRun("(testIC())"); 5240 CompileRun("(testIC())");
5323 } 5241 }
5324 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, MONOMORPHIC); 5242 CheckIC(loadIC, Code::LOAD_IC, 0, MONOMORPHIC);
5325 } 5243 }
5326 5244
5327 5245
5328 TEST(PolymorphicStaysPolymorphicAfterGC) { 5246 TEST(PolymorphicStaysPolymorphicAfterGC) {
5329 if (FLAG_always_opt) return; 5247 if (FLAG_always_opt) return;
5330 CcTest::InitializeVM(); 5248 CcTest::InitializeVM();
5331 Isolate* isolate = CcTest::i_isolate(); 5249 Isolate* isolate = CcTest::i_isolate();
5332 Heap* heap = isolate->heap(); 5250 Heap* heap = isolate->heap();
5333 v8::HandleScope scope(CcTest::isolate()); 5251 v8::HandleScope scope(CcTest::isolate());
5334 CompileRun( 5252 CompileRun(
(...skipping 10 matching lines...) Expand all
5345 " poly.x = true;" 5263 " poly.x = true;"
5346 " loadIC(poly);" 5264 " loadIC(poly);"
5347 " return proto;" 5265 " return proto;"
5348 "};"); 5266 "};");
5349 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); 5267 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC");
5350 { 5268 {
5351 v8::HandleScope scope(CcTest::isolate()); 5269 v8::HandleScope scope(CcTest::isolate());
5352 CompileRun("(testIC())"); 5270 CompileRun("(testIC())");
5353 } 5271 }
5354 heap->CollectAllGarbage(); 5272 heap->CollectAllGarbage();
5355 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, POLYMORPHIC); 5273 CheckIC(loadIC, Code::LOAD_IC, 0, POLYMORPHIC);
5356 { 5274 {
5357 v8::HandleScope scope(CcTest::isolate()); 5275 v8::HandleScope scope(CcTest::isolate());
5358 CompileRun("(testIC())"); 5276 CompileRun("(testIC())");
5359 } 5277 }
5360 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, POLYMORPHIC); 5278 CheckIC(loadIC, Code::LOAD_IC, 0, POLYMORPHIC);
5361 } 5279 }
5362 5280
5363 5281
5364 TEST(WeakCell) { 5282 TEST(WeakCell) {
5365 CcTest::InitializeVM(); 5283 CcTest::InitializeVM();
5366 Isolate* isolate = CcTest::i_isolate(); 5284 Isolate* isolate = CcTest::i_isolate();
5367 v8::internal::Heap* heap = CcTest::heap(); 5285 v8::internal::Heap* heap = CcTest::heap();
5368 v8::internal::Factory* factory = isolate->factory(); 5286 v8::internal::Factory* factory = isolate->factory();
5369 5287
5370 HandleScope outer_scope(isolate); 5288 HandleScope outer_scope(isolate);
(...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after
6761 6679
6762 intptr_t size_before = heap->SizeOfObjects(); 6680 intptr_t size_before = heap->SizeOfObjects();
6763 Handle<FixedArray> array = isolate->factory()->NewFixedArray(200000); 6681 Handle<FixedArray> array = isolate->factory()->NewFixedArray(200000);
6764 array->Shrink(1); 6682 array->Shrink(1);
6765 intptr_t size_after = heap->SizeOfObjects(); 6683 intptr_t size_after = heap->SizeOfObjects();
6766 CHECK_EQ(size_after, size_before + array->Size()); 6684 CHECK_EQ(size_after, size_before + array->Size());
6767 } 6685 }
6768 6686
6769 } // namespace internal 6687 } // namespace internal
6770 } // namespace v8 6688 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-run-jscalls.cc ('k') | test/cctest/interpreter/interpreter-tester.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698