V8 Project
v8::internal::ArrayConcatVisitor Class Reference

A simple visitor visits every element of Array's. More...

+ Collaboration diagram for v8::internal::ArrayConcatVisitor:

Public Member Functions

 ArrayConcatVisitor (Isolate *isolate, Handle< FixedArray > storage, bool fast_elements)
 
 ~ArrayConcatVisitor ()
 
void visit (uint32_t i, Handle< Object > elm)
 
void increase_index_offset (uint32_t delta)
 
bool exceeds_array_limit ()
 
Handle< JSArrayToArray ()
 

Private Member Functions

void SetDictionaryMode ()
 
void clear_storage ()
 
void set_storage (FixedArray *storage)
 

Private Attributes

Isolateisolate_
 
Handle< FixedArraystorage_
 
uint32_t index_offset_
 
bool fast_elements_: 1
 
bool exceeds_array_limit_: 1
 

Detailed Description

A simple visitor visits every element of Array's.

The backend storage can be a fixed array for fast elements case, or a dictionary for sparse array. Since Dictionary is a subtype of FixedArray, the class can be used by both fast and slow cases. The second parameter of the constructor, fast_elements, specifies whether the storage is a FixedArray or Dictionary.

An index limit is used to deal with the situation that a result array length overflows 32-bit non-negative integer.

Definition at line 4605 of file runtime.cc.

Constructor & Destructor Documentation

◆ ArrayConcatVisitor()

v8::internal::ArrayConcatVisitor::ArrayConcatVisitor ( Isolate isolate,
Handle< FixedArray storage,
bool  fast_elements 
)
inline

Definition at line 4607 of file runtime.cc.

4609  : isolate_(isolate),
4611  isolate->global_handles()->Create(*storage))),
4612  index_offset_(0u),
4613  fast_elements_(fast_elements),
4614  exceeds_array_limit_(false) {}
Handle< FixedArray > storage_
Definition: runtime.cc:4713
static Handle< T > cast(Handle< S > that)
Definition: handles.h:116

◆ ~ArrayConcatVisitor()

v8::internal::ArrayConcatVisitor::~ArrayConcatVisitor ( )
inline

Definition at line 4616 of file runtime.cc.

References clear_storage().

+ Here is the call graph for this function:

Member Function Documentation

◆ clear_storage()

void v8::internal::ArrayConcatVisitor::clear_storage ( )
inlineprivate

Definition at line 4703 of file runtime.cc.

4703  {
4705  }
static void Destroy(Object **location)

References v8::internal::GlobalHandles::Destroy(), and storage_.

Referenced by SetDictionaryMode(), visit(), and ~ArrayConcatVisitor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exceeds_array_limit()

bool v8::internal::ArrayConcatVisitor::exceeds_array_limit ( )
inline

Definition at line 4665 of file runtime.cc.

4665 { return exceeds_array_limit_; }

References exceeds_array_limit_.

Referenced by v8::internal::RUNTIME_FUNCTION().

+ Here is the caller graph for this function:

◆ increase_index_offset()

void v8::internal::ArrayConcatVisitor::increase_index_offset ( uint32_t  delta)
inline

Definition at line 4649 of file runtime.cc.

4649  {
4650  if (JSObject::kMaxElementCount - index_offset_ < delta) {
4652  } else {
4653  index_offset_ += delta;
4654  }
4655  // If the initial length estimate was off (see special case in visit()),
4656  // but the array blowing the limit didn't contain elements beyond the
4657  // provided-for index range, go to dictionary mode now.
4658  if (fast_elements_ &&
4659  index_offset_ >
4660  static_cast<uint32_t>(FixedArrayBase::cast(*storage_)->length())) {
4662  }
4663  }
static const uint32_t kMaxElementCount
Definition: objects.h:2161

References fast_elements_, index_offset_, v8::internal::JSObject::kMaxElementCount, and SetDictionaryMode().

Referenced by v8::internal::IterateElements(), and v8::internal::RUNTIME_FUNCTION().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_storage()

void v8::internal::ArrayConcatVisitor::set_storage ( FixedArray storage)
inlineprivate

Definition at line 4707 of file runtime.cc.

4707  {
4708  storage_ =
4710  }
Handle< Object > Create(Object *value)
GlobalHandles * global_handles()
Definition: isolate.h:917

References v8::internal::Handle< T >::cast(), v8::internal::GlobalHandles::Create(), v8::internal::Isolate::global_handles(), isolate_, and storage_.

Referenced by SetDictionaryMode(), and visit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetDictionaryMode()

void v8::internal::ArrayConcatVisitor::SetDictionaryMode ( )
inlineprivate

Definition at line 4681 of file runtime.cc.

4681  {
4683  Handle<FixedArray> current_storage(*storage_);
4684  Handle<SeededNumberDictionary> slow_storage(
4685  SeededNumberDictionary::New(isolate_, current_storage->length()));
4686  uint32_t current_length = static_cast<uint32_t>(current_storage->length());
4687  for (uint32_t i = 0; i < current_length; i++) {
4688  HandleScope loop_scope(isolate_);
4689  Handle<Object> element(current_storage->get(i), isolate_);
4690  if (!element->IsTheHole()) {
4691  Handle<SeededNumberDictionary> new_storage =
4692  SeededNumberDictionary::AtNumberPut(slow_storage, i, element);
4693  if (!new_storage.is_identical_to(slow_storage)) {
4694  slow_storage = loop_scope.CloseAndEscape(new_storage);
4695  }
4696  }
4697  }
4698  clear_storage();
4699  set_storage(*slow_storage);
4700  fast_elements_ = false;
4701  }
void set_storage(FixedArray *storage)
Definition: runtime.cc:4707
static MUST_USE_RESULT Handle< SeededNumberDictionary > New(Isolate *isolate, int at_least_space_for, PretenureFlag pretenure=NOT_TENURED)
Definition: objects.cc:14899
static MUST_USE_RESULT Handle< SeededNumberDictionary > AtNumberPut(Handle< SeededNumberDictionary > dictionary, uint32_t key, Handle< Object > value)
Definition: objects.cc:15108
#define DCHECK(condition)
Definition: logging.h:205

References v8::internal::SeededNumberDictionary::AtNumberPut(), clear_storage(), v8::internal::HandleScope::CloseAndEscape(), DCHECK, fast_elements_, isolate_, v8::internal::Dictionary< SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t >::New(), set_storage(), and storage_.

Referenced by increase_index_offset(), and visit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ToArray()

Handle<JSArray> v8::internal::ArrayConcatVisitor::ToArray ( )
inline

Definition at line 4667 of file runtime.cc.

4667  {
4668  Handle<JSArray> array = isolate_->factory()->NewJSArray(0);
4669  Handle<Object> length =
4670  isolate_->factory()->NewNumber(static_cast<double>(index_offset_));
4673  array->set_map(*map);
4674  array->set_length(*length);
4675  array->set_elements(*storage_);
4676  return array;
4677  }
Factory * factory()
Definition: isolate.h:982
static Handle< Map > GetElementsTransitionMap(Handle< JSObject > object, ElementsKind to_kind)
Definition: objects.cc:3385
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf map

References v8::internal::DICTIONARY_ELEMENTS, v8::internal::Isolate::factory(), fast_elements_, v8::internal::FAST_HOLEY_ELEMENTS, v8::internal::JSObject::GetElementsTransitionMap(), index_offset_, isolate_, map, and storage_.

Referenced by v8::internal::RUNTIME_FUNCTION().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ visit()

void v8::internal::ArrayConcatVisitor::visit ( uint32_t  i,
Handle< Object elm 
)
inline

Definition at line 4618 of file runtime.cc.

4618  {
4620  exceeds_array_limit_ = true;
4621  return;
4622  }
4623  uint32_t index = index_offset_ + i;
4624 
4625  if (fast_elements_) {
4626  if (index < static_cast<uint32_t>(storage_->length())) {
4627  storage_->set(index, *elm);
4628  return;
4629  }
4630  // Our initial estimate of length was foiled, possibly by
4631  // getters on the arrays increasing the length of later arrays
4632  // during iteration.
4633  // This shouldn't happen in anything but pathological cases.
4635  // Fall-through to dictionary mode.
4636  }
4638  Handle<SeededNumberDictionary> dict(
4639  SeededNumberDictionary::cast(*storage_));
4640  Handle<SeededNumberDictionary> result =
4641  SeededNumberDictionary::AtNumberPut(dict, index, elm);
4642  if (!result.is_identical_to(dict)) {
4643  // Dictionary needed to grow.
4644  clear_storage();
4645  set_storage(*result);
4646  }
4647  }

References v8::internal::SeededNumberDictionary::AtNumberPut(), clear_storage(), DCHECK, exceeds_array_limit_, fast_elements_, index_offset_, v8::internal::JSObject::kMaxElementCount, set_storage(), SetDictionaryMode(), and storage_.

Referenced by v8::internal::IterateElements(), v8::internal::IterateExternalArrayElements(), and v8::internal::RUNTIME_FUNCTION().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ exceeds_array_limit_

bool v8::internal::ArrayConcatVisitor::exceeds_array_limit_
private

Definition at line 4718 of file runtime.cc.

Referenced by exceeds_array_limit(), and visit().

◆ fast_elements_

bool v8::internal::ArrayConcatVisitor::fast_elements_
private

Definition at line 4717 of file runtime.cc.

Referenced by increase_index_offset(), SetDictionaryMode(), ToArray(), and visit().

◆ index_offset_

uint32_t v8::internal::ArrayConcatVisitor::index_offset_
private

Definition at line 4716 of file runtime.cc.

Referenced by increase_index_offset(), ToArray(), and visit().

◆ isolate_

Isolate* v8::internal::ArrayConcatVisitor::isolate_
private

Definition at line 4712 of file runtime.cc.

Referenced by set_storage(), SetDictionaryMode(), and ToArray().

◆ storage_

Handle<FixedArray> v8::internal::ArrayConcatVisitor::storage_
private

Definition at line 4713 of file runtime.cc.

Referenced by clear_storage(), set_storage(), SetDictionaryMode(), ToArray(), and visit().


The documentation for this class was generated from the following file: