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

Side by Side Diff: test/cctest/test-feedback-vector.cc

Issue 1507903004: Type Feedback Vector: Calculate profiler counts on the fly. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Comment response. Created 5 years 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/interpreter/test-bytecode-generator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // TODO(mvstanton): Remove this define after this flag is turned on globally 5 // TODO(mvstanton): Remove this define after this flag is turned on globally
6 #define V8_IMMINENT_DEPRECATION_WARNINGS 6 #define V8_IMMINENT_DEPRECATION_WARNINGS
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 #include "test/cctest/cctest.h" 9 #include "test/cctest/cctest.h"
10 10
(...skipping 29 matching lines...) Expand all
40 Isolate* isolate = CcTest::i_isolate(); 40 Isolate* isolate = CcTest::i_isolate();
41 Factory* factory = isolate->factory(); 41 Factory* factory = isolate->factory();
42 Zone* zone = isolate->runtime_zone(); 42 Zone* zone = isolate->runtime_zone();
43 43
44 // Empty vectors are the empty fixed array. 44 // Empty vectors are the empty fixed array.
45 StaticFeedbackVectorSpec empty; 45 StaticFeedbackVectorSpec empty;
46 Handle<TypeFeedbackVector> vector = NewTypeFeedbackVector(isolate, &empty); 46 Handle<TypeFeedbackVector> vector = NewTypeFeedbackVector(isolate, &empty);
47 CHECK(Handle<FixedArray>::cast(vector) 47 CHECK(Handle<FixedArray>::cast(vector)
48 .is_identical_to(factory->empty_fixed_array())); 48 .is_identical_to(factory->empty_fixed_array()));
49 // Which can nonetheless be queried. 49 // Which can nonetheless be queried.
50 CHECK_EQ(0, vector->ic_with_type_info_count());
51 CHECK_EQ(0, vector->ic_generic_count());
52 CHECK(vector->is_empty()); 50 CHECK(vector->is_empty());
53 51
54 { 52 {
55 FeedbackVectorSpec one_slot(zone); 53 FeedbackVectorSpec one_slot(zone);
56 one_slot.AddGeneralSlot(); 54 one_slot.AddGeneralSlot();
57 vector = NewTypeFeedbackVector(isolate, &one_slot); 55 vector = NewTypeFeedbackVector(isolate, &one_slot);
58 FeedbackVectorHelper helper(vector); 56 FeedbackVectorHelper helper(vector);
59 CHECK_EQ(1, helper.slot_count()); 57 CHECK_EQ(1, helper.slot_count());
60 } 58 }
61 59
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 break; 126 break;
129 } 127 }
130 } 128 }
131 129
132 Handle<TypeFeedbackVector> vector = NewTypeFeedbackVector(isolate, &spec); 130 Handle<TypeFeedbackVector> vector = NewTypeFeedbackVector(isolate, &spec);
133 FeedbackVectorHelper helper(vector); 131 FeedbackVectorHelper helper(vector);
134 CHECK_EQ(40, helper.slot_count()); 132 CHECK_EQ(40, helper.slot_count());
135 133
136 // Meanwhile set some feedback values and type feedback values to 134 // Meanwhile set some feedback values and type feedback values to
137 // verify the data structure remains intact. 135 // verify the data structure remains intact.
138 vector->change_ic_with_type_info_count(100);
139 vector->change_ic_generic_count(3333);
140 vector->Set(FeedbackVectorSlot(0), *vector); 136 vector->Set(FeedbackVectorSlot(0), *vector);
141 137
142 // Verify the metadata is correctly set up from the spec. 138 // Verify the metadata is correctly set up from the spec.
143 for (int i = 0; i < 40; i++) { 139 for (int i = 0; i < 40; i++) {
144 FeedbackVectorSlotKind kind = vector->GetKind(helper.slot(i)); 140 FeedbackVectorSlotKind kind = vector->GetKind(helper.slot(i));
145 switch (i % 4) { 141 switch (i % 4) {
146 case 0: 142 case 0:
147 CHECK_EQ(FeedbackVectorSlotKind::GENERAL, kind); 143 CHECK_EQ(FeedbackVectorSlotKind::GENERAL, kind);
148 break; 144 break;
149 case 1: 145 case 1:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 189
194 // The feedback vector slots are cleared. AllocationSites are still granted 190 // The feedback vector slots are cleared. AllocationSites are still granted
195 // an exemption from clearing, as are smis. 191 // an exemption from clearing, as are smis.
196 CHECK_EQ(Smi::FromInt(1), vector->Get(helper.slot(0))); 192 CHECK_EQ(Smi::FromInt(1), vector->Get(helper.slot(0)));
197 CHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(isolate), 193 CHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(isolate),
198 vector->Get(helper.slot(1))); 194 vector->Get(helper.slot(1)));
199 CHECK(vector->Get(helper.slot(2))->IsAllocationSite()); 195 CHECK(vector->Get(helper.slot(2))->IsAllocationSite());
200 } 196 }
201 197
202 198
203 TEST(VectorICProfilerStatistics) {
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 fun() {};"
214 "function f(a) { a(); } f(fun);");
215 Handle<JSFunction> f = GetFunction("f");
216 // There should be one IC.
217 Handle<Code> code = handle(f->shared()->code(), isolate);
218 TypeFeedbackInfo* feedback_info =
219 TypeFeedbackInfo::cast(code->type_feedback_info());
220 CHECK_EQ(1, feedback_info->ic_total_count());
221 CHECK_EQ(0, feedback_info->ic_with_type_info_count());
222 CHECK_EQ(0, feedback_info->ic_generic_count());
223 Handle<TypeFeedbackVector> feedback_vector =
224 handle(f->shared()->feedback_vector(), isolate);
225 FeedbackVectorHelper helper(feedback_vector);
226 CallICNexus nexus(feedback_vector, helper.slot(0));
227 CHECK_EQ(1, feedback_vector->ic_with_type_info_count());
228 CHECK_EQ(0, feedback_vector->ic_generic_count());
229
230 // Now send the information generic.
231 CompileRun("f(Object);");
232 CHECK_EQ(0, feedback_vector->ic_with_type_info_count());
233 CHECK_EQ(1, feedback_vector->ic_generic_count());
234
235 // A collection will not affect the site.
236 heap->CollectAllGarbage();
237 CHECK_EQ(0, feedback_vector->ic_with_type_info_count());
238 CHECK_EQ(1, feedback_vector->ic_generic_count());
239
240 // The Array function is special. A call to array remains monomorphic
241 // and isn't cleared by gc because an AllocationSite is being held.
242 // Clear the IC manually in order to test this case.
243 nexus.Clear(*code);
244 CompileRun("f(Array);");
245 CHECK_EQ(1, feedback_vector->ic_with_type_info_count());
246 CHECK_EQ(0, feedback_vector->ic_generic_count());
247
248
249 CHECK(nexus.GetFeedback()->IsAllocationSite());
250 heap->CollectAllGarbage();
251 CHECK_EQ(1, feedback_vector->ic_with_type_info_count());
252 CHECK_EQ(0, feedback_vector->ic_generic_count());
253 CHECK(nexus.GetFeedback()->IsAllocationSite());
254 }
255
256
257 TEST(VectorCallICStates) { 199 TEST(VectorCallICStates) {
258 if (i::FLAG_always_opt) return; 200 if (i::FLAG_always_opt) return;
259 CcTest::InitializeVM(); 201 CcTest::InitializeVM();
260 LocalContext context; 202 LocalContext context;
261 v8::HandleScope scope(context->GetIsolate()); 203 v8::HandleScope scope(context->GetIsolate());
262 Isolate* isolate = CcTest::i_isolate(); 204 Isolate* isolate = CcTest::i_isolate();
263 Heap* heap = isolate->heap(); 205 Heap* heap = isolate->heap();
264 206
265 // Make sure function f has a call that uses a type feedback slot. 207 // Make sure function f has a call that uses a type feedback slot.
266 CompileRun( 208 CompileRun(
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 // There should be one IC slot. 509 // There should be one IC slot.
568 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); 510 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector());
569 FeedbackVectorHelper helper(feedback_vector); 511 FeedbackVectorHelper helper(feedback_vector);
570 CHECK_EQ(1, helper.slot_count()); 512 CHECK_EQ(1, helper.slot_count());
571 FeedbackVectorSlot slot(0); 513 FeedbackVectorSlot slot(0);
572 StoreICNexus nexus(feedback_vector, slot); 514 StoreICNexus nexus(feedback_vector, slot);
573 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); 515 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
574 } 516 }
575 517
576 } // namespace 518 } // namespace
OLDNEW
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698