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

Side by Side Diff: test/cctest/test-unboxed-doubles.cc

Issue 786193004: PropertyType is divided into PropertyKind and PropertyStoreMode. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments Created 6 years 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
« no previous file with comments | « src/serialize.cc ('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
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 14 matching lines...) Expand all
25 if (obj->IsUnboxedDoubleField(field_index)) { 25 if (obj->IsUnboxedDoubleField(field_index)) {
26 return obj->RawFastDoublePropertyAt(field_index); 26 return obj->RawFastDoublePropertyAt(field_index);
27 } else { 27 } else {
28 Object* value = obj->RawFastPropertyAt(field_index); 28 Object* value = obj->RawFastPropertyAt(field_index);
29 DCHECK(value->IsMutableHeapNumber()); 29 DCHECK(value->IsMutableHeapNumber());
30 return HeapNumber::cast(value)->value(); 30 return HeapNumber::cast(value)->value();
31 } 31 }
32 } 32 }
33 33
34 34
35 enum PropertyKind { 35 enum TestPropertyKind {
36 PROP_CONSTANT, 36 PROP_CONSTANT,
37 PROP_SMI, 37 PROP_SMI,
38 PROP_DOUBLE, 38 PROP_DOUBLE,
39 PROP_TAGGED, 39 PROP_TAGGED,
40 PROP_KIND_NUMBER 40 PROP_KIND_NUMBER
41 }; 41 };
42 42
43 static Representation representations[PROP_KIND_NUMBER] = { 43 static Representation representations[PROP_KIND_NUMBER] = {
44 Representation::None(), Representation::Smi(), Representation::Double(), 44 Representation::None(), Representation::Smi(), Representation::Double(),
45 Representation::Tagged()}; 45 Representation::Tagged()};
46 46
47 47
48 static Handle<DescriptorArray> CreateDescriptorArray(Isolate* isolate, 48 static Handle<DescriptorArray> CreateDescriptorArray(Isolate* isolate,
49 PropertyKind* props, 49 TestPropertyKind* props,
50 int kPropsCount) { 50 int kPropsCount) {
51 Factory* factory = isolate->factory(); 51 Factory* factory = isolate->factory();
52 52
53 Handle<String> func_name = factory->InternalizeUtf8String("func"); 53 Handle<String> func_name = factory->InternalizeUtf8String("func");
54 Handle<JSFunction> func = factory->NewFunction(func_name); 54 Handle<JSFunction> func = factory->NewFunction(func_name);
55 55
56 Handle<DescriptorArray> descriptors = 56 Handle<DescriptorArray> descriptors =
57 DescriptorArray::Allocate(isolate, 0, kPropsCount); 57 DescriptorArray::Allocate(isolate, 0, kPropsCount);
58 58
59 int next_field_offset = 0; 59 int next_field_offset = 0;
60 for (int i = 0; i < kPropsCount; i++) { 60 for (int i = 0; i < kPropsCount; i++) {
61 EmbeddedVector<char, 64> buffer; 61 EmbeddedVector<char, 64> buffer;
62 SNPrintF(buffer, "prop%d", i); 62 SNPrintF(buffer, "prop%d", i);
63 Handle<String> name = factory->InternalizeUtf8String(buffer.start()); 63 Handle<String> name = factory->InternalizeUtf8String(buffer.start());
64 64
65 PropertyKind kind = props[i]; 65 TestPropertyKind kind = props[i];
66 66
67 if (kind == PROP_CONSTANT) { 67 if (kind == PROP_CONSTANT) {
68 ConstantDescriptor d(name, func, NONE); 68 ConstantDescriptor d(name, func, NONE);
69 descriptors->Append(&d); 69 descriptors->Append(&d);
70 70
71 } else { 71 } else {
72 FieldDescriptor f(name, next_field_offset, NONE, representations[kind]); 72 FieldDescriptor f(name, next_field_offset, NONE, representations[kind]);
73 next_field_offset += f.GetDetails().field_width_in_words(); 73 next_field_offset += f.GetDetails().field_width_in_words();
74 descriptors->Append(&f); 74 descriptors->Append(&f);
75 } 75 }
(...skipping 30 matching lines...) Expand all
106 } 106 }
107 107
108 108
109 TEST(LayoutDescriptorBasicSlow) { 109 TEST(LayoutDescriptorBasicSlow) {
110 CcTest::InitializeVM(); 110 CcTest::InitializeVM();
111 Isolate* isolate = CcTest::i_isolate(); 111 Isolate* isolate = CcTest::i_isolate();
112 v8::HandleScope scope(CcTest::isolate()); 112 v8::HandleScope scope(CcTest::isolate());
113 113
114 Handle<LayoutDescriptor> layout_descriptor; 114 Handle<LayoutDescriptor> layout_descriptor;
115 const int kPropsCount = kSmiValueSize * 3; 115 const int kPropsCount = kSmiValueSize * 3;
116 PropertyKind props[kPropsCount]; 116 TestPropertyKind props[kPropsCount];
117 for (int i = 0; i < kPropsCount; i++) { 117 for (int i = 0; i < kPropsCount; i++) {
118 // All properties tagged. 118 // All properties tagged.
119 props[i] = PROP_TAGGED; 119 props[i] = PROP_TAGGED;
120 } 120 }
121 121
122 { 122 {
123 Handle<DescriptorArray> descriptors = 123 Handle<DescriptorArray> descriptors =
124 CreateDescriptorArray(isolate, props, kPropsCount); 124 CreateDescriptorArray(isolate, props, kPropsCount);
125 125
126 Handle<Map> map = Map::Create(isolate, kPropsCount); 126 Handle<Map> map = Map::Create(isolate, kPropsCount);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 195 }
196 } 196 }
197 197
198 198
199 TEST(LayoutDescriptorCreateNewFast) { 199 TEST(LayoutDescriptorCreateNewFast) {
200 CcTest::InitializeVM(); 200 CcTest::InitializeVM();
201 Isolate* isolate = CcTest::i_isolate(); 201 Isolate* isolate = CcTest::i_isolate();
202 v8::HandleScope scope(CcTest::isolate()); 202 v8::HandleScope scope(CcTest::isolate());
203 203
204 Handle<LayoutDescriptor> layout_descriptor; 204 Handle<LayoutDescriptor> layout_descriptor;
205 PropertyKind props[] = { 205 TestPropertyKind props[] = {
206 PROP_CONSTANT, 206 PROP_CONSTANT,
207 PROP_TAGGED, // field #0 207 PROP_TAGGED, // field #0
208 PROP_CONSTANT, 208 PROP_CONSTANT,
209 PROP_DOUBLE, // field #1 209 PROP_DOUBLE, // field #1
210 PROP_CONSTANT, 210 PROP_CONSTANT,
211 PROP_TAGGED, // field #2 211 PROP_TAGGED, // field #2
212 PROP_CONSTANT, 212 PROP_CONSTANT,
213 }; 213 };
214 const int kPropsCount = arraysize(props); 214 const int kPropsCount = arraysize(props);
215 215
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 } 247 }
248 248
249 249
250 TEST(LayoutDescriptorCreateNewSlow) { 250 TEST(LayoutDescriptorCreateNewSlow) {
251 CcTest::InitializeVM(); 251 CcTest::InitializeVM();
252 Isolate* isolate = CcTest::i_isolate(); 252 Isolate* isolate = CcTest::i_isolate();
253 v8::HandleScope scope(CcTest::isolate()); 253 v8::HandleScope scope(CcTest::isolate());
254 254
255 Handle<LayoutDescriptor> layout_descriptor; 255 Handle<LayoutDescriptor> layout_descriptor;
256 const int kPropsCount = kSmiValueSize * 3; 256 const int kPropsCount = kSmiValueSize * 3;
257 PropertyKind props[kPropsCount]; 257 TestPropertyKind props[kPropsCount];
258 for (int i = 0; i < kPropsCount; i++) { 258 for (int i = 0; i < kPropsCount; i++) {
259 props[i] = static_cast<PropertyKind>(i % PROP_KIND_NUMBER); 259 props[i] = static_cast<TestPropertyKind>(i % PROP_KIND_NUMBER);
260 } 260 }
261 261
262 Handle<DescriptorArray> descriptors = 262 Handle<DescriptorArray> descriptors =
263 CreateDescriptorArray(isolate, props, kPropsCount); 263 CreateDescriptorArray(isolate, props, kPropsCount);
264 264
265 { 265 {
266 Handle<Map> map = Map::Create(isolate, 0); 266 Handle<Map> map = Map::Create(isolate, 0);
267 layout_descriptor = LayoutDescriptor::New(map, descriptors, kPropsCount); 267 layout_descriptor = LayoutDescriptor::New(map, descriptors, kPropsCount);
268 CHECK_EQ(LayoutDescriptor::FastPointerLayout(), *layout_descriptor); 268 CHECK_EQ(LayoutDescriptor::FastPointerLayout(), *layout_descriptor);
269 map->InitializeDescriptors(*descriptors, *layout_descriptor); 269 map->InitializeDescriptors(*descriptors, *layout_descriptor);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 LayoutDescriptor::cast_gc_safe(layout_desc)); 327 LayoutDescriptor::cast_gc_safe(layout_desc));
328 328
329 // Restore it back. 329 // Restore it back.
330 layout_desc->set_map_word(map_word); 330 layout_desc->set_map_word(map_word);
331 CHECK_EQ(layout_desc, LayoutDescriptor::cast(layout_desc)); 331 CHECK_EQ(layout_desc, LayoutDescriptor::cast(layout_desc));
332 } 332 }
333 } 333 }
334 334
335 335
336 static Handle<LayoutDescriptor> TestLayoutDescriptorAppend( 336 static Handle<LayoutDescriptor> TestLayoutDescriptorAppend(
337 Isolate* isolate, int inobject_properties, PropertyKind* props, 337 Isolate* isolate, int inobject_properties, TestPropertyKind* props,
338 int kPropsCount) { 338 int kPropsCount) {
339 Factory* factory = isolate->factory(); 339 Factory* factory = isolate->factory();
340 340
341 Handle<String> func_name = factory->InternalizeUtf8String("func"); 341 Handle<String> func_name = factory->InternalizeUtf8String("func");
342 Handle<JSFunction> func = factory->NewFunction(func_name); 342 Handle<JSFunction> func = factory->NewFunction(func_name);
343 343
344 Handle<DescriptorArray> descriptors = 344 Handle<DescriptorArray> descriptors =
345 DescriptorArray::Allocate(isolate, 0, kPropsCount); 345 DescriptorArray::Allocate(isolate, 0, kPropsCount);
346 346
347 Handle<Map> map = Map::Create(isolate, inobject_properties); 347 Handle<Map> map = Map::Create(isolate, inobject_properties);
348 map->InitializeDescriptors(*descriptors, 348 map->InitializeDescriptors(*descriptors,
349 LayoutDescriptor::FastPointerLayout()); 349 LayoutDescriptor::FastPointerLayout());
350 350
351 int next_field_offset = 0; 351 int next_field_offset = 0;
352 for (int i = 0; i < kPropsCount; i++) { 352 for (int i = 0; i < kPropsCount; i++) {
353 EmbeddedVector<char, 64> buffer; 353 EmbeddedVector<char, 64> buffer;
354 SNPrintF(buffer, "prop%d", i); 354 SNPrintF(buffer, "prop%d", i);
355 Handle<String> name = factory->InternalizeUtf8String(buffer.start()); 355 Handle<String> name = factory->InternalizeUtf8String(buffer.start());
356 356
357 Handle<LayoutDescriptor> layout_descriptor; 357 Handle<LayoutDescriptor> layout_descriptor;
358 PropertyKind kind = props[i]; 358 TestPropertyKind kind = props[i];
359 if (kind == PROP_CONSTANT) { 359 if (kind == PROP_CONSTANT) {
360 ConstantDescriptor d(name, func, NONE); 360 ConstantDescriptor d(name, func, NONE);
361 layout_descriptor = LayoutDescriptor::Append(map, d.GetDetails()); 361 layout_descriptor = LayoutDescriptor::Append(map, d.GetDetails());
362 descriptors->Append(&d); 362 descriptors->Append(&d);
363 363
364 } else { 364 } else {
365 FieldDescriptor f(name, next_field_offset, NONE, representations[kind]); 365 FieldDescriptor f(name, next_field_offset, NONE, representations[kind]);
366 int field_width_in_words = f.GetDetails().field_width_in_words(); 366 int field_width_in_words = f.GetDetails().field_width_in_words();
367 next_field_offset += field_width_in_words; 367 next_field_offset += field_width_in_words;
368 layout_descriptor = LayoutDescriptor::Append(map, f.GetDetails()); 368 layout_descriptor = LayoutDescriptor::Append(map, f.GetDetails());
(...skipping 15 matching lines...) Expand all
384 } 384 }
385 385
386 386
387 TEST(LayoutDescriptorAppend) { 387 TEST(LayoutDescriptorAppend) {
388 CcTest::InitializeVM(); 388 CcTest::InitializeVM();
389 Isolate* isolate = CcTest::i_isolate(); 389 Isolate* isolate = CcTest::i_isolate();
390 v8::HandleScope scope(CcTest::isolate()); 390 v8::HandleScope scope(CcTest::isolate());
391 391
392 Handle<LayoutDescriptor> layout_descriptor; 392 Handle<LayoutDescriptor> layout_descriptor;
393 const int kPropsCount = kSmiValueSize * 3; 393 const int kPropsCount = kSmiValueSize * 3;
394 PropertyKind props[kPropsCount]; 394 TestPropertyKind props[kPropsCount];
395 for (int i = 0; i < kPropsCount; i++) { 395 for (int i = 0; i < kPropsCount; i++) {
396 props[i] = static_cast<PropertyKind>(i % PROP_KIND_NUMBER); 396 props[i] = static_cast<TestPropertyKind>(i % PROP_KIND_NUMBER);
397 } 397 }
398 398
399 layout_descriptor = 399 layout_descriptor =
400 TestLayoutDescriptorAppend(isolate, 0, props, kPropsCount); 400 TestLayoutDescriptorAppend(isolate, 0, props, kPropsCount);
401 CHECK(!layout_descriptor->IsSlowLayout()); 401 CHECK(!layout_descriptor->IsSlowLayout());
402 402
403 layout_descriptor = 403 layout_descriptor =
404 TestLayoutDescriptorAppend(isolate, 13, props, kPropsCount); 404 TestLayoutDescriptorAppend(isolate, 13, props, kPropsCount);
405 CHECK(!layout_descriptor->IsSlowLayout()); 405 CHECK(!layout_descriptor->IsSlowLayout());
406 406
(...skipping 11 matching lines...) Expand all
418 } 418 }
419 419
420 420
421 TEST(LayoutDescriptorAppendAllDoubles) { 421 TEST(LayoutDescriptorAppendAllDoubles) {
422 CcTest::InitializeVM(); 422 CcTest::InitializeVM();
423 Isolate* isolate = CcTest::i_isolate(); 423 Isolate* isolate = CcTest::i_isolate();
424 v8::HandleScope scope(CcTest::isolate()); 424 v8::HandleScope scope(CcTest::isolate());
425 425
426 Handle<LayoutDescriptor> layout_descriptor; 426 Handle<LayoutDescriptor> layout_descriptor;
427 const int kPropsCount = kSmiValueSize * 3; 427 const int kPropsCount = kSmiValueSize * 3;
428 PropertyKind props[kPropsCount]; 428 TestPropertyKind props[kPropsCount];
429 for (int i = 0; i < kPropsCount; i++) { 429 for (int i = 0; i < kPropsCount; i++) {
430 props[i] = PROP_DOUBLE; 430 props[i] = PROP_DOUBLE;
431 } 431 }
432 432
433 layout_descriptor = 433 layout_descriptor =
434 TestLayoutDescriptorAppend(isolate, 0, props, kPropsCount); 434 TestLayoutDescriptorAppend(isolate, 0, props, kPropsCount);
435 CHECK(!layout_descriptor->IsSlowLayout()); 435 CHECK(!layout_descriptor->IsSlowLayout());
436 436
437 layout_descriptor = 437 layout_descriptor =
438 TestLayoutDescriptorAppend(isolate, 13, props, kPropsCount); 438 TestLayoutDescriptorAppend(isolate, 13, props, kPropsCount);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 } 516 }
517 517
518 518
519 TEST(LayoutDescriptorAppendIfFastOrUseFull) { 519 TEST(LayoutDescriptorAppendIfFastOrUseFull) {
520 CcTest::InitializeVM(); 520 CcTest::InitializeVM();
521 Isolate* isolate = CcTest::i_isolate(); 521 Isolate* isolate = CcTest::i_isolate();
522 v8::HandleScope scope(CcTest::isolate()); 522 v8::HandleScope scope(CcTest::isolate());
523 523
524 Handle<LayoutDescriptor> layout_descriptor; 524 Handle<LayoutDescriptor> layout_descriptor;
525 const int kPropsCount = kSmiValueSize * 3; 525 const int kPropsCount = kSmiValueSize * 3;
526 PropertyKind props[kPropsCount]; 526 TestPropertyKind props[kPropsCount];
527 for (int i = 0; i < kPropsCount; i++) { 527 for (int i = 0; i < kPropsCount; i++) {
528 props[i] = static_cast<PropertyKind>(i % PROP_KIND_NUMBER); 528 props[i] = static_cast<TestPropertyKind>(i % PROP_KIND_NUMBER);
529 } 529 }
530 Handle<DescriptorArray> descriptors = 530 Handle<DescriptorArray> descriptors =
531 CreateDescriptorArray(isolate, props, kPropsCount); 531 CreateDescriptorArray(isolate, props, kPropsCount);
532 532
533 layout_descriptor = TestLayoutDescriptorAppendIfFastOrUseFull( 533 layout_descriptor = TestLayoutDescriptorAppendIfFastOrUseFull(
534 isolate, 0, descriptors, kPropsCount); 534 isolate, 0, descriptors, kPropsCount);
535 CHECK(!layout_descriptor->IsSlowLayout()); 535 CHECK(!layout_descriptor->IsSlowLayout());
536 536
537 layout_descriptor = TestLayoutDescriptorAppendIfFastOrUseFull( 537 layout_descriptor = TestLayoutDescriptorAppendIfFastOrUseFull(
538 isolate, 13, descriptors, kPropsCount); 538 isolate, 13, descriptors, kPropsCount);
(...skipping 13 matching lines...) Expand all
552 } 552 }
553 553
554 554
555 TEST(LayoutDescriptorAppendIfFastOrUseFullAllDoubles) { 555 TEST(LayoutDescriptorAppendIfFastOrUseFullAllDoubles) {
556 CcTest::InitializeVM(); 556 CcTest::InitializeVM();
557 Isolate* isolate = CcTest::i_isolate(); 557 Isolate* isolate = CcTest::i_isolate();
558 v8::HandleScope scope(CcTest::isolate()); 558 v8::HandleScope scope(CcTest::isolate());
559 559
560 Handle<LayoutDescriptor> layout_descriptor; 560 Handle<LayoutDescriptor> layout_descriptor;
561 const int kPropsCount = kSmiValueSize * 3; 561 const int kPropsCount = kSmiValueSize * 3;
562 PropertyKind props[kPropsCount]; 562 TestPropertyKind props[kPropsCount];
563 for (int i = 0; i < kPropsCount; i++) { 563 for (int i = 0; i < kPropsCount; i++) {
564 props[i] = PROP_DOUBLE; 564 props[i] = PROP_DOUBLE;
565 } 565 }
566 Handle<DescriptorArray> descriptors = 566 Handle<DescriptorArray> descriptors =
567 CreateDescriptorArray(isolate, props, kPropsCount); 567 CreateDescriptorArray(isolate, props, kPropsCount);
568 568
569 layout_descriptor = TestLayoutDescriptorAppendIfFastOrUseFull( 569 layout_descriptor = TestLayoutDescriptorAppendIfFastOrUseFull(
570 isolate, 0, descriptors, kPropsCount); 570 isolate, 0, descriptors, kPropsCount);
571 CHECK(!layout_descriptor->IsSlowLayout()); 571 CHECK(!layout_descriptor->IsSlowLayout());
572 572
(...skipping 30 matching lines...) Expand all
603 } 603 }
604 604
605 605
606 TEST(Regress436816) { 606 TEST(Regress436816) {
607 CcTest::InitializeVM(); 607 CcTest::InitializeVM();
608 Isolate* isolate = CcTest::i_isolate(); 608 Isolate* isolate = CcTest::i_isolate();
609 Factory* factory = isolate->factory(); 609 Factory* factory = isolate->factory();
610 v8::HandleScope scope(CcTest::isolate()); 610 v8::HandleScope scope(CcTest::isolate());
611 611
612 const int kPropsCount = kSmiValueSize * 3; 612 const int kPropsCount = kSmiValueSize * 3;
613 PropertyKind props[kPropsCount]; 613 TestPropertyKind props[kPropsCount];
614 for (int i = 0; i < kPropsCount; i++) { 614 for (int i = 0; i < kPropsCount; i++) {
615 props[i] = PROP_DOUBLE; 615 props[i] = PROP_DOUBLE;
616 } 616 }
617 Handle<DescriptorArray> descriptors = 617 Handle<DescriptorArray> descriptors =
618 CreateDescriptorArray(isolate, props, kPropsCount); 618 CreateDescriptorArray(isolate, props, kPropsCount);
619 619
620 Handle<Map> map = Map::Create(isolate, kPropsCount); 620 Handle<Map> map = Map::Create(isolate, kPropsCount);
621 Handle<LayoutDescriptor> layout_descriptor = 621 Handle<LayoutDescriptor> layout_descriptor =
622 LayoutDescriptor::New(map, descriptors, kPropsCount); 622 LayoutDescriptor::New(map, descriptors, kPropsCount);
623 map->InitializeDescriptors(*descriptors, *layout_descriptor); 623 map->InitializeDescriptors(*descriptors, *layout_descriptor);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address()); 765 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address());
766 chunk->set_scan_on_scavenge(true); 766 chunk->set_scan_on_scavenge(true);
767 767
768 // Trigger GCs and force evacuation. Should not crash there. 768 // Trigger GCs and force evacuation. Should not crash there.
769 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 769 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
770 770
771 CHECK_EQ(boom_value, GetDoubleFieldValue(*obj, field_index)); 771 CHECK_EQ(boom_value, GetDoubleFieldValue(*obj, field_index));
772 } 772 }
773 773
774 #endif 774 #endif
OLDNEW
« no previous file with comments | « src/serialize.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698