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

Side by Side Diff: src/elements.cc

Issue 1543563002: [elements] Enable left-trimming again (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: improve comment Created 4 years, 12 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
« no previous file with comments | « no previous file | src/flag-definitions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 "src/elements.h" 5 #include "src/elements.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/conversions.h" 8 #include "src/conversions.h"
9 #include "src/factory.h" 9 #include "src/factory.h"
10 #include "src/messages.h" 10 #include "src/messages.h"
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 return ElementsAccessorSubclass::ShiftImpl(receiver, backing_store); 670 return ElementsAccessorSubclass::ShiftImpl(receiver, backing_store);
671 } 671 }
672 672
673 static Handle<Object> ShiftImpl(Handle<JSArray> receiver, 673 static Handle<Object> ShiftImpl(Handle<JSArray> receiver,
674 Handle<FixedArrayBase> backing_store) { 674 Handle<FixedArrayBase> backing_store) {
675 UNREACHABLE(); 675 UNREACHABLE();
676 return Handle<Object>(); 676 return Handle<Object>();
677 } 677 }
678 678
679 void SetLength(Handle<JSArray> array, uint32_t length) final { 679 void SetLength(Handle<JSArray> array, uint32_t length) final {
680 ElementsAccessorSubclass::SetLengthImpl(array, length, 680 ElementsAccessorSubclass::SetLengthImpl(array->GetIsolate(), array, length,
681 handle(array->elements())); 681 handle(array->elements()));
682 } 682 }
683 683
684 static void SetLengthImpl(Handle<JSArray> array, uint32_t length, 684 static void SetLengthImpl(Isolate* isolate, Handle<JSArray> array,
685 uint32_t length,
685 Handle<FixedArrayBase> backing_store) { 686 Handle<FixedArrayBase> backing_store) {
686 DCHECK(!array->SetLengthWouldNormalize(length)); 687 DCHECK(!array->SetLengthWouldNormalize(length));
687 DCHECK(IsFastElementsKind(array->GetElementsKind())); 688 DCHECK(IsFastElementsKind(array->GetElementsKind()));
688 uint32_t old_length = 0; 689 uint32_t old_length = 0;
689 CHECK(array->length()->ToArrayIndex(&old_length)); 690 CHECK(array->length()->ToArrayIndex(&old_length));
690 691
691 if (old_length < length) { 692 if (old_length < length) {
692 ElementsKind kind = array->GetElementsKind(); 693 ElementsKind kind = array->GetElementsKind();
693 if (!IsFastHoleyElementsKind(kind)) { 694 if (!IsFastHoleyElementsKind(kind)) {
694 kind = GetHoleyElementsKind(kind); 695 kind = GetHoleyElementsKind(kind);
695 JSObject::TransitionElementsKind(array, kind); 696 JSObject::TransitionElementsKind(array, kind);
696 } 697 }
697 } 698 }
698 699
699 // Check whether the backing store should be shrunk. 700 // Check whether the backing store should be shrunk.
700 uint32_t capacity = backing_store->length(); 701 uint32_t capacity = backing_store->length();
702 old_length = Min(old_length, capacity);
701 if (length == 0) { 703 if (length == 0) {
702 array->initialize_elements(); 704 array->initialize_elements();
703 } else if (length <= capacity) { 705 } else if (length <= capacity) {
704 if (array->HasFastSmiOrObjectElements()) { 706 if (array->HasFastSmiOrObjectElements()) {
705 backing_store = JSObject::EnsureWritableFastElements(array); 707 backing_store = JSObject::EnsureWritableFastElements(array);
706 } 708 }
707 if (2 * length <= capacity) { 709 if (2 * length <= capacity) {
708 // If more than half the elements won't be used, trim the array. 710 // If more than half the elements won't be used, trim the array.
709 array->GetHeap()->RightTrimFixedArray<Heap::CONCURRENT_TO_SWEEPER>( 711 isolate->heap()->RightTrimFixedArray<Heap::CONCURRENT_TO_SWEEPER>(
710 *backing_store, capacity - length); 712 *backing_store, capacity - length);
711 } else { 713 } else {
712 // Otherwise, fill the unused tail with holes. 714 // Otherwise, fill the unused tail with holes.
713 for (uint32_t i = length; i < old_length; i++) { 715 for (uint32_t i = length; i < old_length; i++) {
714 BackingStore::cast(*backing_store)->set_the_hole(i); 716 BackingStore::cast(*backing_store)->set_the_hole(i);
715 } 717 }
716 } 718 }
717 } else { 719 } else {
718 // Check whether the backing store should be expanded. 720 // Check whether the backing store should be expanded.
719 capacity = Max(length, JSObject::NewElementsCapacity(capacity)); 721 capacity = Max(length, JSObject::NewElementsCapacity(capacity));
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 967
966 968
967 class DictionaryElementsAccessor 969 class DictionaryElementsAccessor
968 : public ElementsAccessorBase<DictionaryElementsAccessor, 970 : public ElementsAccessorBase<DictionaryElementsAccessor,
969 ElementsKindTraits<DICTIONARY_ELEMENTS> > { 971 ElementsKindTraits<DICTIONARY_ELEMENTS> > {
970 public: 972 public:
971 explicit DictionaryElementsAccessor(const char* name) 973 explicit DictionaryElementsAccessor(const char* name)
972 : ElementsAccessorBase<DictionaryElementsAccessor, 974 : ElementsAccessorBase<DictionaryElementsAccessor,
973 ElementsKindTraits<DICTIONARY_ELEMENTS> >(name) {} 975 ElementsKindTraits<DICTIONARY_ELEMENTS> >(name) {}
974 976
975 static void SetLengthImpl(Handle<JSArray> array, uint32_t length, 977 static void SetLengthImpl(Isolate* isolate, Handle<JSArray> array,
978 uint32_t length,
976 Handle<FixedArrayBase> backing_store) { 979 Handle<FixedArrayBase> backing_store) {
977 Handle<SeededNumberDictionary> dict = 980 Handle<SeededNumberDictionary> dict =
978 Handle<SeededNumberDictionary>::cast(backing_store); 981 Handle<SeededNumberDictionary>::cast(backing_store);
979 Isolate* isolate = array->GetIsolate();
980 int capacity = dict->Capacity(); 982 int capacity = dict->Capacity();
981 uint32_t old_length = 0; 983 uint32_t old_length = 0;
982 CHECK(array->length()->ToArrayLength(&old_length)); 984 CHECK(array->length()->ToArrayLength(&old_length));
983 if (length < old_length) { 985 if (length < old_length) {
984 if (dict->requires_slow_elements()) { 986 if (dict->requires_slow_elements()) {
985 // Find last non-deletable element in range of elements to be 987 // Find last non-deletable element in range of elements to be
986 // deleted and adjust range accordingly. 988 // deleted and adjust range accordingly.
987 for (int entry = 0; entry < capacity; entry++) { 989 for (int entry = 0; entry < capacity; entry++) {
988 DisallowHeapAllocation no_gc; 990 DisallowHeapAllocation no_gc;
989 Object* index = dict->KeyAt(entry); 991 Object* index = dict->KeyAt(entry);
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 args, push_size, AT_END); 1347 args, push_size, AT_END);
1346 } 1348 }
1347 1349
1348 static uint32_t UnshiftImpl(Handle<JSArray> receiver, 1350 static uint32_t UnshiftImpl(Handle<JSArray> receiver,
1349 Handle<FixedArrayBase> backing_store, 1351 Handle<FixedArrayBase> backing_store,
1350 Arguments* args, uint32_t unshift_size) { 1352 Arguments* args, uint32_t unshift_size) {
1351 return FastElementsAccessorSubclass::AddArguments( 1353 return FastElementsAccessorSubclass::AddArguments(
1352 receiver, backing_store, args, unshift_size, AT_START); 1354 receiver, backing_store, args, unshift_size, AT_START);
1353 } 1355 }
1354 1356
1355 static void MoveElements(Heap* heap, Handle<FixedArrayBase> backing_store, 1357 static void MoveElements(Isolate* isolate, Handle<JSArray> receiver,
1356 int dst_index, int src_index, int len, 1358 Handle<FixedArrayBase> backing_store, int dst_index,
1357 int hole_start, int hole_end) { 1359 int src_index, int len, int hole_start,
1360 int hole_end) {
1358 UNREACHABLE(); 1361 UNREACHABLE();
1359 } 1362 }
1360 1363
1361 static Handle<JSArray> SliceImpl(Handle<JSObject> receiver, 1364 static Handle<JSArray> SliceImpl(Handle<JSObject> receiver,
1362 Handle<FixedArrayBase> backing_store, 1365 Handle<FixedArrayBase> backing_store,
1363 uint32_t start, uint32_t end) { 1366 uint32_t start, uint32_t end) {
1364 DCHECK(start < end); 1367 DCHECK(start < end);
1365 Isolate* isolate = receiver->GetIsolate(); 1368 Isolate* isolate = receiver->GetIsolate();
1366 int result_len = end - start; 1369 int result_len = end - start;
1367 Handle<JSArray> result_array = isolate->factory()->NewJSArray( 1370 Handle<JSArray> result_array = isolate->factory()->NewJSArray(
(...skipping 28 matching lines...) Expand all
1396 KindTraits::Kind, delete_count, delete_count); 1399 KindTraits::Kind, delete_count, delete_count);
1397 if (delete_count > 0) { 1400 if (delete_count > 0) {
1398 DisallowHeapAllocation no_gc; 1401 DisallowHeapAllocation no_gc;
1399 FastElementsAccessorSubclass::CopyElementsImpl( 1402 FastElementsAccessorSubclass::CopyElementsImpl(
1400 *backing_store, start, deleted_elements->elements(), KindTraits::Kind, 1403 *backing_store, start, deleted_elements->elements(), KindTraits::Kind,
1401 0, kPackedSizeNotKnown, delete_count); 1404 0, kPackedSizeNotKnown, delete_count);
1402 } 1405 }
1403 1406
1404 // Delete and move elements to make space for add_count new elements. 1407 // Delete and move elements to make space for add_count new elements.
1405 if (add_count < delete_count) { 1408 if (add_count < delete_count) {
1406 FastElementsAccessorSubclass::SpliceShrinkStep(backing_store, heap, start, 1409 FastElementsAccessorSubclass::SpliceShrinkStep(
1407 delete_count, add_count, 1410 isolate, receiver, backing_store, start, delete_count, add_count,
1408 length, new_length); 1411 length, new_length);
1409 } else if (add_count > delete_count) { 1412 } else if (add_count > delete_count) {
1410 backing_store = FastElementsAccessorSubclass::SpliceGrowStep( 1413 backing_store = FastElementsAccessorSubclass::SpliceGrowStep(
1411 receiver, backing_store, isolate, heap, start, delete_count, 1414 isolate, receiver, backing_store, start, delete_count, add_count,
1412 add_count, length, new_length); 1415 length, new_length);
1413 } 1416 }
1414 1417
1415 // Copy over the arguments. 1418 // Copy over the arguments.
1416 FastElementsAccessorSubclass::CopyArguments(args, backing_store, add_count, 1419 FastElementsAccessorSubclass::CopyArguments(args, backing_store, add_count,
1417 3, start); 1420 3, start);
1418 1421
1419 receiver->set_length(Smi::FromInt(new_length)); 1422 receiver->set_length(Smi::FromInt(new_length));
1420 FastElementsAccessorSubclass::TryTransitionResultArrayToPacked( 1423 FastElementsAccessorSubclass::TryTransitionResultArrayToPacked(
1421 deleted_elements); 1424 deleted_elements);
1422 return deleted_elements; 1425 return deleted_elements;
1423 } 1426 }
1424 1427
1425 private: 1428 private:
1426 static void SpliceShrinkStep(Handle<FixedArrayBase> backing_store, Heap* heap, 1429 // SpliceShrinkStep might modify the backing_store.
1430 static void SpliceShrinkStep(Isolate* isolate, Handle<JSArray> receiver,
1431 Handle<FixedArrayBase> backing_store,
1427 uint32_t start, uint32_t delete_count, 1432 uint32_t start, uint32_t delete_count,
1428 uint32_t add_count, uint32_t len, 1433 uint32_t add_count, uint32_t len,
1429 uint32_t new_length) { 1434 uint32_t new_length) {
1430 const int move_left_count = len - delete_count - start; 1435 const int move_left_count = len - delete_count - start;
1431 const int move_left_dst_index = start + add_count; 1436 const int move_left_dst_index = start + add_count;
1432 FastElementsAccessorSubclass::MoveElements( 1437 FastElementsAccessorSubclass::MoveElements(
1433 heap, backing_store, move_left_dst_index, start + delete_count, 1438 isolate, receiver, backing_store, move_left_dst_index,
1434 move_left_count, new_length, len); 1439 start + delete_count, move_left_count, new_length, len);
1435 } 1440 }
1436 1441
1437 1442 // SpliceGrowStep might modify the backing_store.
1438 static Handle<FixedArrayBase> SpliceGrowStep( 1443 static Handle<FixedArrayBase> SpliceGrowStep(
1439 Handle<JSArray> receiver, Handle<FixedArrayBase> backing_store, 1444 Isolate* isolate, Handle<JSArray> receiver,
1440 Isolate* isolate, Heap* heap, uint32_t start, uint32_t delete_count, 1445 Handle<FixedArrayBase> backing_store, uint32_t start,
1441 uint32_t add_count, uint32_t length, uint32_t new_length) { 1446 uint32_t delete_count, uint32_t add_count, uint32_t length,
1447 uint32_t new_length) {
1442 // Check we do not overflow the new_length. 1448 // Check we do not overflow the new_length.
1443 DCHECK((add_count - delete_count) <= (Smi::kMaxValue - length)); 1449 DCHECK((add_count - delete_count) <= (Smi::kMaxValue - length));
1444 // Check if backing_store is big enough. 1450 // Check if backing_store is big enough.
1445 if (new_length <= static_cast<uint32_t>(backing_store->length())) { 1451 if (new_length <= static_cast<uint32_t>(backing_store->length())) {
1446 FastElementsAccessorSubclass::MoveElements( 1452 FastElementsAccessorSubclass::MoveElements(
1447 heap, backing_store, start + add_count, start + delete_count, 1453 isolate, receiver, backing_store, start + add_count,
1448 (length - delete_count - start), 0, 0); 1454 start + delete_count, (length - delete_count - start), 0, 0);
1455 // MoveElements updates the backing_store in-place.
1449 return backing_store; 1456 return backing_store;
1450 } 1457 }
1451 // New backing storage is needed. 1458 // New backing storage is needed.
1452 int capacity = JSObject::NewElementsCapacity(new_length); 1459 int capacity = JSObject::NewElementsCapacity(new_length);
1453 // Partially copy all elements up to start. 1460 // Partially copy all elements up to start.
1454 Handle<FixedArrayBase> new_elms = 1461 Handle<FixedArrayBase> new_elms =
1455 FastElementsAccessorSubclass::ConvertElementsWithCapacity( 1462 FastElementsAccessorSubclass::ConvertElementsWithCapacity(
1456 receiver, backing_store, KindTraits::Kind, capacity, start); 1463 receiver, backing_store, KindTraits::Kind, capacity, start);
1457 // Copy the trailing elements after start + delete_count 1464 // Copy the trailing elements after start + delete_count
1458 FastElementsAccessorSubclass::CopyElementsImpl( 1465 FastElementsAccessorSubclass::CopyElementsImpl(
1459 *backing_store, start + delete_count, *new_elms, KindTraits::Kind, 1466 *backing_store, start + delete_count, *new_elms, KindTraits::Kind,
1460 start + add_count, kPackedSizeNotKnown, 1467 start + add_count, kPackedSizeNotKnown,
1461 ElementsAccessor::kCopyToEndAndInitializeToHole); 1468 ElementsAccessor::kCopyToEndAndInitializeToHole);
1462 receiver->set_elements(*new_elms); 1469 receiver->set_elements(*new_elms);
1463 return new_elms; 1470 return new_elms;
1464 } 1471 }
1465 1472
1466 static Handle<Object> RemoveElement(Handle<JSArray> receiver, 1473 static Handle<Object> RemoveElement(Handle<JSArray> receiver,
1467 Handle<FixedArrayBase> backing_store, 1474 Handle<FixedArrayBase> backing_store,
1468 Where remove_position) { 1475 Where remove_position) {
1476 Isolate* isolate = receiver->GetIsolate();
1469 uint32_t length = 1477 uint32_t length =
1470 static_cast<uint32_t>(Smi::cast(receiver->length())->value()); 1478 static_cast<uint32_t>(Smi::cast(receiver->length())->value());
1471 Isolate* isolate = receiver->GetIsolate();
1472 DCHECK(length > 0); 1479 DCHECK(length > 0);
1473 int new_length = length - 1; 1480 int new_length = length - 1;
1474 int remove_index = remove_position == AT_START ? 0 : new_length; 1481 int remove_index = remove_position == AT_START ? 0 : new_length;
1475 Handle<Object> result = 1482 Handle<Object> result =
1476 FastElementsAccessorSubclass::GetImpl(backing_store, remove_index); 1483 FastElementsAccessorSubclass::GetImpl(backing_store, remove_index);
1477 if (remove_position == AT_START) { 1484 if (remove_position == AT_START) {
1478 Heap* heap = isolate->heap(); 1485 FastElementsAccessorSubclass::MoveElements(
1479 FastElementsAccessorSubclass::MoveElements(heap, backing_store, 0, 1, 1486 isolate, receiver, backing_store, 0, 1, new_length, 0, 0);
1480 new_length, 0, 0);
1481 } 1487 }
1482 FastElementsAccessorSubclass::SetLengthImpl(receiver, new_length, 1488 FastElementsAccessorSubclass::SetLengthImpl(isolate, receiver, new_length,
1483 backing_store); 1489 backing_store);
1484 1490
1485 if (IsHoleyElementsKind(KindTraits::Kind) && result->IsTheHole()) { 1491 if (IsHoleyElementsKind(KindTraits::Kind) && result->IsTheHole()) {
1486 return receiver->GetIsolate()->factory()->undefined_value(); 1492 return receiver->GetIsolate()->factory()->undefined_value();
1487 } 1493 }
1488 return result; 1494 return result;
1489 } 1495 }
1490 1496
1491 static uint32_t AddArguments(Handle<JSArray> receiver, 1497 static uint32_t AddArguments(Handle<JSArray> receiver,
1492 Handle<FixedArrayBase> backing_store, 1498 Handle<FixedArrayBase> backing_store,
(...skipping 13 matching lines...) Expand all
1506 int copy_dst_index = remove_position == AT_START ? add_size : 0; 1512 int copy_dst_index = remove_position == AT_START ? add_size : 0;
1507 // Copy over all objects to a new backing_store. 1513 // Copy over all objects to a new backing_store.
1508 backing_store = FastElementsAccessorSubclass::ConvertElementsWithCapacity( 1514 backing_store = FastElementsAccessorSubclass::ConvertElementsWithCapacity(
1509 receiver, backing_store, KindTraits::Kind, capacity, 0, 1515 receiver, backing_store, KindTraits::Kind, capacity, 0,
1510 copy_dst_index, ElementsAccessor::kCopyToEndAndInitializeToHole); 1516 copy_dst_index, ElementsAccessor::kCopyToEndAndInitializeToHole);
1511 receiver->set_elements(*backing_store); 1517 receiver->set_elements(*backing_store);
1512 } else if (remove_position == AT_START) { 1518 } else if (remove_position == AT_START) {
1513 // If the backing store has enough capacity and we add elements to the 1519 // If the backing store has enough capacity and we add elements to the
1514 // start we have to shift the existing objects. 1520 // start we have to shift the existing objects.
1515 Isolate* isolate = receiver->GetIsolate(); 1521 Isolate* isolate = receiver->GetIsolate();
1516 FastElementsAccessorSubclass::MoveElements(isolate->heap(), backing_store, 1522 FastElementsAccessorSubclass::MoveElements(
1517 add_size, 0, length, 0, 0); 1523 isolate, receiver, backing_store, add_size, 0, length, 0, 0);
1518 } 1524 }
1519 1525
1520 int insertion_index = remove_position == AT_START ? 0 : length; 1526 int insertion_index = remove_position == AT_START ? 0 : length;
1521 // Copy the arguments to the start. 1527 // Copy the arguments to the start.
1522 FastElementsAccessorSubclass::CopyArguments(args, backing_store, add_size, 1528 FastElementsAccessorSubclass::CopyArguments(args, backing_store, add_size,
1523 1, insertion_index); 1529 1, insertion_index);
1524 // Set the length. 1530 // Set the length.
1525 receiver->set_length(Smi::FromInt(new_length)); 1531 receiver->set_length(Smi::FromInt(new_length));
1526 return new_length; 1532 return new_length;
1527 } 1533 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 Object* value, WriteBarrierMode mode) { 1566 Object* value, WriteBarrierMode mode) {
1561 FixedArray::cast(backing_store)->set(entry, value, mode); 1567 FixedArray::cast(backing_store)->set(entry, value, mode);
1562 } 1568 }
1563 1569
1564 static Object* GetRaw(FixedArray* backing_store, uint32_t entry) { 1570 static Object* GetRaw(FixedArray* backing_store, uint32_t entry) {
1565 uint32_t index = FastElementsAccessorSubclass::GetIndexForEntryImpl( 1571 uint32_t index = FastElementsAccessorSubclass::GetIndexForEntryImpl(
1566 backing_store, entry); 1572 backing_store, entry);
1567 return backing_store->get(index); 1573 return backing_store->get(index);
1568 } 1574 }
1569 1575
1570 static void MoveElements(Heap* heap, Handle<FixedArrayBase> backing_store, 1576 static void MoveElements(Isolate* isolate, Handle<JSArray> receiver,
1571 int dst_index, int src_index, int len, 1577 Handle<FixedArrayBase> backing_store, int dst_index,
1572 int hole_start, int hole_end) { 1578 int src_index, int len, int hole_start,
1579 int hole_end) {
1580 Heap* heap = isolate->heap();
1573 Handle<FixedArray> dst_elms = Handle<FixedArray>::cast(backing_store); 1581 Handle<FixedArray> dst_elms = Handle<FixedArray>::cast(backing_store);
1574 if (len != 0) { 1582 if (heap->CanMoveObjectStart(*dst_elms) && dst_index == 0) {
1583 // Update all the copies of this backing_store handle.
1584 *dst_elms.location() =
1585 FixedArray::cast(heap->LeftTrimFixedArray(*dst_elms, src_index));
1586 receiver->set_elements(*dst_elms);
1587 // Adjust the hole offset as the array has been shrunk.
1588 hole_end -= src_index;
1589 DCHECK_LE(hole_start, backing_store->length());
1590 DCHECK_LE(hole_end, backing_store->length());
1591 } else if (len != 0) {
1575 DisallowHeapAllocation no_gc; 1592 DisallowHeapAllocation no_gc;
1576 heap->MoveElements(*dst_elms, dst_index, src_index, len); 1593 heap->MoveElements(*dst_elms, dst_index, src_index, len);
1577 } 1594 }
1578 if (hole_start != hole_end) { 1595 if (hole_start != hole_end) {
1579 dst_elms->FillWithHoles(hole_start, hole_end); 1596 dst_elms->FillWithHoles(hole_start, hole_end);
1580 } 1597 }
1581 } 1598 }
1582 1599
1583 // NOTE: this method violates the handlified function signature convention: 1600 // NOTE: this method violates the handlified function signature convention:
1584 // raw pointer parameters in the function that allocates. 1601 // raw pointer parameters in the function that allocates.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 static inline void SetImpl(FixedArrayBase* backing_store, uint32_t entry, 1700 static inline void SetImpl(FixedArrayBase* backing_store, uint32_t entry,
1684 Object* value) { 1701 Object* value) {
1685 FixedDoubleArray::cast(backing_store)->set(entry, value->Number()); 1702 FixedDoubleArray::cast(backing_store)->set(entry, value->Number());
1686 } 1703 }
1687 1704
1688 static inline void SetImpl(FixedArrayBase* backing_store, uint32_t entry, 1705 static inline void SetImpl(FixedArrayBase* backing_store, uint32_t entry,
1689 Object* value, WriteBarrierMode mode) { 1706 Object* value, WriteBarrierMode mode) {
1690 FixedDoubleArray::cast(backing_store)->set(entry, value->Number()); 1707 FixedDoubleArray::cast(backing_store)->set(entry, value->Number());
1691 } 1708 }
1692 1709
1693 static void MoveElements(Heap* heap, Handle<FixedArrayBase> backing_store, 1710 static void MoveElements(Isolate* isolate, Handle<JSArray> receiver,
1694 int dst_index, int src_index, int len, 1711 Handle<FixedArrayBase> backing_store, int dst_index,
1695 int hole_start, int hole_end) { 1712 int src_index, int len, int hole_start,
1713 int hole_end) {
1714 Heap* heap = isolate->heap();
1696 Handle<FixedDoubleArray> dst_elms = 1715 Handle<FixedDoubleArray> dst_elms =
1697 Handle<FixedDoubleArray>::cast(backing_store); 1716 Handle<FixedDoubleArray>::cast(backing_store);
1698 if (len != 0) { 1717 if (heap->CanMoveObjectStart(*dst_elms) && dst_index == 0) {
1718 // Update all the copies of this backing_store handle.
1719 *dst_elms.location() = FixedDoubleArray::cast(
1720 heap->LeftTrimFixedArray(*dst_elms, src_index));
1721 receiver->set_elements(*dst_elms);
1722 // Adjust the hole offset as the array has been shrunk.
1723 hole_end -= src_index;
1724 DCHECK_LE(hole_start, backing_store->length());
1725 DCHECK_LE(hole_end, backing_store->length());
1726 } else if (len != 0) {
1699 MemMove(dst_elms->data_start() + dst_index, 1727 MemMove(dst_elms->data_start() + dst_index,
1700 dst_elms->data_start() + src_index, len * kDoubleSize); 1728 dst_elms->data_start() + src_index, len * kDoubleSize);
1701 } 1729 }
1702 if (hole_start != hole_end) { 1730 if (hole_start != hole_end) {
1703 dst_elms->FillWithHoles(hole_start, hole_end); 1731 dst_elms->FillWithHoles(hole_start, hole_end);
1704 } 1732 }
1705 } 1733 }
1706 1734
1707 static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start, 1735 static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start,
1708 FixedArrayBase* to, ElementsKind from_kind, 1736 FixedArrayBase* to, ElementsKind from_kind,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1794 uint32_t entry) { 1822 uint32_t entry) {
1795 uint32_t index = GetIndexForEntryImpl(*backing_store, entry); 1823 uint32_t index = GetIndexForEntryImpl(*backing_store, entry);
1796 return BackingStore::get(Handle<BackingStore>::cast(backing_store), index); 1824 return BackingStore::get(Handle<BackingStore>::cast(backing_store), index);
1797 } 1825 }
1798 1826
1799 static PropertyDetails GetDetailsImpl(FixedArrayBase* backing_store, 1827 static PropertyDetails GetDetailsImpl(FixedArrayBase* backing_store,
1800 uint32_t entry) { 1828 uint32_t entry) {
1801 return PropertyDetails(DONT_DELETE, DATA, 0, PropertyCellType::kNoCell); 1829 return PropertyDetails(DONT_DELETE, DATA, 0, PropertyCellType::kNoCell);
1802 } 1830 }
1803 1831
1804 static void SetLengthImpl(Handle<JSArray> array, uint32_t length, 1832 static void SetLengthImpl(Isolate* isolate, Handle<JSArray> array,
1833 uint32_t length,
1805 Handle<FixedArrayBase> backing_store) { 1834 Handle<FixedArrayBase> backing_store) {
1806 // External arrays do not support changing their length. 1835 // External arrays do not support changing their length.
1807 UNREACHABLE(); 1836 UNREACHABLE();
1808 } 1837 }
1809 1838
1810 static void DeleteImpl(Handle<JSObject> obj, uint32_t entry) { 1839 static void DeleteImpl(Handle<JSObject> obj, uint32_t entry) {
1811 UNREACHABLE(); 1840 UNREACHABLE();
1812 } 1841 }
1813 1842
1814 static uint32_t GetIndexForEntryImpl(FixedArrayBase* backing_store, 1843 static uint32_t GetIndexForEntryImpl(FixedArrayBase* backing_store,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1908 Context* context = Context::cast(parameter_map->get(0)); 1937 Context* context = Context::cast(parameter_map->get(0));
1909 int context_entry = alias->aliased_context_slot(); 1938 int context_entry = alias->aliased_context_slot();
1910 DCHECK(!context->get(context_entry)->IsTheHole()); 1939 DCHECK(!context->get(context_entry)->IsTheHole());
1911 context->set(context_entry, value); 1940 context->set(context_entry, value);
1912 } else { 1941 } else {
1913 ArgumentsAccessor::SetImpl(arguments, entry - length, value); 1942 ArgumentsAccessor::SetImpl(arguments, entry - length, value);
1914 } 1943 }
1915 } 1944 }
1916 } 1945 }
1917 1946
1918 static void SetLengthImpl(Handle<JSArray> array, uint32_t length, 1947 static void SetLengthImpl(Isolate* isolate, Handle<JSArray> array,
1948 uint32_t length,
1919 Handle<FixedArrayBase> parameter_map) { 1949 Handle<FixedArrayBase> parameter_map) {
1920 // Sloppy arguments objects are not arrays. 1950 // Sloppy arguments objects are not arrays.
1921 UNREACHABLE(); 1951 UNREACHABLE();
1922 } 1952 }
1923 1953
1924 static uint32_t GetCapacityImpl(JSObject* holder, 1954 static uint32_t GetCapacityImpl(JSObject* holder,
1925 FixedArrayBase* backing_store) { 1955 FixedArrayBase* backing_store) {
1926 FixedArray* parameter_map = FixedArray::cast(backing_store); 1956 FixedArray* parameter_map = FixedArray::cast(backing_store);
1927 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); 1957 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1));
1928 return parameter_map->length() - 2 + 1958 return parameter_map->length() - 2 +
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
2385 } 2415 }
2386 } 2416 }
2387 2417
2388 DCHECK(j == result_len); 2418 DCHECK(j == result_len);
2389 return result_array; 2419 return result_array;
2390 } 2420 }
2391 2421
2392 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; 2422 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL;
2393 } // namespace internal 2423 } // namespace internal
2394 } // namespace v8 2424 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/flag-definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698