Commit edc03cea authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[cleanup] Replace List with std::vector in debugger code.

Bug: v8:6333
Change-Id: I6292bc6b31c696dddd3e3361a519e7275404b144
Reviewed-on: https://chromium-review.googlesource.com/631879Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47663}
parent cff32a6d
......@@ -11,7 +11,6 @@
#include "src/factory.h"
#include "src/frames-inl.h"
#include "src/isolate-inl.h"
#include "src/list-inl.h"
#include "src/messages.h"
#include "src/property-details.h"
#include "src/prototype.h"
......@@ -822,10 +821,12 @@ static Handle<Object> ArgumentsForInlinedFunction(
static int FindFunctionInFrame(JavaScriptFrame* frame,
Handle<JSFunction> function) {
List<FrameSummary> frames(2);
std::vector<FrameSummary> frames;
frame->Summarize(&frames);
for (int i = frames.length() - 1; i >= 0; i--) {
if (*frames[i].AsJavaScript().function() == *function) return i;
for (size_t i = frames.size(); i != 0; i--) {
if (*frames[i - 1].AsJavaScript().function() == *function) {
return static_cast<int>(i) - 1;
}
}
return -1;
}
......@@ -929,16 +930,16 @@ static inline bool AllowAccessToFunction(Context* current_context,
class FrameFunctionIterator {
public:
explicit FrameFunctionIterator(Isolate* isolate)
: isolate_(isolate), frame_iterator_(isolate), frames_(2), index_(0) {
: isolate_(isolate), frame_iterator_(isolate) {
GetFrames();
}
MaybeHandle<JSFunction> next() {
while (true) {
if (frames_.length() == 0) return MaybeHandle<JSFunction>();
if (frames_.empty()) return MaybeHandle<JSFunction>();
Handle<JSFunction> next_function =
frames_[index_].AsJavaScript().function();
index_--;
if (index_ < 0) {
frames_.back().AsJavaScript().function();
frames_.pop_back();
if (frames_.empty()) {
GetFrames();
}
// Skip functions from other origins.
......@@ -960,18 +961,16 @@ class FrameFunctionIterator {
private:
void GetFrames() {
frames_.Rewind(0);
DCHECK(frames_.empty());
if (frame_iterator_.done()) return;
JavaScriptFrame* frame = frame_iterator_.frame();
frame->Summarize(&frames_);
DCHECK(frames_.length() > 0);
DCHECK(!frames_.empty());
frame_iterator_.Advance();
index_ = frames_.length() - 1;
}
Isolate* isolate_;
JavaScriptFrameIterator frame_iterator_;
List<FrameSummary> frames_;
int index_;
std::vector<FrameSummary> frames_;
};
......
......@@ -210,12 +210,13 @@ int DebugFrameHelper::FindIndexedNonNativeFrame(StackTraceFrameIterator* it,
int index) {
int count = -1;
for (; !it->done(); it->Advance()) {
List<FrameSummary> frames(FLAG_max_inlining_levels + 1);
std::vector<FrameSummary> frames;
frames.reserve(FLAG_max_inlining_levels + 1);
it->frame()->Summarize(&frames);
for (int i = frames.length() - 1; i >= 0; i--) {
for (size_t i = frames.size(); i != 0; i--) {
// Omit functions from native and extension scripts.
if (!frames[i].is_subject_to_debugging()) continue;
if (++count == index) return i;
if (!frames[i - 1].is_subject_to_debugging()) continue;
if (++count == index) return static_cast<int>(i) - 1;
}
}
return -1;
......
......@@ -27,9 +27,10 @@ DebugStackTraceIterator::DebugStackTraceIterator(Isolate* isolate, int index)
iterator_(isolate, isolate->debug()->break_frame_id()),
is_top_frame_(true) {
if (iterator_.done()) return;
List<FrameSummary> frames(FLAG_max_inlining_levels + 1);
std::vector<FrameSummary> frames;
frames.reserve(FLAG_max_inlining_levels + 1);
iterator_.frame()->Summarize(&frames);
inlined_frame_index_ = frames.length();
inlined_frame_index_ = static_cast<int>(frames.size());
Advance();
for (; !Done() && index > 0; --index) Advance();
}
......@@ -58,9 +59,10 @@ void DebugStackTraceIterator::Advance() {
frame_inspector_.reset();
iterator_.Advance();
if (iterator_.done()) break;
List<FrameSummary> frames(FLAG_max_inlining_levels + 1);
std::vector<FrameSummary> frames;
frames.reserve(FLAG_max_inlining_levels + 1);
iterator_.frame()->Summarize(&frames);
inlined_frame_index_ = frames.length();
inlined_frame_index_ = static_cast<int>(frames.size());
}
}
......
......@@ -809,20 +809,20 @@ void Debug::PrepareStepOnThrow() {
// Deoptimize frame to ensure calls are checked for step-in.
Deoptimizer::DeoptimizeFunction(frame->function());
}
List<FrameSummary> summaries;
std::vector<FrameSummary> summaries;
frame->Summarize(&summaries);
for (int i = summaries.length() - 1; i >= 0; i--, current_frame_count--) {
for (size_t i = summaries.size(); i != 0; i--, current_frame_count--) {
const FrameSummary& summary = summaries[i - 1];
if (!found_handler) {
// We have yet to find the handler. If the frame inlines multiple
// functions, we have to check each one for the handler.
// If it only contains one function, we already found the handler.
if (summaries.length() > 1) {
Handle<AbstractCode> code =
summaries[i].AsJavaScript().abstract_code();
if (summaries.size() > 1) {
Handle<AbstractCode> code = summary.AsJavaScript().abstract_code();
CHECK_EQ(AbstractCode::INTERPRETED_FUNCTION, code->kind());
BytecodeArray* bytecode = code->GetBytecodeArray();
HandlerTable* table = HandlerTable::cast(bytecode->handler_table());
int code_offset = summaries[i].code_offset();
int code_offset = summary.code_offset();
HandlerTable::CatchPrediction prediction;
int index = table->LookupRange(code_offset, nullptr, &prediction);
if (index > 0) found_handler = true;
......@@ -839,7 +839,7 @@ void Debug::PrepareStepOnThrow() {
continue;
}
Handle<SharedFunctionInfo> info(
summaries[i].AsJavaScript().function()->shared());
summary.AsJavaScript().function()->shared());
if (IsBlackboxed(info)) continue;
FloodWithOneShot(info);
return;
......
......@@ -768,7 +768,7 @@ void StandardFrame::ComputeCallerState(State* state) const {
bool StandardFrame::IsConstructor() const { return false; }
void StandardFrame::Summarize(List<FrameSummary>* functions,
void StandardFrame::Summarize(std::vector<FrameSummary>* functions,
FrameSummary::Mode mode) const {
// This should only be called on frames which override this method.
UNREACHABLE();
......@@ -993,16 +993,16 @@ void JavaScriptFrame::GetFunctions(
}
}
void JavaScriptFrame::Summarize(List<FrameSummary>* functions,
void JavaScriptFrame::Summarize(std::vector<FrameSummary>* functions,
FrameSummary::Mode mode) const {
DCHECK(functions->length() == 0);
DCHECK(functions->empty());
Code* code = LookupCode();
int offset = static_cast<int>(pc() - code->instruction_start());
AbstractCode* abstract_code = AbstractCode::cast(code);
FrameSummary::JavaScriptFrameSummary summary(isolate(), receiver(),
function(), abstract_code,
offset, IsConstructor(), mode);
functions->Add(summary);
functions->push_back(summary);
}
JSFunction* JavaScriptFrame::function() const {
......@@ -1299,10 +1299,11 @@ FrameSummary::~FrameSummary() {
}
FrameSummary FrameSummary::GetTop(const StandardFrame* frame) {
List<FrameSummary> frames(FLAG_max_inlining_levels + 1);
std::vector<FrameSummary> frames;
frames.reserve(FLAG_max_inlining_levels + 1);
frame->Summarize(&frames);
DCHECK_LT(0, frames.length());
return frames.last();
DCHECK_LT(0, frames.size());
return frames.back();
}
FrameSummary FrameSummary::GetBottom(const StandardFrame* frame) {
......@@ -1310,17 +1311,18 @@ FrameSummary FrameSummary::GetBottom(const StandardFrame* frame) {
}
FrameSummary FrameSummary::GetSingle(const StandardFrame* frame) {
List<FrameSummary> frames(1);
std::vector<FrameSummary> frames;
frame->Summarize(&frames);
DCHECK_EQ(1, frames.length());
return frames.first();
DCHECK_EQ(1, frames.size());
return frames.front();
}
FrameSummary FrameSummary::Get(const StandardFrame* frame, int index) {
DCHECK_LE(0, index);
List<FrameSummary> frames(FLAG_max_inlining_levels + 1);
std::vector<FrameSummary> frames;
frames.reserve(FLAG_max_inlining_levels + 1);
frame->Summarize(&frames);
DCHECK_GT(frames.length(), index);
DCHECK_GT(frames.size(), index);
return frames[index];
}
......@@ -1351,9 +1353,9 @@ FRAME_SUMMARY_DISPATCH(Handle<Context>, native_context)
#undef FRAME_SUMMARY_DISPATCH
void OptimizedFrame::Summarize(List<FrameSummary>* frames,
void OptimizedFrame::Summarize(std::vector<FrameSummary>* frames,
FrameSummary::Mode mode) const {
DCHECK(frames->length() == 0);
DCHECK(frames->empty());
DCHECK(is_optimized());
// Delegate to JS frame in absence of turbofan deoptimization.
......@@ -1421,7 +1423,7 @@ void OptimizedFrame::Summarize(List<FrameSummary>* frames,
FrameSummary::JavaScriptFrameSummary summary(isolate(), *receiver,
*function, *abstract_code,
code_offset, is_constructor);
frames->Add(summary);
frames->push_back(summary);
is_constructor = false;
} else if (it->kind() == TranslatedFrame::kConstructStub) {
// The next encountered JS frame will be marked as a constructor call.
......@@ -1629,15 +1631,15 @@ void InterpretedFrame::WriteInterpreterRegister(int register_index,
return SetExpression(index + register_index, value);
}
void InterpretedFrame::Summarize(List<FrameSummary>* functions,
void InterpretedFrame::Summarize(std::vector<FrameSummary>* functions,
FrameSummary::Mode mode) const {
DCHECK(functions->length() == 0);
DCHECK(functions->empty());
AbstractCode* abstract_code =
AbstractCode::cast(function()->shared()->bytecode_array());
FrameSummary::JavaScriptFrameSummary summary(
isolate(), receiver(), function(), abstract_code, GetBytecodeOffset(),
IsConstructor());
functions->Add(summary);
functions->push_back(summary);
}
int ArgumentsAdaptorFrame::GetNumberOfIncomingArguments() const {
......@@ -1728,15 +1730,15 @@ int WasmCompiledFrame::position() const {
return FrameSummary::GetSingle(this).SourcePosition();
}
void WasmCompiledFrame::Summarize(List<FrameSummary>* functions,
void WasmCompiledFrame::Summarize(std::vector<FrameSummary>* functions,
FrameSummary::Mode mode) const {
DCHECK_EQ(0, functions->length());
DCHECK(functions->empty());
Handle<Code> code(LookupCode(), isolate());
int offset = static_cast<int>(pc() - code->instruction_start());
Handle<WasmInstanceObject> instance(wasm_instance(), isolate());
FrameSummary::WasmCompiledFrameSummary summary(
isolate(), instance, code, offset, at_to_number_conversion());
functions->Add(summary);
functions->push_back(summary);
}
bool WasmCompiledFrame::at_to_number_conversion() const {
......@@ -1775,7 +1777,7 @@ void WasmInterpreterEntryFrame::Print(StringStream* accumulator, PrintMode mode,
if (mode != OVERVIEW) accumulator->Add("\n");
}
void WasmInterpreterEntryFrame::Summarize(List<FrameSummary>* functions,
void WasmInterpreterEntryFrame::Summarize(std::vector<FrameSummary>* functions,
FrameSummary::Mode mode) const {
Handle<WasmInstanceObject> instance(wasm_instance(), isolate());
std::vector<std::pair<uint32_t, int>> interpreted_stack =
......@@ -1784,7 +1786,7 @@ void WasmInterpreterEntryFrame::Summarize(List<FrameSummary>* functions,
for (auto& e : interpreted_stack) {
FrameSummary::WasmInterpretedFrameSummary summary(isolate(), instance,
e.first, e.second);
functions->Add(summary);
functions->push_back(summary);
}
}
......
......@@ -636,7 +636,7 @@ class StandardFrame : public StackFrame {
// The functions are ordered bottom-to-top (i.e. summaries.last() is the
// top-most activation; caller comes before callee).
virtual void Summarize(
List<FrameSummary>* frames,
std::vector<FrameSummary>* frames,
FrameSummary::Mode mode = FrameSummary::kExactSummary) const;
static StandardFrame* cast(StackFrame* frame) {
......@@ -689,7 +689,7 @@ class JavaScriptFrame : public StandardFrame {
Type type() const override { return JAVA_SCRIPT; }
void Summarize(
List<FrameSummary>* frames,
std::vector<FrameSummary>* frames,
FrameSummary::Mode mode = FrameSummary::kExactSummary) const override;
// Accessors.
......@@ -830,7 +830,7 @@ class OptimizedFrame : public JavaScriptFrame {
void GetFunctions(std::vector<SharedFunctionInfo*>* functions) const override;
void Summarize(
List<FrameSummary>* frames,
std::vector<FrameSummary>* frames,
FrameSummary::Mode mode = FrameSummary::kExactSummary) const override;
// Lookup exception handler for current {pc}, returns -1 if none found.
......@@ -884,7 +884,7 @@ class InterpretedFrame : public JavaScriptFrame {
// Build a list with summaries for this frame including all inlined frames.
void Summarize(
List<FrameSummary>* frames,
std::vector<FrameSummary>* frames,
FrameSummary::Mode mode = FrameSummary::kExactSummary) const override;
static int GetBytecodeOffset(Address fp);
......@@ -975,7 +975,7 @@ class WasmCompiledFrame final : public StandardFrame {
int position() const override;
bool at_to_number_conversion() const;
void Summarize(List<FrameSummary>* frames,
void Summarize(std::vector<FrameSummary>* frames,
FrameSummary::Mode mode) const override;
static WasmCompiledFrame* cast(StackFrame* frame) {
......@@ -1004,7 +1004,7 @@ class WasmInterpreterEntryFrame final : public StandardFrame {
int index) const override;
void Summarize(
List<FrameSummary>* frames,
std::vector<FrameSummary>* frames,
FrameSummary::Mode mode = FrameSummary::kExactSummary) const override;
// Determine the code for the frame.
......
......@@ -504,21 +504,23 @@ Handle<Object> Isolate::CaptureSimpleStackTrace(Handle<JSReceiver> error_object,
JavaScriptFrame* js_frame = JavaScriptFrame::cast(frame);
// Set initial size to the maximum inlining level + 1 for the outermost
// function.
List<FrameSummary> frames(FLAG_max_inlining_levels + 1);
std::vector<FrameSummary> frames;
frames.reserve(FLAG_max_inlining_levels + 1);
js_frame->Summarize(&frames);
for (int i = frames.length() - 1;
i >= 0 && elements->FrameCount() < limit; i--) {
const auto& summ = frames[i].AsJavaScript();
for (size_t i = frames.size(); i != 0 && elements->FrameCount() < limit;
i--) {
const FrameSummary& summary = frames[i - 1];
const auto& summ = summary.AsJavaScript();
Handle<JSFunction> fun = summ.function();
// Filter out internal frames that we do not want to show.
if (!helper.IsVisibleInStackTrace(*fun)) continue;
Handle<Object> recv = frames[i].receiver();
Handle<Object> recv = summary.receiver();
Handle<AbstractCode> abstract_code = summ.abstract_code();
const int offset = frames[i].code_offset();
const int offset = summary.code_offset();
bool is_constructor = frames[i].is_constructor();
bool is_constructor = summary.is_constructor();
if (frame->type() == StackFrame::BUILTIN) {
// Help CallSite::IsConstructor correctly detect hand-written
// construct stubs.
......@@ -766,10 +768,11 @@ Handle<FixedArray> Isolate::CaptureCurrentStackTrace(
StandardFrame* frame = it.frame();
// Set initial size to the maximum inlining level + 1 for the outermost
// function.
List<FrameSummary> frames(FLAG_max_inlining_levels + 1);
std::vector<FrameSummary> frames;
frames.reserve(FLAG_max_inlining_levels + 1);
frame->Summarize(&frames);
for (int i = frames.length() - 1; i >= 0 && frames_seen < limit; i--) {
FrameSummary& frame = frames[i];
for (size_t i = frames.size(); i != 0 && frames_seen < limit; i--) {
FrameSummary& frame = frames[i - 1];
if (!frame.is_subject_to_debugging()) continue;
// Filter frames from other security contexts.
if (!(options & StackTrace::kExposeFramesAcrossSecurityOrigins) &&
......@@ -1376,10 +1379,10 @@ HandlerTable::CatchPrediction PredictException(JavaScriptFrame* frame) {
// This optimized frame will catch. It's handler table does not include
// exception prediction, and we need to use the corresponding handler
// tables on the unoptimized code objects.
List<FrameSummary> summaries;
std::vector<FrameSummary> summaries;
frame->Summarize(&summaries);
for (int i = summaries.length() - 1; i >= 0; i--) {
const FrameSummary& summary = summaries[i];
for (size_t i = summaries.size(); i != 0; i--) {
const FrameSummary& summary = summaries[i - 1];
Handle<AbstractCode> code = summary.AsJavaScript().abstract_code();
if (code->IsCode() && code->kind() == AbstractCode::BUILTIN) {
prediction = code->GetCode()->GetBuiltinCatchPrediction();
......@@ -1554,9 +1557,10 @@ bool Isolate::ComputeLocation(MessageLocation* target) {
// Compute the location from the function and the relocation info of the
// baseline code. For optimized code this will use the deoptimization
// information to get canonical location information.
List<FrameSummary> frames(FLAG_max_inlining_levels + 1);
std::vector<FrameSummary> frames;
frames.reserve(FLAG_max_inlining_levels + 1);
frame->Summarize(&frames);
FrameSummary& summary = frames.last();
FrameSummary& summary = frames.back();
int pos = summary.SourcePosition();
Handle<SharedFunctionInfo> shared;
Handle<Object> script = summary.script();
......
......@@ -427,13 +427,14 @@ RUNTIME_FUNCTION(Runtime_GetFrameCount) {
return Smi::kZero;
}
List<FrameSummary> frames(FLAG_max_inlining_levels + 1);
std::vector<FrameSummary> frames;
frames.reserve(FLAG_max_inlining_levels + 1);
for (StackTraceFrameIterator it(isolate, id); !it.done(); it.Advance()) {
frames.Clear();
frames.clear();
it.frame()->Summarize(&frames);
for (int i = frames.length() - 1; i >= 0; i--) {
for (size_t i = frames.size(); i != 0; i--) {
// Omit functions from native and extension scripts.
if (frames[i].is_subject_to_debugging()) n++;
if (frames[i - 1].is_subject_to_debugging()) n++;
}
}
return Smi::FromInt(n);
......
......@@ -369,9 +369,10 @@ bool ComputeLocation(Isolate* isolate, MessageLocation* target) {
// Compute the location from the function and the relocation info of the
// baseline code. For optimized code this will use the deoptimization
// information to get canonical location information.
List<FrameSummary> frames(FLAG_max_inlining_levels + 1);
std::vector<FrameSummary> frames;
frames.reserve(FLAG_max_inlining_levels + 1);
it.frame()->Summarize(&frames);
auto& summary = frames.last().AsJavaScript();
auto& summary = frames.back().AsJavaScript();
Handle<SharedFunctionInfo> shared(summary.function()->shared());
Handle<Object> script(shared->script(), isolate);
int pos = summary.abstract_code()->SourcePosition(summary.code_offset());
......
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