2016-08-31 08:49:14 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
#include "src/optimized-compilation-info.h"
|
2016-08-31 08:49:14 +00:00
|
|
|
|
|
|
|
#include "src/api.h"
|
2016-09-05 11:54:00 +00:00
|
|
|
#include "src/ast/ast.h"
|
2016-08-31 08:49:14 +00:00
|
|
|
#include "src/ast/scopes.h"
|
2016-11-23 12:42:18 +00:00
|
|
|
#include "src/debug/debug.h"
|
2016-08-31 08:49:14 +00:00
|
|
|
#include "src/isolate.h"
|
2017-02-09 08:35:03 +00:00
|
|
|
#include "src/objects-inl.h"
|
2017-08-04 09:22:01 +00:00
|
|
|
#include "src/parsing/parse-info.h"
|
This CL enables precise source positions for all V8 compilers. It merges compiler::SourcePosition and internal::SourcePosition to a single class used throughout the codebase. The new internal::SourcePosition instances store an id identifying an inlined function in addition to a script offset.
SourcePosition::InliningId() refers to a the new table DeoptimizationInputData::InliningPositions(), which provides the following data for every inlining id:
- The inlined SharedFunctionInfo as an offset into DeoptimizationInfo::LiteralArray
- The SourcePosition of the inlining. Recursively, this yields the full inlining stack.
Before the Code object is created, the same information can be found in CompilationInfo::inlined_functions().
If SourcePosition::InliningId() is SourcePosition::kNotInlined, it refers to the outer (non-inlined) function.
So every SourcePosition has full information about its inlining stack, as long as the corresponding Code object is known. The internal represenation of a source position is a positive 64bit integer.
All compilers create now appropriate source positions for inlined functions. In the case of Turbofan, this required using AstGraphBuilderWithPositions for inlined functions too. So this class is now moved to a header file.
At the moment, the additional information in source positions is only used in --trace-deopt and --code-comments. The profiler needs to be updated, at the moment it gets the correct script offsets from the deopt info, but the wrong script id from the reconstructed deopt stack, which can lead to wrong outputs. This should be resolved by making the profiler use the new inlining information for deopts.
I activated the inlined deoptimization tests in test-cpu-profiler.cc for Turbofan, changing them to a case where the deopt stack and the inlining position agree. It is currently still broken for other cases.
The following additional changes were necessary:
- The source position table (internal::SourcePositionTableBuilder etc.) supports now 64bit source positions. Encoding source positions in a single 64bit int together with the difference encoding in the source position table results in very little overhead for the inlining id, since only 12% of the source positions in Octane have a changed inlining id.
- The class HPositionInfo was effectively dead code and is now removed.
- SourcePosition has new printing and information facilities, including computing a full inlining stack.
- I had to rename compiler/source-position.{h,cc} to compiler/compiler-source-position-table.{h,cc} to avoid clashes with the new src/source-position.cc file.
- I wrote the new wrapper PodArray for ByteArray. It is a template working with any POD-type. This is used in DeoptimizationInputData::InliningPositions().
- I removed HInlinedFunctionInfo and HGraph::inlined_function_infos, because they were only used for the now obsolete Crankshaft inlining ids.
- Crankshaft managed a list of inlined functions in Lithium: LChunk::inlined_functions. This is an analog structure to CompilationInfo::inlined_functions. So I removed LChunk::inlined_functions and made Crankshaft use CompilationInfo::inlined_functions instead, because this was necessary to register the offsets into the literal array in a uniform way. This is a safe change because LChunk::inlined_functions has no other uses and the functions in CompilationInfo::inlined_functions have a strictly longer lifespan, being created earlier (in Hydrogen already).
BUG=v8:5432
Review-Url: https://codereview.chromium.org/2451853002
Cr-Commit-Position: refs/heads/master@{#40975}
2016-11-14 17:21:37 +00:00
|
|
|
#include "src/source-position.h"
|
2016-08-31 08:49:14 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
OptimizedCompilationInfo::OptimizedCompilationInfo(
|
|
|
|
Zone* zone, Isolate* isolate, Handle<SharedFunctionInfo> shared,
|
|
|
|
Handle<JSFunction> closure)
|
|
|
|
: OptimizedCompilationInfo({}, AbstractCode::OPTIMIZED_FUNCTION, zone) {
|
2017-08-04 09:22:01 +00:00
|
|
|
shared_info_ = shared;
|
|
|
|
closure_ = closure;
|
|
|
|
optimization_id_ = isolate->NextOptimizationId();
|
2017-11-15 14:36:57 +00:00
|
|
|
dependencies_.reset(new CompilationDependencies(isolate, zone));
|
2017-08-04 09:22:01 +00:00
|
|
|
|
2018-03-26 15:44:44 +00:00
|
|
|
SetFlag(kCalledWithCodeStartRegister);
|
2017-08-04 09:22:01 +00:00
|
|
|
if (FLAG_function_context_specialization) MarkAsFunctionContextSpecializing();
|
|
|
|
if (FLAG_turbo_splitting) MarkAsSplittingEnabled();
|
2018-06-08 11:28:39 +00:00
|
|
|
if (!FLAG_untrusted_code_mitigations) SetFlag(kSwitchJumpTableEnabled);
|
2018-02-26 09:19:41 +00:00
|
|
|
if (FLAG_untrusted_code_mitigations) MarkAsPoisoningRegisterArguments();
|
2017-08-04 09:22:01 +00:00
|
|
|
|
2018-03-29 08:25:16 +00:00
|
|
|
// TODO(yangguo): Disable this in case of debugging for crbug.com/826613
|
|
|
|
if (FLAG_analyze_environment_liveness) {
|
|
|
|
MarkAsAnalyzeEnvironmentLiveness();
|
|
|
|
}
|
|
|
|
|
2017-08-04 09:22:01 +00:00
|
|
|
// Collect source positions for optimized code when profiling or if debugger
|
|
|
|
// is active, to be able to get more precise source positions at the price of
|
|
|
|
// more memory consumption.
|
2017-11-15 14:36:57 +00:00
|
|
|
if (isolate->NeedsSourcePositionsForProfiling()) {
|
2017-08-04 09:22:01 +00:00
|
|
|
MarkAsSourcePositionsEnabled();
|
|
|
|
}
|
2018-05-16 08:50:19 +00:00
|
|
|
|
|
|
|
SetTracingFlags(shared->PassesFilter(FLAG_trace_turbo_filter));
|
2017-08-04 09:22:01 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
OptimizedCompilationInfo::OptimizedCompilationInfo(
|
|
|
|
Vector<const char> debug_name, Zone* zone, Code::Kind code_kind)
|
|
|
|
: OptimizedCompilationInfo(
|
|
|
|
debug_name, static_cast<AbstractCode::Kind>(code_kind), zone) {
|
2018-03-26 15:44:44 +00:00
|
|
|
if (code_kind == Code::BYTECODE_HANDLER) {
|
2018-04-04 20:30:34 +00:00
|
|
|
SetFlag(OptimizedCompilationInfo::kCalledWithCodeStartRegister);
|
2018-02-11 19:17:27 +00:00
|
|
|
}
|
2018-03-22 20:12:42 +00:00
|
|
|
#if ENABLE_GDB_JIT_INTERFACE
|
|
|
|
#if DEBUG
|
|
|
|
if (code_kind == Code::BUILTIN || code_kind == Code::STUB) {
|
|
|
|
MarkAsSourcePositionsEnabled();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
2018-05-16 08:50:19 +00:00
|
|
|
SetTracingFlags(
|
|
|
|
PassesFilter(debug_name, CStrVector(FLAG_trace_turbo_filter)));
|
2018-06-08 11:28:39 +00:00
|
|
|
if (!FLAG_untrusted_code_mitigations) {
|
|
|
|
// Embedded builtins don't support embedded absolute code addresses, so we
|
|
|
|
// cannot use jump tables.
|
|
|
|
if (code_kind != Code::BUILTIN) {
|
|
|
|
SetFlag(kSwitchJumpTableEnabled);
|
|
|
|
}
|
|
|
|
}
|
2018-02-11 19:17:27 +00:00
|
|
|
}
|
2016-08-31 08:49:14 +00:00
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
OptimizedCompilationInfo::OptimizedCompilationInfo(
|
|
|
|
Vector<const char> debug_name, AbstractCode::Kind code_kind, Zone* zone)
|
|
|
|
: flags_(FLAG_untrusted_code_mitigations ? kUntrustedCodeMitigations : 0),
|
2017-09-29 14:59:24 +00:00
|
|
|
code_kind_(code_kind),
|
2017-10-26 13:00:43 +00:00
|
|
|
stub_key_(0),
|
2017-11-16 12:35:58 +00:00
|
|
|
builtin_index_(Builtins::kNoBuiltinId),
|
2017-08-18 15:25:01 +00:00
|
|
|
osr_offset_(BailoutId::None()),
|
2016-08-31 08:49:14 +00:00
|
|
|
zone_(zone),
|
|
|
|
deferred_handles_(nullptr),
|
2017-11-15 14:36:57 +00:00
|
|
|
dependencies_(nullptr),
|
2018-01-03 23:27:03 +00:00
|
|
|
bailout_reason_(BailoutReason::kNoReason),
|
2016-08-31 08:49:14 +00:00
|
|
|
optimization_id_(-1),
|
|
|
|
debug_name_(debug_name) {}
|
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
OptimizedCompilationInfo::~OptimizedCompilationInfo() {
|
2016-08-31 08:49:14 +00:00
|
|
|
if (GetFlag(kDisableFutureOptimization) && has_shared_info()) {
|
|
|
|
shared_info()->DisableOptimization(bailout_reason());
|
|
|
|
}
|
2017-11-15 14:36:57 +00:00
|
|
|
if (dependencies()) {
|
|
|
|
dependencies()->Rollback();
|
|
|
|
}
|
2016-08-31 08:49:14 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
void OptimizedCompilationInfo::set_deferred_handles(
|
2017-02-10 15:01:29 +00:00
|
|
|
std::shared_ptr<DeferredHandles> deferred_handles) {
|
2017-10-18 09:06:55 +00:00
|
|
|
DCHECK_NULL(deferred_handles_);
|
2017-02-10 15:01:29 +00:00
|
|
|
deferred_handles_.swap(deferred_handles);
|
|
|
|
}
|
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
void OptimizedCompilationInfo::set_deferred_handles(
|
|
|
|
DeferredHandles* deferred_handles) {
|
2017-10-18 09:06:55 +00:00
|
|
|
DCHECK_NULL(deferred_handles_);
|
2017-02-10 15:01:29 +00:00
|
|
|
deferred_handles_.reset(deferred_handles);
|
|
|
|
}
|
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
void OptimizedCompilationInfo::ReopenHandlesInNewHandleScope() {
|
2017-07-21 09:32:32 +00:00
|
|
|
if (!shared_info_.is_null()) {
|
|
|
|
shared_info_ = Handle<SharedFunctionInfo>(*shared_info_);
|
|
|
|
}
|
2017-02-10 15:01:29 +00:00
|
|
|
if (!closure_.is_null()) {
|
|
|
|
closure_ = Handle<JSFunction>(*closure_);
|
|
|
|
}
|
2016-08-31 08:49:14 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
std::unique_ptr<char[]> OptimizedCompilationInfo::GetDebugName() const {
|
2017-07-21 09:32:32 +00:00
|
|
|
if (!shared_info().is_null()) {
|
|
|
|
return shared_info()->DebugName()->ToCString();
|
2016-08-31 08:49:14 +00:00
|
|
|
}
|
|
|
|
Vector<const char> name_vec = debug_name_;
|
|
|
|
if (name_vec.is_empty()) name_vec = ArrayVector("unknown");
|
|
|
|
std::unique_ptr<char[]> name(new char[name_vec.length() + 1]);
|
|
|
|
memcpy(name.get(), name_vec.start(), name_vec.length());
|
|
|
|
name[name_vec.length()] = '\0';
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
StackFrame::Type OptimizedCompilationInfo::GetOutputStackFrameType() const {
|
2017-09-29 14:59:24 +00:00
|
|
|
switch (code_kind()) {
|
2016-08-31 08:49:14 +00:00
|
|
|
case Code::STUB:
|
|
|
|
case Code::BYTECODE_HANDLER:
|
|
|
|
case Code::BUILTIN:
|
|
|
|
return StackFrame::STUB;
|
|
|
|
case Code::WASM_FUNCTION:
|
2017-01-11 10:16:10 +00:00
|
|
|
return StackFrame::WASM_COMPILED;
|
2016-08-31 08:49:14 +00:00
|
|
|
case Code::JS_TO_WASM_FUNCTION:
|
|
|
|
return StackFrame::JS_TO_WASM;
|
|
|
|
case Code::WASM_TO_JS_FUNCTION:
|
|
|
|
return StackFrame::WASM_TO_JS;
|
2017-01-11 10:16:10 +00:00
|
|
|
case Code::WASM_INTERPRETER_ENTRY:
|
|
|
|
return StackFrame::WASM_INTERPRETER_ENTRY;
|
2016-08-31 08:49:14 +00:00
|
|
|
default:
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
return StackFrame::NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
bool OptimizedCompilationInfo::has_context() const {
|
|
|
|
return !closure().is_null();
|
2016-08-31 08:49:14 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
Context* OptimizedCompilationInfo::context() const {
|
2016-09-07 12:02:49 +00:00
|
|
|
return has_context() ? closure()->context() : nullptr;
|
|
|
|
}
|
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
bool OptimizedCompilationInfo::has_native_context() const {
|
2016-08-31 08:49:14 +00:00
|
|
|
return !closure().is_null() && (closure()->native_context() != nullptr);
|
|
|
|
}
|
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
Context* OptimizedCompilationInfo::native_context() const {
|
2016-08-31 08:49:14 +00:00
|
|
|
return has_native_context() ? closure()->native_context() : nullptr;
|
|
|
|
}
|
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
bool OptimizedCompilationInfo::has_global_object() const {
|
|
|
|
return has_native_context();
|
|
|
|
}
|
2016-08-31 08:49:14 +00:00
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
JSGlobalObject* OptimizedCompilationInfo::global_object() const {
|
2016-08-31 08:49:14 +00:00
|
|
|
return has_global_object() ? native_context()->global_object() : nullptr;
|
|
|
|
}
|
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
int OptimizedCompilationInfo::AddInlinedFunction(
|
This CL enables precise source positions for all V8 compilers. It merges compiler::SourcePosition and internal::SourcePosition to a single class used throughout the codebase. The new internal::SourcePosition instances store an id identifying an inlined function in addition to a script offset.
SourcePosition::InliningId() refers to a the new table DeoptimizationInputData::InliningPositions(), which provides the following data for every inlining id:
- The inlined SharedFunctionInfo as an offset into DeoptimizationInfo::LiteralArray
- The SourcePosition of the inlining. Recursively, this yields the full inlining stack.
Before the Code object is created, the same information can be found in CompilationInfo::inlined_functions().
If SourcePosition::InliningId() is SourcePosition::kNotInlined, it refers to the outer (non-inlined) function.
So every SourcePosition has full information about its inlining stack, as long as the corresponding Code object is known. The internal represenation of a source position is a positive 64bit integer.
All compilers create now appropriate source positions for inlined functions. In the case of Turbofan, this required using AstGraphBuilderWithPositions for inlined functions too. So this class is now moved to a header file.
At the moment, the additional information in source positions is only used in --trace-deopt and --code-comments. The profiler needs to be updated, at the moment it gets the correct script offsets from the deopt info, but the wrong script id from the reconstructed deopt stack, which can lead to wrong outputs. This should be resolved by making the profiler use the new inlining information for deopts.
I activated the inlined deoptimization tests in test-cpu-profiler.cc for Turbofan, changing them to a case where the deopt stack and the inlining position agree. It is currently still broken for other cases.
The following additional changes were necessary:
- The source position table (internal::SourcePositionTableBuilder etc.) supports now 64bit source positions. Encoding source positions in a single 64bit int together with the difference encoding in the source position table results in very little overhead for the inlining id, since only 12% of the source positions in Octane have a changed inlining id.
- The class HPositionInfo was effectively dead code and is now removed.
- SourcePosition has new printing and information facilities, including computing a full inlining stack.
- I had to rename compiler/source-position.{h,cc} to compiler/compiler-source-position-table.{h,cc} to avoid clashes with the new src/source-position.cc file.
- I wrote the new wrapper PodArray for ByteArray. It is a template working with any POD-type. This is used in DeoptimizationInputData::InliningPositions().
- I removed HInlinedFunctionInfo and HGraph::inlined_function_infos, because they were only used for the now obsolete Crankshaft inlining ids.
- Crankshaft managed a list of inlined functions in Lithium: LChunk::inlined_functions. This is an analog structure to CompilationInfo::inlined_functions. So I removed LChunk::inlined_functions and made Crankshaft use CompilationInfo::inlined_functions instead, because this was necessary to register the offsets into the literal array in a uniform way. This is a safe change because LChunk::inlined_functions has no other uses and the functions in CompilationInfo::inlined_functions have a strictly longer lifespan, being created earlier (in Hydrogen already).
BUG=v8:5432
Review-Url: https://codereview.chromium.org/2451853002
Cr-Commit-Position: refs/heads/master@{#40975}
2016-11-14 17:21:37 +00:00
|
|
|
Handle<SharedFunctionInfo> inlined_function, SourcePosition pos) {
|
|
|
|
int id = static_cast<int>(inlined_functions_.size());
|
2017-05-29 13:25:18 +00:00
|
|
|
inlined_functions_.push_back(InlinedFunctionHolder(inlined_function, pos));
|
This CL enables precise source positions for all V8 compilers. It merges compiler::SourcePosition and internal::SourcePosition to a single class used throughout the codebase. The new internal::SourcePosition instances store an id identifying an inlined function in addition to a script offset.
SourcePosition::InliningId() refers to a the new table DeoptimizationInputData::InliningPositions(), which provides the following data for every inlining id:
- The inlined SharedFunctionInfo as an offset into DeoptimizationInfo::LiteralArray
- The SourcePosition of the inlining. Recursively, this yields the full inlining stack.
Before the Code object is created, the same information can be found in CompilationInfo::inlined_functions().
If SourcePosition::InliningId() is SourcePosition::kNotInlined, it refers to the outer (non-inlined) function.
So every SourcePosition has full information about its inlining stack, as long as the corresponding Code object is known. The internal represenation of a source position is a positive 64bit integer.
All compilers create now appropriate source positions for inlined functions. In the case of Turbofan, this required using AstGraphBuilderWithPositions for inlined functions too. So this class is now moved to a header file.
At the moment, the additional information in source positions is only used in --trace-deopt and --code-comments. The profiler needs to be updated, at the moment it gets the correct script offsets from the deopt info, but the wrong script id from the reconstructed deopt stack, which can lead to wrong outputs. This should be resolved by making the profiler use the new inlining information for deopts.
I activated the inlined deoptimization tests in test-cpu-profiler.cc for Turbofan, changing them to a case where the deopt stack and the inlining position agree. It is currently still broken for other cases.
The following additional changes were necessary:
- The source position table (internal::SourcePositionTableBuilder etc.) supports now 64bit source positions. Encoding source positions in a single 64bit int together with the difference encoding in the source position table results in very little overhead for the inlining id, since only 12% of the source positions in Octane have a changed inlining id.
- The class HPositionInfo was effectively dead code and is now removed.
- SourcePosition has new printing and information facilities, including computing a full inlining stack.
- I had to rename compiler/source-position.{h,cc} to compiler/compiler-source-position-table.{h,cc} to avoid clashes with the new src/source-position.cc file.
- I wrote the new wrapper PodArray for ByteArray. It is a template working with any POD-type. This is used in DeoptimizationInputData::InliningPositions().
- I removed HInlinedFunctionInfo and HGraph::inlined_function_infos, because they were only used for the now obsolete Crankshaft inlining ids.
- Crankshaft managed a list of inlined functions in Lithium: LChunk::inlined_functions. This is an analog structure to CompilationInfo::inlined_functions. So I removed LChunk::inlined_functions and made Crankshaft use CompilationInfo::inlined_functions instead, because this was necessary to register the offsets into the literal array in a uniform way. This is a safe change because LChunk::inlined_functions has no other uses and the functions in CompilationInfo::inlined_functions have a strictly longer lifespan, being created earlier (in Hydrogen already).
BUG=v8:5432
Review-Url: https://codereview.chromium.org/2451853002
Cr-Commit-Position: refs/heads/master@{#40975}
2016-11-14 17:21:37 +00:00
|
|
|
return id;
|
2016-08-31 08:49:14 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 08:50:19 +00:00
|
|
|
void OptimizedCompilationInfo::SetTracingFlags(bool passes_filter) {
|
|
|
|
if (!passes_filter) return;
|
|
|
|
if (FLAG_trace_turbo) SetFlag(kTraceTurboJson);
|
|
|
|
if (FLAG_trace_turbo_graph) SetFlag(kTraceTurboGraph);
|
|
|
|
if (FLAG_trace_turbo_scheduled) SetFlag(kTraceTurboScheduled);
|
|
|
|
}
|
|
|
|
|
2016-08-31 08:49:14 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|