v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
growable-fixed-array-gen.cc
Go to the documentation of this file.
1// Copyright 2018 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include <optional>
8
10
11namespace v8 {
12namespace internal {
13
15
17 Label out(this);
18
19 GotoIf(IntPtrGreaterThanOrEqual(var_capacity_.value(), required_capacity),
20 &out);
21
22 // Gotta grow.
23 TVARIABLE(IntPtrT, var_new_capacity, var_capacity_.value());
24 Label loop(this, &var_new_capacity);
25 Goto(&loop);
26
27 // First find the new capacity.
28 BIND(&loop);
29 {
30 var_new_capacity = NewCapacity(var_new_capacity.value());
31 GotoIf(IntPtrLessThan(var_new_capacity.value(), required_capacity), &loop);
32 }
33
34 // Now grow.
35 var_capacity_ = var_new_capacity.value();
37 Goto(&out);
38
39 BIND(&out);
40}
41
43 const TNode<IntPtrT> length = var_length_.value();
44 const TNode<IntPtrT> capacity = var_capacity_.value();
45
46 Label grow(this), store(this);
47 Branch(IntPtrEqual(capacity, length), &grow, &store);
48
49 BIND(&grow);
50 {
51 var_capacity_ = NewCapacity(capacity);
52 var_array_ = ResizeFixedArray(length, var_capacity_.value());
53
54 Goto(&store);
55 }
56
57 BIND(&store);
58 {
59 const TNode<FixedArray> array = var_array_.value();
60 UnsafeStoreFixedArrayElement(array, length, value);
61
63 }
64}
65
69
72
75
76 // Shrink to fit if necessary.
77 {
78 Label next(this);
79
80 const TNode<IntPtrT> length = var_length_.value();
81 const TNode<IntPtrT> capacity = var_capacity_.value();
82
83 GotoIf(WordEqual(length, capacity), &next);
84
85 var_array_ = ResizeFixedArray(length, length);
87 Goto(&next);
88
89 BIND(&next);
90 }
91
92 const TNode<Smi> result_length = SmiTag(length());
94 AllocateJSArray(array_map, var_array_.value(), result_length);
95 return result;
96}
97
99 TNode<IntPtrT> current_capacity) {
100 CSA_DCHECK(this,
101 IntPtrGreaterThanOrEqual(current_capacity, IntPtrConstant(0)));
102
103 // Growth rate is analog to JSObject::NewElementsCapacity:
104 // new_capacity = (current_capacity + (current_capacity >> 1)) + 16.
105
106 const TNode<IntPtrT> new_capacity =
107 IntPtrAdd(IntPtrAdd(current_capacity, WordShr(current_capacity, 1)),
108 IntPtrConstant(16));
109
110 return new_capacity;
111}
112
114 const TNode<IntPtrT> element_count, const TNode<IntPtrT> new_capacity) {
115 CSA_DCHECK(this, IntPtrGreaterThanOrEqual(element_count, IntPtrConstant(0)));
116 CSA_DCHECK(this, IntPtrGreaterThanOrEqual(new_capacity, IntPtrConstant(0)));
117 CSA_DCHECK(this, IntPtrGreaterThanOrEqual(new_capacity, element_count));
118
119 const TNode<FixedArray> from_array = var_array_.value();
120
124 ExtractFixedArray(from_array, std::optional<TNode<IntPtrT>>(std::nullopt),
125 std::optional<TNode<IntPtrT>>(element_count),
126 std::optional<TNode<IntPtrT>>(new_capacity), flags));
127
128 return to_array;
129}
130
132
133} // namespace internal
134} // namespace v8
#define BIND(label)
#define TVARIABLE(...)
#define CSA_DCHECK(csa,...)
Builtins::Kind kind
Definition builtins.cc:40
TNode< JSArray > AllocateJSArray(ElementsKind kind, TNode< Map > array_map, TNode< IntPtrT > capacity, TNode< Smi > length, std::optional< TNode< AllocationSite > > allocation_site, AllocationFlags allocation_flags=AllocationFlag::kNone)
TNode< Smi > SmiTag(TNode< IntPtrT > value)
TNode< Map > LoadJSArrayElementsMap(ElementsKind kind, TNode< NativeContext > native_context)
TNode< FixedArrayBase > ExtractFixedArray(TNode< FixedArrayBase > source, std::optional< TNode< TIndex > > first, std::optional< TNode< TIndex > > count=std::nullopt, std::optional< TNode< TIndex > > capacity=std::nullopt, ExtractFixedArrayFlags extract_flags=ExtractFixedArrayFlag::kAllFixedArrays, TVariable< BoolT > *var_holes_converted=nullptr, std::optional< TNode< Int32T > > source_elements_kind=std::nullopt)
void UnsafeStoreFixedArrayElement(TNode< FixedArray > object, int index, TNode< Object > value, WriteBarrierMode barrier_mode=UPDATE_WRITE_BARRIER)
TNode< NativeContext > LoadNativeContext(TNode< Context > context)
Uint32LessThanOrEqual IntPtrGreaterThanOrEqual
TNode< JSArray > ToJSArray(const TNode< Context > context)
TNode< FixedArray > ResizeFixedArray(const TNode< IntPtrT > element_count, const TNode< IntPtrT > new_capacity)
void Push(const TNode< Object > value)
void Reserve(TNode< IntPtrT > required_capacity)
TNode< IntPtrT > NewCapacity(TNode< IntPtrT > current_capacity)
TNode< IntPtrT > IntPtrAdd(TNode< IntPtrT > left, TNode< IntPtrT > right)
TNode< IntPtrT > IntPtrConstant(intptr_t value)
TNode< BoolT > WordEqual(TNode< WordT > left, TNode< WordT > right)
void GotoIf(TNode< IntegralT > condition, Label *true_label, GotoHint goto_hint=GotoHint::kNone)
TNode< BoolT > IntPtrEqual(TNode< WordT > left, TNode< WordT > right)
TNode< UintPtrT > WordShr(TNode< UintPtrT > left, TNode< IntegralT > right)
void Branch(TNode< IntegralT > condition, Label *true_label, Label *false_label, BranchHint branch_hint=BranchHint::kNone)
#define CAST(x)
ZoneVector< RpoNumber > & result
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in allocation gc speed threshold for starting incremental marking via a task in percent of available threshold for starting incremental marking immediately in percent of available Use a single schedule for determining a marking schedule between JS and C objects schedules the minor GC task with kUserVisible priority max worker number of concurrent for NumberOfWorkerThreads start background threads that allocate memory concurrent_array_buffer_sweeping use parallel threads to clear weak refs in the atomic pause trace progress of the incremental marking trace object counts and memory usage report a tick only when allocated zone memory changes by this amount TracingFlags::gc_stats store(v8::tracing::TracingCategoryObserver::ENABLED_BY_NATIVE)) DEFINE_GENERIC_IMPLICATION(trace_gc_object_stats
Flag flags[]
Definition flags.cc:3797
!IsContextMap !IsContextMap native_context
Definition map-inl.h:877
constexpr std::array< std::remove_cv_t< T >, N > to_array(T(&a)[N])