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

Side by Side Diff: src/heap/heap.cc

Issue 1305353010: Remove LeftTrimFixedArray (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 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 | « src/heap/heap.h ('k') | no next file » | 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/heap/heap.h" 5 #include "src/heap/heap.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 3469 matching lines...) Expand 10 before | Expand all | Expand 10 after
3480 Marking::IsBlack(Marking::MarkBitFrom(object->address()))) { 3480 Marking::IsBlack(Marking::MarkBitFrom(object->address()))) {
3481 if (mode == SEQUENTIAL_TO_SWEEPER) { 3481 if (mode == SEQUENTIAL_TO_SWEEPER) {
3482 MemoryChunk::IncrementLiveBytesFromGC(object, by); 3482 MemoryChunk::IncrementLiveBytesFromGC(object, by);
3483 } else { 3483 } else {
3484 MemoryChunk::IncrementLiveBytesFromMutator(object, by); 3484 MemoryChunk::IncrementLiveBytesFromMutator(object, by);
3485 } 3485 }
3486 } 3486 }
3487 } 3487 }
3488 3488
3489 3489
3490 FixedArrayBase* Heap::LeftTrimFixedArray(FixedArrayBase* object,
3491 int elements_to_trim) {
3492 DCHECK(!object->IsFixedTypedArrayBase());
3493 const int element_size = object->IsFixedArray() ? kPointerSize : kDoubleSize;
3494 const int bytes_to_trim = elements_to_trim * element_size;
3495 Map* map = object->map();
3496
3497 // For now this trick is only applied to objects in new and paged space.
3498 // In large object space the object's start must coincide with chunk
3499 // and thus the trick is just not applicable.
3500 DCHECK(!lo_space()->Contains(object));
3501 DCHECK(object->map() != fixed_cow_array_map());
3502
3503 STATIC_ASSERT(FixedArrayBase::kMapOffset == 0);
3504 STATIC_ASSERT(FixedArrayBase::kLengthOffset == kPointerSize);
3505 STATIC_ASSERT(FixedArrayBase::kHeaderSize == 2 * kPointerSize);
3506
3507 const int len = object->length();
3508 DCHECK(elements_to_trim <= len);
3509
3510 // Calculate location of new array start.
3511 Address new_start = object->address() + bytes_to_trim;
3512
3513 // Technically in new space this write might be omitted (except for
3514 // debug mode which iterates through the heap), but to play safer
3515 // we still do it.
3516 CreateFillerObjectAt(object->address(), bytes_to_trim);
3517
3518 // Initialize header of the trimmed array. Since left trimming is only
3519 // performed on pages which are not concurrently swept creating a filler
3520 // object does not require synchronization.
3521 DCHECK(CanMoveObjectStart(object));
3522 Object** former_start = HeapObject::RawField(object, 0);
3523 int new_start_index = elements_to_trim * (element_size / kPointerSize);
3524 former_start[new_start_index] = map;
3525 former_start[new_start_index + 1] = Smi::FromInt(len - elements_to_trim);
3526 FixedArrayBase* new_object =
3527 FixedArrayBase::cast(HeapObject::FromAddress(new_start));
3528
3529 // Maintain consistency of live bytes during incremental marking
3530 Marking::TransferMark(this, object->address(), new_start);
3531 AdjustLiveBytes(new_object, -bytes_to_trim, Heap::CONCURRENT_TO_SWEEPER);
3532
3533 // Notify the heap profiler of change in object layout.
3534 OnMoveEvent(new_object, object, new_object->Size());
3535 return new_object;
3536 }
3537
3538
3539 // Force instantiation of templatized method. 3490 // Force instantiation of templatized method.
3540 template void Heap::RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>( 3491 template void Heap::RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(
3541 FixedArrayBase*, int); 3492 FixedArrayBase*, int);
3542 template void Heap::RightTrimFixedArray<Heap::CONCURRENT_TO_SWEEPER>( 3493 template void Heap::RightTrimFixedArray<Heap::CONCURRENT_TO_SWEEPER>(
3543 FixedArrayBase*, int); 3494 FixedArrayBase*, int);
3544 3495
3545 3496
3546 template<Heap::InvocationMode mode> 3497 template<Heap::InvocationMode mode>
3547 void Heap::RightTrimFixedArray(FixedArrayBase* object, int elements_to_trim) { 3498 void Heap::RightTrimFixedArray(FixedArrayBase* object, int elements_to_trim) {
3548 const int len = object->length(); 3499 const int len = object->length();
(...skipping 3025 matching lines...) Expand 10 before | Expand all | Expand 10 after
6574 *object_sub_type = "CODE_AGE/" #name; \ 6525 *object_sub_type = "CODE_AGE/" #name; \
6575 return true; 6526 return true;
6576 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) 6527 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME)
6577 #undef COMPARE_AND_RETURN_NAME 6528 #undef COMPARE_AND_RETURN_NAME
6578 } 6529 }
6579 return false; 6530 return false;
6580 } 6531 }
6581 6532
6582 } // namespace internal 6533 } // namespace internal
6583 } // namespace v8 6534 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/heap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698