bool can_grow,
const char* location) {
i::Handle<i::Context> env = Utils::OpenHandle(context);
+ i::Isolate* isolate = env->GetIsolate();
bool ok =
Utils::ApiCheck(env->IsNativeContext(),
location,
return i::Handle<i::FixedArray>();
}
int new_size = i::Max(index, data->length() << 1) + 1;
- data = i::FixedArray::CopySize(data, new_size);
+ int grow_by = new_size - data->length();
+ data = isolate->factory()->CopyFixedArrayAndGrow(data, grow_by);
env->set_embedder_data(*data);
return data;
}
CHECK(used >= 0 && length > 0 && used < length);
if (used + 1 == length) {
CHECK(length < Smi::kMaxValue / 2);
- result = Handle<ScriptContextTable>::cast(
- FixedArray::CopySize(table, length * 2));
+ Isolate* isolate = table->GetIsolate();
+ Handle<FixedArray> copy =
+ isolate->factory()->CopyFixedArrayAndGrow(table, length);
+ copy->set_map(isolate->heap()->script_context_table_map());
+ result = Handle<ScriptContextTable>::cast(copy);
} else {
result = table;
}
RecordContextsInChain(&inner_context, with_context, with_context);
} else if (scope_type == ScopeIterator::ScopeTypeCatch ||
scope_type == ScopeIterator::ScopeTypeWith) {
- Handle<Context> cloned_context =
- Handle<Context>::cast(FixedArray::CopySize(
- it.CurrentContext(), it.CurrentContext()->length()));
+ Handle<Context> cloned_context = Handle<Context>::cast(
+ isolate->factory()->CopyFixedArray(it.CurrentContext()));
ContextChainElement context_chain_element;
context_chain_element.original_context = it.CurrentContext();
frame_inspector.MaterializeStackLocals(materialized_object,
it.CurrentScopeInfo());
if (it.HasContext()) {
- Handle<Context> cloned_context =
- Handle<Context>::cast(FixedArray::CopySize(
- it.CurrentContext(), it.CurrentContext()->length()));
+ Handle<Context> cloned_context = Handle<Context>::cast(
+ isolate->factory()->CopyFixedArray(it.CurrentContext()));
Handle<Context> with_context = isolate->factory()->NewWithContext(
function, cloned_context, materialized_object);
Handle<FixedArray> Factory::CopyFixedArrayAndGrow(Handle<FixedArray> array,
- int grow_by) {
- CALL_HEAP_FUNCTION(isolate(),
- isolate()->heap()->CopyFixedArrayAndGrow(*array, grow_by),
+ int grow_by,
+ PretenureFlag pretenure) {
+ CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->CopyFixedArrayAndGrow(
+ *array, grow_by, pretenure),
FixedArray);
}
Handle<FixedArray> CopyFixedArrayWithMap(Handle<FixedArray> array,
Handle<Map> map);
- Handle<FixedArray> CopyFixedArrayAndGrow(Handle<FixedArray> array,
- int grow_by);
+ Handle<FixedArray> CopyFixedArrayAndGrow(
+ Handle<FixedArray> array, int grow_by,
+ PretenureFlag pretenure = NOT_TENURED);
Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
}
-AllocationResult Heap::CopyFixedArrayAndGrow(FixedArray* src, int grow_by) {
+AllocationResult Heap::CopyFixedArrayAndGrow(FixedArray* src, int grow_by,
+ PretenureFlag pretenure) {
int old_len = src->length();
int new_len = old_len + grow_by;
+ DCHECK(new_len >= old_len);
HeapObject* obj;
{
- AllocationResult allocation = AllocateRawFixedArray(new_len, NOT_TENURED);
+ AllocationResult allocation = AllocateRawFixedArray(new_len, pretenure);
if (!allocation.To(&obj)) return allocation;
}
obj->set_map_no_write_barrier(fixed_array_map());
// Make a copy of src, also grow the copy, and return the copy.
MUST_USE_RESULT AllocationResult
- CopyFixedArrayAndGrow(FixedArray* src, int grow_by);
+ CopyFixedArrayAndGrow(FixedArray* src, int grow_by, PretenureFlag pretenure);
// Make a copy of src, set the map, and return the copy.
MUST_USE_RESULT AllocationResult
queue = factory()->NewFixedArray(8);
heap()->set_microtask_queue(*queue);
} else if (num_tasks == queue->length()) {
- queue = FixedArray::CopySize(queue, num_tasks * 2);
+ queue = factory()->CopyFixedArrayAndGrow(queue, num_tasks);
heap()->set_microtask_queue(*queue);
}
DCHECK(queue->get(num_tasks)->IsUndefined());
Handle<WeakCell> cell = factory()->NewWeakCell(context);
Handle<FixedArray> detached_contexts(heap()->detached_contexts());
int length = detached_contexts->length();
- detached_contexts = FixedArray::CopySize(detached_contexts, length + 2);
+ detached_contexts = factory()->CopyFixedArrayAndGrow(detached_contexts, 2);
detached_contexts->set(length, Smi::FromInt(0));
detached_contexts->set(length + 1, *cell);
heap()->set_detached_contexts(*detached_contexts);
DCHECK(number_of_fields == old_number_of_fields + 1);
// This migration is a transition from a map that has run out of property
// space. Therefore it could be done by extending the backing store.
+ int grow_by = external - object->properties()->length();
Handle<FixedArray> old_storage = handle(object->properties(), isolate);
Handle<FixedArray> new_storage =
- FixedArray::CopySize(old_storage, external);
+ isolate->factory()->CopyFixedArrayAndGrow(old_storage, grow_by);
// Properly initialize newly added property.
Handle<Object> value;
// Extend the code cache with some new entries (at least one). Must be a
// multiple of the entry size.
- int new_length = length + ((length >> 1)) + kCodeCacheEntrySize;
+ Isolate* isolate = cache->GetIsolate();
+ int new_length = length + (length >> 1) + kCodeCacheEntrySize;
new_length = new_length - new_length % kCodeCacheEntrySize;
DCHECK((new_length % kCodeCacheEntrySize) == 0);
- cache = FixedArray::CopySize(cache, new_length);
+ cache = isolate->factory()->CopyFixedArrayAndGrow(cache, new_length - length);
// Add the (name, code) pair to the new cache.
cache->set(length + kCodeCacheEntryNameOffset, *name);
}
-Handle<FixedArray> FixedArray::CopySize(
- Handle<FixedArray> array, int new_length, PretenureFlag pretenure) {
- Isolate* isolate = array->GetIsolate();
- if (new_length == 0) return isolate->factory()->empty_fixed_array();
- Handle<FixedArray> result =
- isolate->factory()->NewFixedArray(new_length, pretenure);
- // Copy the content
- DisallowHeapAllocation no_gc;
- int len = array->length();
- if (new_length < len) len = new_length;
- // We are taking the map from the old fixed array so the map is sure to
- // be an immortal immutable object.
- result->set_map_no_write_barrier(array->map());
- WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
- for (int i = 0; i < len; i++) {
- result->set(i, array->get(i), mode);
- }
- return result;
-}
-
-
void FixedArray::CopyTo(int pos, FixedArray* dest, int dest_pos, int len) {
DisallowHeapAllocation no_gc;
WriteBarrierMode mode = dest->GetWriteBarrierMode(no_gc);
int capacity = array->length();
bool empty = (capacity == 0);
if (capacity < kFirstIndex + length) {
- capacity = kFirstIndex + length;
- capacity = capacity + Max(capacity / 2, 2);
- array = Handle<ArrayList>::cast(FixedArray::CopySize(array, capacity));
+ Isolate* isolate = array->GetIsolate();
+ int new_capacity = kFirstIndex + length;
+ new_capacity = new_capacity + Max(new_capacity / 2, 2);
+ int grow_by = new_capacity - capacity;
+ array = Handle<ArrayList>::cast(
+ isolate->factory()->CopyFixedArrayAndGrow(array, grow_by));
if (empty) array->SetLength(0);
}
return array;
Handle<DependentCode> DependentCode::EnsureSpace(
Handle<DependentCode> entries) {
+ Isolate* isolate = entries->GetIsolate();
if (entries->length() == 0) {
entries = Handle<DependentCode>::cast(
- FixedArray::CopySize(entries, kCodesStartIndex + 1, TENURED));
+ isolate->factory()->NewFixedArray(kCodesStartIndex + 1, TENURED));
for (int g = 0; g < kGroupCount; g++) {
entries->set_number_of_entries(static_cast<DependencyGroup>(g), 0);
}
GroupStartIndexes starts(*entries);
int capacity =
kCodesStartIndex + DependentCode::Grow(starts.number_of_entries());
+ int grow_by = capacity - entries->length();
return Handle<DependentCode>::cast(
- FixedArray::CopySize(entries, capacity, TENURED));
+ isolate->factory()->CopyFixedArrayAndGrow(entries, grow_by, TENURED));
}
// Shrink length and insert filler objects.
void Shrink(int length);
- // Copy operation.
- // TODO(mstarzinger): Deprecated, use Factory::CopyFixedArrayAndGrow!
- static Handle<FixedArray> CopySize(Handle<FixedArray> array,
- int new_length,
- PretenureFlag pretenure = NOT_TENURED);
-
enum KeyFilter { ALL_KEYS, NON_SYMBOL_KEYS };
// Add the elements of a JSArray to this FixedArray.
// Grow array by factor 2 up to MaxCachedPrototypeTransitions.
int new_capacity = Min(kMaxCachedPrototypeTransitions, transitions * 2);
if (new_capacity == capacity) return;
+ int grow_by = new_capacity - capacity;
- cache = FixedArray::CopySize(cache, header + new_capacity);
+ Isolate* isolate = map->GetIsolate();
+ cache = isolate->factory()->CopyFixedArrayAndGrow(cache, grow_by);
if (capacity < 0) {
// There was no prototype transitions array before, so the size
// couldn't be copied. Initialize it explicitly.