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
|
|
|
#ifndef V8_OPTIMIZED_COMPILATION_INFO_H_
|
|
|
|
#define V8_OPTIMIZED_COMPILATION_INFO_H_
|
2016-08-31 08:49:14 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2018-05-16 10:49:30 +00:00
|
|
|
#include "src/bailout-reason.h"
|
2016-08-31 08:49:14 +00:00
|
|
|
#include "src/frames.h"
|
2017-01-30 19:27:00 +00:00
|
|
|
#include "src/globals.h"
|
2016-08-31 08:49:14 +00:00
|
|
|
#include "src/handles.h"
|
|
|
|
#include "src/objects.h"
|
|
|
|
#include "src/source-position-table.h"
|
|
|
|
#include "src/utils.h"
|
|
|
|
#include "src/vector.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
class DeferredHandles;
|
|
|
|
class FunctionLiteral;
|
|
|
|
class Isolate;
|
2017-08-03 11:00:57 +00:00
|
|
|
class JavaScriptFrame;
|
2018-09-21 12:02:47 +00:00
|
|
|
class JSGlobalObject;
|
2016-08-31 08:49:14 +00:00
|
|
|
class Zone;
|
|
|
|
|
2019-01-21 11:57:22 +00:00
|
|
|
namespace wasm {
|
|
|
|
struct WasmCompilationResult;
|
|
|
|
}
|
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
// OptimizedCompilationInfo encapsulates the information needed to compile
|
|
|
|
// optimized code for a given function, and the results of the optimized
|
|
|
|
// compilation.
|
|
|
|
class V8_EXPORT_PRIVATE OptimizedCompilationInfo final {
|
2016-08-31 08:49:14 +00:00
|
|
|
public:
|
|
|
|
// Various configuration flags for a compilation, as well as some properties
|
|
|
|
// of the compiled code produced by a compilation.
|
|
|
|
enum Flag {
|
2018-04-04 20:30:34 +00:00
|
|
|
kAccessorInliningEnabled = 1 << 0,
|
|
|
|
kFunctionContextSpecializing = 1 << 1,
|
|
|
|
kInliningEnabled = 1 << 2,
|
2018-04-30 12:13:54 +00:00
|
|
|
kDisableFutureOptimization = 1 << 3,
|
|
|
|
kSplittingEnabled = 1 << 4,
|
|
|
|
kSourcePositionsEnabled = 1 << 5,
|
|
|
|
kBailoutOnUninitialized = 1 << 6,
|
|
|
|
kLoopPeelingEnabled = 1 << 7,
|
|
|
|
kUntrustedCodeMitigations = 1 << 8,
|
|
|
|
kSwitchJumpTableEnabled = 1 << 9,
|
|
|
|
kCalledWithCodeStartRegister = 1 << 10,
|
|
|
|
kPoisonRegisterArguments = 1 << 11,
|
|
|
|
kAllocationFoldingEnabled = 1 << 12,
|
|
|
|
kAnalyzeEnvironmentLiveness = 1 << 13,
|
2018-05-16 08:50:19 +00:00
|
|
|
kTraceTurboJson = 1 << 14,
|
|
|
|
kTraceTurboGraph = 1 << 15,
|
|
|
|
kTraceTurboScheduled = 1 << 16,
|
2019-03-21 09:14:34 +00:00
|
|
|
kWasmRuntimeExceptionSupport = 1 << 17,
|
|
|
|
kTurboControlFlowAwareAllocation = 1 << 18,
|
|
|
|
kTurboPreprocessRanges = 1 << 19
|
2016-08-31 08:49:14 +00:00
|
|
|
};
|
|
|
|
|
2017-08-04 09:22:01 +00:00
|
|
|
// Construct a compilation info for optimized compilation.
|
2018-04-04 20:30:34 +00:00
|
|
|
OptimizedCompilationInfo(Zone* zone, Isolate* isolate,
|
|
|
|
Handle<SharedFunctionInfo> shared,
|
|
|
|
Handle<JSFunction> closure);
|
2018-06-08 11:28:39 +00:00
|
|
|
// Construct a compilation info for stub compilation, Wasm, and testing.
|
2018-04-04 20:30:34 +00:00
|
|
|
OptimizedCompilationInfo(Vector<const char> debug_name, Zone* zone,
|
|
|
|
Code::Kind code_kind);
|
2016-08-31 08:49:14 +00:00
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
~OptimizedCompilationInfo();
|
2016-08-31 08:49:14 +00:00
|
|
|
|
|
|
|
Zone* zone() { return zone_; }
|
2017-08-18 15:25:01 +00:00
|
|
|
bool is_osr() const { return !osr_offset_.IsNone(); }
|
2017-07-21 09:32:32 +00:00
|
|
|
Handle<SharedFunctionInfo> shared_info() const { return shared_info_; }
|
|
|
|
bool has_shared_info() const { return !shared_info().is_null(); }
|
2018-11-03 22:45:55 +00:00
|
|
|
Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; }
|
|
|
|
bool has_bytecode_array() const { return !bytecode_array_.is_null(); }
|
2016-08-31 08:49:14 +00:00
|
|
|
Handle<JSFunction> closure() const { return closure_; }
|
2018-11-15 08:54:13 +00:00
|
|
|
Handle<Code> code() const { return code_; }
|
2018-09-05 12:36:46 +00:00
|
|
|
Code::Kind code_kind() const { return code_kind_; }
|
2017-11-16 12:35:58 +00:00
|
|
|
int32_t builtin_index() const { return builtin_index_; }
|
|
|
|
void set_builtin_index(int32_t index) { builtin_index_ = index; }
|
2017-08-18 15:25:01 +00:00
|
|
|
BailoutId osr_offset() const { return osr_offset_; }
|
2016-08-31 08:49:14 +00:00
|
|
|
JavaScriptFrame* osr_frame() const { return osr_frame_; }
|
2017-10-19 15:12:42 +00:00
|
|
|
|
2017-08-03 11:04:47 +00:00
|
|
|
// Flags used by optimized compilation.
|
2016-08-31 08:49:14 +00:00
|
|
|
|
2019-03-21 09:14:34 +00:00
|
|
|
void MarkAsTurboControlFlowAwareAllocation() {
|
|
|
|
SetFlag(kTurboControlFlowAwareAllocation);
|
|
|
|
}
|
|
|
|
bool is_turbo_control_flow_aware_allocation() const {
|
|
|
|
return GetFlag(kTurboControlFlowAwareAllocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarkAsTurboPreprocessRanges() { SetFlag(kTurboPreprocessRanges); }
|
|
|
|
bool is_turbo_preprocess_ranges() const {
|
|
|
|
return GetFlag(kTurboPreprocessRanges);
|
|
|
|
}
|
|
|
|
|
2016-08-31 08:49:14 +00:00
|
|
|
void MarkAsFunctionContextSpecializing() {
|
|
|
|
SetFlag(kFunctionContextSpecializing);
|
|
|
|
}
|
|
|
|
bool is_function_context_specializing() const {
|
|
|
|
return GetFlag(kFunctionContextSpecializing);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarkAsAccessorInliningEnabled() { SetFlag(kAccessorInliningEnabled); }
|
|
|
|
bool is_accessor_inlining_enabled() const {
|
|
|
|
return GetFlag(kAccessorInliningEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarkAsSourcePositionsEnabled() { SetFlag(kSourcePositionsEnabled); }
|
|
|
|
bool is_source_positions_enabled() const {
|
|
|
|
return GetFlag(kSourcePositionsEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarkAsInliningEnabled() { SetFlag(kInliningEnabled); }
|
|
|
|
bool is_inlining_enabled() const { return GetFlag(kInliningEnabled); }
|
|
|
|
|
2018-04-30 12:13:54 +00:00
|
|
|
void SetPoisoningMitigationLevel(PoisoningMitigationLevel poisoning_level) {
|
|
|
|
poisoning_level_ = poisoning_level;
|
|
|
|
}
|
|
|
|
PoisoningMitigationLevel GetPoisoningMitigationLevel() const {
|
|
|
|
return poisoning_level_;
|
|
|
|
}
|
2018-02-13 14:31:46 +00:00
|
|
|
|
2016-08-31 08:49:14 +00:00
|
|
|
void MarkAsSplittingEnabled() { SetFlag(kSplittingEnabled); }
|
|
|
|
bool is_splitting_enabled() const { return GetFlag(kSplittingEnabled); }
|
|
|
|
|
|
|
|
void MarkAsBailoutOnUninitialized() { SetFlag(kBailoutOnUninitialized); }
|
|
|
|
bool is_bailout_on_uninitialized() const {
|
|
|
|
return GetFlag(kBailoutOnUninitialized);
|
|
|
|
}
|
|
|
|
|
2016-11-29 14:05:44 +00:00
|
|
|
void MarkAsLoopPeelingEnabled() { SetFlag(kLoopPeelingEnabled); }
|
|
|
|
bool is_loop_peeling_enabled() const { return GetFlag(kLoopPeelingEnabled); }
|
|
|
|
|
2018-01-04 12:31:00 +00:00
|
|
|
bool has_untrusted_code_mitigations() const {
|
|
|
|
return GetFlag(kUntrustedCodeMitigations);
|
|
|
|
}
|
|
|
|
|
2018-01-31 16:24:56 +00:00
|
|
|
bool switch_jump_table_enabled() const {
|
|
|
|
return GetFlag(kSwitchJumpTableEnabled);
|
|
|
|
}
|
|
|
|
|
2018-03-26 15:44:44 +00:00
|
|
|
bool called_with_code_start_register() const {
|
|
|
|
bool enabled = GetFlag(kCalledWithCodeStartRegister);
|
2018-02-26 09:19:41 +00:00
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarkAsPoisoningRegisterArguments() {
|
|
|
|
DCHECK(has_untrusted_code_mitigations());
|
|
|
|
SetFlag(kPoisonRegisterArguments);
|
|
|
|
}
|
|
|
|
bool is_poisoning_register_arguments() const {
|
|
|
|
bool enabled = GetFlag(kPoisonRegisterArguments);
|
2018-02-11 19:17:27 +00:00
|
|
|
DCHECK_IMPLIES(enabled, has_untrusted_code_mitigations());
|
2018-03-26 15:44:44 +00:00
|
|
|
DCHECK_IMPLIES(enabled, called_with_code_start_register());
|
2018-02-11 19:17:27 +00:00
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
2018-03-21 09:46:22 +00:00
|
|
|
void MarkAsAllocationFoldingEnabled() { SetFlag(kAllocationFoldingEnabled); }
|
|
|
|
bool is_allocation_folding_enabled() const {
|
|
|
|
return GetFlag(kAllocationFoldingEnabled);
|
|
|
|
}
|
|
|
|
|
2018-03-29 08:25:16 +00:00
|
|
|
void MarkAsAnalyzeEnvironmentLiveness() {
|
|
|
|
SetFlag(kAnalyzeEnvironmentLiveness);
|
|
|
|
}
|
|
|
|
bool is_analyze_environment_liveness() const {
|
|
|
|
return GetFlag(kAnalyzeEnvironmentLiveness);
|
|
|
|
}
|
|
|
|
|
2018-08-23 11:24:17 +00:00
|
|
|
void SetWasmRuntimeExceptionSupport() {
|
|
|
|
SetFlag(kWasmRuntimeExceptionSupport);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wasm_runtime_exception_support() {
|
|
|
|
return GetFlag(kWasmRuntimeExceptionSupport);
|
|
|
|
}
|
|
|
|
|
2018-05-16 08:50:19 +00:00
|
|
|
bool trace_turbo_json_enabled() const { return GetFlag(kTraceTurboJson); }
|
|
|
|
|
|
|
|
bool trace_turbo_graph_enabled() const { return GetFlag(kTraceTurboGraph); }
|
|
|
|
|
|
|
|
bool trace_turbo_scheduled_enabled() const {
|
|
|
|
return GetFlag(kTraceTurboScheduled);
|
|
|
|
}
|
|
|
|
|
2017-08-03 11:04:47 +00:00
|
|
|
// Code getters and setters.
|
2017-08-03 11:00:57 +00:00
|
|
|
|
2018-11-15 08:54:13 +00:00
|
|
|
void SetCode(Handle<Code> code) { code_ = code; }
|
2016-08-31 08:49:14 +00:00
|
|
|
|
2019-01-21 11:57:22 +00:00
|
|
|
void SetWasmCompilationResult(std::unique_ptr<wasm::WasmCompilationResult>);
|
|
|
|
std::unique_ptr<wasm::WasmCompilationResult> ReleaseWasmCompilationResult();
|
|
|
|
|
2016-09-07 12:02:49 +00:00
|
|
|
bool has_context() const;
|
2018-11-23 10:06:32 +00:00
|
|
|
Context context() const;
|
2016-09-07 12:02:49 +00:00
|
|
|
|
2016-08-31 08:49:14 +00:00
|
|
|
bool has_native_context() const;
|
2018-11-23 10:06:32 +00:00
|
|
|
Context native_context() const;
|
2016-08-31 08:49:14 +00:00
|
|
|
|
|
|
|
bool has_global_object() const;
|
2018-12-08 02:59:17 +00:00
|
|
|
JSGlobalObject global_object() const;
|
2016-08-31 08:49:14 +00:00
|
|
|
|
|
|
|
// Accessors for the different compilation modes.
|
2018-09-05 12:36:46 +00:00
|
|
|
bool IsOptimizing() const { return code_kind() == Code::OPTIMIZED_FUNCTION; }
|
|
|
|
bool IsWasm() const { return code_kind() == Code::WASM_FUNCTION; }
|
2018-12-07 14:53:22 +00:00
|
|
|
bool IsNotOptimizedFunctionOrWasmFunction() const {
|
2018-09-05 12:36:46 +00:00
|
|
|
return code_kind() != Code::OPTIMIZED_FUNCTION &&
|
|
|
|
code_kind() != Code::WASM_FUNCTION;
|
2018-02-13 15:40:56 +00:00
|
|
|
}
|
2017-08-18 15:25:01 +00:00
|
|
|
void SetOptimizingForOsr(BailoutId osr_offset, JavaScriptFrame* osr_frame) {
|
2017-08-04 09:22:01 +00:00
|
|
|
DCHECK(IsOptimizing());
|
2017-08-18 15:25:01 +00:00
|
|
|
osr_offset_ = osr_offset;
|
2016-08-31 08:49:14 +00:00
|
|
|
osr_frame_ = osr_frame;
|
|
|
|
}
|
|
|
|
|
2017-02-10 15:01:29 +00:00
|
|
|
void set_deferred_handles(std::shared_ptr<DeferredHandles> deferred_handles);
|
|
|
|
void set_deferred_handles(DeferredHandles* deferred_handles);
|
|
|
|
std::shared_ptr<DeferredHandles> deferred_handles() {
|
|
|
|
return deferred_handles_;
|
2016-08-31 08:49:14 +00:00
|
|
|
}
|
|
|
|
|
2018-06-23 09:05:50 +00:00
|
|
|
void ReopenHandlesInNewHandleScope(Isolate* isolate);
|
2016-08-31 08:49:14 +00:00
|
|
|
|
|
|
|
void AbortOptimization(BailoutReason reason) {
|
2018-01-03 23:27:03 +00:00
|
|
|
DCHECK_NE(reason, BailoutReason::kNoReason);
|
|
|
|
if (bailout_reason_ == BailoutReason::kNoReason) bailout_reason_ = reason;
|
2016-08-31 08:49:14 +00:00
|
|
|
SetFlag(kDisableFutureOptimization);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RetryOptimization(BailoutReason reason) {
|
2018-01-03 23:27:03 +00:00
|
|
|
DCHECK_NE(reason, BailoutReason::kNoReason);
|
2016-08-31 08:49:14 +00:00
|
|
|
if (GetFlag(kDisableFutureOptimization)) return;
|
|
|
|
bailout_reason_ = reason;
|
|
|
|
}
|
|
|
|
|
|
|
|
BailoutReason bailout_reason() const { return bailout_reason_; }
|
|
|
|
|
2017-08-04 09:22:01 +00:00
|
|
|
int optimization_id() const {
|
|
|
|
DCHECK(IsOptimizing());
|
|
|
|
return optimization_id_;
|
|
|
|
}
|
2016-08-31 08:49:14 +00:00
|
|
|
|
|
|
|
struct InlinedFunctionHolder {
|
|
|
|
Handle<SharedFunctionInfo> shared_info;
|
2019-02-13 13:03:24 +00:00
|
|
|
Handle<BytecodeArray> bytecode_array; // Explicit to prevent flushing.
|
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
|
|
|
InliningPosition position;
|
|
|
|
|
2016-08-31 08:49:14 +00:00
|
|
|
InlinedFunctionHolder(Handle<SharedFunctionInfo> inlined_shared_info,
|
2018-11-15 13:45:09 +00:00
|
|
|
Handle<BytecodeArray> inlined_bytecode,
|
2019-02-13 13:03:24 +00:00
|
|
|
SourcePosition 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
|
|
|
|
|
|
|
void RegisterInlinedFunctionId(size_t inlined_function_id) {
|
|
|
|
position.inlined_function_id = static_cast<int>(inlined_function_id);
|
|
|
|
}
|
2016-08-31 08:49:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<InlinedFunctionHolder> InlinedFunctionList;
|
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
|
|
|
InlinedFunctionList& inlined_functions() { return inlined_functions_; }
|
2016-08-31 08:49:14 +00:00
|
|
|
|
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
|
|
|
// Returns the inlining id for source position tracking.
|
|
|
|
int AddInlinedFunction(Handle<SharedFunctionInfo> inlined_function,
|
2018-11-15 13:45:09 +00:00
|
|
|
Handle<BytecodeArray> inlined_bytecode,
|
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
|
|
|
SourcePosition pos);
|
2016-08-31 08:49:14 +00:00
|
|
|
|
|
|
|
std::unique_ptr<char[]> GetDebugName() const;
|
|
|
|
|
|
|
|
StackFrame::Type GetOutputStackFrameType() const;
|
|
|
|
|
2018-06-13 15:50:21 +00:00
|
|
|
const char* trace_turbo_filename() const {
|
|
|
|
return trace_turbo_filename_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_trace_turbo_filename(std::unique_ptr<char[]> filename) {
|
|
|
|
trace_turbo_filename_ = std::move(filename);
|
|
|
|
}
|
|
|
|
|
2016-08-31 08:49:14 +00:00
|
|
|
private:
|
2018-09-05 12:36:46 +00:00
|
|
|
OptimizedCompilationInfo(Code::Kind code_kind, Zone* zone);
|
|
|
|
void ConfigureFlags();
|
2016-08-31 08:49:14 +00:00
|
|
|
|
|
|
|
void SetFlag(Flag flag) { flags_ |= flag; }
|
|
|
|
bool GetFlag(Flag flag) const { return (flags_ & flag) != 0; }
|
|
|
|
|
2018-05-16 08:50:19 +00:00
|
|
|
void SetTracingFlags(bool passes_filter);
|
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
// Compilation flags.
|
2018-09-05 12:36:46 +00:00
|
|
|
unsigned flags_ = 0;
|
2018-04-30 12:13:54 +00:00
|
|
|
PoisoningMitigationLevel poisoning_level_ =
|
|
|
|
PoisoningMitigationLevel::kDontPoison;
|
2016-08-31 08:49:14 +00:00
|
|
|
|
2018-09-05 12:36:46 +00:00
|
|
|
Code::Kind code_kind_;
|
|
|
|
int32_t builtin_index_ = -1;
|
2016-08-31 08:49:14 +00:00
|
|
|
|
2018-11-03 22:45:55 +00:00
|
|
|
// We retain a reference the bytecode array specifically to ensure it doesn't
|
|
|
|
// get flushed while we are optimizing the code.
|
|
|
|
Handle<BytecodeArray> bytecode_array_;
|
|
|
|
|
2017-07-21 09:32:32 +00:00
|
|
|
Handle<SharedFunctionInfo> shared_info_;
|
|
|
|
|
2016-08-31 08:49:14 +00:00
|
|
|
Handle<JSFunction> closure_;
|
|
|
|
|
|
|
|
// The compiled code.
|
2018-11-15 08:54:13 +00:00
|
|
|
Handle<Code> code_;
|
2016-08-31 08:49:14 +00:00
|
|
|
|
2019-01-21 11:57:22 +00:00
|
|
|
// The WebAssembly compilation result, not published in the NativeModule yet.
|
|
|
|
std::unique_ptr<wasm::WasmCompilationResult> wasm_compilation_result_;
|
|
|
|
|
2018-02-13 15:40:56 +00:00
|
|
|
// Entry point when compiling for OSR, {BailoutId::None} otherwise.
|
2018-09-05 12:36:46 +00:00
|
|
|
BailoutId osr_offset_ = BailoutId::None();
|
2016-08-31 08:49:14 +00:00
|
|
|
|
|
|
|
// The zone from which the compilation pipeline working on this
|
2018-04-04 20:30:34 +00:00
|
|
|
// OptimizedCompilationInfo allocates.
|
2016-08-31 08:49:14 +00:00
|
|
|
Zone* zone_;
|
|
|
|
|
2017-02-10 15:01:29 +00:00
|
|
|
std::shared_ptr<DeferredHandles> deferred_handles_;
|
2016-08-31 08:49:14 +00:00
|
|
|
|
2018-09-05 12:36:46 +00:00
|
|
|
BailoutReason bailout_reason_ = BailoutReason::kNoReason;
|
2016-08-31 08:49:14 +00:00
|
|
|
|
|
|
|
InlinedFunctionList inlined_functions_;
|
|
|
|
|
2018-09-05 12:36:46 +00:00
|
|
|
int optimization_id_ = -1;
|
2016-08-31 08:49:14 +00:00
|
|
|
|
|
|
|
// The current OSR frame for specialization or {nullptr}.
|
|
|
|
JavaScriptFrame* osr_frame_ = nullptr;
|
|
|
|
|
|
|
|
Vector<const char> debug_name_;
|
2018-06-13 15:50:21 +00:00
|
|
|
std::unique_ptr<char[]> trace_turbo_filename_;
|
2016-08-31 08:49:14 +00:00
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(OptimizedCompilationInfo);
|
2016-08-31 08:49:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
#endif // V8_OPTIMIZED_COMPILATION_INFO_H_
|