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 3891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3902 } | 3902 } |
3903 return NULL; | 3903 return NULL; |
3904 } | 3904 } |
3905 | 3905 |
3906 | 3906 |
3907 static void CheckVectorIC(Handle<JSFunction> f, int ic_slot_index, | 3907 static void CheckVectorIC(Handle<JSFunction> f, int ic_slot_index, |
3908 InlineCacheState desired_state) { | 3908 InlineCacheState desired_state) { |
3909 Handle<TypeFeedbackVector> vector = | 3909 Handle<TypeFeedbackVector> vector = |
3910 Handle<TypeFeedbackVector>(f->shared()->feedback_vector()); | 3910 Handle<TypeFeedbackVector>(f->shared()->feedback_vector()); |
3911 FeedbackVectorICSlot slot(ic_slot_index); | 3911 FeedbackVectorICSlot slot(ic_slot_index); |
3912 LoadICNexus nexus(vector, slot); | 3912 if (vector->GetKind(slot) == Code::LOAD_IC) { |
3913 CHECK(nexus.StateFromFeedback() == desired_state); | 3913 LoadICNexus nexus(vector, slot); |
| 3914 CHECK(nexus.StateFromFeedback() == desired_state); |
| 3915 } else { |
| 3916 CHECK(vector->GetKind(slot) == Code::KEYED_LOAD_IC); |
| 3917 KeyedLoadICNexus nexus(vector, slot); |
| 3918 CHECK(nexus.StateFromFeedback() == desired_state); |
| 3919 } |
3914 } | 3920 } |
3915 | 3921 |
3916 | 3922 |
3917 static void CheckVectorICCleared(Handle<JSFunction> f, int ic_slot_index) { | 3923 static void CheckVectorICCleared(Handle<JSFunction> f, int ic_slot_index) { |
3918 Handle<TypeFeedbackVector> vector = | 3924 Handle<TypeFeedbackVector> vector = |
3919 Handle<TypeFeedbackVector>(f->shared()->feedback_vector()); | 3925 Handle<TypeFeedbackVector>(f->shared()->feedback_vector()); |
3920 FeedbackVectorICSlot slot(ic_slot_index); | 3926 FeedbackVectorICSlot slot(ic_slot_index); |
3921 LoadICNexus nexus(vector, slot); | 3927 LoadICNexus nexus(vector, slot); |
3922 CHECK(IC::IsCleared(&nexus)); | 3928 CHECK(IC::IsCleared(&nexus)); |
3923 } | 3929 } |
3924 | 3930 |
3925 | 3931 |
| 3932 TEST(ICInBuiltInIsClearedAppropriately) { |
| 3933 if (i::FLAG_always_opt) return; |
| 3934 CcTest::InitializeVM(); |
| 3935 v8::HandleScope scope(CcTest::isolate()); |
| 3936 |
| 3937 Handle<JSFunction> apply; |
| 3938 { |
| 3939 LocalContext env; |
| 3940 v8::Local<v8::Value> res = CompileRun("Function.apply"); |
| 3941 Handle<JSObject> maybe_apply = |
| 3942 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
| 3943 apply = Handle<JSFunction>::cast(maybe_apply); |
| 3944 TypeFeedbackVector* vector = apply->shared()->feedback_vector(); |
| 3945 CHECK(vector->ICSlots() == 1); |
| 3946 CheckVectorIC(apply, 0, UNINITIALIZED); |
| 3947 CompileRun( |
| 3948 "function b(a1, a2, a3) { return a1 + a2 + a3; }" |
| 3949 "function fun(bar) { bar.apply({}, [1, 2, 3]); };" |
| 3950 "fun(b); fun(b)"); |
| 3951 CheckVectorIC(apply, 0, MONOMORPHIC); |
| 3952 } |
| 3953 |
| 3954 // Fire context dispose notification. |
| 3955 CcTest::isolate()->ContextDisposedNotification(); |
| 3956 SimulateIncrementalMarking(CcTest::heap()); |
| 3957 CcTest::heap()->CollectAllGarbage(); |
| 3958 |
| 3959 // The IC in apply has been cleared, ready to learn again. |
| 3960 CheckVectorIC(apply, 0, PREMONOMORPHIC); |
| 3961 } |
| 3962 |
| 3963 |
3926 TEST(IncrementalMarkingPreservesMonomorphicConstructor) { | 3964 TEST(IncrementalMarkingPreservesMonomorphicConstructor) { |
3927 if (i::FLAG_always_opt) return; | 3965 if (i::FLAG_always_opt) return; |
3928 CcTest::InitializeVM(); | 3966 CcTest::InitializeVM(); |
3929 v8::HandleScope scope(CcTest::isolate()); | 3967 v8::HandleScope scope(CcTest::isolate()); |
3930 | 3968 |
3931 // Prepare function f that contains a monomorphic IC for object | 3969 // Prepare function f that contains a monomorphic IC for object |
3932 // originating from the same native context. | 3970 // originating from the same native context. |
3933 CompileRun( | 3971 CompileRun( |
3934 "function fun() { this.x = 1; };" | 3972 "function fun() { this.x = 1; };" |
3935 "function f(o) { return new o(); } f(fun); f(fun);"); | 3973 "function f(o) { return new o(); } f(fun); f(fun);"); |
(...skipping 2702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6638 heap->CollectAllGarbage(); | 6676 heap->CollectAllGarbage(); |
6639 | 6677 |
6640 int sfi_count = 0; | 6678 int sfi_count = 0; |
6641 { | 6679 { |
6642 HeapIterator it(heap); | 6680 HeapIterator it(heap); |
6643 for (HeapObject* obj = it.next(); obj != NULL; obj = it.next()) { | 6681 for (HeapObject* obj = it.next(); obj != NULL; obj = it.next()) { |
6644 if (!obj->IsSharedFunctionInfo()) continue; | 6682 if (!obj->IsSharedFunctionInfo()) continue; |
6645 // Shared function infos without a script (API functions or C++ builtins) | 6683 // Shared function infos without a script (API functions or C++ builtins) |
6646 // are not returned by the iterator because they are not created from a | 6684 // are not returned by the iterator because they are not created from a |
6647 // script. They are not interesting for type feedback vector anyways. | 6685 // script. They are not interesting for type feedback vector anyways. |
| 6686 |
| 6687 // TODO(mvstanton): There are builtins that use type feedback vectors, |
| 6688 // consider adding these to the iterator. |
6648 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); | 6689 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); |
6649 if (shared->script()->IsUndefined()) { | 6690 if (shared->script()->IsUndefined()) { |
6650 CHECK_EQ(0, shared->feedback_vector()->ICSlots()); | 6691 CHECK(shared->native() || 0 == shared->feedback_vector()->ICSlots()); |
6651 } else { | 6692 } else { |
6652 sfi_count++; | 6693 sfi_count++; |
6653 } | 6694 } |
6654 } | 6695 } |
6655 } | 6696 } |
6656 | 6697 |
6657 { | 6698 { |
6658 SharedFunctionInfo::Iterator iterator(isolate); | 6699 SharedFunctionInfo::Iterator iterator(isolate); |
6659 while (iterator.Next()) sfi_count--; | 6700 while (iterator.Next()) sfi_count--; |
6660 } | 6701 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6692 // The CollectGarbage call above starts sweeper threads. | 6733 // The CollectGarbage call above starts sweeper threads. |
6693 // The crash will happen if the following two functions | 6734 // The crash will happen if the following two functions |
6694 // are called before sweeping finishes. | 6735 // are called before sweeping finishes. |
6695 heap->StartIncrementalMarking(); | 6736 heap->StartIncrementalMarking(); |
6696 heap->FinalizeIncrementalMarkingIfComplete("test"); | 6737 heap->FinalizeIncrementalMarkingIfComplete("test"); |
6697 } | 6738 } |
6698 | 6739 |
6699 | 6740 |
6700 } // namespace internal | 6741 } // namespace internal |
6701 } // namespace v8 | 6742 } // namespace v8 |
OLD | NEW |