OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 |
3591 | 3604 // header of the trimmed array. |
3592 // Calculate location of new array end. | 3605 object->synchronized_set_length(len - elements_to_trim); |
3593 Address new_end = object->address() + object->Size() - bytes_to_trim; | 3606 return; |
3607 } | |
3594 | 3608 |
3595 // Technically in new space this write might be omitted (except for | 3609 // Technically in new space this write might be omitted (except for |
3596 // debug mode which iterates through the heap), but to play safer | 3610 // debug mode which iterates through the heap), but to play safer |
3597 // we still do it. | 3611 // we still do it. |
3598 // We do not create a filler for objects in large object space. | 3612 // 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 | 3613 // TODO(hpayer): We should shrink the large object page if the size |
3600 // of the object changed significantly. | 3614 // of the object changed significantly. |
3601 if (!lo_space()->Contains(object)) { | 3615 if (!lo_space()->Contains(object)) { |
3616 // Calculate location of new array end. | |
3617 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.
| |
3602 CreateFillerObjectAt(new_end, bytes_to_trim); | 3618 CreateFillerObjectAt(new_end, bytes_to_trim); |
3603 } | 3619 } |
3604 | 3620 |
3605 // Initialize header of the trimmed array. We are storing the new length | 3621 // Initialize header of the trimmed array. We are storing the new length |
3606 // using release store after creating a filler for the left-over space to | 3622 // using release store after creating a filler for the left-over space to |
3607 // avoid races with the sweeper thread. | 3623 // avoid races with the sweeper thread. |
3608 object->synchronized_set_length(len - elements_to_trim); | 3624 object->synchronized_set_length(len - elements_to_trim); |
3609 | 3625 |
3610 // Maintain consistency of live bytes during incremental marking | 3626 // Maintain consistency of live bytes during incremental marking |
3611 AdjustLiveBytes(object->address(), -bytes_to_trim, mode); | 3627 AdjustLiveBytes(object->address(), -bytes_to_trim, mode); |
(...skipping 2806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6418 static_cast<int>(object_sizes_last_time_[index])); | 6434 static_cast<int>(object_sizes_last_time_[index])); |
6419 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 6435 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
6420 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 6436 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
6421 | 6437 |
6422 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 6438 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
6423 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 6439 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
6424 ClearObjectStats(); | 6440 ClearObjectStats(); |
6425 } | 6441 } |
6426 } | 6442 } |
6427 } // namespace v8::internal | 6443 } // namespace v8::internal |
OLD | NEW |