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

Unified Diff: src/heap/heap.cc

Issue 1058793002: Support for typed arrays added to Heap::RightTrimFixedArray(). (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/objects.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « no previous file | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698