v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
optimized-compilation-info.cc
Go to the documentation of this file.
1// Copyright 2016 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 "src/api/api.h"
10#include "src/debug/debug.h"
16
17#if V8_ENABLE_WEBASSEMBLY
19#endif // V8_ENABLE_WEBASSEMBLY
20
21namespace v8 {
22namespace internal {
23
25 Zone* zone, Isolate* isolate, IndirectHandle<SharedFunctionInfo> shared,
26 IndirectHandle<JSFunction> closure, CodeKind code_kind,
27 BytecodeOffset osr_offset)
28 : isolate_unsafe_(isolate),
29 code_kind_(code_kind),
30 osr_offset_(osr_offset),
31 zone_(zone),
32 optimization_id_(isolate->NextOptimizationId()) {
33 DCHECK_EQ(*shared, closure->shared());
34 DCHECK(shared->is_compiled());
36 bytecode_array_ = handle(shared->GetBytecodeArray(isolate), isolate);
39 canonical_handles_ = std::make_unique<CanonicalHandlesMap>(
40 isolate->heap(), ZoneAllocationPolicy(zone));
41
42 // Collect source positions for optimized code when profiling or if debugger
43 // is active, to be able to get more precise source positions at the price of
44 // more memory consumption.
45 if (isolate->NeedsDetailedOptimizedCodeLineInfo()) {
46 // We might not have source positions if collection fails (e.g. because we
47 // run out of stack space).
48 if (bytecode_array_->HasSourcePositionTable()) {
49 set_source_positions();
50 }
51 }
52
53 SetTracingFlags(shared->PassesFilter(v8_flags.trace_turbo_filter));
55
56 if (isolate->node_observer()) {
57 SetNodeObserver(isolate->node_observer());
58 }
59}
60
62 base::Vector<const char> debug_name, Zone* zone, CodeKind code_kind,
63 Builtin builtin)
64 : isolate_unsafe_(nullptr),
65 code_kind_(code_kind),
66 builtin_(builtin),
67 zone_(zone),
68 optimization_id_(kNoOptimizationId),
69 debug_name_(debug_name) {
71 (code_kind_ == CodeKind::BUILTIN ||
72 code_kind_ == CodeKind::BYTECODE_HANDLER));
74 PassesFilter(debug_name, base::CStrVector(v8_flags.trace_turbo_filter)));
77}
78
80 if (v8_flags.turbo_inline_js_wasm_calls) set_inline_js_wasm_calls();
81
82 if (v8_flags.cet_compatible) {
83 set_shadow_stack_compliant_lazy_deopt();
84 }
85
86 switch (code_kind_) {
87 case CodeKind::TURBOFAN_JS:
88 set_called_with_code_start_register();
89 set_switch_jump_table();
90 if (v8_flags.analyze_environment_liveness) {
91 set_analyze_environment_liveness();
92 }
93 if (v8_flags.turbo_splitting) set_splitting();
94 break;
95 case CodeKind::BYTECODE_HANDLER:
96 set_called_with_code_start_register();
97 if (v8_flags.turbo_splitting) set_splitting();
98 if (v8_flags.enable_allocation_folding) set_allocation_folding();
99 break;
100 case CodeKind::BUILTIN:
101#ifdef V8_ENABLE_BUILTIN_JUMP_TABLE_SWITCH
102 set_switch_jump_table();
103#endif // V8_TARGET_ARCH_X64
104 [[fallthrough]];
105 case CodeKind::FOR_TESTING:
106 if (v8_flags.turbo_splitting) set_splitting();
107 if (v8_flags.enable_allocation_folding) set_allocation_folding();
108#if ENABLE_GDB_JIT_INTERFACE && DEBUG
109 set_source_positions();
110#endif // ENABLE_GDB_JIT_INTERFACE && DEBUG
111 break;
112 case CodeKind::WASM_FUNCTION:
113 case CodeKind::WASM_TO_CAPI_FUNCTION:
114 set_switch_jump_table();
115 break;
116 case CodeKind::C_WASM_ENTRY:
117 case CodeKind::JS_TO_WASM_FUNCTION:
118 case CodeKind::WASM_TO_JS_FUNCTION:
119 break;
120 case CodeKind::BASELINE:
121 case CodeKind::MAGLEV:
122 case CodeKind::INTERPRETED_FUNCTION:
123 case CodeKind::REGEXP:
124 UNREACHABLE();
125 }
126}
127
129 if (disable_future_optimization() && has_shared_info()) {
131 shared_info()->DisableOptimization(isolate_unsafe_, bailout_reason());
132 }
133}
134
136 Isolate* isolate) {
137 if (!shared_info_.is_null()) {
139 }
140 if (!bytecode_array_.is_null()) {
142 }
143 if (!closure_.is_null()) {
144 closure_ = CanonicalHandle(*closure_, isolate);
145 }
146 DCHECK(code_.is_null());
147}
148
150 DCHECK_NE(reason, BailoutReason::kNoReason);
151 if (bailout_reason_ == BailoutReason::kNoReason) {
152 bailout_reason_ = reason;
153 }
154 set_disable_future_optimization();
155}
156
158 DCHECK_NE(reason, BailoutReason::kNoReason);
159 if (disable_future_optimization()) return;
160 bailout_reason_ = reason;
161}
162
163std::unique_ptr<char[]> OptimizedCompilationInfo::GetDebugName() const {
164 if (!shared_info().is_null()) {
165 return shared_info()->DebugNameCStr();
166 }
168 if (name_vec.empty()) name_vec = base::ArrayVector("unknown");
169 std::unique_ptr<char[]> name(new char[name_vec.length() + 1]);
170 memcpy(name.get(), name_vec.begin(), name_vec.length());
171 name[name_vec.length()] = '\0';
172 return name;
173}
174
176 switch (code_kind()) {
177 case CodeKind::FOR_TESTING:
178 case CodeKind::BYTECODE_HANDLER:
179 case CodeKind::BUILTIN:
180 return StackFrame::STUB;
181#if V8_ENABLE_WEBASSEMBLY
182 case CodeKind::WASM_FUNCTION:
183 return StackFrame::WASM;
184 case CodeKind::WASM_TO_CAPI_FUNCTION:
185 return StackFrame::WASM_EXIT;
186 case CodeKind::JS_TO_WASM_FUNCTION:
187 return StackFrame::JS_TO_WASM;
188 case CodeKind::WASM_TO_JS_FUNCTION:
189 return StackFrame::WASM_TO_JS;
190 case CodeKind::C_WASM_ENTRY:
191 return StackFrame::C_WASM_ENTRY;
192#endif // V8_ENABLE_WEBASSEMBLY
193 default:
195 }
196}
197
202
204 return !closure().is_null();
205}
206
209 return closure()->context();
210}
211
213 return !closure().is_null() && !closure()->native_context().is_null();
214}
215
220
224
229
231 IndirectHandle<SharedFunctionInfo> inlined_function,
233 int id = static_cast<int>(inlined_functions_.size());
234 inlined_functions_.push_back(
235 InlinedFunctionHolder(inlined_function, inlined_bytecode, pos));
236 return id;
237}
238
240 if (!passes_filter) return;
241 if (v8_flags.trace_turbo) set_trace_turbo_json();
242 if (v8_flags.trace_turbo_graph) set_trace_turbo_graph();
243 if (v8_flags.trace_turbo_scheduled) set_trace_turbo_scheduled();
244 if (v8_flags.trace_turbo_alloc) set_trace_turbo_allocation();
245 if (v8_flags.trace_heap_broker) set_trace_heap_broker();
246 if (v8_flags.turboshaft_trace_reduction) set_turboshaft_trace_reduction();
247}
248
250 was_cancelled_.store(true, std::memory_order_relaxed);
251}
252
254 IndirectHandle<SharedFunctionInfo> inlined_shared_info,
256 : shared_info(inlined_shared_info), bytecode_array(inlined_bytecode) {
258 // initialized when generating the deoptimization literals
260}
261
262} // namespace internal
263} // namespace v8
SourcePosition pos
int length() const
Definition vector.h:64
constexpr bool empty() const
Definition vector.h:73
constexpr T * begin() const
Definition vector.h:96
IndirectHandle< SharedFunctionInfo > shared_info_
int AddInlinedFunction(IndirectHandle< SharedFunctionInfo > inlined_function, IndirectHandle< BytecodeArray > inlined_bytecode, SourcePosition pos)
IndirectHandle< SharedFunctionInfo > shared_info() const
IndirectHandle< BytecodeArray > bytecode_array_
std::unique_ptr< CanonicalHandlesMap > canonical_handles_
IndirectHandle< JSFunction > closure() const
void SetNodeObserver(compiler::NodeObserver *observer)
IndirectHandle< T > CanonicalHandle(Tagged< T > object, Isolate *isolate)
OptimizedCompilationInfo(Zone *zone, Isolate *isolate, IndirectHandle< SharedFunctionInfo > shared, IndirectHandle< JSFunction > closure, CodeKind code_kind, BytecodeOffset osr_offset)
Zone * zone_
SharedFunctionInfoRef shared
constexpr Vector< T > ArrayVector(T(&arr)[N])
Definition vector.h:354
Vector< const char > CStrVector(const char *data)
Definition vector.h:331
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
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 name
Definition flags.cc:2086
bool PassesFilter(base::Vector< const char > name, base::Vector< const char > filter)
Definition utils.cc:238
V8_EXPORT_PRIVATE FlagValues v8_flags
#define DCHECK_NOT_NULL(val)
Definition logging.h:492
#define DCHECK_IMPLIES(v1, v2)
Definition logging.h:493
#define DCHECK_NE(v1, v2)
Definition logging.h:486
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
InlinedFunctionHolder(IndirectHandle< SharedFunctionInfo > inlined_shared_info, IndirectHandle< BytecodeArray > inlined_bytecode, SourcePosition pos)