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

Side by Side Diff: src/objects.cc

Issue 2270783002: Add new FrameArray type (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address comments Created 4 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/objects.h ('k') | src/objects-inl.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <memory> 9 #include <memory>
10 #include <sstream> 10 #include <sstream>
(...skipping 10159 matching lines...) Expand 10 before | Expand all | Expand 10 after
10170 array->SetLength(length + 2); 10170 array->SetLength(length + 2);
10171 return array; 10171 return array;
10172 } 10172 }
10173 10173
10174 10174
10175 bool ArrayList::IsFull() { 10175 bool ArrayList::IsFull() {
10176 int capacity = length(); 10176 int capacity = length();
10177 return kFirstIndex + Length() == capacity; 10177 return kFirstIndex + Length() == capacity;
10178 } 10178 }
10179 10179
10180 namespace {
10180 10181
10181 Handle<ArrayList> ArrayList::EnsureSpace(Handle<ArrayList> array, int length) { 10182 Handle<FixedArray> EnsureSpaceInFixedArray(Handle<FixedArray> array,
10183 int length) {
10182 int capacity = array->length(); 10184 int capacity = array->length();
10183 bool empty = (capacity == 0); 10185 if (capacity < length) {
10184 if (capacity < kFirstIndex + length) {
10185 Isolate* isolate = array->GetIsolate(); 10186 Isolate* isolate = array->GetIsolate();
10186 int new_capacity = kFirstIndex + length; 10187 int new_capacity = length;
10187 new_capacity = new_capacity + Max(new_capacity / 2, 2); 10188 new_capacity = new_capacity + Max(new_capacity / 2, 2);
10188 int grow_by = new_capacity - capacity; 10189 int grow_by = new_capacity - capacity;
10189 array = Handle<ArrayList>::cast( 10190 array = Handle<ArrayList>::cast(
10190 isolate->factory()->CopyFixedArrayAndGrow(array, grow_by)); 10191 isolate->factory()->CopyFixedArrayAndGrow(array, grow_by));
10191 if (empty) array->SetLength(0);
10192 } 10192 }
10193 return array; 10193 return array;
10194 } 10194 }
10195 10195
10196 } // namespace
10197
10198 Handle<ArrayList> ArrayList::EnsureSpace(Handle<ArrayList> array, int length) {
10199 const bool empty = (array->length() == 0);
10200 auto ret = Handle<ArrayList>::cast(
10201 EnsureSpaceInFixedArray(array, kFirstIndex + length));
10202 if (empty) ret->SetLength(0);
10203 return ret;
10204 }
10205
10206 // static
10207 Handle<FrameArray> FrameArray::AppendJSFrame(Handle<FrameArray> in,
10208 Handle<Object> receiver,
10209 Handle<JSFunction> function,
10210 Handle<AbstractCode> code,
10211 int offset) {
10212 const int frame_count = in->FrameCount();
10213 const int new_length = LengthFor(frame_count + 1);
10214 Handle<FrameArray> array = EnsureSpace(in, new_length);
10215 array->SetReceiver(frame_count, *receiver);
10216 array->SetFunction(frame_count, *function);
10217 array->SetCode(frame_count, *code);
10218 array->SetOffset(frame_count, Smi::FromInt(offset));
10219 array->set(kFrameCountIndex, Smi::FromInt(frame_count + 1));
10220 return array;
10221 }
10222
10223 // static
10224 Handle<FrameArray> FrameArray::AppendWasmFrame(Handle<FrameArray> in,
10225 Handle<Object> wasm_object,
10226 int wasm_function_index,
10227 Handle<AbstractCode> code,
10228 int offset) {
10229 const int frame_count = in->FrameCount();
10230 const int new_length = LengthFor(frame_count + 1);
10231 Handle<FrameArray> array = EnsureSpace(in, new_length);
10232 array->SetWasmObject(frame_count, *wasm_object);
10233 array->SetWasmFunctionIndex(frame_count, Smi::FromInt(wasm_function_index));
10234 array->SetCode(frame_count, *code);
10235 array->SetOffset(frame_count, Smi::FromInt(offset));
10236 array->set(kFrameCountIndex, Smi::FromInt(frame_count + 1));
10237 return array;
10238 }
10239
10240 void FrameArray::ShrinkToFit() { Shrink(LengthFor(FrameCount())); }
10241
10242 // static
10243 Handle<FrameArray> FrameArray::EnsureSpace(Handle<FrameArray> array,
10244 int length) {
10245 return Handle<FrameArray>::cast(EnsureSpaceInFixedArray(array, length));
10246 }
10247
10196 Handle<DescriptorArray> DescriptorArray::Allocate(Isolate* isolate, 10248 Handle<DescriptorArray> DescriptorArray::Allocate(Isolate* isolate,
10197 int number_of_descriptors, 10249 int number_of_descriptors,
10198 int slack, 10250 int slack,
10199 PretenureFlag pretenure) { 10251 PretenureFlag pretenure) {
10200 DCHECK(0 <= number_of_descriptors); 10252 DCHECK(0 <= number_of_descriptors);
10201 Factory* factory = isolate->factory(); 10253 Factory* factory = isolate->factory();
10202 // Do not use DescriptorArray::cast on incomplete object. 10254 // Do not use DescriptorArray::cast on incomplete object.
10203 int size = number_of_descriptors + slack; 10255 int size = number_of_descriptors + slack;
10204 if (size == 0) return factory->empty_descriptor_array(); 10256 if (size == 0) return factory->empty_descriptor_array();
10205 // Allocate the array of keys. 10257 // Allocate the array of keys.
(...skipping 9070 matching lines...) Expand 10 before | Expand all | Expand 10 after
19276 for (PrototypeIterator iter(isolate, this, kStartAtReceiver, 19328 for (PrototypeIterator iter(isolate, this, kStartAtReceiver,
19277 PrototypeIterator::END_AT_NULL); 19329 PrototypeIterator::END_AT_NULL);
19278 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) { 19330 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) {
19279 if (iter.GetCurrent<Object>()->IsJSProxy()) return true; 19331 if (iter.GetCurrent<Object>()->IsJSProxy()) return true;
19280 } 19332 }
19281 return false; 19333 return false;
19282 } 19334 }
19283 19335
19284 } // namespace internal 19336 } // namespace internal
19285 } // namespace v8 19337 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698