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

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

Issue 1690953002: [runtime/heap] Introduce CopyFixedArrayUpTo to match CopyFixedArrayAndGrow, copying to a smaller ar… (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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') | src/objects.cc » ('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/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/ast/scopeinfo.h" 9 #include "src/ast/scopeinfo.h"
10 #include "src/base/bits.h" 10 #include "src/base/bits.h"
(...skipping 3763 matching lines...) Expand 10 before | Expand all | Expand 10 after
3774 AllocationResult Heap::CopyFixedArrayAndGrow(FixedArray* src, int grow_by, 3774 AllocationResult Heap::CopyFixedArrayAndGrow(FixedArray* src, int grow_by,
3775 PretenureFlag pretenure) { 3775 PretenureFlag pretenure) {
3776 int old_len = src->length(); 3776 int old_len = src->length();
3777 int new_len = old_len + grow_by; 3777 int new_len = old_len + grow_by;
3778 DCHECK(new_len >= old_len); 3778 DCHECK(new_len >= old_len);
3779 HeapObject* obj = nullptr; 3779 HeapObject* obj = nullptr;
3780 { 3780 {
3781 AllocationResult allocation = AllocateRawFixedArray(new_len, pretenure); 3781 AllocationResult allocation = AllocateRawFixedArray(new_len, pretenure);
3782 if (!allocation.To(&obj)) return allocation; 3782 if (!allocation.To(&obj)) return allocation;
3783 } 3783 }
3784
3784 obj->set_map_no_write_barrier(fixed_array_map()); 3785 obj->set_map_no_write_barrier(fixed_array_map());
3785 FixedArray* result = FixedArray::cast(obj); 3786 FixedArray* result = FixedArray::cast(obj);
3786 result->set_length(new_len); 3787 result->set_length(new_len);
3787 3788
3788 // Copy the content. 3789 // Copy the content.
3789 DisallowHeapAllocation no_gc; 3790 DisallowHeapAllocation no_gc;
3790 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); 3791 WriteBarrierMode mode = obj->GetWriteBarrierMode(no_gc);
3791 for (int i = 0; i < old_len; i++) result->set(i, src->get(i), mode); 3792 for (int i = 0; i < old_len; i++) result->set(i, src->get(i), mode);
3792 MemsetPointer(result->data_start() + old_len, undefined_value(), grow_by); 3793 MemsetPointer(result->data_start() + old_len, undefined_value(), grow_by);
3793 return result; 3794 return result;
3794 } 3795 }
3795 3796
3797 AllocationResult Heap::CopyFixedArrayUpTo(FixedArray* src, int new_len,
3798 PretenureFlag pretenure) {
3799 if (new_len == 0) return empty_fixed_array();
3800
3801 DCHECK_LE(new_len, src->length());
3802
3803 HeapObject* obj = nullptr;
3804 {
3805 AllocationResult allocation = AllocateRawFixedArray(new_len, pretenure);
3806 if (!allocation.To(&obj)) return allocation;
3807 }
3808 obj->set_map_no_write_barrier(fixed_array_map());
3809
3810 FixedArray* result = FixedArray::cast(obj);
3811 result->set_length(new_len);
3812
3813 // Copy the content.
3814 DisallowHeapAllocation no_gc;
3815 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
3816 for (int i = 0; i < new_len; i++) result->set(i, src->get(i), mode);
3817 return result;
3818 }
3796 3819
3797 AllocationResult Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) { 3820 AllocationResult Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) {
3798 int len = src->length(); 3821 int len = src->length();
3799 HeapObject* obj = nullptr; 3822 HeapObject* obj = nullptr;
3800 { 3823 {
3801 AllocationResult allocation = AllocateRawFixedArray(len, NOT_TENURED); 3824 AllocationResult allocation = AllocateRawFixedArray(len, NOT_TENURED);
3802 if (!allocation.To(&obj)) return allocation; 3825 if (!allocation.To(&obj)) return allocation;
3803 } 3826 }
3827 obj->set_map_no_write_barrier(map);
3804 if (InNewSpace(obj)) { 3828 if (InNewSpace(obj)) {
3805 obj->set_map_no_write_barrier(map);
3806 CopyBlock(obj->address() + kPointerSize, src->address() + kPointerSize, 3829 CopyBlock(obj->address() + kPointerSize, src->address() + kPointerSize,
3807 FixedArray::SizeFor(len) - kPointerSize); 3830 FixedArray::SizeFor(len) - kPointerSize);
3808 return obj; 3831 return obj;
3809 } 3832 }
3810 obj->set_map_no_write_barrier(map);
3811 FixedArray* result = FixedArray::cast(obj); 3833 FixedArray* result = FixedArray::cast(obj);
3812 result->set_length(len); 3834 result->set_length(len);
3813 3835
3814 // Copy the content. 3836 // Copy the content.
3815 DisallowHeapAllocation no_gc; 3837 DisallowHeapAllocation no_gc;
3816 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); 3838 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
3817 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode); 3839 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode);
3818 return result; 3840 return result;
3819 } 3841 }
3820 3842
(...skipping 2393 matching lines...) Expand 10 before | Expand all | Expand 10 after
6214 } 6236 }
6215 6237
6216 6238
6217 // static 6239 // static
6218 int Heap::GetStaticVisitorIdForMap(Map* map) { 6240 int Heap::GetStaticVisitorIdForMap(Map* map) {
6219 return StaticVisitorBase::GetVisitorId(map); 6241 return StaticVisitorBase::GetVisitorId(map);
6220 } 6242 }
6221 6243
6222 } // namespace internal 6244 } // namespace internal
6223 } // namespace v8 6245 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/heap.h ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698