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 <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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 CcTest::InitializeVM(); | 130 CcTest::InitializeVM(); |
131 v8::HandleScope scope(CcTest::isolate()); | 131 v8::HandleScope scope(CcTest::isolate()); |
132 | 132 |
133 LayoutDescriptor* layout_desc = LayoutDescriptor::FastPointerLayout(); | 133 LayoutDescriptor* layout_desc = LayoutDescriptor::FastPointerLayout(); |
134 | 134 |
135 CHECK(!layout_desc->IsSlowLayout()); | 135 CHECK(!layout_desc->IsSlowLayout()); |
136 CHECK(layout_desc->IsFastPointerLayout()); | 136 CHECK(layout_desc->IsFastPointerLayout()); |
137 CHECK_EQ(kSmiValueSize, layout_desc->capacity()); | 137 CHECK_EQ(kSmiValueSize, layout_desc->capacity()); |
138 | 138 |
139 for (int i = 0; i < kSmiValueSize + 13; i++) { | 139 for (int i = 0; i < kSmiValueSize + 13; i++) { |
140 CHECK_EQ(true, layout_desc->IsTagged(i)); | 140 CHECK(layout_desc->IsTagged(i)); |
141 } | 141 } |
142 CHECK_EQ(true, layout_desc->IsTagged(-1)); | 142 CHECK(layout_desc->IsTagged(-1)); |
143 CHECK_EQ(true, layout_desc->IsTagged(-12347)); | 143 CHECK(layout_desc->IsTagged(-12347)); |
144 CHECK_EQ(true, layout_desc->IsTagged(15635)); | 144 CHECK(layout_desc->IsTagged(15635)); |
145 CHECK(layout_desc->IsFastPointerLayout()); | 145 CHECK(layout_desc->IsFastPointerLayout()); |
146 | 146 |
147 for (int i = 0; i < kSmiValueSize; i++) { | 147 for (int i = 0; i < kSmiValueSize; i++) { |
148 layout_desc = layout_desc->SetTaggedForTesting(i, false); | 148 layout_desc = layout_desc->SetTaggedForTesting(i, false); |
149 CHECK_EQ(false, layout_desc->IsTagged(i)); | 149 CHECK(!layout_desc->IsTagged(i)); |
150 layout_desc = layout_desc->SetTaggedForTesting(i, true); | 150 layout_desc = layout_desc->SetTaggedForTesting(i, true); |
151 CHECK_EQ(true, layout_desc->IsTagged(i)); | 151 CHECK(layout_desc->IsTagged(i)); |
152 } | 152 } |
153 CHECK(layout_desc->IsFastPointerLayout()); | 153 CHECK(layout_desc->IsFastPointerLayout()); |
154 | 154 |
155 int sequence_length; | 155 int sequence_length; |
156 CHECK_EQ(true, layout_desc->IsTagged(0, std::numeric_limits<int>::max(), | 156 CHECK_EQ(true, layout_desc->IsTagged(0, std::numeric_limits<int>::max(), |
157 &sequence_length)); | 157 &sequence_length)); |
158 CHECK_EQ(std::numeric_limits<int>::max(), sequence_length); | 158 CHECK_EQ(std::numeric_limits<int>::max(), sequence_length); |
159 | 159 |
160 CHECK_EQ(true, layout_desc->IsTagged(0, 7, &sequence_length)); | 160 CHECK(layout_desc->IsTagged(0, 7, &sequence_length)); |
161 CHECK_EQ(7, sequence_length); | 161 CHECK_EQ(7, sequence_length); |
162 } | 162 } |
163 | 163 |
164 | 164 |
165 TEST(LayoutDescriptorBasicSlow) { | 165 TEST(LayoutDescriptorBasicSlow) { |
166 CcTest::InitializeVM(); | 166 CcTest::InitializeVM(); |
167 Isolate* isolate = CcTest::i_isolate(); | 167 Isolate* isolate = CcTest::i_isolate(); |
168 v8::HandleScope scope(CcTest::isolate()); | 168 v8::HandleScope scope(CcTest::isolate()); |
169 | 169 |
170 Handle<LayoutDescriptor> layout_descriptor; | 170 Handle<LayoutDescriptor> layout_descriptor; |
(...skipping 25 matching lines...) Expand all Loading... |
196 { | 196 { |
197 int inobject_properties = kPropsCount - 1; | 197 int inobject_properties = kPropsCount - 1; |
198 Handle<Map> map = Map::Create(isolate, inobject_properties); | 198 Handle<Map> map = Map::Create(isolate, inobject_properties); |
199 | 199 |
200 // Should be fast as the only double property is the first one. | 200 // Should be fast as the only double property is the first one. |
201 layout_descriptor = LayoutDescriptor::New(map, descriptors, kPropsCount); | 201 layout_descriptor = LayoutDescriptor::New(map, descriptors, kPropsCount); |
202 CHECK_NE(LayoutDescriptor::FastPointerLayout(), *layout_descriptor); | 202 CHECK_NE(LayoutDescriptor::FastPointerLayout(), *layout_descriptor); |
203 CHECK(!layout_descriptor->IsSlowLayout()); | 203 CHECK(!layout_descriptor->IsSlowLayout()); |
204 CHECK(!layout_descriptor->IsFastPointerLayout()); | 204 CHECK(!layout_descriptor->IsFastPointerLayout()); |
205 | 205 |
206 CHECK_EQ(false, layout_descriptor->IsTagged(0)); | 206 CHECK(!layout_descriptor->IsTagged(0)); |
207 for (int i = 1; i < kPropsCount; i++) { | 207 for (int i = 1; i < kPropsCount; i++) { |
208 CHECK_EQ(true, layout_descriptor->IsTagged(i)); | 208 CHECK(layout_descriptor->IsTagged(i)); |
209 } | 209 } |
210 InitializeVerifiedMapDescriptors(*map, *descriptors, *layout_descriptor); | 210 InitializeVerifiedMapDescriptors(*map, *descriptors, *layout_descriptor); |
211 } | 211 } |
212 | 212 |
213 { | 213 { |
214 int inobject_properties = kPropsCount; | 214 int inobject_properties = kPropsCount; |
215 Handle<Map> map = Map::Create(isolate, inobject_properties); | 215 Handle<Map> map = Map::Create(isolate, inobject_properties); |
216 | 216 |
217 layout_descriptor = LayoutDescriptor::New(map, descriptors, kPropsCount); | 217 layout_descriptor = LayoutDescriptor::New(map, descriptors, kPropsCount); |
218 CHECK_NE(LayoutDescriptor::FastPointerLayout(), *layout_descriptor); | 218 CHECK_NE(LayoutDescriptor::FastPointerLayout(), *layout_descriptor); |
219 CHECK(layout_descriptor->IsSlowLayout()); | 219 CHECK(layout_descriptor->IsSlowLayout()); |
220 CHECK(!layout_descriptor->IsFastPointerLayout()); | 220 CHECK(!layout_descriptor->IsFastPointerLayout()); |
221 CHECK(layout_descriptor->capacity() > kSmiValueSize); | 221 CHECK(layout_descriptor->capacity() > kSmiValueSize); |
222 | 222 |
223 CHECK_EQ(false, layout_descriptor->IsTagged(0)); | 223 CHECK(!layout_descriptor->IsTagged(0)); |
224 CHECK_EQ(false, layout_descriptor->IsTagged(kPropsCount - 1)); | 224 CHECK(!layout_descriptor->IsTagged(kPropsCount - 1)); |
225 for (int i = 1; i < kPropsCount - 1; i++) { | 225 for (int i = 1; i < kPropsCount - 1; i++) { |
226 CHECK_EQ(true, layout_descriptor->IsTagged(i)); | 226 CHECK(layout_descriptor->IsTagged(i)); |
227 } | 227 } |
228 | 228 |
229 InitializeVerifiedMapDescriptors(*map, *descriptors, *layout_descriptor); | 229 InitializeVerifiedMapDescriptors(*map, *descriptors, *layout_descriptor); |
230 | 230 |
231 // Here we have truly slow layout descriptor, so play with the bits. | 231 // Here we have truly slow layout descriptor, so play with the bits. |
232 CHECK_EQ(true, layout_descriptor->IsTagged(-1)); | 232 CHECK(layout_descriptor->IsTagged(-1)); |
233 CHECK_EQ(true, layout_descriptor->IsTagged(-12347)); | 233 CHECK(layout_descriptor->IsTagged(-12347)); |
234 CHECK_EQ(true, layout_descriptor->IsTagged(15635)); | 234 CHECK(layout_descriptor->IsTagged(15635)); |
235 | 235 |
236 LayoutDescriptor* layout_desc = *layout_descriptor; | 236 LayoutDescriptor* layout_desc = *layout_descriptor; |
237 // Play with the bits but leave it in consistent state with map at the end. | 237 // Play with the bits but leave it in consistent state with map at the end. |
238 for (int i = 1; i < kPropsCount - 1; i++) { | 238 for (int i = 1; i < kPropsCount - 1; i++) { |
239 layout_desc = layout_desc->SetTaggedForTesting(i, false); | 239 layout_desc = layout_desc->SetTaggedForTesting(i, false); |
240 CHECK_EQ(false, layout_desc->IsTagged(i)); | 240 CHECK(!layout_desc->IsTagged(i)); |
241 layout_desc = layout_desc->SetTaggedForTesting(i, true); | 241 layout_desc = layout_desc->SetTaggedForTesting(i, true); |
242 CHECK_EQ(true, layout_desc->IsTagged(i)); | 242 CHECK(layout_desc->IsTagged(i)); |
243 } | 243 } |
244 CHECK(layout_desc->IsSlowLayout()); | 244 CHECK(layout_desc->IsSlowLayout()); |
245 CHECK(!layout_desc->IsFastPointerLayout()); | 245 CHECK(!layout_desc->IsFastPointerLayout()); |
246 CHECK(layout_descriptor->IsConsistentWithMap(*map, true)); | 246 CHECK(layout_descriptor->IsConsistentWithMap(*map, true)); |
247 } | 247 } |
248 } | 248 } |
249 | 249 |
250 | 250 |
251 static void TestLayoutDescriptorQueries(int layout_descriptor_length, | 251 static void TestLayoutDescriptorQueries(int layout_descriptor_length, |
252 int* bit_flip_positions, | 252 int* bit_flip_positions, |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 layout_descriptor = LayoutDescriptor::New(map, descriptors, kPropsCount); | 513 layout_descriptor = LayoutDescriptor::New(map, descriptors, kPropsCount); |
514 CHECK_EQ(LayoutDescriptor::FastPointerLayout(), *layout_descriptor); | 514 CHECK_EQ(LayoutDescriptor::FastPointerLayout(), *layout_descriptor); |
515 InitializeVerifiedMapDescriptors(*map, *descriptors, *layout_descriptor); | 515 InitializeVerifiedMapDescriptors(*map, *descriptors, *layout_descriptor); |
516 } | 516 } |
517 | 517 |
518 { | 518 { |
519 Handle<Map> map = Map::Create(isolate, 2); | 519 Handle<Map> map = Map::Create(isolate, 2); |
520 layout_descriptor = LayoutDescriptor::New(map, descriptors, kPropsCount); | 520 layout_descriptor = LayoutDescriptor::New(map, descriptors, kPropsCount); |
521 CHECK_NE(LayoutDescriptor::FastPointerLayout(), *layout_descriptor); | 521 CHECK_NE(LayoutDescriptor::FastPointerLayout(), *layout_descriptor); |
522 CHECK(!layout_descriptor->IsSlowLayout()); | 522 CHECK(!layout_descriptor->IsSlowLayout()); |
523 CHECK_EQ(true, layout_descriptor->IsTagged(0)); | 523 CHECK(layout_descriptor->IsTagged(0)); |
524 CHECK_EQ(false, layout_descriptor->IsTagged(1)); | 524 CHECK(!layout_descriptor->IsTagged(1)); |
525 CHECK_EQ(true, layout_descriptor->IsTagged(2)); | 525 CHECK(layout_descriptor->IsTagged(2)); |
526 CHECK_EQ(true, layout_descriptor->IsTagged(125)); | 526 CHECK(layout_descriptor->IsTagged(125)); |
527 InitializeVerifiedMapDescriptors(*map, *descriptors, *layout_descriptor); | 527 InitializeVerifiedMapDescriptors(*map, *descriptors, *layout_descriptor); |
528 } | 528 } |
529 } | 529 } |
530 | 530 |
531 | 531 |
532 TEST(LayoutDescriptorCreateNewSlow) { | 532 TEST(LayoutDescriptorCreateNewSlow) { |
533 CcTest::InitializeVM(); | 533 CcTest::InitializeVM(); |
534 Isolate* isolate = CcTest::i_isolate(); | 534 Isolate* isolate = CcTest::i_isolate(); |
535 v8::HandleScope scope(CcTest::isolate()); | 535 v8::HandleScope scope(CcTest::isolate()); |
536 | 536 |
(...skipping 19 matching lines...) Expand all Loading... |
556 layout_descriptor = LayoutDescriptor::New(map, descriptors, kPropsCount); | 556 layout_descriptor = LayoutDescriptor::New(map, descriptors, kPropsCount); |
557 CHECK_EQ(LayoutDescriptor::FastPointerLayout(), *layout_descriptor); | 557 CHECK_EQ(LayoutDescriptor::FastPointerLayout(), *layout_descriptor); |
558 InitializeVerifiedMapDescriptors(*map, *descriptors, *layout_descriptor); | 558 InitializeVerifiedMapDescriptors(*map, *descriptors, *layout_descriptor); |
559 } | 559 } |
560 | 560 |
561 { | 561 { |
562 Handle<Map> map = Map::Create(isolate, 2); | 562 Handle<Map> map = Map::Create(isolate, 2); |
563 layout_descriptor = LayoutDescriptor::New(map, descriptors, kPropsCount); | 563 layout_descriptor = LayoutDescriptor::New(map, descriptors, kPropsCount); |
564 CHECK_NE(LayoutDescriptor::FastPointerLayout(), *layout_descriptor); | 564 CHECK_NE(LayoutDescriptor::FastPointerLayout(), *layout_descriptor); |
565 CHECK(!layout_descriptor->IsSlowLayout()); | 565 CHECK(!layout_descriptor->IsSlowLayout()); |
566 CHECK_EQ(true, layout_descriptor->IsTagged(0)); | 566 CHECK(layout_descriptor->IsTagged(0)); |
567 CHECK_EQ(false, layout_descriptor->IsTagged(1)); | 567 CHECK(!layout_descriptor->IsTagged(1)); |
568 CHECK_EQ(true, layout_descriptor->IsTagged(2)); | 568 CHECK(layout_descriptor->IsTagged(2)); |
569 CHECK_EQ(true, layout_descriptor->IsTagged(125)); | 569 CHECK(layout_descriptor->IsTagged(125)); |
570 InitializeVerifiedMapDescriptors(*map, *descriptors, *layout_descriptor); | 570 InitializeVerifiedMapDescriptors(*map, *descriptors, *layout_descriptor); |
571 } | 571 } |
572 | 572 |
573 { | 573 { |
574 int inobject_properties = kPropsCount / 2; | 574 int inobject_properties = kPropsCount / 2; |
575 Handle<Map> map = Map::Create(isolate, inobject_properties); | 575 Handle<Map> map = Map::Create(isolate, inobject_properties); |
576 layout_descriptor = LayoutDescriptor::New(map, descriptors, kPropsCount); | 576 layout_descriptor = LayoutDescriptor::New(map, descriptors, kPropsCount); |
577 CHECK_NE(LayoutDescriptor::FastPointerLayout(), *layout_descriptor); | 577 CHECK_NE(LayoutDescriptor::FastPointerLayout(), *layout_descriptor); |
578 CHECK(layout_descriptor->IsSlowLayout()); | 578 CHECK(layout_descriptor->IsSlowLayout()); |
579 for (int i = 0; i < inobject_properties; i++) { | 579 for (int i = 0; i < inobject_properties; i++) { |
580 // PROP_DOUBLE has index 1 among DATA properties. | 580 // PROP_DOUBLE has index 1 among DATA properties. |
581 const bool tagged = (i % (PROP_KIND_NUMBER - 1)) != 1; | 581 const bool tagged = (i % (PROP_KIND_NUMBER - 1)) != 1; |
582 CHECK_EQ(tagged, layout_descriptor->IsTagged(i)); | 582 CHECK_EQ(tagged, layout_descriptor->IsTagged(i)); |
583 } | 583 } |
584 // Every property after inobject_properties must be tagged. | 584 // Every property after inobject_properties must be tagged. |
585 for (int i = inobject_properties; i < kPropsCount; i++) { | 585 for (int i = inobject_properties; i < kPropsCount; i++) { |
586 CHECK_EQ(true, layout_descriptor->IsTagged(i)); | 586 CHECK(layout_descriptor->IsTagged(i)); |
587 } | 587 } |
588 InitializeVerifiedMapDescriptors(*map, *descriptors, *layout_descriptor); | 588 InitializeVerifiedMapDescriptors(*map, *descriptors, *layout_descriptor); |
589 | 589 |
590 // Now test LayoutDescriptor::cast_gc_safe(). | 590 // Now test LayoutDescriptor::cast_gc_safe(). |
591 Handle<LayoutDescriptor> layout_descriptor_copy = | 591 Handle<LayoutDescriptor> layout_descriptor_copy = |
592 LayoutDescriptor::New(map, descriptors, kPropsCount); | 592 LayoutDescriptor::New(map, descriptors, kPropsCount); |
593 | 593 |
594 LayoutDescriptor* layout_desc = *layout_descriptor; | 594 LayoutDescriptor* layout_desc = *layout_descriptor; |
595 CHECK_EQ(layout_desc, LayoutDescriptor::cast(layout_desc)); | 595 CHECK_EQ(layout_desc, LayoutDescriptor::cast(layout_desc)); |
596 CHECK_EQ(layout_desc, LayoutDescriptor::cast_gc_safe(layout_desc)); | 596 CHECK_EQ(layout_desc, LayoutDescriptor::cast_gc_safe(layout_desc)); |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 CHECK(end_of_region_offset % kPointerSize == 0); | 1217 CHECK(end_of_region_offset % kPointerSize == 0); |
1218 CHECK(end_of_region_offset <= instance_size); | 1218 CHECK(end_of_region_offset <= instance_size); |
1219 | 1219 |
1220 for (int offset = index.offset(); offset < end_of_region_offset; | 1220 for (int offset = index.offset(); offset < end_of_region_offset; |
1221 offset += kPointerSize) { | 1221 offset += kPointerSize) { |
1222 CHECK_EQ(expected_tagged, helper.IsTagged(index.offset())); | 1222 CHECK_EQ(expected_tagged, helper.IsTagged(index.offset())); |
1223 } | 1223 } |
1224 if (end_of_region_offset < instance_size) { | 1224 if (end_of_region_offset < instance_size) { |
1225 CHECK_EQ(!expected_tagged, helper.IsTagged(end_of_region_offset)); | 1225 CHECK_EQ(!expected_tagged, helper.IsTagged(end_of_region_offset)); |
1226 } else { | 1226 } else { |
1227 CHECK_EQ(true, helper.IsTagged(end_of_region_offset)); | 1227 CHECK(helper.IsTagged(end_of_region_offset)); |
1228 } | 1228 } |
1229 } | 1229 } |
1230 | 1230 |
1231 for (int offset = 0; offset < JSObject::kHeaderSize; offset += kPointerSize) { | 1231 for (int offset = 0; offset < JSObject::kHeaderSize; offset += kPointerSize) { |
1232 // Header queries | 1232 // Header queries |
1233 CHECK_EQ(true, helper.IsTagged(offset)); | 1233 CHECK(helper.IsTagged(offset)); |
1234 int end_of_region_offset; | 1234 int end_of_region_offset; |
1235 CHECK_EQ(true, helper.IsTagged(offset, end_offset, &end_of_region_offset)); | 1235 CHECK(helper.IsTagged(offset, end_offset, &end_of_region_offset)); |
1236 CHECK_EQ(first_non_tagged_field_offset, end_of_region_offset); | 1236 CHECK_EQ(first_non_tagged_field_offset, end_of_region_offset); |
1237 | 1237 |
1238 // Out of bounds queries | 1238 // Out of bounds queries |
1239 CHECK_EQ(true, helper.IsTagged(offset + instance_size)); | 1239 CHECK(helper.IsTagged(offset + instance_size)); |
1240 } | 1240 } |
1241 | 1241 |
1242 CHECK_EQ(all_fields_tagged, helper.all_fields_tagged()); | 1242 CHECK_EQ(all_fields_tagged, helper.all_fields_tagged()); |
1243 } | 1243 } |
1244 | 1244 |
1245 | 1245 |
1246 TEST(LayoutDescriptorHelperMixed) { | 1246 TEST(LayoutDescriptorHelperMixed) { |
1247 CcTest::InitializeVM(); | 1247 CcTest::InitializeVM(); |
1248 Isolate* isolate = CcTest::i_isolate(); | 1248 Isolate* isolate = CcTest::i_isolate(); |
1249 v8::HandleScope scope(CcTest::isolate()); | 1249 v8::HandleScope scope(CcTest::isolate()); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 | 1562 |
1563 // TODO(ishell): add respective tests for property kind reconfiguring from | 1563 // TODO(ishell): add respective tests for property kind reconfiguring from |
1564 // accessor field to double, once accessor fields are supported by | 1564 // accessor field to double, once accessor fields are supported by |
1565 // Map::ReconfigureProperty(). | 1565 // Map::ReconfigureProperty(). |
1566 | 1566 |
1567 | 1567 |
1568 // TODO(ishell): add respective tests for fast property removal case once | 1568 // TODO(ishell): add respective tests for fast property removal case once |
1569 // Map::ReconfigureProperty() supports that. | 1569 // Map::ReconfigureProperty() supports that. |
1570 | 1570 |
1571 #endif | 1571 #endif |
OLD | NEW |