Index: src/heap/heap.cc |
diff --git a/src/heap/heap.cc b/src/heap/heap.cc |
index b0ddc7d457e8dd6091d28802475f9bfe57cc27f1..85c59696a77357d3ebf565298bc1b270abb57190 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,14 +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); |
+ 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; |
+ } |
// Calculate location of new array end. |
Address new_end = object->address() + object->Size() - bytes_to_trim; |