Commit c0198937 authored by jarin's avatar jarin Committed by Commit bot

Handlify DeoptimizedFrameInfo, remove custom GC iteration.

TBR=mstarzinger@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#33926}
parent 09d84535
......@@ -128,7 +128,7 @@ DebugEvaluate::ContextBuilder::ContextBuilder(Isolate* isolate,
inlined_jsframe_index_(inlined_jsframe_index) {
FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate);
Handle<JSFunction> local_function =
handle(JSFunction::cast(frame_inspector.GetFunction()));
Handle<JSFunction>::cast(frame_inspector.GetFunction());
Handle<Context> outer_context(local_function->context());
native_context_ = Handle<Context>(outer_context->native_context());
Handle<JSFunction> global_function(native_context_->closure());
......
......@@ -44,27 +44,25 @@ int FrameInspector::GetParametersCount() {
: frame_->ComputeParametersCount();
}
Object* FrameInspector::GetFunction() {
return is_optimized_ ? deoptimized_frame_->GetFunction() : frame_->function();
Handle<Object> FrameInspector::GetFunction() {
return is_optimized_ ? deoptimized_frame_->GetFunction()
: handle(frame_->function(), isolate_);
}
Object* FrameInspector::GetParameter(int index) {
Handle<Object> FrameInspector::GetParameter(int index) {
return is_optimized_ ? deoptimized_frame_->GetParameter(index)
: frame_->GetParameter(index);
: handle(frame_->GetParameter(index), isolate_);
}
Object* FrameInspector::GetExpression(int index) {
Handle<Object> FrameInspector::GetExpression(int index) {
// TODO(turbofan): Revisit once we support deoptimization.
if (frame_->LookupCode()->is_turbofanned() &&
frame_->function()->shared()->asm_function() &&
!FLAG_turbo_asm_deoptimization) {
return isolate_->heap()->undefined_value();
return isolate_->factory()->undefined_value();
}
return is_optimized_ ? deoptimized_frame_->GetExpression(index)
: frame_->GetExpression(index);
: handle(frame_->GetExpression(index), isolate_);
}
......@@ -85,9 +83,9 @@ bool FrameInspector::IsConstructor() {
: frame_->IsConstructor();
}
Object* FrameInspector::GetContext() {
return is_optimized_ ? deoptimized_frame_->GetContext() : frame_->context();
Handle<Object> FrameInspector::GetContext() {
return is_optimized_ ? deoptimized_frame_->GetContext()
: handle(frame_->context(), isolate_);
}
......@@ -114,10 +112,10 @@ void FrameInspector::MaterializeStackLocals(Handle<JSObject> target,
Handle<String> name(scope_info->ParameterName(i));
if (ParameterIsShadowedByContextLocal(scope_info, name)) continue;
Handle<Object> value(i < GetParametersCount()
? GetParameter(i)
: isolate_->heap()->undefined_value(),
isolate_);
Handle<Object> value =
i < GetParametersCount()
? GetParameter(i)
: Handle<Object>::cast(isolate_->factory()->undefined_value());
DCHECK(!value->IsTheHole());
JSObject::SetOwnPropertyIgnoreAttributes(target, name, value, NONE).Check();
......@@ -127,8 +125,7 @@ void FrameInspector::MaterializeStackLocals(Handle<JSObject> target,
for (int i = 0; i < scope_info->StackLocalCount(); ++i) {
if (scope_info->LocalIsSynthetic(i)) continue;
Handle<String> name(scope_info->StackLocalName(i));
Handle<Object> value(GetExpression(scope_info->StackLocalIndex(i)),
isolate_);
Handle<Object> value = GetExpression(scope_info->StackLocalIndex(i));
if (value->IsTheHole()) value = isolate_->factory()->undefined_value();
JSObject::SetOwnPropertyIgnoreAttributes(target, name, value, NONE).Check();
......
......@@ -21,12 +21,12 @@ class FrameInspector {
~FrameInspector();
int GetParametersCount();
Object* GetFunction();
Object* GetParameter(int index);
Object* GetExpression(int index);
Handle<Object> GetFunction();
Handle<Object> GetParameter(int index);
Handle<Object> GetExpression(int index);
int GetSourcePosition();
bool IsConstructor();
Object* GetContext();
Handle<Object> GetContext();
JavaScriptFrame* GetArgumentsFrame() { return frame_; }
void SetArgumentsFrame(JavaScriptFrame* frame);
......
......@@ -28,7 +28,7 @@ ScopeIterator::ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector,
return;
}
context_ = Handle<Context>(Context::cast(frame_inspector->GetContext()));
context_ = Handle<Context>::cast(frame_inspector->GetContext());
// Catch the case when the debugger stops in an internal function.
Handle<JSFunction> function = GetFunction();
......@@ -458,7 +458,8 @@ MaybeHandle<JSObject> ScopeIterator::MaterializeLocalScope() {
isolate_->factory()->NewJSObject(isolate_->object_function());
frame_inspector_->MaterializeStackLocals(local_scope, function);
Handle<Context> frame_context(Context::cast(frame_inspector_->GetContext()));
Handle<Context> frame_context =
Handle<Context>::cast(frame_inspector_->GetContext());
HandleScope scope(isolate_);
Handle<SharedFunctionInfo> shared(function->shared());
......
......@@ -96,8 +96,7 @@ class ScopeIterator {
}
inline Handle<JSFunction> GetFunction() {
return Handle<JSFunction>(
JSFunction::cast(frame_inspector_->GetFunction()));
return Handle<JSFunction>::cast(frame_inspector_->GetFunction());
}
static bool InternalizedStringMatch(void* key1, void* key2) {
......
......@@ -36,7 +36,6 @@ static MemoryChunk* AllocateCodeChunk(MemoryAllocator* allocator) {
DeoptimizerData::DeoptimizerData(MemoryAllocator* allocator)
: allocator_(allocator),
deoptimized_frame_info_(NULL),
current_(NULL) {
for (int i = 0; i < Deoptimizer::kBailoutTypesWithCodeEntry; ++i) {
deopt_entry_code_entries_[i] = -1;
......@@ -53,13 +52,6 @@ DeoptimizerData::~DeoptimizerData() {
}
void DeoptimizerData::Iterate(ObjectVisitor* v) {
if (deoptimized_frame_info_ != NULL) {
deoptimized_frame_info_->Iterate(v);
}
}
Code* Deoptimizer::FindDeoptimizingCode(Address addr) {
if (function_->IsHeapObject()) {
// Search all deoptimizing code in the native context of the function.
......@@ -141,7 +133,6 @@ DeoptimizedFrameInfo* Deoptimizer::DebuggerInspectableFrame(
int jsframe_index,
Isolate* isolate) {
CHECK(frame->is_optimized());
CHECK(isolate->deoptimizer_data()->deoptimized_frame_info_ == NULL);
// Get the function and code from the frame.
JSFunction* function = frame->function();
......@@ -197,7 +188,6 @@ DeoptimizedFrameInfo* Deoptimizer::DebuggerInspectableFrame(
frame_index,
has_arguments_adaptor,
has_construct_stub);
isolate->deoptimizer_data()->deoptimized_frame_info_ = info;
// Done with the GC-unsafe frame descriptions. This re-enables allocation.
deoptimizer->DeleteFrameDescriptions();
......@@ -215,9 +205,7 @@ DeoptimizedFrameInfo* Deoptimizer::DebuggerInspectableFrame(
void Deoptimizer::DeleteDebuggerInspectableFrame(DeoptimizedFrameInfo* info,
Isolate* isolate) {
CHECK_EQ(isolate->deoptimizer_data()->deoptimized_frame_info_, info);
delete info;
isolate->deoptimizer_data()->deoptimized_frame_info_ = NULL;
}
......@@ -1920,7 +1908,7 @@ void Deoptimizer::MaterializeHeapNumbersForDebuggerInspectableFrame(
arg_iter++; // Skip the receiver.
for (int i = 0; i < parameter_count; i++, arg_iter++) {
if (!arg_iter->IsMaterializedObject()) {
info->SetParameter(i, *(arg_iter->GetValue()));
info->SetParameter(i, arg_iter->GetValue());
}
}
......@@ -1931,7 +1919,7 @@ void Deoptimizer::MaterializeHeapNumbersForDebuggerInspectableFrame(
for (int i = 0; i < expression_count; i++, iter++) {
if (!iter->IsMaterializedObject()) {
info->SetExpression(i, *(iter->GetValue()));
info->SetExpression(i, iter->GetValue());
}
}
}
......@@ -2508,24 +2496,27 @@ DeoptimizedFrameInfo::DeoptimizedFrameInfo(Deoptimizer* deoptimizer,
bool has_arguments_adaptor,
bool has_construct_stub) {
FrameDescription* output_frame = deoptimizer->output_[frame_index];
function_ = output_frame->GetFunction();
context_ = reinterpret_cast<Object*>(output_frame->GetContext());
function_ =
Handle<JSFunction>(output_frame->GetFunction(), deoptimizer->isolate());
context_ =
Handle<Object>(reinterpret_cast<Object*>(output_frame->GetContext()),
deoptimizer->isolate());
has_construct_stub_ = has_construct_stub;
expression_count_ = output_frame->GetExpressionCount();
expression_stack_ = new Object* [expression_count_];
expression_stack_.resize(
static_cast<size_t>(output_frame->GetExpressionCount()));
// Get the source position using the unoptimized code.
Address pc = reinterpret_cast<Address>(output_frame->GetPc());
Code* code = Code::cast(deoptimizer->isolate()->FindCodeObject(pc));
int offset = static_cast<int>(pc - code->instruction_start());
source_position_ = code->SourcePosition(offset);
for (int i = 0; i < expression_count_; i++) {
for (int i = 0; i < static_cast<int>(expression_count()); i++) {
Object* value = output_frame->GetExpression(i);
// Replace materialization markers with the undefined value.
if (value == deoptimizer->isolate()->heap()->arguments_marker()) {
value = deoptimizer->isolate()->heap()->undefined_value();
}
SetExpression(i, value);
SetExpression(i, Handle<Object>(value, deoptimizer->isolate()));
}
if (has_arguments_adaptor) {
......@@ -2533,33 +2524,19 @@ DeoptimizedFrameInfo::DeoptimizedFrameInfo(Deoptimizer* deoptimizer,
CHECK_EQ(output_frame->GetFrameType(), StackFrame::ARGUMENTS_ADAPTOR);
}
parameters_count_ = output_frame->ComputeParametersCount();
parameters_ = new Object* [parameters_count_];
for (int i = 0; i < parameters_count_; i++) {
parameters_.resize(
static_cast<size_t>(output_frame->ComputeParametersCount()));
for (int i = 0; i < output_frame->ComputeParametersCount(); i++) {
Object* value = output_frame->GetParameter(i);
// Replace materialization markers with the undefined value.
if (value == deoptimizer->isolate()->heap()->arguments_marker()) {
value = deoptimizer->isolate()->heap()->undefined_value();
}
SetParameter(i, value);
SetParameter(i, Handle<Object>(value, deoptimizer->isolate()));
}
}
DeoptimizedFrameInfo::~DeoptimizedFrameInfo() {
delete[] expression_stack_;
delete[] parameters_;
}
void DeoptimizedFrameInfo::Iterate(ObjectVisitor* v) {
v->VisitPointer(bit_cast<Object**>(&function_));
v->VisitPointer(&context_);
v->VisitPointers(parameters_, parameters_ + parameters_count_);
v->VisitPointers(expression_stack_, expression_stack_ + expression_count_);
}
const char* Deoptimizer::GetDeoptReason(DeoptReason deopt_reason) {
DCHECK(deopt_reason < kLastDeoptReason);
#define DEOPT_MESSAGES_TEXTS(C, T) T,
......
......@@ -907,15 +907,11 @@ class DeoptimizerData {
explicit DeoptimizerData(MemoryAllocator* allocator);
~DeoptimizerData();
void Iterate(ObjectVisitor* v);
private:
MemoryAllocator* allocator_;
int deopt_entry_code_entries_[Deoptimizer::kBailoutTypesWithCodeEntry];
MemoryChunk* deopt_entry_code_[Deoptimizer::kBailoutTypesWithCodeEntry];
DeoptimizedFrameInfo* deoptimized_frame_info_;
Deoptimizer* current_;
friend class Deoptimizer;
......@@ -1077,24 +1073,17 @@ class DeoptimizedFrameInfo : public Malloced {
int frame_index,
bool has_arguments_adaptor,
bool has_construct_stub);
virtual ~DeoptimizedFrameInfo();
// GC support.
void Iterate(ObjectVisitor* v);
// Return the number of incoming arguments.
int parameters_count() { return parameters_count_; }
int parameters_count() { return static_cast<int>(parameters_.size()); }
// Return the height of the expression stack.
int expression_count() { return expression_count_; }
int expression_count() { return static_cast<int>(expression_stack_.size()); }
// Get the frame function.
JSFunction* GetFunction() {
return function_;
}
Handle<JSFunction> GetFunction() { return function_; }
// Get the frame context.
Object* GetContext() { return context_; }
Handle<Object> GetContext() { return context_; }
// Check if this frame is preceded by construct stub frame. The bottom-most
// inlined frame might still be called by an uninlined construct stub.
......@@ -1103,13 +1092,13 @@ class DeoptimizedFrameInfo : public Malloced {
}
// Get an incoming argument.
Object* GetParameter(int index) {
Handle<Object> GetParameter(int index) {
DCHECK(0 <= index && index < parameters_count());
return parameters_[index];
}
// Get an expression from the expression stack.
Object* GetExpression(int index) {
Handle<Object> GetExpression(int index) {
DCHECK(0 <= index && index < expression_count());
return expression_stack_[index];
}
......@@ -1120,24 +1109,22 @@ class DeoptimizedFrameInfo : public Malloced {
private:
// Set an incoming argument.
void SetParameter(int index, Object* obj) {
void SetParameter(int index, Handle<Object> obj) {
DCHECK(0 <= index && index < parameters_count());
parameters_[index] = obj;
}
// Set an expression on the expression stack.
void SetExpression(int index, Object* obj) {
void SetExpression(int index, Handle<Object> obj) {
DCHECK(0 <= index && index < expression_count());
expression_stack_[index] = obj;
}
JSFunction* function_;
Object* context_;
Handle<JSFunction> function_;
Handle<Object> context_;
bool has_construct_stub_;
int parameters_count_;
int expression_count_;
Object** parameters_;
Object** expression_stack_;
std::vector<Handle<Object> > parameters_;
std::vector<Handle<Object> > expression_stack_;
int source_position_;
friend class Deoptimizer;
......
......@@ -4616,10 +4616,6 @@ void Heap::IterateStrongRoots(ObjectVisitor* v, VisitMode mode) {
Relocatable::Iterate(isolate_, v);
v->Synchronize(VisitorSynchronization::kRelocatable);
if (isolate_->deoptimizer_data() != NULL) {
isolate_->deoptimizer_data()->Iterate(v);
}
v->Synchronize(VisitorSynchronization::kDebug);
isolate_->compilation_cache()->Iterate(v);
v->Synchronize(VisitorSynchronization::kCompilationCache);
......
......@@ -528,7 +528,8 @@ RUNTIME_FUNCTION(Runtime_GetFrameDetails) {
bool constructor = frame_inspector.IsConstructor();
// Get scope info and read from it for local variable information.
Handle<JSFunction> function(JSFunction::cast(frame_inspector.GetFunction()));
Handle<JSFunction> function =
Handle<JSFunction>::cast(frame_inspector.GetFunction());
RUNTIME_ASSERT(function->shared()->IsSubjectToDebugging());
Handle<SharedFunctionInfo> shared(function->shared());
Handle<ScopeInfo> scope_info(shared->scope_info());
......@@ -552,13 +553,13 @@ RUNTIME_FUNCTION(Runtime_GetFrameDetails) {
// Use the value from the stack.
if (scope_info->LocalIsSynthetic(i)) continue;
locals->set(local * 2, scope_info->LocalName(i));
locals->set(local * 2 + 1, frame_inspector.GetExpression(i));
locals->set(local * 2 + 1, *(frame_inspector.GetExpression(i)));
local++;
}
if (local < local_count) {
// Get the context containing declarations.
Handle<Context> context(
Context::cast(frame_inspector.GetContext())->closure_context());
Handle<Context>::cast(frame_inspector.GetContext())->closure_context());
for (; i < scope_info->LocalCount(); ++i) {
if (scope_info->LocalIsSynthetic(i)) continue;
Handle<String> name(scope_info->LocalName(i));
......@@ -637,7 +638,7 @@ RUNTIME_FUNCTION(Runtime_GetFrameDetails) {
details->set(kFrameDetailsFrameIdIndex, *frame_id);
// Add the function (same as in function frame).
details->set(kFrameDetailsFunctionIndex, frame_inspector.GetFunction());
details->set(kFrameDetailsFunctionIndex, *(frame_inspector.GetFunction()));
// Add the arguments count.
details->set(kFrameDetailsArgumentCountIndex, Smi::FromInt(argument_count));
......@@ -687,7 +688,7 @@ RUNTIME_FUNCTION(Runtime_GetFrameDetails) {
// Parameter value.
if (i < frame_inspector.GetParametersCount()) {
// Get the value from the stack.
details->set(details_index++, frame_inspector.GetParameter(i));
details->set(details_index++, *(frame_inspector.GetParameter(i)));
} else {
details->set(details_index++, heap->undefined_value());
}
......
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