OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2011 the V8 project authors. All rights reserved. | |
Jakob Kummerow
2014/10/14 15:27:20
nit: 2014, and use the short license header please
mvstanton
2014/10/16 10:54:15
Done.
| |
2 // Redistribution and use in source and binary forms, with or without | |
3 // modification, are permitted provided that the following conditions are | |
4 // met: | |
5 // | |
6 // * Redistributions of source code must retain the above copyright | |
7 // notice, this list of conditions and the following disclaimer. | |
8 // * Redistributions in binary form must reproduce the above | |
9 // copyright notice, this list of conditions and the following | |
10 // disclaimer in the documentation and/or other materials provided | |
11 // with the distribution. | |
12 // * Neither the name of Google Inc. nor the names of its | |
13 // contributors may be used to endorse or promote products derived | |
14 // from this software without specific prior written permission. | |
15 // | |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | |
28 #include "src/v8.h" | |
29 #include "test/cctest/cctest.h" | |
30 | |
31 #include "src/api.h" | |
32 #include "src/debug.h" | |
33 #include "src/execution.h" | |
34 #include "src/factory.h" | |
35 #include "src/global-handles.h" | |
36 #include "src/macro-assembler.h" | |
37 #include "src/objects.h" | |
38 | |
39 using namespace v8::internal; | |
40 | |
41 namespace { | |
42 | |
43 TEST(VectorStructure) { | |
44 LocalContext context; | |
45 v8::HandleScope scope(context->GetIsolate()); | |
46 Isolate* isolate = CcTest::i_isolate(); | |
47 Factory* factory = isolate->factory(); | |
48 | |
49 // Empty vectors are the empty fixed array. | |
50 Handle<TypeFeedbackVector> vector = factory->NewTypeFeedbackVector(0, 0); | |
51 CHECK(Handle<FixedArray>::cast(vector) | |
52 .is_identical_to(factory->empty_fixed_array())); | |
53 // Which can nonetheless be queried. | |
54 CHECK_EQ(0, vector->ic_with_type_info_count()); | |
55 CHECK_EQ(0, vector->ic_generic_count()); | |
56 CHECK_EQ(0, vector->Slots()); | |
57 CHECK_EQ(0, vector->ICSlots()); | |
58 | |
59 vector = factory->NewTypeFeedbackVector(1, 0); | |
60 CHECK_EQ(1, vector->Slots()); | |
61 CHECK_EQ(0, vector->ICSlots()); | |
62 | |
63 vector = factory->NewTypeFeedbackVector(0, 1); | |
64 CHECK_EQ(0, vector->Slots()); | |
65 CHECK_EQ(1, vector->ICSlots()); | |
66 | |
67 vector = factory->NewTypeFeedbackVector(3, 5); | |
68 CHECK_EQ(3, vector->Slots()); | |
69 CHECK_EQ(5, vector->ICSlots()); | |
70 | |
71 int index = vector->GetIndex(FeedbackVectorSlot(0)); | |
72 CHECK_EQ(index, TypeFeedbackVector::kReservedIndexCount); | |
Jakob Kummerow
2014/10/14 15:27:20
nit: order is "expected, actual".
mvstanton
2014/10/16 10:54:15
Done.
| |
73 CHECK(FeedbackVectorSlot(0) == vector->ToSlot(index)); | |
74 | |
75 index = vector->GetIndex(FeedbackVectorICSlot(0)); | |
76 CHECK_EQ(index, TypeFeedbackVector::kReservedIndexCount + 3); | |
77 CHECK(FeedbackVectorICSlot(0) == vector->ToICSlot(index)); | |
78 | |
79 CHECK_EQ(TypeFeedbackVector::kReservedIndexCount + 3 + 5, vector->length()); | |
80 } | |
81 | |
82 | |
83 TEST(VectorClearing) { | |
84 LocalContext context; | |
85 v8::HandleScope scope(context->GetIsolate()); | |
86 Isolate* isolate = CcTest::i_isolate(); | |
87 Factory* factory = isolate->factory(); | |
88 | |
89 // Empty vectors are the empty fixed array. | |
Jakob Kummerow
2014/10/14 15:27:20
comment out of place?
mvstanton
2014/10/16 10:54:15
Done.
| |
90 Handle<TypeFeedbackVector> vector = factory->NewTypeFeedbackVector(5, 1); | |
91 | |
92 // Fill with information | |
93 vector->Set(FeedbackVectorSlot(0), Smi::FromInt(1)); | |
94 vector->Set(FeedbackVectorSlot(1), *factory->fixed_array_map()); | |
95 vector->Set(FeedbackVectorSlot(2), *factory->NewAllocationSite()); | |
96 | |
97 vector->Set(FeedbackVectorICSlot(0), *factory->fixed_array_map()); | |
98 | |
99 vector->ClearSlots(); | |
100 | |
101 // The feedback vector slots are cleared. The ic slots are not. | |
102 // AllocationSites are granted an exemption from clearing, as are | |
103 // smis. | |
104 CHECK_EQ(vector->Get(FeedbackVectorSlot(0)), Smi::FromInt(1)); | |
Jakob Kummerow
2014/10/14 15:27:20
nit: order is "expected, actual" (again below).
mvstanton
2014/10/16 10:54:15
Done.
mvstanton
2014/10/16 10:54:16
Done.
| |
105 CHECK_EQ(vector->Get(FeedbackVectorSlot(1)), | |
106 *TypeFeedbackVector::UninitializedSentinel(isolate)); | |
107 CHECK(vector->Get(FeedbackVectorSlot(2))->IsAllocationSite()); | |
108 | |
109 CHECK_EQ(vector->Get(FeedbackVectorICSlot(0)), *factory->fixed_array_map()); | |
110 } | |
111 | |
112 | |
113 TEST(VectorICProfilerStatistics) { | |
114 if (i::FLAG_always_opt) return; | |
115 CcTest::InitializeVM(); | |
116 LocalContext context; | |
117 v8::HandleScope scope(context->GetIsolate()); | |
118 Isolate* isolate = CcTest::i_isolate(); | |
119 Heap* heap = isolate->heap(); | |
120 | |
121 // Make sure function f has a call that uses a type feedback slot. | |
122 CompileRun( | |
123 "function fun() {};" | |
124 "function f(a) { a(); } f(fun);"); | |
125 Handle<JSFunction> f = v8::Utils::OpenHandle( | |
126 *v8::Handle<v8::Function>::Cast(CcTest::global()->Get(v8_str("f")))); | |
127 // There should be one IC. | |
128 Code* code = f->shared()->code(); | |
129 TypeFeedbackInfo* feedback_info = | |
130 TypeFeedbackInfo::cast(code->type_feedback_info()); | |
131 CHECK_EQ(1, feedback_info->ic_total_count()); | |
132 CHECK_EQ(0, feedback_info->ic_with_type_info_count()); | |
133 CHECK_EQ(0, feedback_info->ic_generic_count()); | |
134 TypeFeedbackVector* feedback_vector = f->shared()->feedback_vector(); | |
135 CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); | |
136 CHECK_EQ(0, feedback_vector->ic_generic_count()); | |
137 | |
138 // Now send the information generic. | |
139 CompileRun("f(Object);"); | |
140 feedback_vector = f->shared()->feedback_vector(); | |
141 CHECK_EQ(0, feedback_vector->ic_with_type_info_count()); | |
142 CHECK_EQ(1, feedback_vector->ic_generic_count()); | |
143 | |
144 // A collection will make the site uninitialized again. | |
145 heap->CollectAllGarbage(i::Heap::kNoGCFlags); | |
146 feedback_vector = f->shared()->feedback_vector(); | |
147 CHECK_EQ(0, feedback_vector->ic_with_type_info_count()); | |
148 CHECK_EQ(0, feedback_vector->ic_generic_count()); | |
149 | |
150 // The Array function is special. A call to array remains monomorphic | |
151 // and isn't cleared by gc because an AllocationSite is being held. | |
152 CompileRun("f(Array);"); | |
153 feedback_vector = f->shared()->feedback_vector(); | |
154 CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); | |
155 CHECK_EQ(0, feedback_vector->ic_generic_count()); | |
156 | |
157 CHECK(feedback_vector->Get(FeedbackVectorICSlot(0))->IsAllocationSite()); | |
158 heap->CollectAllGarbage(i::Heap::kNoGCFlags); | |
159 feedback_vector = f->shared()->feedback_vector(); | |
160 CHECK_EQ(1, feedback_vector->ic_with_type_info_count()); | |
161 CHECK_EQ(0, feedback_vector->ic_generic_count()); | |
162 CHECK(feedback_vector->Get(FeedbackVectorICSlot(0))->IsAllocationSite()); | |
163 } | |
164 } | |
OLD | NEW |