Chromium Code Reviews| Index: src/heap/heap.cc |
| diff --git a/src/heap/heap.cc b/src/heap/heap.cc |
| index b0ddc7d457e8dd6091d28802475f9bfe57cc27f1..0273abc525e147c08bd5fefc6e01a3c40f98641f 100644 |
| --- a/src/heap/heap.cc |
| +++ b/src/heap/heap.cc |
| @@ -3525,6 +3525,7 @@ void Heap::AdjustLiveBytes(Address address, int by, InvocationMode mode) { |
| FixedArrayBase* Heap::LeftTrimFixedArray(FixedArrayBase* object, |
| int elements_to_trim) { |
| + DCHECK(!object->IsFixedTypedArrayBase()); |
| const int element_size = object->IsFixedArray() ? kPointerSize : kDoubleSize; |
| const int bytes_to_trim = elements_to_trim * element_size; |
| Map* map = object->map(); |
| @@ -3580,17 +3581,30 @@ void Heap::RightTrimFixedArray<Heap::FROM_MUTATOR>(FixedArrayBase*, int); |
| template<Heap::InvocationMode mode> |
| void Heap::RightTrimFixedArray(FixedArrayBase* object, int elements_to_trim) { |
| - const int element_size = object->IsFixedArray() ? kPointerSize : kDoubleSize; |
| - const int bytes_to_trim = elements_to_trim * element_size; |
| + const int len = object->length(); |
| + DCHECK(elements_to_trim < len); |
| + |
| + int bytes_to_trim; |
| + if (object->IsFixedTypedArrayBase()) { |
| + InstanceType type = object->map()->instance_type(); |
| + bytes_to_trim = |
| + FixedTypedArrayBase::TypedArraySize(type, len) - |
| + FixedTypedArrayBase::TypedArraySize(type, len - elements_to_trim); |
| + } else { |
| + const int element_size = |
| + object->IsFixedArray() ? kPointerSize : kDoubleSize; |
| + bytes_to_trim = elements_to_trim * element_size; |
| + } |
| // For now this trick is only applied to objects in new and paged space. |
| DCHECK(object->map() != fixed_cow_array_map()); |
| - const int len = object->length(); |
| - DCHECK(elements_to_trim < len); |
| - |
| - // Calculate location of new array end. |
| - Address new_end = object->address() + object->Size() - bytes_to_trim; |
| + if (bytes_to_trim == 0) { |
| + // No need to create filler and update live bytes counters, just initialize |
| + // header of the trimmed array. |
| + object->synchronized_set_length(len - elements_to_trim); |
| + return; |
| + } |
| // Technically in new space this write might be omitted (except for |
| // debug mode which iterates through the heap), but to play safer |
| @@ -3599,6 +3613,8 @@ void Heap::RightTrimFixedArray(FixedArrayBase* object, int elements_to_trim) { |
| // TODO(hpayer): We should shrink the large object page if the size |
| // of the object changed significantly. |
| if (!lo_space()->Contains(object)) { |
| + // Calculate location of new array end. |
| + Address new_end = object->address() + object->Size() - bytes_to_trim; |
|
Michael Starzinger
2015/04/02 10:45:27
nit: Can we keep the calculation outside where it
Igor Sheludko
2015/04/02 11:03:10
Done.
|
| CreateFillerObjectAt(new_end, bytes_to_trim); |
| } |