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

Side by Side 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, 8 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/objects.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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api.h" 8 #include "src/api.h"
9 #include "src/base/bits.h" 9 #include "src/base/bits.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 3507 matching lines...) Expand 10 before | Expand all | Expand 10 after
3518 MemoryChunk::IncrementLiveBytesFromGC(address, by); 3518 MemoryChunk::IncrementLiveBytesFromGC(address, by);
3519 } else { 3519 } else {
3520 MemoryChunk::IncrementLiveBytesFromMutator(address, by); 3520 MemoryChunk::IncrementLiveBytesFromMutator(address, by);
3521 } 3521 }
3522 } 3522 }
3523 } 3523 }
3524 3524
3525 3525
3526 FixedArrayBase* Heap::LeftTrimFixedArray(FixedArrayBase* object, 3526 FixedArrayBase* Heap::LeftTrimFixedArray(FixedArrayBase* object,
3527 int elements_to_trim) { 3527 int elements_to_trim) {
3528 DCHECK(!object->IsFixedTypedArrayBase());
3528 const int element_size = object->IsFixedArray() ? kPointerSize : kDoubleSize; 3529 const int element_size = object->IsFixedArray() ? kPointerSize : kDoubleSize;
3529 const int bytes_to_trim = elements_to_trim * element_size; 3530 const int bytes_to_trim = elements_to_trim * element_size;
3530 Map* map = object->map(); 3531 Map* map = object->map();
3531 3532
3532 // For now this trick is only applied to objects in new and paged space. 3533 // For now this trick is only applied to objects in new and paged space.
3533 // In large object space the object's start must coincide with chunk 3534 // In large object space the object's start must coincide with chunk
3534 // and thus the trick is just not applicable. 3535 // and thus the trick is just not applicable.
3535 DCHECK(!lo_space()->Contains(object)); 3536 DCHECK(!lo_space()->Contains(object));
3536 DCHECK(object->map() != fixed_cow_array_map()); 3537 DCHECK(object->map() != fixed_cow_array_map());
3537 3538
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3573 3574
3574 // Force instantiation of templatized method. 3575 // Force instantiation of templatized method.
3575 template 3576 template
3576 void Heap::RightTrimFixedArray<Heap::FROM_GC>(FixedArrayBase*, int); 3577 void Heap::RightTrimFixedArray<Heap::FROM_GC>(FixedArrayBase*, int);
3577 template 3578 template
3578 void Heap::RightTrimFixedArray<Heap::FROM_MUTATOR>(FixedArrayBase*, int); 3579 void Heap::RightTrimFixedArray<Heap::FROM_MUTATOR>(FixedArrayBase*, int);
3579 3580
3580 3581
3581 template<Heap::InvocationMode mode> 3582 template<Heap::InvocationMode mode>
3582 void Heap::RightTrimFixedArray(FixedArrayBase* object, int elements_to_trim) { 3583 void Heap::RightTrimFixedArray(FixedArrayBase* object, int elements_to_trim) {
3583 const int element_size = object->IsFixedArray() ? kPointerSize : kDoubleSize; 3584 const int len = object->length();
3584 const int bytes_to_trim = elements_to_trim * element_size; 3585 DCHECK(elements_to_trim < len);
3586
3587 int bytes_to_trim;
3588 if (object->IsFixedTypedArrayBase()) {
3589 InstanceType type = object->map()->instance_type();
3590 bytes_to_trim =
3591 FixedTypedArrayBase::TypedArraySize(type, len) -
3592 FixedTypedArrayBase::TypedArraySize(type, len - elements_to_trim);
3593 } else {
3594 const int element_size =
3595 object->IsFixedArray() ? kPointerSize : kDoubleSize;
3596 bytes_to_trim = elements_to_trim * element_size;
3597 }
3585 3598
3586 // For now this trick is only applied to objects in new and paged space. 3599 // For now this trick is only applied to objects in new and paged space.
3587 DCHECK(object->map() != fixed_cow_array_map()); 3600 DCHECK(object->map() != fixed_cow_array_map());
3588 3601
3589 const int len = object->length(); 3602 if (bytes_to_trim == 0) {
3590 DCHECK(elements_to_trim < len); 3603 // No need to create filler and update live bytes counters, just initialize
3604 // header of the trimmed array.
3605 object->synchronized_set_length(len - elements_to_trim);
3606 return;
3607 }
3591 3608
3592 // Calculate location of new array end. 3609 // Calculate location of new array end.
3593 Address new_end = object->address() + object->Size() - bytes_to_trim; 3610 Address new_end = object->address() + object->Size() - bytes_to_trim;
3594 3611
3595 // Technically in new space this write might be omitted (except for 3612 // Technically in new space this write might be omitted (except for
3596 // debug mode which iterates through the heap), but to play safer 3613 // debug mode which iterates through the heap), but to play safer
3597 // we still do it. 3614 // we still do it.
3598 // We do not create a filler for objects in large object space. 3615 // We do not create a filler for objects in large object space.
3599 // TODO(hpayer): We should shrink the large object page if the size 3616 // TODO(hpayer): We should shrink the large object page if the size
3600 // of the object changed significantly. 3617 // of the object changed significantly.
(...skipping 2817 matching lines...) Expand 10 before | Expand all | Expand 10 after
6418 static_cast<int>(object_sizes_last_time_[index])); 6435 static_cast<int>(object_sizes_last_time_[index]));
6419 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 6436 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
6420 #undef ADJUST_LAST_TIME_OBJECT_COUNT 6437 #undef ADJUST_LAST_TIME_OBJECT_COUNT
6421 6438
6422 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 6439 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
6423 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 6440 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
6424 ClearObjectStats(); 6441 ClearObjectStats();
6425 } 6442 }
6426 } 6443 }
6427 } // namespace v8::internal 6444 } // namespace v8::internal
OLDNEW
« 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