Commit 3494a3dc authored by yangguo's avatar yangguo Committed by Commit bot

[deoptimizer] use correct code/bytecode to compute source position.

With --ignition-preserve-bytecode, we don't have the guarantee that
SharedFunctionInfo::abstract_code() returns the code we deopt to.

R=mstarzinger@chromium.org
BUG=v8:5265

Review-Url: https://codereview.chromium.org/2239773003
Cr-Commit-Position: refs/heads/master@{#38614}
parent 1617043c
......@@ -2683,8 +2683,14 @@ DeoptimizedFrameInfo::DeoptimizedFrameInfo(TranslatedState* state,
parameter_frame != state->begin() &&
(parameter_frame - 1)->kind() == TranslatedFrame::kConstructStub;
source_position_ = Deoptimizer::ComputeSourcePosition(
if (frame_it->kind() == TranslatedFrame::kInterpretedFunction) {
source_position_ = Deoptimizer::ComputeSourcePositionFromBytecodeArray(
*frame_it->shared_info(), frame_it->node_id());
} else {
DCHECK_EQ(TranslatedFrame::kFunction, frame_it->kind());
source_position_ = Deoptimizer::ComputeSourcePositionFromBaselineCode(
*frame_it->shared_info(), frame_it->node_id());
}
TranslatedFrame::iterator value_it = frame_it->begin();
// Get the function. Note that this might materialize the function.
......@@ -2762,22 +2768,27 @@ Deoptimizer::DeoptInfo Deoptimizer::GetDeoptInfo(Code* code, Address pc) {
// static
int Deoptimizer::ComputeSourcePosition(SharedFunctionInfo* shared,
BailoutId node_id) {
AbstractCode* abstract_code = shared->abstract_code();
int code_offset;
if (abstract_code->IsBytecodeArray()) {
// BailoutId points to the next bytecode in the bytecode aray. Subtract
// 1 to get the end of current bytecode.
code_offset = node_id.ToInt() - 1;
} else {
FixedArray* raw_data = abstract_code->GetCode()->deoptimization_data();
int Deoptimizer::ComputeSourcePositionFromBaselineCode(
SharedFunctionInfo* shared, BailoutId node_id) {
DCHECK(shared->HasBaselineCode());
Code* code = shared->code();
FixedArray* raw_data = code->deoptimization_data();
DeoptimizationOutputData* data = DeoptimizationOutputData::cast(raw_data);
unsigned pc_and_state = Deoptimizer::GetOutputInfo(data, node_id, shared);
code_offset =
int code_offset =
static_cast<int>(FullCodeGenerator::PcField::decode(pc_and_state));
}
return abstract_code->SourcePosition(code_offset);
return AbstractCode::cast(code)->SourcePosition(code_offset);
}
// static
int Deoptimizer::ComputeSourcePositionFromBytecodeArray(
SharedFunctionInfo* shared, BailoutId node_id) {
DCHECK(shared->HasBytecodeArray());
// BailoutId points to the next bytecode in the bytecode aray. Subtract
// 1 to get the end of current bytecode.
int code_offset = node_id.ToInt() - 1;
return AbstractCode::cast(shared->bytecode_array())
->SourcePosition(code_offset);
}
// static
......
......@@ -357,7 +357,9 @@ class Deoptimizer : public Malloced {
static DeoptInfo GetDeoptInfo(Code* code, byte* from);
static int ComputeSourcePosition(SharedFunctionInfo* shared,
static int ComputeSourcePositionFromBaselineCode(SharedFunctionInfo* shared,
BailoutId node_id);
static int ComputeSourcePositionFromBytecodeArray(SharedFunctionInfo* shared,
BailoutId node_id);
struct JumpTableEntry : public ZoneObject {
......
......@@ -283,7 +283,15 @@ void ProfilerListener::RecordDeoptInlinedFrames(CodeEntry* entry,
it.Next(); // Skip height
SharedFunctionInfo* shared = SharedFunctionInfo::cast(
deopt_input_data->LiteralArray()->get(shared_info_id));
int source_position = Deoptimizer::ComputeSourcePosition(shared, ast_id);
int source_position;
if (opcode == Translation::INTERPRETED_FRAME) {
source_position =
Deoptimizer::ComputeSourcePositionFromBytecodeArray(shared, ast_id);
} else {
DCHECK(opcode == Translation::JS_FRAME);
source_position =
Deoptimizer::ComputeSourcePositionFromBaselineCode(shared, ast_id);
}
int script_id = v8::UnboundScript::kNoScriptId;
if (shared->script()->IsScript()) {
Script* script = Script::cast(shared->script());
......
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