5 #include "src/optimized-compilation-info.h" 8 #include "src/debug/debug.h" 9 #include "src/isolate.h" 10 #include "src/objects-inl.h" 11 #include "src/objects/shared-function-info.h" 12 #include "src/source-position.h" 17 OptimizedCompilationInfo::OptimizedCompilationInfo(
18 Zone* zone, Isolate* isolate, Handle<SharedFunctionInfo> shared,
19 Handle<JSFunction> closure)
20 : OptimizedCompilationInfo(Code::OPTIMIZED_FUNCTION, zone) {
21 DCHECK(shared->is_compiled());
22 bytecode_array_ = handle(shared->GetBytecodeArray(), isolate);
23 shared_info_ = shared;
25 optimization_id_ = isolate->NextOptimizationId();
30 if (isolate->NeedsDetailedOptimizedCodeLineInfo()) {
31 MarkAsSourcePositionsEnabled();
34 SetTracingFlags(shared->PassesFilter(FLAG_trace_turbo_filter));
37 OptimizedCompilationInfo::OptimizedCompilationInfo(
38 Vector<const char> debug_name, Zone* zone, Code::Kind code_kind)
39 : OptimizedCompilationInfo(code_kind, zone) {
40 debug_name_ = debug_name;
43 PassesFilter(debug_name, CStrVector(FLAG_trace_turbo_filter)));
46 OptimizedCompilationInfo::OptimizedCompilationInfo(Code::Kind code_kind,
48 : code_kind_(code_kind), zone_(zone) {
52 void OptimizedCompilationInfo::ConfigureFlags() {
53 if (FLAG_untrusted_code_mitigations) SetFlag(kUntrustedCodeMitigations);
56 case Code::OPTIMIZED_FUNCTION:
57 SetFlag(kCalledWithCodeStartRegister);
58 SetFlag(kSwitchJumpTableEnabled);
59 if (FLAG_function_context_specialization) {
60 MarkAsFunctionContextSpecializing();
62 if (FLAG_turbo_splitting) {
63 MarkAsSplittingEnabled();
65 if (FLAG_untrusted_code_mitigations) {
66 MarkAsPoisoningRegisterArguments();
68 if (FLAG_analyze_environment_liveness) {
70 MarkAsAnalyzeEnvironmentLiveness();
73 case Code::BYTECODE_HANDLER:
74 SetFlag(kCalledWithCodeStartRegister);
78 #if ENABLE_GDB_JIT_INTERFACE && DEBUG 79 MarkAsSourcePositionsEnabled();
80 #endif // ENABLE_GDB_JIT_INTERFACE && DEBUG 82 case Code::WASM_FUNCTION:
83 SetFlag(kSwitchJumpTableEnabled);
90 OptimizedCompilationInfo::~OptimizedCompilationInfo() {
91 if (GetFlag(kDisableFutureOptimization) && has_shared_info()) {
92 shared_info()->DisableOptimization(bailout_reason());
96 void OptimizedCompilationInfo::set_deferred_handles(
97 std::shared_ptr<DeferredHandles> deferred_handles) {
98 DCHECK_NULL(deferred_handles_);
99 deferred_handles_.swap(deferred_handles);
102 void OptimizedCompilationInfo::set_deferred_handles(
103 DeferredHandles* deferred_handles) {
104 DCHECK_NULL(deferred_handles_);
105 deferred_handles_.reset(deferred_handles);
108 void OptimizedCompilationInfo::ReopenHandlesInNewHandleScope(Isolate* isolate) {
109 if (!shared_info_.is_null()) {
110 shared_info_ = Handle<SharedFunctionInfo>(*shared_info_, isolate);
112 if (!bytecode_array_.is_null()) {
113 bytecode_array_ = Handle<BytecodeArray>(*bytecode_array_, isolate);
115 if (!closure_.is_null()) {
116 closure_ = Handle<JSFunction>(*closure_, isolate);
120 std::unique_ptr<char[]> OptimizedCompilationInfo::GetDebugName()
const {
121 if (!shared_info().is_null()) {
122 return shared_info()->DebugName()->ToCString();
124 Vector<const char> name_vec = debug_name_;
125 if (name_vec.is_empty()) name_vec = ArrayVector(
"unknown");
126 std::unique_ptr<char[]> name(
new char[name_vec.length() + 1]);
127 memcpy(name.get(), name_vec.start(), name_vec.length());
128 name[name_vec.length()] =
'\0';
132 StackFrame::Type OptimizedCompilationInfo::GetOutputStackFrameType()
const {
133 switch (code_kind()) {
135 case Code::BYTECODE_HANDLER:
137 return StackFrame::STUB;
138 case Code::WASM_FUNCTION:
139 return StackFrame::WASM_COMPILED;
140 case Code::JS_TO_WASM_FUNCTION:
141 return StackFrame::JS_TO_WASM;
142 case Code::WASM_TO_JS_FUNCTION:
143 return StackFrame::WASM_TO_JS;
144 case Code::WASM_INTERPRETER_ENTRY:
145 return StackFrame::WASM_INTERPRETER_ENTRY;
148 return StackFrame::NONE;
152 bool OptimizedCompilationInfo::has_context()
const {
153 return !closure().is_null();
156 Context OptimizedCompilationInfo::context()
const {
157 DCHECK(has_context());
158 return closure()->context();
161 bool OptimizedCompilationInfo::has_native_context()
const {
162 return !closure().is_null() && !closure()->native_context().is_null();
165 Context OptimizedCompilationInfo::native_context()
const {
166 DCHECK(has_native_context());
167 return closure()->native_context();
170 bool OptimizedCompilationInfo::has_global_object()
const {
171 return has_native_context();
174 JSGlobalObject* OptimizedCompilationInfo::global_object()
const {
175 DCHECK(has_global_object());
176 return native_context()->global_object();
179 int OptimizedCompilationInfo::AddInlinedFunction(
180 Handle<SharedFunctionInfo> inlined_function,
181 Handle<BytecodeArray> inlined_bytecode, SourcePosition pos) {
182 int id =
static_cast<int>(inlined_functions_.size());
183 inlined_functions_.push_back(
184 InlinedFunctionHolder(inlined_function, inlined_bytecode, pos));
188 void OptimizedCompilationInfo::SetTracingFlags(
bool passes_filter) {
189 if (!passes_filter)
return;
190 if (FLAG_trace_turbo) SetFlag(kTraceTurboJson);
191 if (FLAG_trace_turbo_graph) SetFlag(kTraceTurboGraph);
192 if (FLAG_trace_turbo_scheduled) SetFlag(kTraceTurboScheduled);