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

Side by Side Diff: test/cctest/test-transitions.cc

Issue 661133002: TransitionArray now uses <is_data_property, name, attributes> tuple as a key, which allows to have … (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments Created 6 years, 1 month 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 | Annotate | Revision Log
« src/transitions-inl.h ('K') | « test/cctest/cctest.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <stdlib.h>
6 #include <utility>
7
8 #include "src/v8.h"
9
10 #include "src/compilation-cache.h"
11 #include "src/execution.h"
12 #include "src/factory.h"
13 #include "src/global-handles.h"
14 #include "test/cctest/cctest.h"
15
16 using namespace v8::internal;
17
18
19 //
20 // Helper functions.
21 //
22
23 static void ConnectTransition(Handle<Map> parent,
24 Handle<TransitionArray> transitions,
25 Handle<Map> child) {
26 parent->set_transitions(*transitions);
27 child->SetBackPointer(*parent);
28 }
29
30
31 TEST(TransitionArray_SimpleFieldTransitions) {
32 CcTest::InitializeVM();
33 v8::HandleScope scope(CcTest::isolate());
34 Isolate* isolate = CcTest::i_isolate();
35 Factory* factory = isolate->factory();
36
37 Handle<String> name1 = factory->InternalizeUtf8String("foo");
38 Handle<String> name2 = factory->InternalizeUtf8String("bar");
39 PropertyAttributes attributes = NONE;
40
41 Handle<Map> map0 = Map::Create(isolate, 0);
42 Handle<Map> map1 =
43 Map::CopyWithField(map0, name1, handle(HeapType::Any(), isolate),
44 attributes, Representation::Tagged(),
45 OMIT_TRANSITION).ToHandleChecked();
46 Handle<Map> map2 =
47 Map::CopyWithField(map0, name2, handle(HeapType::Any(), isolate),
48 attributes, Representation::Tagged(),
49 OMIT_TRANSITION).ToHandleChecked();
50
51 CHECK(!map0->HasTransitionArray());
52 Handle<TransitionArray> transitions = TransitionArray::Allocate(isolate, 0);
53 CHECK(transitions->IsFullTransitionArray());
54
55 int transition;
56 transitions = transitions->CopyInsert(map0, name1, map1, SIMPLE_TRANSITION);
57 ConnectTransition(map0, transitions, map1);
58 CHECK(transitions->IsSimpleTransition());
59 transition = transitions->Search(FIELD, *name1, attributes);
60 CHECK_EQ(TransitionArray::kSimpleTransitionIndex, transition);
61 CHECK_EQ(*name1, transitions->GetKey(transition));
62 CHECK_EQ(*map1, transitions->GetTarget(transition));
63
64 transitions = transitions->CopyInsert(map0, name2, map2, SIMPLE_TRANSITION);
65 ConnectTransition(map0, transitions, map2);
66 CHECK(transitions->IsFullTransitionArray());
67
68 transition = transitions->Search(FIELD, *name1, attributes);
69 CHECK_EQ(*name1, transitions->GetKey(transition));
70 CHECK_EQ(*map1, transitions->GetTarget(transition));
71
72 transition = transitions->Search(FIELD, *name2, attributes);
73 CHECK_EQ(*name2, transitions->GetKey(transition));
74 CHECK_EQ(*map2, transitions->GetTarget(transition));
75 }
76
77
78 TEST(TransitionArray_FullFieldTransitions) {
79 CcTest::InitializeVM();
80 v8::HandleScope scope(CcTest::isolate());
81 Isolate* isolate = CcTest::i_isolate();
82 Factory* factory = isolate->factory();
83
84 Handle<String> name1 = factory->InternalizeUtf8String("foo");
85 Handle<String> name2 = factory->InternalizeUtf8String("bar");
86 PropertyAttributes attributes = NONE;
87
88 Handle<Map> map0 = Map::Create(isolate, 0);
89 Handle<Map> map1 =
90 Map::CopyWithField(map0, name1, handle(HeapType::Any(), isolate),
91 attributes, Representation::Tagged(),
92 OMIT_TRANSITION).ToHandleChecked();
93 Handle<Map> map2 =
94 Map::CopyWithField(map0, name2, handle(HeapType::Any(), isolate),
95 attributes, Representation::Tagged(),
96 OMIT_TRANSITION).ToHandleChecked();
97
98 CHECK(!map0->HasTransitionArray());
99 Handle<TransitionArray> transitions = TransitionArray::Allocate(isolate, 0);
100 CHECK(transitions->IsFullTransitionArray());
101
102 int transition;
103 transitions = transitions->CopyInsert(map0, name1, map1, FULL_TRANSITION);
104 ConnectTransition(map0, transitions, map1);
105 CHECK(transitions->IsFullTransitionArray());
106 transition = transitions->Search(FIELD, *name1, attributes);
107 CHECK_EQ(*name1, transitions->GetKey(transition));
108 CHECK_EQ(*map1, transitions->GetTarget(transition));
109
110 transitions = transitions->CopyInsert(map0, name2, map2, FULL_TRANSITION);
111 ConnectTransition(map0, transitions, map2);
112 CHECK(transitions->IsFullTransitionArray());
113
114 transition = transitions->Search(FIELD, *name1, attributes);
115 CHECK_EQ(*name1, transitions->GetKey(transition));
116 CHECK_EQ(*map1, transitions->GetTarget(transition));
117
118 transition = transitions->Search(FIELD, *name2, attributes);
119 CHECK_EQ(*name2, transitions->GetKey(transition));
120 CHECK_EQ(*map2, transitions->GetTarget(transition));
121 }
122
123
124 TEST(TransitionArray_DifferentFieldNames) {
125 CcTest::InitializeVM();
126 v8::HandleScope scope(CcTest::isolate());
127 Isolate* isolate = CcTest::i_isolate();
128 Factory* factory = isolate->factory();
129
130 const int PROPS_COUNT = 10;
131 Handle<String> names[PROPS_COUNT];
132 Handle<Map> maps[PROPS_COUNT];
133 PropertyAttributes attributes = NONE;
134
135 Handle<Map> map0 = Map::Create(isolate, 0);
136 CHECK(!map0->HasTransitionArray());
137 Handle<TransitionArray> transitions = TransitionArray::Allocate(isolate, 0);
138 CHECK(transitions->IsFullTransitionArray());
139
140 for (int i = 0; i < PROPS_COUNT; i++) {
141 EmbeddedVector<char, 64> buffer;
142 SNPrintF(buffer, "prop%d", i);
143 Handle<String> name = factory->InternalizeUtf8String(buffer.start());
144 Handle<Map> map =
145 Map::CopyWithField(map0, name, handle(HeapType::Any(), isolate),
146 attributes, Representation::Tagged(),
147 OMIT_TRANSITION).ToHandleChecked();
148 names[i] = name;
149 maps[i] = map;
150
151 transitions = transitions->CopyInsert(map0, name, map, FULL_TRANSITION);
152 ConnectTransition(map0, transitions, map);
153 }
154
155 for (int i = 0; i < PROPS_COUNT; i++) {
156 int transition = transitions->Search(FIELD, *names[i], attributes);
157 CHECK_EQ(*names[i], transitions->GetKey(transition));
158 CHECK_EQ(*maps[i], transitions->GetTarget(transition));
159 }
160 }
161
162
163 TEST(TransitionArray_SameFieldNamesDifferentAttributesSimple) {
164 CcTest::InitializeVM();
165 v8::HandleScope scope(CcTest::isolate());
166 Isolate* isolate = CcTest::i_isolate();
167 Factory* factory = isolate->factory();
168
169 Handle<Map> map0 = Map::Create(isolate, 0);
170 CHECK(!map0->HasTransitionArray());
171 Handle<TransitionArray> transitions = TransitionArray::Allocate(isolate, 0);
172 CHECK(transitions->IsFullTransitionArray());
173
174 const int ATTRS_COUNT = (READ_ONLY | DONT_ENUM | DONT_DELETE) + 1;
175 STATIC_ASSERT(ATTRS_COUNT == 8);
176 Handle<Map> attr_maps[ATTRS_COUNT];
177 Handle<String> name = factory->InternalizeUtf8String("foo");
178
179 // Add transitions for same field name but different attributes.
180 for (int i = 0; i < ATTRS_COUNT; i++) {
181 PropertyAttributes attributes = static_cast<PropertyAttributes>(i);
182
183 Handle<Map> map =
184 Map::CopyWithField(map0, name, handle(HeapType::Any(), isolate),
185 attributes, Representation::Tagged(),
186 OMIT_TRANSITION).ToHandleChecked();
187 attr_maps[i] = map;
188
189 transitions = transitions->CopyInsert(map0, name, map, FULL_TRANSITION);
190 ConnectTransition(map0, transitions, map);
191 }
192
193 // Ensure that transitions for |name| field are valid.
194 for (int i = 0; i < ATTRS_COUNT; i++) {
195 PropertyAttributes attributes = static_cast<PropertyAttributes>(i);
196
197 int transition = transitions->Search(FIELD, *name, attributes);
198 CHECK_EQ(*name, transitions->GetKey(transition));
199 CHECK_EQ(*attr_maps[i], transitions->GetTarget(transition));
200 }
201 }
202
203
204 TEST(TransitionArray_SameFieldNamesDifferentAttributes) {
205 CcTest::InitializeVM();
206 v8::HandleScope scope(CcTest::isolate());
207 Isolate* isolate = CcTest::i_isolate();
208 Factory* factory = isolate->factory();
209
210 const int PROPS_COUNT = 10;
211 Handle<String> names[PROPS_COUNT];
212 Handle<Map> maps[PROPS_COUNT];
213
214 Handle<Map> map0 = Map::Create(isolate, 0);
215 CHECK(!map0->HasTransitionArray());
216 Handle<TransitionArray> transitions = TransitionArray::Allocate(isolate, 0);
217 CHECK(transitions->IsFullTransitionArray());
218
219 // Some number of fields.
220 for (int i = 0; i < PROPS_COUNT; i++) {
221 EmbeddedVector<char, 64> buffer;
222 SNPrintF(buffer, "prop%d", i);
223 Handle<String> name = factory->InternalizeUtf8String(buffer.start());
224 Handle<Map> map =
225 Map::CopyWithField(map0, name, handle(HeapType::Any(), isolate), NONE,
226 Representation::Tagged(),
227 OMIT_TRANSITION).ToHandleChecked();
228 names[i] = name;
229 maps[i] = map;
230
231 transitions = transitions->CopyInsert(map0, name, map, FULL_TRANSITION);
232 ConnectTransition(map0, transitions, map);
233 }
234
235 const int ATTRS_COUNT = (READ_ONLY | DONT_ENUM | DONT_DELETE) + 1;
236 STATIC_ASSERT(ATTRS_COUNT == 8);
237 Handle<Map> attr_maps[ATTRS_COUNT];
238 Handle<String> name = factory->InternalizeUtf8String("foo");
239
240 // Add transitions for same field name but different attributes.
241 for (int i = 0; i < ATTRS_COUNT; i++) {
242 PropertyAttributes attributes = static_cast<PropertyAttributes>(i);
243
244 Handle<Map> map =
245 Map::CopyWithField(map0, name, handle(HeapType::Any(), isolate),
246 attributes, Representation::Tagged(),
247 OMIT_TRANSITION).ToHandleChecked();
248 attr_maps[i] = map;
249
250 transitions = transitions->CopyInsert(map0, name, map, FULL_TRANSITION);
251 ConnectTransition(map0, transitions, map);
252 }
253
254 // Ensure that transitions for |name| field are valid.
255 for (int i = 0; i < ATTRS_COUNT; i++) {
256 PropertyAttributes attributes = static_cast<PropertyAttributes>(i);
257
258 int transition = transitions->Search(FIELD, *name, attributes);
259 CHECK_EQ(*name, transitions->GetKey(transition));
260 CHECK_EQ(*attr_maps[i], transitions->GetTarget(transition));
261 }
262
263 // Ensure that info about the other fields still valid.
264 for (int i = 0; i < PROPS_COUNT; i++) {
265 int transition = transitions->Search(FIELD, *names[i], NONE);
266 CHECK_EQ(*names[i], transitions->GetKey(transition));
267 CHECK_EQ(*maps[i], transitions->GetTarget(transition));
268 }
269 }
OLDNEW
« src/transitions-inl.h ('K') | « test/cctest/cctest.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698