| 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/debug.h" | 9 #include "src/debug/debug.h" |
| 10 #include "src/execution.h" | 10 #include "src/execution.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 | 23 |
| 24 TEST(VectorStructure) { | 24 TEST(VectorStructure) { |
| 25 LocalContext context; | 25 LocalContext context; |
| 26 v8::HandleScope scope(context->GetIsolate()); | 26 v8::HandleScope scope(context->GetIsolate()); |
| 27 Isolate* isolate = CcTest::i_isolate(); | 27 Isolate* isolate = CcTest::i_isolate(); |
| 28 Factory* factory = isolate->factory(); | 28 Factory* factory = isolate->factory(); |
| 29 Zone* zone = isolate->runtime_zone(); | 29 Zone* zone = isolate->runtime_zone(); |
| 30 | 30 |
| 31 // Empty vectors are the empty fixed array. | 31 // Empty vectors are the empty fixed array. |
| 32 FeedbackVectorSpec empty; | 32 StaticFeedbackVectorSpec empty; |
| 33 Handle<TypeFeedbackVector> vector = factory->NewTypeFeedbackVector(&empty); | 33 Handle<TypeFeedbackVector> vector = factory->NewTypeFeedbackVector(&empty); |
| 34 CHECK(Handle<FixedArray>::cast(vector) | 34 CHECK(Handle<FixedArray>::cast(vector) |
| 35 .is_identical_to(factory->empty_fixed_array())); | 35 .is_identical_to(factory->empty_fixed_array())); |
| 36 // Which can nonetheless be queried. | 36 // Which can nonetheless be queried. |
| 37 CHECK_EQ(0, vector->ic_with_type_info_count()); | 37 CHECK_EQ(0, vector->ic_with_type_info_count()); |
| 38 CHECK_EQ(0, vector->ic_generic_count()); | 38 CHECK_EQ(0, vector->ic_generic_count()); |
| 39 CHECK_EQ(0, vector->Slots()); | 39 CHECK_EQ(0, vector->Slots()); |
| 40 CHECK_EQ(0, vector->ICSlots()); | 40 CHECK_EQ(0, vector->ICSlots()); |
| 41 | 41 |
| 42 FeedbackVectorSpec one_slot(1); | 42 FeedbackVectorSpec one_slot(zone); |
| 43 one_slot.AddStubSlot(); |
| 43 vector = factory->NewTypeFeedbackVector(&one_slot); | 44 vector = factory->NewTypeFeedbackVector(&one_slot); |
| 44 CHECK_EQ(1, vector->Slots()); | 45 CHECK_EQ(1, vector->Slots()); |
| 45 CHECK_EQ(0, vector->ICSlots()); | 46 CHECK_EQ(0, vector->ICSlots()); |
| 46 | 47 |
| 47 ZoneFeedbackVectorSpec one_icslot(zone, 0, 1); | 48 FeedbackVectorSpec one_icslot(zone); |
| 48 one_icslot.SetKind(0, FeedbackVectorSlotKind::CALL_IC); | 49 one_icslot.AddSlot(FeedbackVectorSlotKind::CALL_IC); |
| 49 vector = factory->NewTypeFeedbackVector(&one_icslot); | 50 vector = factory->NewTypeFeedbackVector(&one_icslot); |
| 50 CHECK_EQ(0, vector->Slots()); | 51 CHECK_EQ(0, vector->Slots()); |
| 51 CHECK_EQ(1, vector->ICSlots()); | 52 CHECK_EQ(1, vector->ICSlots()); |
| 52 | 53 |
| 53 ZoneFeedbackVectorSpec spec(zone, 3, 5); | 54 FeedbackVectorSpec spec(zone); |
| 54 for (int i = 0; i < 5; i++) spec.SetKind(i, FeedbackVectorSlotKind::CALL_IC); | 55 spec.AddStubSlots(3); |
| 56 spec.AddSlots(FeedbackVectorSlotKind::CALL_IC, 5); |
| 55 vector = factory->NewTypeFeedbackVector(&spec); | 57 vector = factory->NewTypeFeedbackVector(&spec); |
| 56 CHECK_EQ(3, vector->Slots()); | 58 CHECK_EQ(3, vector->Slots()); |
| 57 CHECK_EQ(5, vector->ICSlots()); | 59 CHECK_EQ(5, vector->ICSlots()); |
| 58 | 60 |
| 59 int metadata_length = vector->ic_metadata_length(); | 61 int metadata_length = vector->ic_metadata_length(); |
| 60 CHECK(metadata_length > 0); | 62 CHECK(metadata_length > 0); |
| 61 | 63 |
| 62 int index = vector->GetIndex(FeedbackVectorSlot(0)); | 64 int index = vector->GetIndex(FeedbackVectorSlot(0)); |
| 63 | 65 |
| 64 CHECK_EQ(TypeFeedbackVector::kReservedIndexCount + metadata_length, index); | 66 CHECK_EQ(TypeFeedbackVector::kReservedIndexCount + metadata_length, index); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 75 | 77 |
| 76 | 78 |
| 77 // IC slots need an encoding to recognize what is in there. | 79 // IC slots need an encoding to recognize what is in there. |
| 78 TEST(VectorICMetadata) { | 80 TEST(VectorICMetadata) { |
| 79 LocalContext context; | 81 LocalContext context; |
| 80 v8::HandleScope scope(context->GetIsolate()); | 82 v8::HandleScope scope(context->GetIsolate()); |
| 81 Isolate* isolate = CcTest::i_isolate(); | 83 Isolate* isolate = CcTest::i_isolate(); |
| 82 Factory* factory = isolate->factory(); | 84 Factory* factory = isolate->factory(); |
| 83 Zone* zone = isolate->runtime_zone(); | 85 Zone* zone = isolate->runtime_zone(); |
| 84 | 86 |
| 85 ZoneFeedbackVectorSpec spec(zone, 10, 3 * 10); | 87 FeedbackVectorSpec spec(zone); |
| 86 // Set metadata. | 88 // Set metadata. |
| 89 spec.AddStubSlots(10); |
| 87 for (int i = 0; i < 30; i++) { | 90 for (int i = 0; i < 30; i++) { |
| 88 FeedbackVectorSlotKind kind; | 91 switch (i % 3) { |
| 89 if (i % 3 == 0) { | 92 case 0: |
| 90 kind = FeedbackVectorSlotKind::CALL_IC; | 93 spec.AddSlot(FeedbackVectorSlotKind::CALL_IC); |
| 91 } else if (i % 3 == 1) { | 94 break; |
| 92 kind = FeedbackVectorSlotKind::LOAD_IC; | 95 case 1: |
| 93 } else { | 96 spec.AddSlot(FeedbackVectorSlotKind::LOAD_IC); |
| 94 kind = FeedbackVectorSlotKind::KEYED_LOAD_IC; | 97 break; |
| 98 case 2: |
| 99 spec.AddSlot(FeedbackVectorSlotKind::KEYED_LOAD_IC); |
| 100 break; |
| 95 } | 101 } |
| 96 spec.SetKind(i, kind); | |
| 97 } | 102 } |
| 98 | 103 |
| 99 Handle<TypeFeedbackVector> vector = factory->NewTypeFeedbackVector(&spec); | 104 Handle<TypeFeedbackVector> vector = factory->NewTypeFeedbackVector(&spec); |
| 100 CHECK_EQ(10, vector->Slots()); | 105 CHECK_EQ(10, vector->Slots()); |
| 101 CHECK_EQ(3 * 10, vector->ICSlots()); | 106 CHECK_EQ(3 * 10, vector->ICSlots()); |
| 102 | 107 |
| 103 // Meanwhile set some feedback values and type feedback values to | 108 // Meanwhile set some feedback values and type feedback values to |
| 104 // verify the data structure remains intact. | 109 // verify the data structure remains intact. |
| 105 vector->change_ic_with_type_info_count(100); | 110 vector->change_ic_with_type_info_count(100); |
| 106 vector->change_ic_generic_count(3333); | 111 vector->change_ic_generic_count(3333); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 118 } | 123 } |
| 119 } | 124 } |
| 120 } | 125 } |
| 121 | 126 |
| 122 | 127 |
| 123 TEST(VectorSlotClearing) { | 128 TEST(VectorSlotClearing) { |
| 124 LocalContext context; | 129 LocalContext context; |
| 125 v8::HandleScope scope(context->GetIsolate()); | 130 v8::HandleScope scope(context->GetIsolate()); |
| 126 Isolate* isolate = CcTest::i_isolate(); | 131 Isolate* isolate = CcTest::i_isolate(); |
| 127 Factory* factory = isolate->factory(); | 132 Factory* factory = isolate->factory(); |
| 133 Zone* zone = isolate->runtime_zone(); |
| 128 | 134 |
| 129 // We only test clearing FeedbackVectorSlots, not FeedbackVectorICSlots. | 135 // We only test clearing FeedbackVectorSlots, not FeedbackVectorICSlots. |
| 130 // The reason is that FeedbackVectorICSlots need a full code environment | 136 // The reason is that FeedbackVectorICSlots need a full code environment |
| 131 // to fully test (See VectorICProfilerStatistics test below). | 137 // to fully test (See VectorICProfilerStatistics test below). |
| 132 FeedbackVectorSpec spec(5); | 138 FeedbackVectorSpec spec(zone); |
| 139 spec.AddStubSlots(5); |
| 133 Handle<TypeFeedbackVector> vector = factory->NewTypeFeedbackVector(&spec); | 140 Handle<TypeFeedbackVector> vector = factory->NewTypeFeedbackVector(&spec); |
| 134 | 141 |
| 135 // Fill with information | 142 // Fill with information |
| 136 vector->Set(FeedbackVectorSlot(0), Smi::FromInt(1)); | 143 vector->Set(FeedbackVectorSlot(0), Smi::FromInt(1)); |
| 137 Handle<WeakCell> cell = factory->NewWeakCell(factory->fixed_array_map()); | 144 Handle<WeakCell> cell = factory->NewWeakCell(factory->fixed_array_map()); |
| 138 vector->Set(FeedbackVectorSlot(1), *cell); | 145 vector->Set(FeedbackVectorSlot(1), *cell); |
| 139 Handle<AllocationSite> site = factory->NewAllocationSite(); | 146 Handle<AllocationSite> site = factory->NewAllocationSite(); |
| 140 vector->Set(FeedbackVectorSlot(2), *site); | 147 vector->Set(FeedbackVectorSlot(2), *site); |
| 141 | 148 |
| 142 // GC time clearing leaves slots alone. | 149 // GC time clearing leaves slots alone. |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 Handle<JSFunction> f = GetFunction("f"); | 553 Handle<JSFunction> f = GetFunction("f"); |
| 547 // There should be one IC slot. | 554 // There should be one IC slot. |
| 548 Handle<TypeFeedbackVector> feedback_vector = | 555 Handle<TypeFeedbackVector> feedback_vector = |
| 549 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); | 556 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); |
| 550 CHECK_EQ(1, feedback_vector->ICSlots()); | 557 CHECK_EQ(1, feedback_vector->ICSlots()); |
| 551 FeedbackVectorICSlot slot(0); | 558 FeedbackVectorICSlot slot(0); |
| 552 StoreICNexus nexus(feedback_vector, slot); | 559 StoreICNexus nexus(feedback_vector, slot); |
| 553 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); | 560 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); |
| 554 } | 561 } |
| 555 } | 562 } |
| OLD | NEW |