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.
|
|
|
|
|
|
|
|
#ifndef V8_COMPILATION_INFO_H_
|
|
|
|
#define V8_COMPILATION_INFO_H_
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
|
|
|
// CompilationInfo encapsulates some information known at compile time. It
|
|
|
|
// is constructed based on the resources available at compile-time.
|
2017-11-15 14:36:57 +00:00
|
|
|
// TODO(rmcilroy): Split CompilationInfo into two classes, one for unoptimized
|
|
|
|
// compilation and one for optimized compilation, since they don't share much.
|
2017-01-30 19:27:00 +00:00
|
|
|
class V8_EXPORT_PRIVATE CompilationInfo 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 {
|
2017-08-17 12:40:24 +00:00
|
|
|
kIsEval = 1 << 0,
|
|
|
|
kIsNative = 1 << 1,
|
2017-11-09 10:04:29 +00:00
|
|
|
kCollectTypeProfile = 1 << 2,
|
|
|
|
kAccessorInliningEnabled = 1 << 3,
|
|
|
|
kFunctionContextSpecializing = 1 << 4,
|
|
|
|
kInliningEnabled = 1 << 5,
|
2018-02-13 14:31:46 +00:00
|
|
|
kPoisonLoads = 1 << 6,
|
|
|
|
kDisableFutureOptimization = 1 << 7,
|
|
|
|
kSplittingEnabled = 1 << 8,
|
|
|
|
kSourcePositionsEnabled = 1 << 9,
|
|
|
|
kBailoutOnUninitialized = 1 << 10,
|
|
|
|
kLoopPeelingEnabled = 1 << 11,
|
|
|
|
kUntrustedCodeMitigations = 1 << 12,
|
|
|
|
kSwitchJumpTableEnabled = 1 << 13,
|
2018-02-26 09:19:41 +00:00
|
|
|
kGenerateSpeculationPoisonOnEntry = 1 << 14,
|
|
|
|
kPoisonRegisterArguments = 1 << 15,
|
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
|
|
|
|
// that point, the Handle<Code> member of CompilationInfo would also be
|
|
|
|
// removed.
|
|
|
|
struct WasmCodeDesc {
|
|
|
|
CodeDesc code_desc;
|
|
|
|
size_t safepoint_table_offset = 0;
|
|
|
|
uint32_t frame_slot_count = 0;
|
|
|
|
Handle<ByteArray> source_positions_table;
|
|
|
|
MaybeHandle<HandlerTable> handler_table;
|
|
|
|
};
|
|
|
|
|
2017-08-04 09:22:01 +00:00
|
|
|
// Construct a compilation info for unoptimized compilation.
|
2017-11-15 14:36:57 +00:00
|
|
|
CompilationInfo(Zone* zone, ParseInfo* parse_info, FunctionLiteral* literal);
|
2017-08-04 09:22:01 +00:00
|
|
|
// Construct a compilation info for optimized compilation.
|
2017-09-28 17:33:07 +00:00
|
|
|
CompilationInfo(Zone* zone, Isolate* isolate,
|
2017-07-21 09:32:32 +00:00
|
|
|
Handle<SharedFunctionInfo> shared,
|
2017-02-10 09:55:22 +00:00
|
|
|
Handle<JSFunction> closure);
|
2017-08-04 09:22:01 +00:00
|
|
|
// Construct a compilation info for stub compilation (or testing).
|
2017-11-15 14:36:57 +00:00
|
|
|
CompilationInfo(Vector<const char> debug_name, Zone* zone,
|
2017-09-29 14:59:24 +00:00
|
|
|
Code::Kind code_kind);
|
2016-08-31 08:49:14 +00:00
|
|
|
~CompilationInfo();
|
|
|
|
|
2017-08-03 11:00:57 +00:00
|
|
|
FunctionLiteral* literal() const { return literal_; }
|
|
|
|
void set_literal(FunctionLiteral* literal) {
|
|
|
|
DCHECK_NOT_NULL(literal);
|
|
|
|
literal_ = literal;
|
|
|
|
}
|
|
|
|
|
2017-08-11 11:29:46 +00:00
|
|
|
bool has_source_range_map() const { return source_range_map_ != nullptr; }
|
2017-08-03 11:00:57 +00:00
|
|
|
SourceRangeMap* source_range_map() const { return source_range_map_; }
|
|
|
|
void set_source_range_map(SourceRangeMap* source_range_map) {
|
|
|
|
source_range_map_ = source_range_map;
|
|
|
|
}
|
2016-08-31 08:49:14 +00:00
|
|
|
|
|
|
|
DeclarationScope* scope() const;
|
|
|
|
|
|
|
|
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_; }
|
|
|
|
void set_shared_info(Handle<SharedFunctionInfo> shared_info) {
|
|
|
|
shared_info_ = 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_; }
|
|
|
|
int num_parameters() const;
|
|
|
|
int num_parameters_including_this() const;
|
|
|
|
|
|
|
|
bool has_bytecode_array() const { return !bytecode_array_.is_null(); }
|
|
|
|
Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; }
|
|
|
|
|
2017-07-25 09:46:22 +00:00
|
|
|
bool has_asm_wasm_data() const { return !asm_wasm_data_.is_null(); }
|
|
|
|
Handle<FixedArray> asm_wasm_data() const { return asm_wasm_data_; }
|
|
|
|
|
2017-08-03 11:04:47 +00:00
|
|
|
// Flags used by unoptimized compilation.
|
2016-08-31 08:49:14 +00:00
|
|
|
|
2017-08-03 11:04:47 +00:00
|
|
|
void MarkAsEval() { SetFlag(kIsEval); }
|
|
|
|
bool is_eval() const { return GetFlag(kIsEval); }
|
2016-08-31 08:49:14 +00:00
|
|
|
|
2017-08-03 11:04:47 +00:00
|
|
|
void MarkAsNative() { SetFlag(kIsNative); }
|
|
|
|
bool is_native() const { return GetFlag(kIsNative); }
|
2016-08-31 08:49:14 +00:00
|
|
|
|
2017-10-19 15:12:42 +00:00
|
|
|
void MarkAsCollectTypeProfile() { SetFlag(kCollectTypeProfile); }
|
|
|
|
bool collect_type_profile() const { return GetFlag(kCollectTypeProfile); }
|
|
|
|
|
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-02-13 14:31:46 +00:00
|
|
|
void MarkAsPoisonLoads() { SetFlag(kPoisonLoads); }
|
|
|
|
bool is_poison_loads() const { return GetFlag(kPoisonLoads); }
|
|
|
|
|
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-02-26 09:19:41 +00:00
|
|
|
bool is_generating_speculation_poison_on_entry() const {
|
|
|
|
bool enabled = GetFlag(kGenerateSpeculationPoisonOnEntry);
|
|
|
|
DCHECK_IMPLIES(enabled, has_untrusted_code_mitigations());
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarkAsPoisoningRegisterArguments() {
|
|
|
|
DCHECK(has_untrusted_code_mitigations());
|
|
|
|
SetFlag(kGenerateSpeculationPoisonOnEntry);
|
|
|
|
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());
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
void SetBytecodeArray(Handle<BytecodeArray> bytecode_array) {
|
|
|
|
bytecode_array_ = bytecode_array;
|
|
|
|
}
|
|
|
|
|
2017-07-25 09:46:22 +00:00
|
|
|
void SetAsmWasmData(Handle<FixedArray> asm_wasm_data) {
|
|
|
|
asm_wasm_data_ = asm_wasm_data;
|
2016-08-31 08:49:14 +00:00
|
|
|
}
|
|
|
|
|
2017-10-19 15:12:42 +00:00
|
|
|
FeedbackVectorSpec* feedback_vector_spec() { return &feedback_vector_spec_; }
|
|
|
|
|
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 &&
|
|
|
|
abstract_code_kind() != AbstractCode::WASM_FUNCTION &&
|
|
|
|
abstract_code_kind() != AbstractCode::INTERPRETED_FUNCTION;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
bool has_simple_parameters();
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
int GetDeclareGlobalsFlags() const;
|
|
|
|
|
|
|
|
SourcePositionTableBuilder::RecordingMode SourcePositionRecordingMode() const;
|
|
|
|
|
2017-06-06 15:44:55 +00:00
|
|
|
bool has_coverage_info() const { return !coverage_info_.is_null(); }
|
|
|
|
Handle<CoverageInfo> coverage_info() const { return coverage_info_; }
|
|
|
|
void set_coverage_info(Handle<CoverageInfo> coverage_info) {
|
|
|
|
coverage_info_ = coverage_info;
|
|
|
|
}
|
|
|
|
|
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-02-13 15:40:56 +00:00
|
|
|
CompilationInfo(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; }
|
|
|
|
|
|
|
|
void SetFlag(Flag flag, bool value) {
|
|
|
|
flags_ = value ? flags_ | flag : flags_ & ~flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetFlag(Flag flag) const { return (flags_ & flag) != 0; }
|
|
|
|
|
2017-08-03 11:00:57 +00:00
|
|
|
FunctionLiteral* literal_;
|
|
|
|
SourceRangeMap* source_range_map_; // Used when block coverage is enabled.
|
2016-10-07 09:12:48 +00:00
|
|
|
|
2016-08-31 08:49:14 +00:00
|
|
|
unsigned flags_;
|
|
|
|
|
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
|
|
|
|
|
|
|
// Holds the bytecode array generated by the interpreter.
|
|
|
|
// TODO(rmcilroy/mstarzinger): Temporary work-around until compiler.cc is
|
|
|
|
// refactored to avoid us needing to carry the BytcodeArray around.
|
|
|
|
Handle<BytecodeArray> bytecode_array_;
|
|
|
|
|
2017-07-25 09:46:22 +00:00
|
|
|
// Holds the asm_wasm array generated by the asmjs compiler.
|
|
|
|
Handle<FixedArray> asm_wasm_data_;
|
|
|
|
|
2017-10-19 15:12:42 +00:00
|
|
|
// Holds the feedback vector spec generated during compilation
|
|
|
|
FeedbackVectorSpec feedback_vector_spec_;
|
|
|
|
|
2016-08-31 08:49:14 +00:00
|
|
|
// The zone from which the compilation pipeline working on this
|
|
|
|
// CompilationInfo allocates.
|
|
|
|
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_;
|
|
|
|
|
2017-06-06 15:44:55 +00:00
|
|
|
// Encapsulates coverage information gathered by the bytecode generator.
|
|
|
|
// Needs to be stored on the shared function info once compilation completes.
|
|
|
|
Handle<CoverageInfo> coverage_info_;
|
|
|
|
|
2016-08-31 08:49:14 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(CompilationInfo);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
#endif // V8_COMPILATION_INFO_H_
|