Commit cc1458a9 authored by loislo's avatar loislo Committed by Commit bot

CpuProfile: rename HSourcePosition to SourcePosition and move it to compiler.*

Fix CompilationInfo::TraceInlinedFunction argument.
Fix leaked CodeTracer in Isolate

BUG=452067
LOG=n

Review URL: https://codereview.chromium.org/928343003

Cr-Commit-Position: refs/heads/master@{#26689}
parent 74876fd6
......@@ -35,6 +35,17 @@ namespace v8 {
namespace internal {
std::ostream& operator<<(std::ostream& os, const SourcePosition& p) {
if (p.IsUnknown()) {
return os << "<?>";
} else if (FLAG_hydrogen_track_positions) {
return os << "<" << p.inlining_id() << ":" << p.position() << ">";
} else {
return os << "<0:" << p.raw() << ">";
}
}
ScriptData::ScriptData(const byte* data, int length)
: owns_data_(false), rejected_(false), data_(data), length_(length) {
if (!IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment)) {
......@@ -324,7 +335,7 @@ bool CompilationInfo::is_simple_parameter_list() {
int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared,
int raw_position) {
SourcePosition position) {
if (!FLAG_hydrogen_track_positions) {
return 0;
}
......@@ -369,7 +380,6 @@ int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared,
if (inline_id != 0) {
CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
OFStream os(tracing_scope.file());
HSourcePosition position = HSourcePosition::FromRaw(raw_position);
os << "INLINE (" << shared->DebugName()->ToCString().get() << ") id{"
<< optimization_id() << "," << id << "} AS " << inline_id << " AT "
<< position << std::endl;
......
......@@ -30,6 +30,62 @@ struct OffsetRange {
};
// This class encapsulates encoding and decoding of sources positions from
// which hydrogen values originated.
// When FLAG_track_hydrogen_positions is set this object encodes the
// identifier of the inlining and absolute offset from the start of the
// inlined function.
// When the flag is not set we simply track absolute offset from the
// script start.
class SourcePosition {
public:
SourcePosition(const SourcePosition& other) : value_(other.value_) {}
static SourcePosition Unknown() {
return SourcePosition(RelocInfo::kNoPosition);
}
bool IsUnknown() const { return value_ == RelocInfo::kNoPosition; }
int position() const { return PositionField::decode(value_); }
void set_position(int position) {
if (FLAG_hydrogen_track_positions) {
value_ = static_cast<int>(PositionField::update(value_, position));
} else {
value_ = position;
}
}
int inlining_id() const { return InliningIdField::decode(value_); }
void set_inlining_id(int inlining_id) {
if (FLAG_hydrogen_track_positions) {
value_ = static_cast<int>(InliningIdField::update(value_, inlining_id));
}
}
int raw() const { return value_; }
private:
typedef BitField<int, 0, 9> InliningIdField;
// Offset from the start of the inlined function.
typedef BitField<int, 9, 23> PositionField;
explicit SourcePosition(int value) : value_(value) {}
friend class HPositionInfo;
friend class LCodeGenBase;
// If FLAG_hydrogen_track_positions is set contains bitfields InliningIdField
// and PositionField.
// Otherwise contains absolute offset from the script start.
int value_;
};
std::ostream& operator<<(std::ostream& os, const SourcePosition& p);
class InlinedFunctionInfo {
public:
explicit InlinedFunctionInfo(Handle<SharedFunctionInfo> shared)
......@@ -403,7 +459,8 @@ class CompilationInfo {
List<int>* inlining_id_to_function_id() {
return inlining_id_to_function_id_;
}
int TraceInlinedFunction(Handle<SharedFunctionInfo> shared, int raw_position);
int TraceInlinedFunction(Handle<SharedFunctionInfo> shared,
SourcePosition position);
Handle<Foreign> object_wrapper() {
if (object_wrapper_.is_null()) {
......
......@@ -622,17 +622,6 @@ void HValue::ComputeInitialRange(Zone* zone) {
}
std::ostream& operator<<(std::ostream& os, const HSourcePosition& p) {
if (p.IsUnknown()) {
return os << "<?>";
} else if (FLAG_hydrogen_track_positions) {
return os << "<" << p.inlining_id() << ":" << p.position() << ">";
} else {
return os << "<0:" << p.raw() << ">";
}
}
std::ostream& HInstruction::PrintTo(std::ostream& os) const { // NOLINT
os << Mnemonic() << " ";
PrintDataTo(os) << ChangesOf(this) << TypeOf(this);
......@@ -1816,9 +1805,7 @@ Range* HConstant::InferRange(Zone* zone) {
}
HSourcePosition HPhi::position() const {
return block()->first()->position();
}
SourcePosition HPhi::position() const { return block()->first()->position(); }
Range* HPhi::InferRange(Zone* zone) {
......
......@@ -412,65 +412,6 @@ class DecompositionResult FINAL BASE_EMBEDDED {
typedef EnumSet<GVNFlag, int32_t> GVNFlagSet;
// This class encapsulates encoding and decoding of sources positions from
// which hydrogen values originated.
// When FLAG_track_hydrogen_positions is set this object encodes the
// identifier of the inlining and absolute offset from the start of the
// inlined function.
// When the flag is not set we simply track absolute offset from the
// script start.
class HSourcePosition {
public:
HSourcePosition(const HSourcePosition& other) : value_(other.value_) { }
static HSourcePosition Unknown() {
return HSourcePosition(RelocInfo::kNoPosition);
}
static HSourcePosition FromRaw(int raw_value) {
return HSourcePosition(raw_value);
}
bool IsUnknown() const { return value_ == RelocInfo::kNoPosition; }
int position() const { return PositionField::decode(value_); }
void set_position(int position) {
if (FLAG_hydrogen_track_positions) {
value_ = static_cast<int>(PositionField::update(value_, position));
} else {
value_ = position;
}
}
int inlining_id() const { return InliningIdField::decode(value_); }
void set_inlining_id(int inlining_id) {
if (FLAG_hydrogen_track_positions) {
value_ = static_cast<int>(InliningIdField::update(value_, inlining_id));
}
}
int raw() const { return value_; }
private:
typedef BitField<int, 0, 9> InliningIdField;
// Offset from the start of the inlined function.
typedef BitField<int, 9, 23> PositionField;
explicit HSourcePosition(int value) : value_(value) { }
friend class HPositionInfo;
friend class LCodeGenBase;
// If FLAG_hydrogen_track_positions is set contains bitfields InliningIdField
// and PositionField.
// Otherwise contains absolute offset from the script start.
int value_;
};
std::ostream& operator<<(std::ostream& os, const HSourcePosition& p);
class HValue : public ZoneObject {
public:
static const int kNoNumber = -1;
......@@ -566,10 +507,8 @@ class HValue : public ZoneObject {
flags_(0) {}
virtual ~HValue() {}
virtual HSourcePosition position() const {
return HSourcePosition::Unknown();
}
virtual HSourcePosition operand_position(int index) const {
virtual SourcePosition position() const { return SourcePosition::Unknown(); }
virtual SourcePosition operand_position(int index) const {
return position();
}
......@@ -1039,14 +978,14 @@ class HPositionInfo {
public:
explicit HPositionInfo(int pos) : data_(TagPosition(pos)) { }
HSourcePosition position() const {
SourcePosition position() const {
if (has_operand_positions()) {
return operand_positions()[kInstructionPosIndex];
}
return HSourcePosition(static_cast<int>(UntagPosition(data_)));
return SourcePosition(static_cast<int>(UntagPosition(data_)));
}
void set_position(HSourcePosition pos) {
void set_position(SourcePosition pos) {
if (has_operand_positions()) {
operand_positions()[kInstructionPosIndex] = pos;
} else {
......@@ -1060,27 +999,26 @@ class HPositionInfo {
}
const int length = kFirstOperandPosIndex + operand_count;
HSourcePosition* positions =
zone->NewArray<HSourcePosition>(length);
SourcePosition* positions = zone->NewArray<SourcePosition>(length);
for (int i = 0; i < length; i++) {
positions[i] = HSourcePosition::Unknown();
positions[i] = SourcePosition::Unknown();
}
const HSourcePosition pos = position();
const SourcePosition pos = position();
data_ = reinterpret_cast<intptr_t>(positions);
set_position(pos);
DCHECK(has_operand_positions());
}
HSourcePosition operand_position(int idx) const {
SourcePosition operand_position(int idx) const {
if (!has_operand_positions()) {
return position();
}
return *operand_position_slot(idx);
}
void set_operand_position(int idx, HSourcePosition pos) {
void set_operand_position(int idx, SourcePosition pos) {
*operand_position_slot(idx) = pos;
}
......@@ -1088,7 +1026,7 @@ class HPositionInfo {
static const intptr_t kInstructionPosIndex = 0;
static const intptr_t kFirstOperandPosIndex = 1;
HSourcePosition* operand_position_slot(int idx) const {
SourcePosition* operand_position_slot(int idx) const {
DCHECK(has_operand_positions());
return &(operand_positions()[kFirstOperandPosIndex + idx]);
}
......@@ -1097,9 +1035,9 @@ class HPositionInfo {
return !IsTaggedPosition(data_);
}
HSourcePosition* operand_positions() const {
SourcePosition* operand_positions() const {
DCHECK(has_operand_positions());
return reinterpret_cast<HSourcePosition*>(data_);
return reinterpret_cast<SourcePosition*>(data_);
}
static const intptr_t kPositionTag = 1;
......@@ -1147,23 +1085,23 @@ class HInstruction : public HValue {
}
// The position is a write-once variable.
HSourcePosition position() const OVERRIDE {
return HSourcePosition(position_.position());
SourcePosition position() const OVERRIDE {
return SourcePosition(position_.position());
}
bool has_position() const {
return !position().IsUnknown();
}
void set_position(HSourcePosition position) {
void set_position(SourcePosition position) {
DCHECK(!has_position());
DCHECK(!position.IsUnknown());
position_.set_position(position);
}
HSourcePosition operand_position(int index) const OVERRIDE {
const HSourcePosition pos = position_.operand_position(index);
SourcePosition operand_position(int index) const OVERRIDE {
const SourcePosition pos = position_.operand_position(index);
return pos.IsUnknown() ? position() : pos;
}
void set_operand_position(Zone* zone, int index, HSourcePosition pos) {
void set_operand_position(Zone* zone, int index, SourcePosition pos) {
DCHECK(0 <= index && index < OperandCount());
position_.ensure_storage_for_operand_positions(zone, OperandCount());
position_.set_operand_position(index, pos);
......@@ -3300,7 +3238,7 @@ class HPhi FINAL : public HValue {
bool IsReceiver() const { return merged_index_ == 0; }
bool HasMergedIndex() const { return merged_index_ != kInvalidMergedIndex; }
HSourcePosition position() const OVERRIDE;
SourcePosition position() const OVERRIDE;
int merged_index() const { return merged_index_; }
......@@ -3869,9 +3807,8 @@ class HBinaryOperation : public HTemplateInstruction<3> {
return representation();
}
void SetOperandPositions(Zone* zone,
HSourcePosition left_pos,
HSourcePosition right_pos) {
void SetOperandPositions(Zone* zone, SourcePosition left_pos,
SourcePosition right_pos) {
set_operand_position(zone, 1, left_pos);
set_operand_position(zone, 2, right_pos);
}
......@@ -4329,9 +4266,8 @@ class HCompareNumericAndBranch : public HTemplateControlInstruction<2, 2> {
std::ostream& PrintDataTo(std::ostream& os) const OVERRIDE; // NOLINT
void SetOperandPositions(Zone* zone,
HSourcePosition left_pos,
HSourcePosition right_pos) {
void SetOperandPositions(Zone* zone, SourcePosition left_pos,
SourcePosition right_pos) {
set_operand_position(zone, 0, left_pos);
set_operand_position(zone, 1, right_pos);
}
......
......@@ -129,8 +129,7 @@ void HBasicBlock::RemovePhi(HPhi* phi) {
}
void HBasicBlock::AddInstruction(HInstruction* instr,
HSourcePosition position) {
void HBasicBlock::AddInstruction(HInstruction* instr, SourcePosition position) {
DCHECK(!IsStartBlock() || !IsFinished());
DCHECK(!instr->IsLinked());
DCHECK(!IsFinished());
......@@ -199,7 +198,7 @@ HSimulate* HBasicBlock::CreateSimulate(BailoutId ast_id,
}
void HBasicBlock::Finish(HControlInstruction* end, HSourcePosition position) {
void HBasicBlock::Finish(HControlInstruction* end, SourcePosition position) {
DCHECK(!IsFinished());
AddInstruction(end, position);
end_ = end;
......@@ -209,10 +208,8 @@ void HBasicBlock::Finish(HControlInstruction* end, HSourcePosition position) {
}
void HBasicBlock::Goto(HBasicBlock* block,
HSourcePosition position,
FunctionState* state,
bool add_simulate) {
void HBasicBlock::Goto(HBasicBlock* block, SourcePosition position,
FunctionState* state, bool add_simulate) {
bool drop_extra = state != NULL &&
state->inlining_kind() == NORMAL_RETURN;
......@@ -231,9 +228,8 @@ void HBasicBlock::Goto(HBasicBlock* block,
}
void HBasicBlock::AddLeaveInlined(HValue* return_value,
FunctionState* state,
HSourcePosition position) {
void HBasicBlock::AddLeaveInlined(HValue* return_value, FunctionState* state,
SourcePosition position) {
HBasicBlock* target = state->function_return();
bool drop_extra = state->inlining_kind() == NORMAL_RETURN;
......@@ -1029,7 +1025,7 @@ void HGraphBuilder::IfBuilder::End() {
if (current->deopt_ && current->block_ != NULL) {
current->block_->FinishExit(
HAbnormalExit::New(builder()->isolate(), builder()->zone(), NULL),
HSourcePosition::Unknown());
SourcePosition::Unknown());
}
current = current->next_;
}
......@@ -3422,7 +3418,7 @@ HBasicBlock* HOptimizedGraphBuilder::BuildLoopEntry(
void HBasicBlock::FinishExit(HControlInstruction* instruction,
HSourcePosition position) {
SourcePosition position) {
Finish(instruction, position);
ClearEnvironment();
}
......@@ -3457,8 +3453,7 @@ HGraph::HGraph(CompilationInfo* info)
start_environment_ = new (zone_)
HEnvironment(zone_, descriptor.GetEnvironmentParameterCount());
} else {
info->TraceInlinedFunction(info->shared_info(),
HSourcePosition::Unknown().raw());
info->TraceInlinedFunction(info->shared_info(), SourcePosition::Unknown());
start_environment_ =
new(zone_) HEnvironment(NULL, info->scope(), info->closure(), zone_);
}
......@@ -3486,7 +3481,7 @@ void HGraph::FinalizeUniqueness() {
}
int HGraph::SourcePositionToScriptPosition(HSourcePosition pos) {
int HGraph::SourcePositionToScriptPosition(SourcePosition pos) {
if (!FLAG_hydrogen_track_positions || pos.IsUnknown()) {
return pos.raw();
}
......@@ -3880,8 +3875,7 @@ void HGraph::CollectPhis() {
// Implementation of utility class to encapsulate the translation state for
// a (possibly inlined) function.
FunctionState::FunctionState(HOptimizedGraphBuilder* owner,
CompilationInfo* info,
InliningKind inlining_kind,
CompilationInfo* info, InliningKind inlining_kind,
int inlining_id)
: owner_(owner),
compilation_info_(info),
......@@ -3893,7 +3887,7 @@ FunctionState::FunctionState(HOptimizedGraphBuilder* owner,
arguments_object_(NULL),
arguments_elements_(NULL),
inlining_id_(inlining_id),
outer_source_position_(HSourcePosition::Unknown()),
outer_source_position_(SourcePosition::Unknown()),
outer_(owner->function_state()) {
if (outer_ != NULL) {
// State for an inline function.
......@@ -7816,10 +7810,9 @@ int HOptimizedGraphBuilder::InliningAstSize(Handle<JSFunction> target) {
bool HOptimizedGraphBuilder::TryInline(Handle<JSFunction> target,
int arguments_count,
HValue* implicit_return_value,
BailoutId ast_id,
BailoutId return_id,
BailoutId ast_id, BailoutId return_id,
InliningKind inlining_kind,
HSourcePosition position) {
SourcePosition position) {
int nodes_added = InliningAstSize(target);
if (nodes_added == kNotInlinable) return false;
......@@ -7931,8 +7924,7 @@ bool HOptimizedGraphBuilder::TryInline(Handle<JSFunction> target,
DCHECK(target_shared->has_deoptimization_support());
AstTyper::Run(&target_info);
int function_id =
top_info()->TraceInlinedFunction(target_shared, position.raw());
int function_id = top_info()->TraceInlinedFunction(target_shared, position);
// Save the pending call context. Set up new one for the inlined function.
// The function state is new-allocated because we need to delete it
......@@ -10939,15 +10931,9 @@ void HOptimizedGraphBuilder::VisitCompareOperation(CompareOperation* expr) {
HControlInstruction* HOptimizedGraphBuilder::BuildCompareInstruction(
Token::Value op,
HValue* left,
HValue* right,
Type* left_type,
Type* right_type,
Type* combined_type,
HSourcePosition left_position,
HSourcePosition right_position,
PushBeforeSimulateBehavior push_sim_result,
Token::Value op, HValue* left, HValue* right, Type* left_type,
Type* right_type, Type* combined_type, SourcePosition left_position,
SourcePosition right_position, PushBeforeSimulateBehavior push_sim_result,
BailoutId bailout_id) {
// Cases handled below depend on collected type feedback. They should
// soft deoptimize when there is no type feedback.
......@@ -13256,7 +13242,7 @@ void HTracer::Trace(const char* name, HGraph* graph, LChunk* chunk) {
if (FLAG_hydrogen_track_positions &&
instruction->has_position() &&
instruction->position().raw() != 0) {
const HSourcePosition pos = instruction->position();
const SourcePosition pos = instruction->position();
os << " pos:";
if (pos.inlining_id() != 0) os << pos.inlining_id() << "_";
os << pos.position();
......
......@@ -88,7 +88,7 @@ class HBasicBlock FINAL : public ZoneObject {
bool IsFinished() const { return end_ != NULL; }
void AddPhi(HPhi* phi);
void RemovePhi(HPhi* phi);
void AddInstruction(HInstruction* instr, HSourcePosition position);
void AddInstruction(HInstruction* instr, SourcePosition position);
bool Dominates(HBasicBlock* other) const;
bool EqualToOrDominates(HBasicBlock* other) const;
int LoopNestingDepth() const;
......@@ -114,8 +114,7 @@ class HBasicBlock FINAL : public ZoneObject {
int PredecessorIndexOf(HBasicBlock* predecessor) const;
HPhi* AddNewPhi(int merged_index);
HSimulate* AddNewSimulate(BailoutId ast_id,
HSourcePosition position,
HSimulate* AddNewSimulate(BailoutId ast_id, SourcePosition position,
RemovableSimulate removable = FIXED_SIMULATE) {
HSimulate* instr = CreateSimulate(ast_id, removable);
AddInstruction(instr, position);
......@@ -167,21 +166,18 @@ class HBasicBlock FINAL : public ZoneObject {
friend class HGraphBuilder;
HSimulate* CreateSimulate(BailoutId ast_id, RemovableSimulate removable);
void Finish(HControlInstruction* last, HSourcePosition position);
void FinishExit(HControlInstruction* instruction, HSourcePosition position);
void Goto(HBasicBlock* block,
HSourcePosition position,
FunctionState* state = NULL,
bool add_simulate = true);
void GotoNoSimulate(HBasicBlock* block, HSourcePosition position) {
void Finish(HControlInstruction* last, SourcePosition position);
void FinishExit(HControlInstruction* instruction, SourcePosition position);
void Goto(HBasicBlock* block, SourcePosition position,
FunctionState* state = NULL, bool add_simulate = true);
void GotoNoSimulate(HBasicBlock* block, SourcePosition position) {
Goto(block, position, NULL, false);
}
// Add the inlined function exit sequence, adding an HLeaveInlined
// instruction and updating the bailout environment.
void AddLeaveInlined(HValue* return_value,
FunctionState* state,
HSourcePosition position);
void AddLeaveInlined(HValue* return_value, FunctionState* state,
SourcePosition position);
private:
void RegisterPredecessor(HBasicBlock* pred);
......@@ -461,11 +457,11 @@ class HGraph FINAL : public ZoneObject {
// identifier to each inlining and dumps function source if it was inlined
// for the first time during the current optimization.
int TraceInlinedFunction(Handle<SharedFunctionInfo> shared,
HSourcePosition position);
SourcePosition position);
// Converts given HSourcePosition to the absolute offset from the start of
// Converts given SourcePosition to the absolute offset from the start of
// the corresponding script.
int SourcePositionToScriptPosition(HSourcePosition position);
int SourcePositionToScriptPosition(SourcePosition position);
private:
HConstant* ReinsertConstantIfNecessary(HConstant* constant);
......@@ -941,7 +937,7 @@ class FunctionState FINAL {
HArgumentsElements* arguments_elements_;
int inlining_id_;
HSourcePosition outer_source_position_;
SourcePosition outer_source_position_;
FunctionState* outer_;
};
......@@ -1029,7 +1025,7 @@ class HGraphBuilder {
graph_(NULL),
current_block_(NULL),
scope_(info->scope()),
position_(HSourcePosition::Unknown()),
position_(SourcePosition::Unknown()),
start_position_(0) {}
virtual ~HGraphBuilder() {}
......@@ -1885,18 +1881,16 @@ class HGraphBuilder {
}
// Convert the given absolute offset from the start of the script to
// the HSourcePosition assuming that this position corresponds to the
// the SourcePosition assuming that this position corresponds to the
// same function as current position_.
HSourcePosition ScriptPositionToSourcePosition(int position) {
HSourcePosition pos = position_;
SourcePosition ScriptPositionToSourcePosition(int position) {
SourcePosition pos = position_;
pos.set_position(position - start_position_);
return pos;
}
HSourcePosition source_position() { return position_; }
void set_source_position(HSourcePosition position) {
position_ = position;
}
SourcePosition source_position() { return position_; }
void set_source_position(SourcePosition position) { position_ = position; }
template <typename ViewClass>
void BuildArrayBufferViewInitialization(HValue* obj,
......@@ -1916,7 +1910,7 @@ class HGraphBuilder {
HGraph* graph_;
HBasicBlock* current_block_;
Scope* scope_;
HSourcePosition position_;
SourcePosition position_;
int start_position_;
};
......@@ -2325,13 +2319,10 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor {
Handle<JSFunction> target);
int InliningAstSize(Handle<JSFunction> target);
bool TryInline(Handle<JSFunction> target,
int arguments_count,
HValue* implicit_return_value,
BailoutId ast_id,
BailoutId return_id,
InliningKind inlining_kind,
HSourcePosition position);
bool TryInline(Handle<JSFunction> target, int arguments_count,
HValue* implicit_return_value, BailoutId ast_id,
BailoutId return_id, InliningKind inlining_kind,
SourcePosition position);
bool TryInlineCall(Call* expr);
bool TryInlineConstruct(CallNew* expr, HValue* implicit_return_value);
......@@ -2597,15 +2588,9 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor {
};
HControlInstruction* BuildCompareInstruction(
Token::Value op,
HValue* left,
HValue* right,
Type* left_type,
Type* right_type,
Type* combined_type,
HSourcePosition left_position,
HSourcePosition right_position,
PushBeforeSimulateBehavior push_sim_result,
Token::Value op, HValue* left, HValue* right, Type* left_type,
Type* right_type, Type* combined_type, SourcePosition left_position,
SourcePosition right_position, PushBeforeSimulateBehavior push_sim_result,
BailoutId bailout_id);
HInstruction* BuildStringCharCodeAt(HValue* string,
......
......@@ -1906,6 +1906,9 @@ Isolate::~Isolate() {
delete handle_scope_implementer_;
handle_scope_implementer_ = NULL;
delete code_tracer();
set_code_tracer(NULL);
delete compilation_cache_;
compilation_cache_ = NULL;
delete bootstrapper_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment