| 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 3304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3315 CcTest::global()->Set(v8_str("fun2"), fun2); | 3315 CcTest::global()->Set(v8_str("fun2"), fun2); |
| 3316 CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);"); | 3316 CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);"); |
| 3317 | 3317 |
| 3318 Handle<JSFunction> f = | 3318 Handle<JSFunction> f = |
| 3319 v8::Utils::OpenHandle( | 3319 v8::Utils::OpenHandle( |
| 3320 *v8::Handle<v8::Function>::Cast( | 3320 *v8::Handle<v8::Function>::Cast( |
| 3321 CcTest::global()->Get(v8_str("f")))); | 3321 CcTest::global()->Get(v8_str("f")))); |
| 3322 | 3322 |
| 3323 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); | 3323 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); |
| 3324 | 3324 |
| 3325 int expected_slots = 2; | 3325 int expected_slots = 3; |
| 3326 CHECK_EQ(expected_slots, feedback_vector->ICSlots()); | 3326 CHECK_EQ(expected_slots, feedback_vector->ICSlots()); |
| 3327 int slot1 = 0; | 3327 int slot1 = 1; |
| 3328 int slot2 = 1; | 3328 int slot2 = 2; |
| 3329 CHECK(feedback_vector->Get(FeedbackVectorICSlot(slot1))->IsWeakCell()); | 3329 CHECK(feedback_vector->Get(FeedbackVectorICSlot(slot1))->IsWeakCell()); |
| 3330 CHECK(feedback_vector->Get(FeedbackVectorICSlot(slot2))->IsWeakCell()); | 3330 CHECK(feedback_vector->Get(FeedbackVectorICSlot(slot2))->IsWeakCell()); |
| 3331 | 3331 |
| 3332 SimulateIncrementalMarking(CcTest::heap()); | 3332 SimulateIncrementalMarking(CcTest::heap()); |
| 3333 CcTest::heap()->CollectAllGarbage(); | 3333 CcTest::heap()->CollectAllGarbage(); |
| 3334 | 3334 |
| 3335 CHECK(!WeakCell::cast(feedback_vector->Get(FeedbackVectorICSlot(slot1))) | 3335 CHECK(!WeakCell::cast(feedback_vector->Get(FeedbackVectorICSlot(slot1))) |
| 3336 ->cleared()); | 3336 ->cleared()); |
| 3337 CHECK(!WeakCell::cast(feedback_vector->Get(FeedbackVectorICSlot(slot2))) | 3337 CHECK(!WeakCell::cast(feedback_vector->Get(FeedbackVectorICSlot(slot2))) |
| 3338 ->cleared()); | 3338 ->cleared()); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3441 // Prepare function f that contains a monomorphic IC for object | 3441 // Prepare function f that contains a monomorphic IC for object |
| 3442 // originating from the same native context. | 3442 // originating from the same native context. |
| 3443 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" | 3443 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" |
| 3444 "function f(o) { return o.x; } f(obj); f(obj);"); | 3444 "function f(o) { return o.x; } f(obj); f(obj);"); |
| 3445 Handle<JSFunction> f = | 3445 Handle<JSFunction> f = |
| 3446 v8::Utils::OpenHandle( | 3446 v8::Utils::OpenHandle( |
| 3447 *v8::Handle<v8::Function>::Cast( | 3447 *v8::Handle<v8::Function>::Cast( |
| 3448 CcTest::global()->Get(v8_str("f")))); | 3448 CcTest::global()->Get(v8_str("f")))); |
| 3449 | 3449 |
| 3450 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3450 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3451 CheckVectorIC(f, 0, MONOMORPHIC); | 3451 CheckVectorIC(f, 1, MONOMORPHIC); |
| 3452 CHECK(ic_before->ic_state() == DEFAULT); | 3452 CHECK(ic_before->ic_state() == DEFAULT); |
| 3453 | 3453 |
| 3454 SimulateIncrementalMarking(CcTest::heap()); | 3454 SimulateIncrementalMarking(CcTest::heap()); |
| 3455 CcTest::heap()->CollectAllGarbage(); | 3455 CcTest::heap()->CollectAllGarbage(); |
| 3456 | 3456 |
| 3457 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3457 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3458 CheckVectorIC(f, 0, MONOMORPHIC); | 3458 CheckVectorIC(f, 1, MONOMORPHIC); |
| 3459 CHECK(ic_after->ic_state() == DEFAULT); | 3459 CHECK(ic_after->ic_state() == DEFAULT); |
| 3460 } | 3460 } |
| 3461 | 3461 |
| 3462 | 3462 |
| 3463 TEST(IncrementalMarkingClearsMonomorphicIC) { | 3463 TEST(IncrementalMarkingClearsMonomorphicIC) { |
| 3464 if (i::FLAG_always_opt) return; | 3464 if (i::FLAG_always_opt) return; |
| 3465 CcTest::InitializeVM(); | 3465 CcTest::InitializeVM(); |
| 3466 v8::HandleScope scope(CcTest::isolate()); | 3466 v8::HandleScope scope(CcTest::isolate()); |
| 3467 v8::Local<v8::Value> obj1; | 3467 v8::Local<v8::Value> obj1; |
| 3468 | 3468 |
| 3469 { | 3469 { |
| 3470 LocalContext env; | 3470 LocalContext env; |
| 3471 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); | 3471 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); |
| 3472 obj1 = env->Global()->Get(v8_str("obj")); | 3472 obj1 = env->Global()->Get(v8_str("obj")); |
| 3473 } | 3473 } |
| 3474 | 3474 |
| 3475 // Prepare function f that contains a monomorphic IC for object | 3475 // Prepare function f that contains a monomorphic IC for object |
| 3476 // originating from a different native context. | 3476 // originating from a different native context. |
| 3477 CcTest::global()->Set(v8_str("obj1"), obj1); | 3477 CcTest::global()->Set(v8_str("obj1"), obj1); |
| 3478 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1);"); | 3478 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1);"); |
| 3479 Handle<JSFunction> f = v8::Utils::OpenHandle( | 3479 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 3480 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 3480 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 3481 | 3481 |
| 3482 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3482 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3483 CheckVectorIC(f, 0, MONOMORPHIC); | 3483 CheckVectorIC(f, 1, MONOMORPHIC); |
| 3484 CHECK(ic_before->ic_state() == DEFAULT); | 3484 CHECK(ic_before->ic_state() == DEFAULT); |
| 3485 | 3485 |
| 3486 // Fire context dispose notification. | 3486 // Fire context dispose notification. |
| 3487 CcTest::isolate()->ContextDisposedNotification(); | 3487 CcTest::isolate()->ContextDisposedNotification(); |
| 3488 SimulateIncrementalMarking(CcTest::heap()); | 3488 SimulateIncrementalMarking(CcTest::heap()); |
| 3489 CcTest::heap()->CollectAllGarbage(); | 3489 CcTest::heap()->CollectAllGarbage(); |
| 3490 | 3490 |
| 3491 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3491 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3492 CheckVectorICCleared(f, 0); | 3492 CheckVectorICCleared(f, 1); |
| 3493 CHECK(ic_after->ic_state() == DEFAULT); | 3493 CHECK(ic_after->ic_state() == DEFAULT); |
| 3494 } | 3494 } |
| 3495 | 3495 |
| 3496 | 3496 |
| 3497 TEST(IncrementalMarkingPreservesPolymorphicIC) { | 3497 TEST(IncrementalMarkingPreservesPolymorphicIC) { |
| 3498 if (i::FLAG_always_opt) return; | 3498 if (i::FLAG_always_opt) return; |
| 3499 CcTest::InitializeVM(); | 3499 CcTest::InitializeVM(); |
| 3500 v8::HandleScope scope(CcTest::isolate()); | 3500 v8::HandleScope scope(CcTest::isolate()); |
| 3501 v8::Local<v8::Value> obj1, obj2; | 3501 v8::Local<v8::Value> obj1, obj2; |
| 3502 | 3502 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3514 | 3514 |
| 3515 // Prepare function f that contains a polymorphic IC for objects | 3515 // Prepare function f that contains a polymorphic IC for objects |
| 3516 // originating from two different native contexts. | 3516 // originating from two different native contexts. |
| 3517 CcTest::global()->Set(v8_str("obj1"), obj1); | 3517 CcTest::global()->Set(v8_str("obj1"), obj1); |
| 3518 CcTest::global()->Set(v8_str("obj2"), obj2); | 3518 CcTest::global()->Set(v8_str("obj2"), obj2); |
| 3519 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); | 3519 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); |
| 3520 Handle<JSFunction> f = v8::Utils::OpenHandle( | 3520 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 3521 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 3521 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 3522 | 3522 |
| 3523 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3523 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3524 CheckVectorIC(f, 0, POLYMORPHIC); | 3524 CheckVectorIC(f, 1, POLYMORPHIC); |
| 3525 CHECK(ic_before->ic_state() == DEFAULT); | 3525 CHECK(ic_before->ic_state() == DEFAULT); |
| 3526 | 3526 |
| 3527 // Fire context dispose notification. | 3527 // Fire context dispose notification. |
| 3528 SimulateIncrementalMarking(CcTest::heap()); | 3528 SimulateIncrementalMarking(CcTest::heap()); |
| 3529 CcTest::heap()->CollectAllGarbage(); | 3529 CcTest::heap()->CollectAllGarbage(); |
| 3530 | 3530 |
| 3531 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3531 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3532 CheckVectorIC(f, 0, POLYMORPHIC); | 3532 CheckVectorIC(f, 1, POLYMORPHIC); |
| 3533 CHECK(ic_after->ic_state() == DEFAULT); | 3533 CHECK(ic_after->ic_state() == DEFAULT); |
| 3534 } | 3534 } |
| 3535 | 3535 |
| 3536 | 3536 |
| 3537 TEST(IncrementalMarkingClearsPolymorphicIC) { | 3537 TEST(IncrementalMarkingClearsPolymorphicIC) { |
| 3538 if (i::FLAG_always_opt) return; | 3538 if (i::FLAG_always_opt) return; |
| 3539 CcTest::InitializeVM(); | 3539 CcTest::InitializeVM(); |
| 3540 v8::HandleScope scope(CcTest::isolate()); | 3540 v8::HandleScope scope(CcTest::isolate()); |
| 3541 v8::Local<v8::Value> obj1, obj2; | 3541 v8::Local<v8::Value> obj1, obj2; |
| 3542 | 3542 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3554 | 3554 |
| 3555 // Prepare function f that contains a polymorphic IC for objects | 3555 // Prepare function f that contains a polymorphic IC for objects |
| 3556 // originating from two different native contexts. | 3556 // originating from two different native contexts. |
| 3557 CcTest::global()->Set(v8_str("obj1"), obj1); | 3557 CcTest::global()->Set(v8_str("obj1"), obj1); |
| 3558 CcTest::global()->Set(v8_str("obj2"), obj2); | 3558 CcTest::global()->Set(v8_str("obj2"), obj2); |
| 3559 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); | 3559 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); |
| 3560 Handle<JSFunction> f = v8::Utils::OpenHandle( | 3560 Handle<JSFunction> f = v8::Utils::OpenHandle( |
| 3561 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | 3561 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); |
| 3562 | 3562 |
| 3563 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 3563 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
| 3564 CheckVectorIC(f, 0, POLYMORPHIC); | 3564 CheckVectorIC(f, 1, POLYMORPHIC); |
| 3565 CHECK(ic_before->ic_state() == DEFAULT); | 3565 CHECK(ic_before->ic_state() == DEFAULT); |
| 3566 | 3566 |
| 3567 // Fire context dispose notification. | 3567 // Fire context dispose notification. |
| 3568 CcTest::isolate()->ContextDisposedNotification(); | 3568 CcTest::isolate()->ContextDisposedNotification(); |
| 3569 SimulateIncrementalMarking(CcTest::heap()); | 3569 SimulateIncrementalMarking(CcTest::heap()); |
| 3570 CcTest::heap()->CollectAllGarbage(); | 3570 CcTest::heap()->CollectAllGarbage(); |
| 3571 | 3571 |
| 3572 CheckVectorICCleared(f, 0); | 3572 CheckVectorICCleared(f, 1); |
| 3573 CHECK(ic_before->ic_state() == DEFAULT); | 3573 CHECK(ic_before->ic_state() == DEFAULT); |
| 3574 } | 3574 } |
| 3575 | 3575 |
| 3576 | 3576 |
| 3577 class SourceResource : public v8::String::ExternalOneByteStringResource { | 3577 class SourceResource : public v8::String::ExternalOneByteStringResource { |
| 3578 public: | 3578 public: |
| 3579 explicit SourceResource(const char* data) | 3579 explicit SourceResource(const char* data) |
| 3580 : data_(data), length_(strlen(data)) { } | 3580 : data_(data), length_(strlen(data)) { } |
| 3581 | 3581 |
| 3582 virtual void Dispose() { | 3582 virtual void Dispose() { |
| (...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4712 " loadIC(obj);" | 4712 " loadIC(obj);" |
| 4713 " loadIC(obj);" | 4713 " loadIC(obj);" |
| 4714 " return proto;" | 4714 " return proto;" |
| 4715 "};"); | 4715 "};"); |
| 4716 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); | 4716 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); |
| 4717 { | 4717 { |
| 4718 v8::HandleScope scope(CcTest::isolate()); | 4718 v8::HandleScope scope(CcTest::isolate()); |
| 4719 CompileRun("(testIC())"); | 4719 CompileRun("(testIC())"); |
| 4720 } | 4720 } |
| 4721 heap->CollectAllGarbage(); | 4721 heap->CollectAllGarbage(); |
| 4722 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, MONOMORPHIC); | 4722 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 1, MONOMORPHIC); |
| 4723 { | 4723 { |
| 4724 v8::HandleScope scope(CcTest::isolate()); | 4724 v8::HandleScope scope(CcTest::isolate()); |
| 4725 CompileRun("(testIC())"); | 4725 CompileRun("(testIC())"); |
| 4726 } | 4726 } |
| 4727 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, MONOMORPHIC); | 4727 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 1, MONOMORPHIC); |
| 4728 } | 4728 } |
| 4729 | 4729 |
| 4730 | 4730 |
| 4731 TEST(PolymorphicStaysPolymorphicAfterGC) { | 4731 TEST(PolymorphicStaysPolymorphicAfterGC) { |
| 4732 if (FLAG_always_opt) return; | 4732 if (FLAG_always_opt) return; |
| 4733 CcTest::InitializeVM(); | 4733 CcTest::InitializeVM(); |
| 4734 Isolate* isolate = CcTest::i_isolate(); | 4734 Isolate* isolate = CcTest::i_isolate(); |
| 4735 Heap* heap = isolate->heap(); | 4735 Heap* heap = isolate->heap(); |
| 4736 v8::HandleScope scope(CcTest::isolate()); | 4736 v8::HandleScope scope(CcTest::isolate()); |
| 4737 CompileRun( | 4737 CompileRun( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4748 " poly.x = true;" | 4748 " poly.x = true;" |
| 4749 " loadIC(poly);" | 4749 " loadIC(poly);" |
| 4750 " return proto;" | 4750 " return proto;" |
| 4751 "};"); | 4751 "};"); |
| 4752 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); | 4752 Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC"); |
| 4753 { | 4753 { |
| 4754 v8::HandleScope scope(CcTest::isolate()); | 4754 v8::HandleScope scope(CcTest::isolate()); |
| 4755 CompileRun("(testIC())"); | 4755 CompileRun("(testIC())"); |
| 4756 } | 4756 } |
| 4757 heap->CollectAllGarbage(); | 4757 heap->CollectAllGarbage(); |
| 4758 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, POLYMORPHIC); | 4758 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 1, POLYMORPHIC); |
| 4759 { | 4759 { |
| 4760 v8::HandleScope scope(CcTest::isolate()); | 4760 v8::HandleScope scope(CcTest::isolate()); |
| 4761 CompileRun("(testIC())"); | 4761 CompileRun("(testIC())"); |
| 4762 } | 4762 } |
| 4763 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 0, POLYMORPHIC); | 4763 CheckIC(loadIC->code(), Code::LOAD_IC, loadIC->shared(), 1, POLYMORPHIC); |
| 4764 } | 4764 } |
| 4765 | 4765 |
| 4766 | 4766 |
| 4767 TEST(WeakCell) { | 4767 TEST(WeakCell) { |
| 4768 CcTest::InitializeVM(); | 4768 CcTest::InitializeVM(); |
| 4769 Isolate* isolate = CcTest::i_isolate(); | 4769 Isolate* isolate = CcTest::i_isolate(); |
| 4770 v8::internal::Heap* heap = CcTest::heap(); | 4770 v8::internal::Heap* heap = CcTest::heap(); |
| 4771 v8::internal::Factory* factory = isolate->factory(); | 4771 v8::internal::Factory* factory = isolate->factory(); |
| 4772 | 4772 |
| 4773 HandleScope outer_scope(isolate); | 4773 HandleScope outer_scope(isolate); |
| (...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5634 size_t counter2 = 2000; | 5634 size_t counter2 = 2000; |
| 5635 tracer->SampleAllocation(time2, counter2, counter2); | 5635 tracer->SampleAllocation(time2, counter2, counter2); |
| 5636 size_t throughput = tracer->AllocationThroughputInBytesPerMillisecond(100); | 5636 size_t throughput = tracer->AllocationThroughputInBytesPerMillisecond(100); |
| 5637 CHECK_EQ(2 * (counter2 - counter1) / (time2 - time1), throughput); | 5637 CHECK_EQ(2 * (counter2 - counter1) / (time2 - time1), throughput); |
| 5638 int time3 = 1000; | 5638 int time3 = 1000; |
| 5639 size_t counter3 = 30000; | 5639 size_t counter3 = 30000; |
| 5640 tracer->SampleAllocation(time3, counter3, counter3); | 5640 tracer->SampleAllocation(time3, counter3, counter3); |
| 5641 throughput = tracer->AllocationThroughputInBytesPerMillisecond(100); | 5641 throughput = tracer->AllocationThroughputInBytesPerMillisecond(100); |
| 5642 CHECK_EQ(2 * (counter3 - counter1) / (time3 - time1), throughput); | 5642 CHECK_EQ(2 * (counter3 - counter1) / (time3 - time1), throughput); |
| 5643 } | 5643 } |
| OLD | NEW |