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.h" | 9 #include "src/debug.h" |
10 #include "src/execution.h" | 10 #include "src/execution.h" |
11 #include "src/factory.h" | 11 #include "src/factory.h" |
12 #include "src/global-handles.h" | 12 #include "src/global-handles.h" |
13 #include "src/macro-assembler.h" | 13 #include "src/macro-assembler.h" |
14 #include "src/objects.h" | 14 #include "src/objects.h" |
15 | 15 |
16 using namespace v8::internal; | 16 using namespace v8::internal; |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 TEST(VectorStructure) { | 20 TEST(VectorStructure) { |
21 LocalContext context; | 21 LocalContext context; |
22 v8::HandleScope scope(context->GetIsolate()); | 22 v8::HandleScope scope(context->GetIsolate()); |
23 Isolate* isolate = CcTest::i_isolate(); | 23 Isolate* isolate = CcTest::i_isolate(); |
24 Factory* factory = isolate->factory(); | 24 Factory* factory = isolate->factory(); |
| 25 Zone* zone = isolate->runtime_zone(); |
25 | 26 |
26 // Empty vectors are the empty fixed array. | 27 // Empty vectors are the empty fixed array. |
27 FeedbackVectorSpec empty; | 28 FeedbackVectorSpec empty; |
28 Handle<TypeFeedbackVector> vector = factory->NewTypeFeedbackVector(empty); | 29 Handle<TypeFeedbackVector> vector = factory->NewTypeFeedbackVector(&empty); |
29 CHECK(Handle<FixedArray>::cast(vector) | 30 CHECK(Handle<FixedArray>::cast(vector) |
30 .is_identical_to(factory->empty_fixed_array())); | 31 .is_identical_to(factory->empty_fixed_array())); |
31 // Which can nonetheless be queried. | 32 // Which can nonetheless be queried. |
32 CHECK_EQ(0, vector->ic_with_type_info_count()); | 33 CHECK_EQ(0, vector->ic_with_type_info_count()); |
33 CHECK_EQ(0, vector->ic_generic_count()); | 34 CHECK_EQ(0, vector->ic_generic_count()); |
34 CHECK_EQ(0, vector->Slots()); | 35 CHECK_EQ(0, vector->Slots()); |
35 CHECK_EQ(0, vector->ICSlots()); | 36 CHECK_EQ(0, vector->ICSlots()); |
36 | 37 |
37 FeedbackVectorSpec one_slot(1, 0); | 38 FeedbackVectorSpec one_slot(1); |
38 vector = factory->NewTypeFeedbackVector(one_slot); | 39 vector = factory->NewTypeFeedbackVector(&one_slot); |
39 CHECK_EQ(1, vector->Slots()); | 40 CHECK_EQ(1, vector->Slots()); |
40 CHECK_EQ(0, vector->ICSlots()); | 41 CHECK_EQ(0, vector->ICSlots()); |
41 | 42 |
42 FeedbackVectorSpec one_icslot(0, 1); | 43 FeedbackVectorSpec one_icslot(0, Code::CALL_IC); |
43 if (FLAG_vector_ics) { | 44 vector = factory->NewTypeFeedbackVector(&one_icslot); |
44 one_icslot.SetKind(0, Code::CALL_IC); | |
45 } | |
46 vector = factory->NewTypeFeedbackVector(one_icslot); | |
47 CHECK_EQ(0, vector->Slots()); | 45 CHECK_EQ(0, vector->Slots()); |
48 CHECK_EQ(1, vector->ICSlots()); | 46 CHECK_EQ(1, vector->ICSlots()); |
49 | 47 |
50 FeedbackVectorSpec spec(3, 5); | 48 ZoneFeedbackVectorSpec spec(zone, 3, 5); |
51 if (FLAG_vector_ics) { | 49 if (FLAG_vector_ics) { |
52 for (int i = 0; i < 5; i++) spec.SetKind(i, Code::CALL_IC); | 50 for (int i = 0; i < 5; i++) spec.SetKind(i, Code::CALL_IC); |
53 } | 51 } |
54 vector = factory->NewTypeFeedbackVector(spec); | 52 vector = factory->NewTypeFeedbackVector(&spec); |
55 CHECK_EQ(3, vector->Slots()); | 53 CHECK_EQ(3, vector->Slots()); |
56 CHECK_EQ(5, vector->ICSlots()); | 54 CHECK_EQ(5, vector->ICSlots()); |
57 | 55 |
58 int metadata_length = vector->ic_metadata_length(); | 56 int metadata_length = vector->ic_metadata_length(); |
59 if (!FLAG_vector_ics) { | 57 if (!FLAG_vector_ics) { |
60 CHECK_EQ(0, metadata_length); | 58 CHECK_EQ(0, metadata_length); |
61 } else { | 59 } else { |
62 CHECK(metadata_length > 0); | 60 CHECK(metadata_length > 0); |
63 } | 61 } |
64 | 62 |
(...skipping 16 matching lines...) Expand all Loading... |
81 TEST(VectorICMetadata) { | 79 TEST(VectorICMetadata) { |
82 LocalContext context; | 80 LocalContext context; |
83 v8::HandleScope scope(context->GetIsolate()); | 81 v8::HandleScope scope(context->GetIsolate()); |
84 if (!FLAG_vector_ics) { | 82 if (!FLAG_vector_ics) { |
85 // If FLAG_vector_ics is false, we only store CALL_ICs in the vector, so | 83 // If FLAG_vector_ics is false, we only store CALL_ICs in the vector, so |
86 // there is no need for metadata to describe the slots. | 84 // there is no need for metadata to describe the slots. |
87 return; | 85 return; |
88 } | 86 } |
89 Isolate* isolate = CcTest::i_isolate(); | 87 Isolate* isolate = CcTest::i_isolate(); |
90 Factory* factory = isolate->factory(); | 88 Factory* factory = isolate->factory(); |
| 89 Zone* zone = isolate->runtime_zone(); |
91 | 90 |
92 FeedbackVectorSpec spec(10, 3 * 10); | 91 ZoneFeedbackVectorSpec spec(zone, 10, 3 * 10); |
93 // Set metadata. | 92 // Set metadata. |
94 for (int i = 0; i < 30; i++) { | 93 for (int i = 0; i < 30; i++) { |
95 Code::Kind kind; | 94 Code::Kind kind; |
96 if (i % 3 == 0) { | 95 if (i % 3 == 0) { |
97 kind = Code::CALL_IC; | 96 kind = Code::CALL_IC; |
98 } else if (i % 3 == 1) { | 97 } else if (i % 3 == 1) { |
99 kind = Code::LOAD_IC; | 98 kind = Code::LOAD_IC; |
100 } else { | 99 } else { |
101 kind = Code::KEYED_LOAD_IC; | 100 kind = Code::KEYED_LOAD_IC; |
102 } | 101 } |
103 spec.SetKind(i, kind); | 102 spec.SetKind(i, kind); |
104 } | 103 } |
105 | 104 |
106 Handle<TypeFeedbackVector> vector = factory->NewTypeFeedbackVector(spec); | 105 Handle<TypeFeedbackVector> vector = factory->NewTypeFeedbackVector(&spec); |
107 CHECK_EQ(10, vector->Slots()); | 106 CHECK_EQ(10, vector->Slots()); |
108 CHECK_EQ(3 * 10, vector->ICSlots()); | 107 CHECK_EQ(3 * 10, vector->ICSlots()); |
109 | 108 |
110 // Meanwhile set some feedback values and type feedback values to | 109 // Meanwhile set some feedback values and type feedback values to |
111 // verify the data structure remains intact. | 110 // verify the data structure remains intact. |
112 vector->change_ic_with_type_info_count(100); | 111 vector->change_ic_with_type_info_count(100); |
113 vector->change_ic_generic_count(3333); | 112 vector->change_ic_generic_count(3333); |
114 vector->Set(FeedbackVectorSlot(0), *vector); | 113 vector->Set(FeedbackVectorSlot(0), *vector); |
115 | 114 |
116 // Verify the metadata is correctly set up from the spec. | 115 // Verify the metadata is correctly set up from the spec. |
(...skipping 12 matching lines...) Expand all Loading... |
129 | 128 |
130 TEST(VectorSlotClearing) { | 129 TEST(VectorSlotClearing) { |
131 LocalContext context; | 130 LocalContext context; |
132 v8::HandleScope scope(context->GetIsolate()); | 131 v8::HandleScope scope(context->GetIsolate()); |
133 Isolate* isolate = CcTest::i_isolate(); | 132 Isolate* isolate = CcTest::i_isolate(); |
134 Factory* factory = isolate->factory(); | 133 Factory* factory = isolate->factory(); |
135 | 134 |
136 // We only test clearing FeedbackVectorSlots, not FeedbackVectorICSlots. | 135 // We only test clearing FeedbackVectorSlots, not FeedbackVectorICSlots. |
137 // The reason is that FeedbackVectorICSlots need a full code environment | 136 // The reason is that FeedbackVectorICSlots need a full code environment |
138 // to fully test (See VectorICProfilerStatistics test below). | 137 // to fully test (See VectorICProfilerStatistics test below). |
139 FeedbackVectorSpec spec(5, 0); | 138 FeedbackVectorSpec spec(5); |
140 Handle<TypeFeedbackVector> vector = factory->NewTypeFeedbackVector(spec); | 139 Handle<TypeFeedbackVector> vector = factory->NewTypeFeedbackVector(&spec); |
141 | 140 |
142 // Fill with information | 141 // Fill with information |
143 vector->Set(FeedbackVectorSlot(0), Smi::FromInt(1)); | 142 vector->Set(FeedbackVectorSlot(0), Smi::FromInt(1)); |
144 vector->Set(FeedbackVectorSlot(1), *factory->fixed_array_map()); | 143 vector->Set(FeedbackVectorSlot(1), *factory->fixed_array_map()); |
145 Handle<AllocationSite> site = factory->NewAllocationSite(); | 144 Handle<AllocationSite> site = factory->NewAllocationSite(); |
146 vector->Set(FeedbackVectorSlot(2), *site); | 145 vector->Set(FeedbackVectorSlot(2), *site); |
147 | 146 |
148 vector->ClearSlots(NULL); | 147 vector->ClearSlots(NULL); |
149 | 148 |
150 // The feedback vector slots are cleared. AllocationSites are granted | 149 // The feedback vector slots are cleared. AllocationSites are granted |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 CHECK(number_map_found && o_map_found); | 384 CHECK(number_map_found && o_map_found); |
386 | 385 |
387 // The degree of polymorphism doesn't change. | 386 // The degree of polymorphism doesn't change. |
388 CompileRun("f(100)"); | 387 CompileRun("f(100)"); |
389 CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback()); | 388 CHECK_EQ(POLYMORPHIC, nexus.StateFromFeedback()); |
390 MapHandleList maps2; | 389 MapHandleList maps2; |
391 nexus.FindAllMaps(&maps2); | 390 nexus.FindAllMaps(&maps2); |
392 CHECK_EQ(2, maps2.length()); | 391 CHECK_EQ(2, maps2.length()); |
393 } | 392 } |
394 } | 393 } |
OLD | NEW |