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>
|
|
|
|
|
|
|
|
#include "src/compilation-dependencies.h"
|
2017-10-19 15:12:42 +00:00
|
|
|
#include "src/feedback-vector.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 {
|
|
|
|
|
2017-06-06 15:44:55 +00:00
|
|
|
class CoverageInfo;
|
2016-08-31 08:49:14 +00:00
|
|
|
class DeclarationScope;
|
|
|
|
class DeferredHandles;
|
|
|
|
class FunctionLiteral;
|
|
|
|
class Isolate;
|
2017-08-03 11:00:57 +00:00
|
|
|
class JavaScriptFrame;
|
2017-08-04 09:22:01 +00:00
|
|
|
class ParseInfo;
|
2017-08-03 11:00:57 +00:00
|
|
|
class SourceRangeMap;
|
2016-08-31 08:49:14 +00:00
|
|
|
class Zone;
|
|
|
|
|
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,
|
2016-08-31 08:49:14 +00:00
|
|
|
};
|
|
|
|
|
2017-11-28 22:25:36 +00:00
|
|
|
// TODO(mtrofin): investigate if this might be generalized outside wasm, with
|
|
|
|
// the goal of better separating the compiler from where compilation lands. At
|
2018-04-04 20:30:34 +00:00
|
|
|
// that point, the Handle<Code> member of OptimizedCompilationInfo would also
|
|
|
|
// be removed.
|
2017-11-28 22:25:36 +00:00
|
|
|
struct WasmCodeDesc {
|
|
|
|
CodeDesc code_desc;
|
|
|
|
size_t safepoint_table_offset = 0;
|
2018-02-27 09:23:48 +00:00
|
|
|
size_t handler_table_offset = 0;
|
2017-11-28 22:25:36 +00:00
|
|
|
uint32_t frame_slot_count = 0;
|
|
|
|
Handle<ByteArray> source_positions_table;
|
|
|
|
};
|
|
|
|
|
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);
|
2017-08-04 09:22:01 +00:00
|
|
|
// Construct a compilation info for stub compilation (or 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(); }
|
2016-08-31 08:49:14 +00:00
|
|
|
Handle<JSFunction> closure() const { return closure_; }
|
|
|
|
Handle<Code> code() const { return code_; }
|
2018-02-13 15:40:56 +00:00
|
|
|
AbstractCode::Kind abstract_code_kind() const { return code_kind_; }
|
|
|
|
Code::Kind code_kind() const {
|
|
|
|
DCHECK(code_kind_ < static_cast<AbstractCode::Kind>(Code::NUMBER_OF_KINDS));
|
|
|
|
return static_cast<Code::Kind>(code_kind_);
|
|
|
|
}
|
2017-10-26 13:00:43 +00:00
|
|
|
uint32_t stub_key() const { return stub_key_; }
|
|
|
|
void set_stub_key(uint32_t stub_key) { stub_key_ = stub_key; }
|
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
|
|
|
|
|
|
|
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-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
|
|
|
|
2016-08-31 08:49:14 +00:00
|
|
|
void SetCode(Handle<Code> code) { code_ = code; }
|
|
|
|
|
2016-09-07 12:02:49 +00:00
|
|
|
bool has_context() const;
|
|
|
|
Context* context() const;
|
|
|
|
|
2016-08-31 08:49:14 +00:00
|
|
|
bool has_native_context() const;
|
|
|
|
Context* native_context() const;
|
|
|
|
|
|
|
|
bool has_global_object() const;
|
|
|
|
JSGlobalObject* global_object() const;
|
|
|
|
|
|
|
|
// Accessors for the different compilation modes.
|
2018-02-13 15:40:56 +00:00
|
|
|
bool IsOptimizing() const {
|
|
|
|
return abstract_code_kind() == AbstractCode::OPTIMIZED_FUNCTION;
|
|
|
|
}
|
|
|
|
bool IsWasm() const {
|
|
|
|
return abstract_code_kind() == AbstractCode::WASM_FUNCTION;
|
|
|
|
}
|
|
|
|
bool IsStub() const {
|
|
|
|
return abstract_code_kind() != AbstractCode::OPTIMIZED_FUNCTION &&
|
2018-04-04 20:30:34 +00:00
|
|
|
abstract_code_kind() != AbstractCode::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
|
|
|
}
|
|
|
|
|
|
|
|
void ReopenHandlesInNewHandleScope();
|
|
|
|
|
|
|
|
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-11-15 14:36:57 +00:00
|
|
|
CompilationDependencies* dependencies() { return dependencies_.get(); }
|
2016-08-31 08:49:14 +00:00
|
|
|
|
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;
|
|
|
|
|
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,
|
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)
|
2017-05-29 13:25:18 +00:00
|
|
|
: shared_info(inlined_shared_info) {
|
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
|
|
|
position.position = pos;
|
|
|
|
// initialized when generating the deoptimization literals
|
2017-10-18 11:53:25 +00:00
|
|
|
position.inlined_function_id = DeoptimizationData::kNotInlinedIndex;
|
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,
|
|
|
|
SourcePosition pos);
|
2016-08-31 08:49:14 +00:00
|
|
|
|
|
|
|
std::unique_ptr<char[]> GetDebugName() const;
|
|
|
|
|
|
|
|
StackFrame::Type GetOutputStackFrameType() const;
|
|
|
|
|
2017-11-28 22:25:36 +00:00
|
|
|
WasmCodeDesc* wasm_code_desc() { return &wasm_code_desc_; }
|
|
|
|
|
2016-08-31 08:49:14 +00:00
|
|
|
private:
|
2018-04-04 20:30:34 +00:00
|
|
|
OptimizedCompilationInfo(Vector<const char> debug_name,
|
|
|
|
AbstractCode::Kind code_kind, Zone* zone);
|
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.
|
2016-08-31 08:49:14 +00:00
|
|
|
unsigned flags_;
|
2018-04-30 12:13:54 +00:00
|
|
|
PoisoningMitigationLevel poisoning_level_ =
|
|
|
|
PoisoningMitigationLevel::kDontPoison;
|
2016-08-31 08:49:14 +00:00
|
|
|
|
2018-02-13 15:40:56 +00:00
|
|
|
AbstractCode::Kind code_kind_;
|
2017-10-26 13:00:43 +00:00
|
|
|
uint32_t stub_key_;
|
2017-11-16 12:35:58 +00:00
|
|
|
int32_t builtin_index_;
|
2016-08-31 08:49:14 +00:00
|
|
|
|
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.
|
|
|
|
Handle<Code> code_;
|
2017-11-28 22:25:36 +00:00
|
|
|
WasmCodeDesc wasm_code_desc_;
|
2016-08-31 08:49:14 +00:00
|
|
|
|
2018-02-13 15:40:56 +00:00
|
|
|
// Entry point when compiling for OSR, {BailoutId::None} otherwise.
|
2017-08-18 15:25:01 +00:00
|
|
|
BailoutId osr_offset_;
|
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
|
|
|
|
|
|
|
// Dependencies for this compilation, e.g. stable maps.
|
2017-11-15 14:36:57 +00:00
|
|
|
std::unique_ptr<CompilationDependencies> dependencies_;
|
2016-08-31 08:49:14 +00:00
|
|
|
|
|
|
|
BailoutReason bailout_reason_;
|
|
|
|
|
|
|
|
InlinedFunctionList inlined_functions_;
|
|
|
|
|
|
|
|
int optimization_id_;
|
|
|
|
|
|
|
|
// The current OSR frame for specialization or {nullptr}.
|
|
|
|
JavaScriptFrame* osr_frame_ = nullptr;
|
|
|
|
|
|
|
|
Vector<const char> debug_name_;
|
|
|
|
|
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_
|