OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 #include "test/cctest/cctest.h" | 6 #include "test/cctest/cctest.h" |
7 | 7 |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/debug.h" | 9 #include "src/debug.h" |
10 #include "src/execution.h" | 10 #include "src/execution.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 Factory* factory = isolate->factory(); | 79 Factory* factory = isolate->factory(); |
80 | 80 |
81 Handle<TypeFeedbackVector> vector = | 81 Handle<TypeFeedbackVector> vector = |
82 factory->NewTypeFeedbackVector(10, 3 * 10); | 82 factory->NewTypeFeedbackVector(10, 3 * 10); |
83 CHECK_EQ(10, vector->Slots()); | 83 CHECK_EQ(10, vector->Slots()); |
84 CHECK_EQ(3 * 10, vector->ICSlots()); | 84 CHECK_EQ(3 * 10, vector->ICSlots()); |
85 | 85 |
86 // Set metadata. | 86 // Set metadata. |
87 for (int i = 0; i < 30; i++) { | 87 for (int i = 0; i < 30; i++) { |
88 Code::Kind kind; | 88 Code::Kind kind; |
89 if (i % 3 == 0) { | 89 if (i % 3 == 0) |
90 kind = Code::CALL_IC; | 90 kind = Code::CALL_IC; |
91 } else if (i % 3 == 1) { | 91 else if (i % 3 == 1) |
92 kind = Code::LOAD_IC; | 92 kind = Code::LOAD_IC; |
93 } else { | 93 else |
94 kind = Code::KEYED_LOAD_IC; | 94 kind = Code::KEYED_LOAD_IC; |
95 } | |
96 vector->SetKind(FeedbackVectorICSlot(i), kind); | 95 vector->SetKind(FeedbackVectorICSlot(i), kind); |
97 } | 96 } |
98 | 97 |
99 // Meanwhile set some feedback values and type feedback values to | 98 // Meanwhile set some feedback values and type feedback values to |
100 // verify the data structure remains intact. | 99 // verify the data structure remains intact. |
101 vector->change_ic_with_type_info_count(100); | 100 vector->change_ic_with_type_info_count(100); |
102 vector->change_ic_generic_count(3333); | 101 vector->change_ic_generic_count(3333); |
103 vector->Set(FeedbackVectorSlot(0), *vector); | 102 vector->Set(FeedbackVectorSlot(0), *vector); |
104 | 103 |
105 // Verify the metadata remains the same. | 104 // Verify the metadata remains the same. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 int ic_slot = FLAG_vector_ics ? 1 : 0; | 190 int ic_slot = FLAG_vector_ics ? 1 : 0; |
192 CHECK( | 191 CHECK( |
193 feedback_vector->Get(FeedbackVectorICSlot(ic_slot))->IsAllocationSite()); | 192 feedback_vector->Get(FeedbackVectorICSlot(ic_slot))->IsAllocationSite()); |
194 heap->CollectAllGarbage(i::Heap::kNoGCFlags); | 193 heap->CollectAllGarbage(i::Heap::kNoGCFlags); |
195 feedback_vector = f->shared()->feedback_vector(); | 194 feedback_vector = f->shared()->feedback_vector(); |
196 CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); | 195 CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); |
197 CHECK_EQ(0, feedback_vector->ic_generic_count()); | 196 CHECK_EQ(0, feedback_vector->ic_generic_count()); |
198 CHECK( | 197 CHECK( |
199 feedback_vector->Get(FeedbackVectorICSlot(ic_slot))->IsAllocationSite()); | 198 feedback_vector->Get(FeedbackVectorICSlot(ic_slot))->IsAllocationSite()); |
200 } | 199 } |
201 | |
202 | |
203 TEST(VectorCallICStates) { | |
204 if (i::FLAG_always_opt) return; | |
205 CcTest::InitializeVM(); | |
206 LocalContext context; | |
207 v8::HandleScope scope(context->GetIsolate()); | |
208 Isolate* isolate = CcTest::i_isolate(); | |
209 Heap* heap = isolate->heap(); | |
210 | |
211 // Make sure function f has a call that uses a type feedback slot. | |
212 CompileRun( | |
213 "function foo() { return 17; }" | |
214 "function f(a) { a(); } f(foo);"); | |
215 Handle<JSFunction> f = v8::Utils::OpenHandle( | |
216 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | |
217 // There should be one IC. | |
218 Handle<TypeFeedbackVector> feedback_vector = | |
219 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); | |
220 FeedbackVectorICSlot slot(FLAG_vector_ics ? 1 : 0); | |
221 CallICNexus nexus(feedback_vector, slot); | |
222 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); | |
223 // CallIC doesn't return map feedback. | |
224 CHECK_EQ(NULL, nexus.FindFirstMap()); | |
225 | |
226 CompileRun("f(function() { return 16; })"); | |
227 CHECK_EQ(GENERIC, nexus.StateFromFeedback()); | |
228 | |
229 // After a collection, state should be reset to UNINITIALIZED. | |
230 heap->CollectAllGarbage(i::Heap::kNoGCFlags); | |
231 CHECK_EQ(UNINITIALIZED, nexus.StateFromFeedback()); | |
232 | |
233 // Array is special. It will remain monomorphic across gcs and it contains an | |
234 // AllocationSite. | |
235 CompileRun("f(Array)"); | |
236 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); | |
237 CHECK(feedback_vector->Get(FeedbackVectorICSlot(slot))->IsAllocationSite()); | |
238 | |
239 heap->CollectAllGarbage(i::Heap::kNoGCFlags); | |
240 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); | |
241 } | 200 } |
242 } | |
OLD | NEW |