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

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

Issue 1255173006: Introduce safe interface to "copy and grow" FixedArray. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed nits. Created 5 years, 4 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.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 4408 matching lines...) Expand 10 before | Expand all | Expand 10 after
4419 int len = src->length(); 4419 int len = src->length();
4420 HeapObject* obj; 4420 HeapObject* obj;
4421 { 4421 {
4422 AllocationResult allocation = AllocateRawFixedArray(len, TENURED); 4422 AllocationResult allocation = AllocateRawFixedArray(len, TENURED);
4423 if (!allocation.To(&obj)) return allocation; 4423 if (!allocation.To(&obj)) return allocation;
4424 } 4424 }
4425 obj->set_map_no_write_barrier(fixed_array_map()); 4425 obj->set_map_no_write_barrier(fixed_array_map());
4426 FixedArray* result = FixedArray::cast(obj); 4426 FixedArray* result = FixedArray::cast(obj);
4427 result->set_length(len); 4427 result->set_length(len);
4428 4428
4429 // Copy the content 4429 // Copy the content.
4430 DisallowHeapAllocation no_gc; 4430 DisallowHeapAllocation no_gc;
4431 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); 4431 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
4432 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode); 4432 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode);
4433 4433
4434 // TODO(mvstanton): The map is set twice because of protection against calling 4434 // TODO(mvstanton): The map is set twice because of protection against calling
4435 // set() on a COW FixedArray. Issue v8:3221 created to track this, and 4435 // set() on a COW FixedArray. Issue v8:3221 created to track this, and
4436 // we might then be able to remove this whole method. 4436 // we might then be able to remove this whole method.
4437 HeapObject::cast(obj)->set_map_no_write_barrier(fixed_cow_array_map()); 4437 HeapObject::cast(obj)->set_map_no_write_barrier(fixed_cow_array_map());
4438 return result; 4438 return result;
4439 } 4439 }
4440 4440
4441 4441
4442 AllocationResult Heap::AllocateEmptyFixedTypedArray( 4442 AllocationResult Heap::AllocateEmptyFixedTypedArray(
4443 ExternalArrayType array_type) { 4443 ExternalArrayType array_type) {
4444 return AllocateFixedTypedArray(0, array_type, false, TENURED); 4444 return AllocateFixedTypedArray(0, array_type, false, TENURED);
4445 } 4445 }
4446 4446
4447 4447
4448 AllocationResult Heap::CopyFixedArrayAndGrow(FixedArray* src, int grow_by) {
4449 int old_len = src->length();
4450 int new_len = old_len + grow_by;
4451 HeapObject* obj;
4452 {
4453 AllocationResult allocation = AllocateRawFixedArray(new_len, NOT_TENURED);
4454 if (!allocation.To(&obj)) return allocation;
4455 }
4456 obj->set_map_no_write_barrier(fixed_array_map());
4457 FixedArray* result = FixedArray::cast(obj);
4458 result->set_length(new_len);
4459
4460 // Copy the content.
4461 DisallowHeapAllocation no_gc;
4462 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
4463 for (int i = 0; i < old_len; i++) result->set(i, src->get(i), mode);
4464 MemsetPointer(result->data_start() + old_len, undefined_value(), grow_by);
4465 return result;
4466 }
4467
4468
4448 AllocationResult Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) { 4469 AllocationResult Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) {
4449 int len = src->length(); 4470 int len = src->length();
4450 HeapObject* obj; 4471 HeapObject* obj;
4451 { 4472 {
4452 AllocationResult allocation = AllocateRawFixedArray(len, NOT_TENURED); 4473 AllocationResult allocation = AllocateRawFixedArray(len, NOT_TENURED);
4453 if (!allocation.To(&obj)) return allocation; 4474 if (!allocation.To(&obj)) return allocation;
4454 } 4475 }
4455 if (InNewSpace(obj)) { 4476 if (InNewSpace(obj)) {
4456 obj->set_map_no_write_barrier(map); 4477 obj->set_map_no_write_barrier(map);
4457 CopyBlock(obj->address() + kPointerSize, src->address() + kPointerSize, 4478 CopyBlock(obj->address() + kPointerSize, src->address() + kPointerSize,
4458 FixedArray::SizeFor(len) - kPointerSize); 4479 FixedArray::SizeFor(len) - kPointerSize);
4459 return obj; 4480 return obj;
4460 } 4481 }
4461 obj->set_map_no_write_barrier(map); 4482 obj->set_map_no_write_barrier(map);
4462 FixedArray* result = FixedArray::cast(obj); 4483 FixedArray* result = FixedArray::cast(obj);
4463 result->set_length(len); 4484 result->set_length(len);
4464 4485
4465 // Copy the content 4486 // Copy the content.
4466 DisallowHeapAllocation no_gc; 4487 DisallowHeapAllocation no_gc;
4467 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); 4488 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
4468 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode); 4489 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode);
4469 return result; 4490 return result;
4470 } 4491 }
4471 4492
4472 4493
4473 AllocationResult Heap::CopyFixedDoubleArrayWithMap(FixedDoubleArray* src, 4494 AllocationResult Heap::CopyFixedDoubleArrayWithMap(FixedDoubleArray* src,
4474 Map* map) { 4495 Map* map) {
4475 int len = src->length(); 4496 int len = src->length();
(...skipping 2382 matching lines...) Expand 10 before | Expand all | Expand 10 after
6858 *object_type = "CODE_TYPE"; \ 6879 *object_type = "CODE_TYPE"; \
6859 *object_sub_type = "CODE_AGE/" #name; \ 6880 *object_sub_type = "CODE_AGE/" #name; \
6860 return true; 6881 return true;
6861 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) 6882 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME)
6862 #undef COMPARE_AND_RETURN_NAME 6883 #undef COMPARE_AND_RETURN_NAME
6863 } 6884 }
6864 return false; 6885 return false;
6865 } 6886 }
6866 } // namespace internal 6887 } // namespace internal
6867 } // namespace v8 6888 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/heap.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698