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

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

Issue 866493003: Retry "Use a WeakCell in the CallIC type vector." (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: REBASE. Created 5 years, 10 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/test-compiler.cc ('k') | test/cctest/test-heap.cc » ('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 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 Isolate* isolate = CcTest::i_isolate(); 164 Isolate* isolate = CcTest::i_isolate();
165 Heap* heap = isolate->heap(); 165 Heap* heap = isolate->heap();
166 166
167 // Make sure function f has a call that uses a type feedback slot. 167 // Make sure function f has a call that uses a type feedback slot.
168 CompileRun( 168 CompileRun(
169 "function fun() {};" 169 "function fun() {};"
170 "function f(a) { a(); } f(fun);"); 170 "function f(a) { a(); } f(fun);");
171 Handle<JSFunction> f = v8::Utils::OpenHandle( 171 Handle<JSFunction> f = v8::Utils::OpenHandle(
172 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); 172 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f"))));
173 // There should be one IC. 173 // There should be one IC.
174 Code* code = f->shared()->code(); 174 Handle<Code> code = handle(f->shared()->code(), isolate);
175 TypeFeedbackInfo* feedback_info = 175 TypeFeedbackInfo* feedback_info =
176 TypeFeedbackInfo::cast(code->type_feedback_info()); 176 TypeFeedbackInfo::cast(code->type_feedback_info());
177 CHECK_EQ(1, feedback_info->ic_total_count()); 177 CHECK_EQ(1, feedback_info->ic_total_count());
178 CHECK_EQ(0, feedback_info->ic_with_type_info_count()); 178 CHECK_EQ(0, feedback_info->ic_with_type_info_count());
179 CHECK_EQ(0, feedback_info->ic_generic_count()); 179 CHECK_EQ(0, feedback_info->ic_generic_count());
180 TypeFeedbackVector* feedback_vector = f->shared()->feedback_vector(); 180 Handle<TypeFeedbackVector> feedback_vector =
181 handle(f->shared()->feedback_vector(), isolate);
182 int ic_slot = 0;
183 CallICNexus nexus(feedback_vector, FeedbackVectorICSlot(ic_slot));
181 CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); 184 CHECK_EQ(1, feedback_vector->ic_with_type_info_count());
182 CHECK_EQ(0, feedback_vector->ic_generic_count()); 185 CHECK_EQ(0, feedback_vector->ic_generic_count());
183 186
184 // Now send the information generic. 187 // Now send the information generic.
185 CompileRun("f(Object);"); 188 CompileRun("f(Object);");
186 feedback_vector = f->shared()->feedback_vector();
187 CHECK_EQ(0, feedback_vector->ic_with_type_info_count()); 189 CHECK_EQ(0, feedback_vector->ic_with_type_info_count());
188 CHECK_EQ(1, feedback_vector->ic_generic_count()); 190 CHECK_EQ(1, feedback_vector->ic_generic_count());
189 191
190 // A collection will make the site uninitialized again. 192 // A collection will not affect the site.
191 heap->CollectAllGarbage(i::Heap::kNoGCFlags); 193 heap->CollectAllGarbage(i::Heap::kNoGCFlags);
192 feedback_vector = f->shared()->feedback_vector();
193 CHECK_EQ(0, feedback_vector->ic_with_type_info_count()); 194 CHECK_EQ(0, feedback_vector->ic_with_type_info_count());
194 CHECK_EQ(0, feedback_vector->ic_generic_count()); 195 CHECK_EQ(1, feedback_vector->ic_generic_count());
195 196
196 // The Array function is special. A call to array remains monomorphic 197 // The Array function is special. A call to array remains monomorphic
197 // and isn't cleared by gc because an AllocationSite is being held. 198 // and isn't cleared by gc because an AllocationSite is being held.
199 // Clear the IC manually in order to test this case.
200 nexus.Clear(*code);
198 CompileRun("f(Array);"); 201 CompileRun("f(Array);");
199 feedback_vector = f->shared()->feedback_vector();
200 CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); 202 CHECK_EQ(1, feedback_vector->ic_with_type_info_count());
201 CHECK_EQ(0, feedback_vector->ic_generic_count()); 203 CHECK_EQ(0, feedback_vector->ic_generic_count());
202 204
203 int ic_slot = 0; 205
204 CHECK( 206 CHECK(nexus.GetFeedback()->IsAllocationSite());
205 feedback_vector->Get(FeedbackVectorICSlot(ic_slot))->IsAllocationSite());
206 heap->CollectAllGarbage(i::Heap::kNoGCFlags); 207 heap->CollectAllGarbage(i::Heap::kNoGCFlags);
207 feedback_vector = f->shared()->feedback_vector();
208 CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); 208 CHECK_EQ(1, feedback_vector->ic_with_type_info_count());
209 CHECK_EQ(0, feedback_vector->ic_generic_count()); 209 CHECK_EQ(0, feedback_vector->ic_generic_count());
210 CHECK( 210 CHECK(nexus.GetFeedback()->IsAllocationSite());
211 feedback_vector->Get(FeedbackVectorICSlot(ic_slot))->IsAllocationSite());
212 } 211 }
213 212
214 213
215 TEST(VectorCallICStates) { 214 TEST(VectorCallICStates) {
216 if (i::FLAG_always_opt) return; 215 if (i::FLAG_always_opt) return;
217 CcTest::InitializeVM(); 216 CcTest::InitializeVM();
218 LocalContext context; 217 LocalContext context;
219 v8::HandleScope scope(context->GetIsolate()); 218 v8::HandleScope scope(context->GetIsolate());
220 Isolate* isolate = CcTest::i_isolate(); 219 Isolate* isolate = CcTest::i_isolate();
221 Heap* heap = isolate->heap(); 220 Heap* heap = isolate->heap();
222 221
223 // Make sure function f has a call that uses a type feedback slot. 222 // Make sure function f has a call that uses a type feedback slot.
224 CompileRun( 223 CompileRun(
225 "function foo() { return 17; }" 224 "function foo() { return 17; }"
226 "function f(a) { a(); } f(foo);"); 225 "function f(a) { a(); } f(foo);");
227 Handle<JSFunction> f = v8::Utils::OpenHandle( 226 Handle<JSFunction> f = v8::Utils::OpenHandle(
228 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); 227 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f"))));
229 // There should be one IC. 228 // There should be one IC.
230 Handle<TypeFeedbackVector> feedback_vector = 229 Handle<TypeFeedbackVector> feedback_vector =
231 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); 230 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate);
232 FeedbackVectorICSlot slot(0); 231 FeedbackVectorICSlot slot(0);
233 CallICNexus nexus(feedback_vector, slot); 232 CallICNexus nexus(feedback_vector, slot);
234 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); 233 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
235 // CallIC doesn't return map feedback. 234 // CallIC doesn't return map feedback.
236 CHECK(!nexus.FindFirstMap()); 235 CHECK(!nexus.FindFirstMap());
237 236
238 CompileRun("f(function() { return 16; })"); 237 CompileRun("f(function() { return 16; })");
239 CHECK_EQ(GENERIC, nexus.StateFromFeedback()); 238 CHECK_EQ(GENERIC, nexus.StateFromFeedback());
240 239
241 // After a collection, state should be reset to UNINITIALIZED. 240 // After a collection, state should remain GENERIC.
242 heap->CollectAllGarbage(i::Heap::kNoGCFlags); 241 heap->CollectAllGarbage(i::Heap::kNoGCFlags);
243 CHECK_EQ(UNINITIALIZED, nexus.StateFromFeedback()); 242 CHECK_EQ(GENERIC, nexus.StateFromFeedback());
244 243
245 // Array is special. It will remain monomorphic across gcs and it contains an 244 // A call to Array is special, it contains an AllocationSite as feedback.
246 // AllocationSite. 245 // Clear the IC manually in order to test this case.
246 nexus.Clear(f->shared()->code());
247 CompileRun("f(Array)"); 247 CompileRun("f(Array)");
248 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); 248 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
249 CHECK(feedback_vector->Get(FeedbackVectorICSlot(slot))->IsAllocationSite()); 249 CHECK(nexus.GetFeedback()->IsAllocationSite());
250 250
251 heap->CollectAllGarbage(i::Heap::kNoGCFlags); 251 heap->CollectAllGarbage(i::Heap::kNoGCFlags);
252 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); 252 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
253 } 253 }
254 254
255 255
256 TEST(VectorLoadICStates) { 256 TEST(VectorLoadICStates) {
257 if (i::FLAG_always_opt || !i::FLAG_vector_ics) return; 257 if (i::FLAG_always_opt || !i::FLAG_vector_ics) return;
258 CcTest::InitializeVM(); 258 CcTest::InitializeVM();
259 LocalContext context; 259 LocalContext context;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 CHECK(number_map_found && o_map_found); 357 CHECK(number_map_found && o_map_found);
358 358
359 // The degree of polymorphism doesn't change. 359 // The degree of polymorphism doesn't change.
360 CompileRun("f(100)"); 360 CompileRun("f(100)");
361 CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback()); 361 CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback());
362 MapHandleList maps2; 362 MapHandleList maps2;
363 nexus.FindAllMaps(&maps2); 363 nexus.FindAllMaps(&maps2);
364 CHECK_EQ(2, maps2.length()); 364 CHECK_EQ(2, maps2.length());
365 } 365 }
366 } 366 }
OLDNEW
« no previous file with comments | « test/cctest/test-compiler.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698