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

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

Issue 1636013002: Replace HeapType with a non-templated FieldType class. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix tracing of generalizations Created 4 years, 11 months 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
OLDNEW
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 <stdlib.h> 5 #include <stdlib.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/compilation-cache.h" 10 #include "src/compilation-cache.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 v8::HandleScope scope(CcTest::isolate()); 44 v8::HandleScope scope(CcTest::isolate());
45 Isolate* isolate = CcTest::i_isolate(); 45 Isolate* isolate = CcTest::i_isolate();
46 Factory* factory = isolate->factory(); 46 Factory* factory = isolate->factory();
47 47
48 Handle<String> name1 = factory->InternalizeUtf8String("foo"); 48 Handle<String> name1 = factory->InternalizeUtf8String("foo");
49 Handle<String> name2 = factory->InternalizeUtf8String("bar"); 49 Handle<String> name2 = factory->InternalizeUtf8String("bar");
50 PropertyAttributes attributes = NONE; 50 PropertyAttributes attributes = NONE;
51 51
52 Handle<Map> map0 = Map::Create(isolate, 0); 52 Handle<Map> map0 = Map::Create(isolate, 0);
53 Handle<Map> map1 = 53 Handle<Map> map1 =
54 Map::CopyWithField(map0, name1, handle(HeapType::Any(), isolate), 54 Map::CopyWithField(map0, name1, handle(FieldType::Any(), isolate),
55 attributes, Representation::Tagged(), 55 attributes, Representation::Tagged(), OMIT_TRANSITION)
56 OMIT_TRANSITION).ToHandleChecked(); 56 .ToHandleChecked();
57 Handle<Map> map2 = 57 Handle<Map> map2 =
58 Map::CopyWithField(map0, name2, handle(HeapType::Any(), isolate), 58 Map::CopyWithField(map0, name2, handle(FieldType::Any(), isolate),
59 attributes, Representation::Tagged(), 59 attributes, Representation::Tagged(), OMIT_TRANSITION)
60 OMIT_TRANSITION).ToHandleChecked(); 60 .ToHandleChecked();
61 61
62 CHECK(map0->raw_transitions()->IsSmi()); 62 CHECK(map0->raw_transitions()->IsSmi());
63 63
64 TransitionArray::Insert(map0, name1, map1, SIMPLE_PROPERTY_TRANSITION); 64 TransitionArray::Insert(map0, name1, map1, SIMPLE_PROPERTY_TRANSITION);
65 CHECK(TransitionArray::IsSimpleTransition(map0->raw_transitions())); 65 CHECK(TransitionArray::IsSimpleTransition(map0->raw_transitions()));
66 CHECK_EQ(*map1, 66 CHECK_EQ(*map1,
67 TransitionArray::SearchTransition(*map0, kData, *name1, attributes)); 67 TransitionArray::SearchTransition(*map0, kData, *name1, attributes));
68 CHECK_EQ(1, TransitionArray::NumberOfTransitions(map0->raw_transitions())); 68 CHECK_EQ(1, TransitionArray::NumberOfTransitions(map0->raw_transitions()));
69 CHECK_EQ(*name1, TransitionArray::GetKey(map0->raw_transitions(), 0)); 69 CHECK_EQ(*name1, TransitionArray::GetKey(map0->raw_transitions(), 0));
70 CHECK_EQ(*map1, TransitionArray::GetTarget(map0->raw_transitions(), 0)); 70 CHECK_EQ(*map1, TransitionArray::GetTarget(map0->raw_transitions(), 0));
(...skipping 24 matching lines...) Expand all
95 v8::HandleScope scope(CcTest::isolate()); 95 v8::HandleScope scope(CcTest::isolate());
96 Isolate* isolate = CcTest::i_isolate(); 96 Isolate* isolate = CcTest::i_isolate();
97 Factory* factory = isolate->factory(); 97 Factory* factory = isolate->factory();
98 98
99 Handle<String> name1 = factory->InternalizeUtf8String("foo"); 99 Handle<String> name1 = factory->InternalizeUtf8String("foo");
100 Handle<String> name2 = factory->InternalizeUtf8String("bar"); 100 Handle<String> name2 = factory->InternalizeUtf8String("bar");
101 PropertyAttributes attributes = NONE; 101 PropertyAttributes attributes = NONE;
102 102
103 Handle<Map> map0 = Map::Create(isolate, 0); 103 Handle<Map> map0 = Map::Create(isolate, 0);
104 Handle<Map> map1 = 104 Handle<Map> map1 =
105 Map::CopyWithField(map0, name1, handle(HeapType::Any(), isolate), 105 Map::CopyWithField(map0, name1, handle(FieldType::Any(), isolate),
106 attributes, Representation::Tagged(), 106 attributes, Representation::Tagged(), OMIT_TRANSITION)
107 OMIT_TRANSITION).ToHandleChecked(); 107 .ToHandleChecked();
108 Handle<Map> map2 = 108 Handle<Map> map2 =
109 Map::CopyWithField(map0, name2, handle(HeapType::Any(), isolate), 109 Map::CopyWithField(map0, name2, handle(FieldType::Any(), isolate),
110 attributes, Representation::Tagged(), 110 attributes, Representation::Tagged(), OMIT_TRANSITION)
111 OMIT_TRANSITION).ToHandleChecked(); 111 .ToHandleChecked();
112 112
113 CHECK(map0->raw_transitions()->IsSmi()); 113 CHECK(map0->raw_transitions()->IsSmi());
114 114
115 TransitionArray::Insert(map0, name1, map1, PROPERTY_TRANSITION); 115 TransitionArray::Insert(map0, name1, map1, PROPERTY_TRANSITION);
116 CHECK(TransitionArray::IsFullTransitionArray(map0->raw_transitions())); 116 CHECK(TransitionArray::IsFullTransitionArray(map0->raw_transitions()));
117 CHECK_EQ(*map1, 117 CHECK_EQ(*map1,
118 TransitionArray::SearchTransition(*map0, kData, *name1, attributes)); 118 TransitionArray::SearchTransition(*map0, kData, *name1, attributes));
119 CHECK_EQ(1, TransitionArray::NumberOfTransitions(map0->raw_transitions())); 119 CHECK_EQ(1, TransitionArray::NumberOfTransitions(map0->raw_transitions()));
120 CHECK_EQ(*name1, TransitionArray::GetKey(map0->raw_transitions(), 0)); 120 CHECK_EQ(*name1, TransitionArray::GetKey(map0->raw_transitions(), 0));
121 CHECK_EQ(*map1, TransitionArray::GetTarget(map0->raw_transitions(), 0)); 121 CHECK_EQ(*map1, TransitionArray::GetTarget(map0->raw_transitions(), 0));
(...skipping 30 matching lines...) Expand all
152 Handle<Map> maps[PROPS_COUNT]; 152 Handle<Map> maps[PROPS_COUNT];
153 PropertyAttributes attributes = NONE; 153 PropertyAttributes attributes = NONE;
154 154
155 Handle<Map> map0 = Map::Create(isolate, 0); 155 Handle<Map> map0 = Map::Create(isolate, 0);
156 CHECK(map0->raw_transitions()->IsSmi()); 156 CHECK(map0->raw_transitions()->IsSmi());
157 157
158 for (int i = 0; i < PROPS_COUNT; i++) { 158 for (int i = 0; i < PROPS_COUNT; i++) {
159 EmbeddedVector<char, 64> buffer; 159 EmbeddedVector<char, 64> buffer;
160 SNPrintF(buffer, "prop%d", i); 160 SNPrintF(buffer, "prop%d", i);
161 Handle<String> name = factory->InternalizeUtf8String(buffer.start()); 161 Handle<String> name = factory->InternalizeUtf8String(buffer.start());
162 Handle<Map> map = 162 Handle<Map> map = Map::CopyWithField(
163 Map::CopyWithField(map0, name, handle(HeapType::Any(), isolate), 163 map0, name, handle(FieldType::Any(), isolate),
164 attributes, Representation::Tagged(), 164 attributes, Representation::Tagged(), OMIT_TRANSITION)
165 OMIT_TRANSITION).ToHandleChecked(); 165 .ToHandleChecked();
166 names[i] = name; 166 names[i] = name;
167 maps[i] = map; 167 maps[i] = map;
168 168
169 TransitionArray::Insert(map0, name, map, PROPERTY_TRANSITION); 169 TransitionArray::Insert(map0, name, map, PROPERTY_TRANSITION);
170 } 170 }
171 171
172 for (int i = 0; i < PROPS_COUNT; i++) { 172 for (int i = 0; i < PROPS_COUNT; i++) {
173 CHECK_EQ(*maps[i], TransitionArray::SearchTransition( 173 CHECK_EQ(*maps[i], TransitionArray::SearchTransition(
174 *map0, kData, *names[i], attributes)); 174 *map0, kData, *names[i], attributes));
175 } 175 }
(...skipping 25 matching lines...) Expand all
201 201
202 const int ATTRS_COUNT = (READ_ONLY | DONT_ENUM | DONT_DELETE) + 1; 202 const int ATTRS_COUNT = (READ_ONLY | DONT_ENUM | DONT_DELETE) + 1;
203 STATIC_ASSERT(ATTRS_COUNT == 8); 203 STATIC_ASSERT(ATTRS_COUNT == 8);
204 Handle<Map> attr_maps[ATTRS_COUNT]; 204 Handle<Map> attr_maps[ATTRS_COUNT];
205 Handle<String> name = factory->InternalizeUtf8String("foo"); 205 Handle<String> name = factory->InternalizeUtf8String("foo");
206 206
207 // Add transitions for same field name but different attributes. 207 // Add transitions for same field name but different attributes.
208 for (int i = 0; i < ATTRS_COUNT; i++) { 208 for (int i = 0; i < ATTRS_COUNT; i++) {
209 PropertyAttributes attributes = static_cast<PropertyAttributes>(i); 209 PropertyAttributes attributes = static_cast<PropertyAttributes>(i);
210 210
211 Handle<Map> map = 211 Handle<Map> map = Map::CopyWithField(
212 Map::CopyWithField(map0, name, handle(HeapType::Any(), isolate), 212 map0, name, handle(FieldType::Any(), isolate),
213 attributes, Representation::Tagged(), 213 attributes, Representation::Tagged(), OMIT_TRANSITION)
214 OMIT_TRANSITION).ToHandleChecked(); 214 .ToHandleChecked();
215 attr_maps[i] = map; 215 attr_maps[i] = map;
216 216
217 TransitionArray::Insert(map0, name, map, PROPERTY_TRANSITION); 217 TransitionArray::Insert(map0, name, map, PROPERTY_TRANSITION);
218 } 218 }
219 219
220 // Ensure that transitions for |name| field are valid. 220 // Ensure that transitions for |name| field are valid.
221 for (int i = 0; i < ATTRS_COUNT; i++) { 221 for (int i = 0; i < ATTRS_COUNT; i++) {
222 PropertyAttributes attributes = static_cast<PropertyAttributes>(i); 222 PropertyAttributes attributes = static_cast<PropertyAttributes>(i);
223 CHECK_EQ(*attr_maps[i], TransitionArray::SearchTransition( 223 CHECK_EQ(*attr_maps[i], TransitionArray::SearchTransition(
224 *map0, kData, *name, attributes)); 224 *map0, kData, *name, attributes));
(...skipping 20 matching lines...) Expand all
245 245
246 Handle<Map> map0 = Map::Create(isolate, 0); 246 Handle<Map> map0 = Map::Create(isolate, 0);
247 CHECK(map0->raw_transitions()->IsSmi()); 247 CHECK(map0->raw_transitions()->IsSmi());
248 248
249 // Some number of fields. 249 // Some number of fields.
250 for (int i = 0; i < PROPS_COUNT; i++) { 250 for (int i = 0; i < PROPS_COUNT; i++) {
251 EmbeddedVector<char, 64> buffer; 251 EmbeddedVector<char, 64> buffer;
252 SNPrintF(buffer, "prop%d", i); 252 SNPrintF(buffer, "prop%d", i);
253 Handle<String> name = factory->InternalizeUtf8String(buffer.start()); 253 Handle<String> name = factory->InternalizeUtf8String(buffer.start());
254 Handle<Map> map = 254 Handle<Map> map =
255 Map::CopyWithField(map0, name, handle(HeapType::Any(), isolate), NONE, 255 Map::CopyWithField(map0, name, handle(FieldType::Any(), isolate), NONE,
256 Representation::Tagged(), 256 Representation::Tagged(), OMIT_TRANSITION)
257 OMIT_TRANSITION).ToHandleChecked(); 257 .ToHandleChecked();
258 names[i] = name; 258 names[i] = name;
259 maps[i] = map; 259 maps[i] = map;
260 260
261 TransitionArray::Insert(map0, name, map, PROPERTY_TRANSITION); 261 TransitionArray::Insert(map0, name, map, PROPERTY_TRANSITION);
262 } 262 }
263 263
264 const int ATTRS_COUNT = (READ_ONLY | DONT_ENUM | DONT_DELETE) + 1; 264 const int ATTRS_COUNT = (READ_ONLY | DONT_ENUM | DONT_DELETE) + 1;
265 STATIC_ASSERT(ATTRS_COUNT == 8); 265 STATIC_ASSERT(ATTRS_COUNT == 8);
266 Handle<Map> attr_maps[ATTRS_COUNT]; 266 Handle<Map> attr_maps[ATTRS_COUNT];
267 Handle<String> name = factory->InternalizeUtf8String("foo"); 267 Handle<String> name = factory->InternalizeUtf8String("foo");
268 268
269 // Add transitions for same field name but different attributes. 269 // Add transitions for same field name but different attributes.
270 for (int i = 0; i < ATTRS_COUNT; i++) { 270 for (int i = 0; i < ATTRS_COUNT; i++) {
271 PropertyAttributes attributes = static_cast<PropertyAttributes>(i); 271 PropertyAttributes attributes = static_cast<PropertyAttributes>(i);
272 272
273 Handle<Map> map = 273 Handle<Map> map = Map::CopyWithField(
274 Map::CopyWithField(map0, name, handle(HeapType::Any(), isolate), 274 map0, name, handle(FieldType::Any(), isolate),
275 attributes, Representation::Tagged(), 275 attributes, Representation::Tagged(), OMIT_TRANSITION)
276 OMIT_TRANSITION).ToHandleChecked(); 276 .ToHandleChecked();
277 attr_maps[i] = map; 277 attr_maps[i] = map;
278 278
279 TransitionArray::Insert(map0, name, map, PROPERTY_TRANSITION); 279 TransitionArray::Insert(map0, name, map, PROPERTY_TRANSITION);
280 } 280 }
281 281
282 // Ensure that transitions for |name| field are valid. 282 // Ensure that transitions for |name| field are valid.
283 for (int i = 0; i < ATTRS_COUNT; i++) { 283 for (int i = 0; i < ATTRS_COUNT; i++) {
284 PropertyAttributes attr = static_cast<PropertyAttributes>(i); 284 PropertyAttributes attr = static_cast<PropertyAttributes>(i);
285 CHECK_EQ(*attr_maps[i], 285 CHECK_EQ(*attr_maps[i],
286 TransitionArray::SearchTransition(*map0, kData, *name, attr)); 286 TransitionArray::SearchTransition(*map0, kData, *name, attr));
(...skipping 17 matching lines...) Expand all
304 break; 304 break;
305 } 305 }
306 } 306 }
307 } 307 }
308 } 308 }
309 309
310 #ifdef DEBUG 310 #ifdef DEBUG
311 CHECK(TransitionArray::IsSortedNoDuplicates(*map0)); 311 CHECK(TransitionArray::IsSortedNoDuplicates(*map0));
312 #endif 312 #endif
313 } 313 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698