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

Side by Side Diff: test/cctest/test-feedback-vector.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, 6 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
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/debug.h" 9 #include "src/debug/debug.h"
10 #include "src/execution.h" 10 #include "src/execution.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 Isolate* isolate = CcTest::i_isolate(); 201 Isolate* isolate = CcTest::i_isolate();
202 Heap* heap = isolate->heap(); 202 Heap* heap = isolate->heap();
203 203
204 // Make sure function f has a call that uses a type feedback slot. 204 // Make sure function f has a call that uses a type feedback slot.
205 CompileRun( 205 CompileRun(
206 "function foo() { return 17; }" 206 "function foo() { return 17; }"
207 "function f(a) { a(); } f(foo);"); 207 "function f(a) { a(); } f(foo);");
208 Handle<JSFunction> f = GetFunction("f"); 208 Handle<JSFunction> f = GetFunction("f");
209 // There should be one IC. 209 // There should be one IC.
210 Handle<TypeFeedbackVector> feedback_vector = 210 Handle<TypeFeedbackVector> feedback_vector =
211 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); 211 Handle<TypeFeedbackVector>(f->feedback_vector(), isolate);
212 FeedbackVectorSlot slot(0); 212 FeedbackVectorSlot slot(0);
213 CallICNexus nexus(feedback_vector, slot); 213 CallICNexus nexus(feedback_vector, slot);
214 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); 214 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
215 // CallIC doesn't return map feedback. 215 // CallIC doesn't return map feedback.
216 CHECK(!nexus.FindFirstMap()); 216 CHECK(!nexus.FindFirstMap());
217 217
218 CompileRun("f(function() { return 16; })"); 218 CompileRun("f(function() { return 16; })");
219 CHECK_EQ(GENERIC, nexus.StateFromFeedback()); 219 CHECK_EQ(GENERIC, nexus.StateFromFeedback());
220 220
221 // After a collection, state should remain GENERIC. 221 // After a collection, state should remain GENERIC.
(...skipping 18 matching lines...) Expand all
240 v8::HandleScope scope(context->GetIsolate()); 240 v8::HandleScope scope(context->GetIsolate());
241 Isolate* isolate = CcTest::i_isolate(); 241 Isolate* isolate = CcTest::i_isolate();
242 242
243 // Make sure function f has a call that uses a type feedback slot. 243 // Make sure function f has a call that uses a type feedback slot.
244 CompileRun( 244 CompileRun(
245 "function foo() { return 17; }" 245 "function foo() { return 17; }"
246 "function f(a) { a(); } f(foo);"); 246 "function f(a) { a(); } f(foo);");
247 Handle<JSFunction> f = GetFunction("f"); 247 Handle<JSFunction> f = GetFunction("f");
248 // There should be one IC. 248 // There should be one IC.
249 Handle<TypeFeedbackVector> feedback_vector = 249 Handle<TypeFeedbackVector> feedback_vector =
250 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); 250 Handle<TypeFeedbackVector>(f->feedback_vector(), isolate);
251 FeedbackVectorSlot slot(0); 251 FeedbackVectorSlot slot(0);
252 CallICNexus nexus(feedback_vector, slot); 252 CallICNexus nexus(feedback_vector, slot);
253 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); 253 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
254 254
255 CompileRun("f(foo); f(foo);"); 255 CompileRun("f(foo); f(foo);");
256 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); 256 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
257 CHECK_EQ(3, nexus.ExtractCallCount()); 257 CHECK_EQ(3, nexus.ExtractCallCount());
258 258
259 CompileRun( 259 CompileRun(
260 "function Foo() {}" 260 "function Foo() {}"
261 "function f(a) { new a(); } f(Foo);"); 261 "function f(a) { new a(); } f(Foo);");
262 f = GetFunction("f"); 262 f = GetFunction("f");
263 // There should be one IC. 263 // There should be one IC.
264 feedback_vector = 264 feedback_vector = Handle<TypeFeedbackVector>(f->feedback_vector(), isolate);
265 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate);
266 FeedbackVectorSlot cslot(1); 265 FeedbackVectorSlot cslot(1);
267 266
268 CompileRun("f(Foo); f(Foo);"); 267 CompileRun("f(Foo); f(Foo);");
269 CHECK(feedback_vector->Get(cslot)->IsSmi()); 268 CHECK(feedback_vector->Get(cslot)->IsSmi());
270 CHECK_EQ(3, Smi::cast(feedback_vector->Get(cslot))->value()); 269 CHECK_EQ(3, Smi::cast(feedback_vector->Get(cslot))->value());
271 } 270 }
272 271
273 TEST(VectorLoadICStates) { 272 TEST(VectorLoadICStates) {
274 if (i::FLAG_always_opt) return; 273 if (i::FLAG_always_opt) return;
275 CcTest::InitializeVM(); 274 CcTest::InitializeVM();
276 LocalContext context; 275 LocalContext context;
277 v8::HandleScope scope(context->GetIsolate()); 276 v8::HandleScope scope(context->GetIsolate());
278 Isolate* isolate = CcTest::i_isolate(); 277 Isolate* isolate = CcTest::i_isolate();
279 Heap* heap = isolate->heap(); 278 Heap* heap = isolate->heap();
280 279
281 // Make sure function f has a call that uses a type feedback slot. 280 // Make sure function f has a call that uses a type feedback slot.
282 CompileRun( 281 CompileRun(
283 "var o = { foo: 3 };" 282 "var o = { foo: 3 };"
284 "function f(a) { return a.foo; } f(o);"); 283 "function f(a) { return a.foo; } f(o);");
285 Handle<JSFunction> f = GetFunction("f"); 284 Handle<JSFunction> f = GetFunction("f");
286 // There should be one IC. 285 // There should be one IC.
287 Handle<TypeFeedbackVector> feedback_vector = 286 Handle<TypeFeedbackVector> feedback_vector =
288 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); 287 Handle<TypeFeedbackVector>(f->feedback_vector(), isolate);
289 FeedbackVectorSlot slot(0); 288 FeedbackVectorSlot slot(0);
290 LoadICNexus nexus(feedback_vector, slot); 289 LoadICNexus nexus(feedback_vector, slot);
291 CHECK_EQ(PREMONOMORPHIC, nexus.StateFromFeedback()); 290 CHECK_EQ(PREMONOMORPHIC, nexus.StateFromFeedback());
292 291
293 CompileRun("f(o)"); 292 CompileRun("f(o)");
294 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); 293 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
295 // Verify that the monomorphic map is the one we expect. 294 // Verify that the monomorphic map is the one we expect.
296 v8::MaybeLocal<v8::Value> v8_o = 295 v8::MaybeLocal<v8::Value> v8_o =
297 CcTest::global()->Get(context.local(), v8_str("o")); 296 CcTest::global()->Get(context.local(), v8_str("o"));
298 Handle<JSObject> o = 297 Handle<JSObject> o =
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 CompileRun( 336 CompileRun(
338 "o = 10;" 337 "o = 10;"
339 "function f() {" 338 "function f() {"
340 " var x = o + 10;" 339 " var x = o + 10;"
341 " return o + x + o;" 340 " return o + x + o;"
342 "}" 341 "}"
343 "f();"); 342 "f();");
344 Handle<JSFunction> f = GetFunction("f"); 343 Handle<JSFunction> f = GetFunction("f");
345 // There should be one IC slot. 344 // There should be one IC slot.
346 Handle<TypeFeedbackVector> feedback_vector = 345 Handle<TypeFeedbackVector> feedback_vector =
347 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); 346 Handle<TypeFeedbackVector>(f->feedback_vector(), isolate);
348 FeedbackVectorHelper helper(feedback_vector); 347 FeedbackVectorHelper helper(feedback_vector);
349 CHECK_EQ(1, helper.slot_count()); 348 CHECK_EQ(1, helper.slot_count());
350 FeedbackVectorSlot slot(0); 349 FeedbackVectorSlot slot(0);
351 LoadICNexus nexus(feedback_vector, slot); 350 LoadICNexus nexus(feedback_vector, slot);
352 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); 351 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
353 } 352 }
354 353
355 354
356 TEST(VectorLoadICOnSmi) { 355 TEST(VectorLoadICOnSmi) {
357 if (i::FLAG_always_opt) return; 356 if (i::FLAG_always_opt) return;
358 CcTest::InitializeVM(); 357 CcTest::InitializeVM();
359 LocalContext context; 358 LocalContext context;
360 v8::HandleScope scope(context->GetIsolate()); 359 v8::HandleScope scope(context->GetIsolate());
361 Isolate* isolate = CcTest::i_isolate(); 360 Isolate* isolate = CcTest::i_isolate();
362 Heap* heap = isolate->heap(); 361 Heap* heap = isolate->heap();
363 362
364 // Make sure function f has a call that uses a type feedback slot. 363 // Make sure function f has a call that uses a type feedback slot.
365 CompileRun( 364 CompileRun(
366 "var o = { foo: 3 };" 365 "var o = { foo: 3 };"
367 "function f(a) { return a.foo; } f(o);"); 366 "function f(a) { return a.foo; } f(o);");
368 Handle<JSFunction> f = GetFunction("f"); 367 Handle<JSFunction> f = GetFunction("f");
369 // There should be one IC. 368 // There should be one IC.
370 Handle<TypeFeedbackVector> feedback_vector = 369 Handle<TypeFeedbackVector> feedback_vector =
371 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); 370 Handle<TypeFeedbackVector>(f->feedback_vector(), isolate);
372 FeedbackVectorSlot slot(0); 371 FeedbackVectorSlot slot(0);
373 LoadICNexus nexus(feedback_vector, slot); 372 LoadICNexus nexus(feedback_vector, slot);
374 CHECK_EQ(PREMONOMORPHIC, nexus.StateFromFeedback()); 373 CHECK_EQ(PREMONOMORPHIC, nexus.StateFromFeedback());
375 374
376 CompileRun("f(34)"); 375 CompileRun("f(34)");
377 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); 376 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
378 // Verify that the monomorphic map is the one we expect. 377 // Verify that the monomorphic map is the one we expect.
379 Map* number_map = heap->heap_number_map(); 378 Map* number_map = heap->heap_number_map();
380 CHECK_EQ(number_map, nexus.FindFirstMap()); 379 CHECK_EQ(number_map, nexus.FindFirstMap());
381 380
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 " y = a;" 425 " y = a;"
427 " return y;" 426 " return y;"
428 "}" 427 "}"
429 "a = 3;" 428 "a = 3;"
430 "testvar({});"); 429 "testvar({});");
431 430
432 Handle<JSFunction> f = GetFunction("testvar"); 431 Handle<JSFunction> f = GetFunction("testvar");
433 432
434 // There should be two LOAD_ICs, one for a and one for y at the end. 433 // There should be two LOAD_ICs, one for a and one for y at the end.
435 Handle<TypeFeedbackVector> feedback_vector = 434 Handle<TypeFeedbackVector> feedback_vector =
436 handle(f->shared()->feedback_vector(), isolate); 435 handle(f->feedback_vector(), isolate);
437 FeedbackVectorHelper helper(feedback_vector); 436 FeedbackVectorHelper helper(feedback_vector);
438 CHECK_EQ(4, helper.slot_count()); 437 CHECK_EQ(4, helper.slot_count());
439 CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::STORE_IC); 438 CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::STORE_IC);
440 CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::LOAD_IC); 439 CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::LOAD_IC);
441 CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::STORE_IC); 440 CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::STORE_IC);
442 CHECK_SLOT_KIND(helper, 3, FeedbackVectorSlotKind::LOAD_IC); 441 CHECK_SLOT_KIND(helper, 3, FeedbackVectorSlotKind::LOAD_IC);
443 } 442 }
444 443
445 { 444 {
446 CompileRun( 445 CompileRun(
447 "function testprop(x) {" 446 "function testprop(x) {"
448 " x.blue = a;" 447 " x.blue = a;"
449 "}" 448 "}"
450 "testprop({ blue: 3 });"); 449 "testprop({ blue: 3 });");
451 450
452 Handle<JSFunction> f = GetFunction("testprop"); 451 Handle<JSFunction> f = GetFunction("testprop");
453 452
454 // There should be one LOAD_IC, for the load of a. 453 // There should be one LOAD_IC, for the load of a.
455 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); 454 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector());
456 FeedbackVectorHelper helper(feedback_vector); 455 FeedbackVectorHelper helper(feedback_vector);
457 CHECK_EQ(2, helper.slot_count()); 456 CHECK_EQ(2, helper.slot_count());
458 } 457 }
459 458
460 { 459 {
461 CompileRun( 460 CompileRun(
462 "function testpropfunc(x) {" 461 "function testpropfunc(x) {"
463 " x().blue = a;" 462 " x().blue = a;"
464 " return x().blue;" 463 " return x().blue;"
465 "}" 464 "}"
466 "function makeresult() { return { blue: 3 }; }" 465 "function makeresult() { return { blue: 3 }; }"
467 "testpropfunc(makeresult);"); 466 "testpropfunc(makeresult);");
468 467
469 Handle<JSFunction> f = GetFunction("testpropfunc"); 468 Handle<JSFunction> f = GetFunction("testpropfunc");
470 469
471 // There should be 2 LOAD_ICs and 2 CALL_ICs. 470 // There should be 2 LOAD_ICs and 2 CALL_ICs.
472 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); 471 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector());
473 FeedbackVectorHelper helper(feedback_vector); 472 FeedbackVectorHelper helper(feedback_vector);
474 CHECK_EQ(5, helper.slot_count()); 473 CHECK_EQ(5, helper.slot_count());
475 CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::CALL_IC); 474 CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::CALL_IC);
476 CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::LOAD_IC); 475 CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::LOAD_IC);
477 CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::STORE_IC); 476 CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::STORE_IC);
478 CHECK_SLOT_KIND(helper, 3, FeedbackVectorSlotKind::CALL_IC); 477 CHECK_SLOT_KIND(helper, 3, FeedbackVectorSlotKind::CALL_IC);
479 CHECK_SLOT_KIND(helper, 4, FeedbackVectorSlotKind::LOAD_IC); 478 CHECK_SLOT_KIND(helper, 4, FeedbackVectorSlotKind::LOAD_IC);
480 } 479 }
481 480
482 { 481 {
483 CompileRun( 482 CompileRun(
484 "function testkeyedprop(x) {" 483 "function testkeyedprop(x) {"
485 " x[0] = a;" 484 " x[0] = a;"
486 " return x[0];" 485 " return x[0];"
487 "}" 486 "}"
488 "testkeyedprop([0, 1, 2]);"); 487 "testkeyedprop([0, 1, 2]);");
489 488
490 Handle<JSFunction> f = GetFunction("testkeyedprop"); 489 Handle<JSFunction> f = GetFunction("testkeyedprop");
491 490
492 // There should be 1 LOAD_ICs for the load of a, and one KEYED_LOAD_IC for 491 // There should be 1 LOAD_ICs for the load of a, and one KEYED_LOAD_IC for
493 // the load of x[0] in the return statement. 492 // the load of x[0] in the return statement.
494 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); 493 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector());
495 FeedbackVectorHelper helper(feedback_vector); 494 FeedbackVectorHelper helper(feedback_vector);
496 CHECK_EQ(3, helper.slot_count()); 495 CHECK_EQ(3, helper.slot_count());
497 CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::LOAD_IC); 496 CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::LOAD_IC);
498 CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::KEYED_STORE_IC); 497 CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::KEYED_STORE_IC);
499 CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::KEYED_LOAD_IC); 498 CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::KEYED_LOAD_IC);
500 } 499 }
501 500
502 { 501 {
503 CompileRun( 502 CompileRun(
504 "function testcompound(x) {" 503 "function testcompound(x) {"
505 " x.old = x.young = x.in_between = a;" 504 " x.old = x.young = x.in_between = a;"
506 " return x.old + x.young;" 505 " return x.old + x.young;"
507 "}" 506 "}"
508 "testcompound({ old: 3, young: 3, in_between: 3 });"); 507 "testcompound({ old: 3, young: 3, in_between: 3 });");
509 508
510 Handle<JSFunction> f = GetFunction("testcompound"); 509 Handle<JSFunction> f = GetFunction("testcompound");
511 510
512 // There should be 3 LOAD_ICs, for load of a and load of x.old and x.young. 511 // There should be 3 LOAD_ICs, for load of a and load of x.old and x.young.
513 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); 512 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector());
514 FeedbackVectorHelper helper(feedback_vector); 513 FeedbackVectorHelper helper(feedback_vector);
515 CHECK_EQ(6, helper.slot_count()); 514 CHECK_EQ(6, helper.slot_count());
516 CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::LOAD_IC); 515 CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::LOAD_IC);
517 CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::STORE_IC); 516 CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::STORE_IC);
518 CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::STORE_IC); 517 CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::STORE_IC);
519 CHECK_SLOT_KIND(helper, 3, FeedbackVectorSlotKind::STORE_IC); 518 CHECK_SLOT_KIND(helper, 3, FeedbackVectorSlotKind::STORE_IC);
520 CHECK_SLOT_KIND(helper, 4, FeedbackVectorSlotKind::LOAD_IC); 519 CHECK_SLOT_KIND(helper, 4, FeedbackVectorSlotKind::LOAD_IC);
521 CHECK_SLOT_KIND(helper, 5, FeedbackVectorSlotKind::LOAD_IC); 520 CHECK_SLOT_KIND(helper, 5, FeedbackVectorSlotKind::LOAD_IC);
522 } 521 }
523 } 522 }
524 523
525 524
526 TEST(VectorStoreICBasic) { 525 TEST(VectorStoreICBasic) {
527 if (i::FLAG_always_opt) return; 526 if (i::FLAG_always_opt) return;
528 527
529 CcTest::InitializeVM(); 528 CcTest::InitializeVM();
530 LocalContext context; 529 LocalContext context;
531 v8::HandleScope scope(context->GetIsolate()); 530 v8::HandleScope scope(context->GetIsolate());
532 531
533 CompileRun( 532 CompileRun(
534 "function f(a) {" 533 "function f(a) {"
535 " a.foo = 5;" 534 " a.foo = 5;"
536 "}" 535 "}"
537 "var a = { foo: 3 };" 536 "var a = { foo: 3 };"
538 "f(a);" 537 "f(a);"
539 "f(a);" 538 "f(a);"
540 "f(a);"); 539 "f(a);");
541 Handle<JSFunction> f = GetFunction("f"); 540 Handle<JSFunction> f = GetFunction("f");
542 // There should be one IC slot. 541 // There should be one IC slot.
543 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); 542 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector());
544 FeedbackVectorHelper helper(feedback_vector); 543 FeedbackVectorHelper helper(feedback_vector);
545 CHECK_EQ(1, helper.slot_count()); 544 CHECK_EQ(1, helper.slot_count());
546 FeedbackVectorSlot slot(0); 545 FeedbackVectorSlot slot(0);
547 StoreICNexus nexus(feedback_vector, slot); 546 StoreICNexus nexus(feedback_vector, slot);
548 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); 547 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback());
549 } 548 }
550 549
551 } // namespace 550 } // namespace
OLDNEW
« no previous file with comments | « test/cctest/test-compiler.cc ('k') | test/unittests/interpreter/interpreter-assembler-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698