From 28aca51e8f17a3904817d4b4de19165a5fadef10 Mon Sep 17 00:00:00 2001 From: "titzer@chromium.org" Date: Thu, 11 Jul 2013 16:45:58 +0000 Subject: [PATCH] Refactor JavaScriptFrame::function() to return a JSFunction* and remove associated casts. BUG= Review URL: https://codereview.chromium.org/18404009 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15638 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/compiler.cc | 3 +- src/debug.cc | 18 ++++--- src/deoptimizer.cc | 4 +- src/frames-inl.h | 6 +-- src/frames.cc | 125 ++++++++++++++++++++++-------------------------- src/frames.h | 2 +- src/ic.cc | 2 +- src/isolate.cc | 11 ++--- src/liveedit.cc | 3 +- src/runtime-profiler.cc | 2 +- src/runtime.cc | 24 +++++----- 11 files changed, 89 insertions(+), 111 deletions(-) diff --git a/src/compiler.cc b/src/compiler.cc index 7497f09..c299577 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -565,8 +565,7 @@ static Handle MakeFunctionInfo(CompilationInfo* info) { if (info->is_eval()) { StackTraceFrameIterator it(isolate); if (!it.done()) { - script->set_eval_from_shared( - JSFunction::cast(it.frame()->function())->shared()); + script->set_eval_from_shared(it.frame()->function()->shared()); Code* code = it.frame()->LookupCode(); int offset = static_cast( it.frame()->pc() - code->instruction_start()); diff --git a/src/debug.cc b/src/debug.cc index 5d39a1c..41eac5f 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -965,7 +965,7 @@ Object* Debug::Break(Arguments args) { // Get the debug info (create it if it does not exist). Handle shared = - Handle(JSFunction::cast(frame->function())->shared()); + Handle(frame->function()->shared()); Handle debug_info = GetDebugInfo(shared); // Find the break point where execution has stopped. @@ -1348,8 +1348,7 @@ void Debug::FloodHandlerWithOneShot() { JavaScriptFrame* frame = it.frame(); if (frame->HasHandler()) { // Flood the function with the catch block with break points - JSFunction* function = JSFunction::cast(frame->function()); - FloodWithOneShot(Handle(function)); + FloodWithOneShot(Handle(frame->function())); return; } } @@ -1415,13 +1414,13 @@ void Debug::PrepareStep(StepAction step_action, int step_count) { // breakpoints. frames_it.Advance(); // Fill the function to return to with one-shot break points. - JSFunction* function = JSFunction::cast(frames_it.frame()->function()); + JSFunction* function = frames_it.frame()->function(); FloodWithOneShot(Handle(function)); return; } // Get the debug info (create it if it does not exist). - Handle function(JSFunction::cast(frame->function())); + Handle function(frame->function()); Handle shared(function->shared()); if (!EnsureDebugInfo(shared, function)) { // Return if ensuring debug info failed. @@ -1486,15 +1485,14 @@ void Debug::PrepareStep(StepAction step_action, int step_count) { frames_it.Advance(); } // Skip builtin functions on the stack. - while (!frames_it.done() && - JSFunction::cast(frames_it.frame()->function())->IsBuiltin()) { + while (!frames_it.done() && frames_it.frame()->function()->IsBuiltin()) { frames_it.Advance(); } // Step out: If there is a JavaScript caller frame, we need to // flood it with breakpoints. if (!frames_it.done()) { // Fill the function to return to with one-shot break points. - JSFunction* function = JSFunction::cast(frames_it.frame()->function()); + JSFunction* function = frames_it.frame()->function(); FloodWithOneShot(Handle(function)); // Set target frame pointer. ActivateStepOut(frames_it.frame()); @@ -1916,7 +1914,7 @@ static void CollectActiveFunctionsFromThread( function->shared()->code()->set_gc_metadata(active_code_marker); } } else if (frame->function()->IsJSFunction()) { - JSFunction* function = JSFunction::cast(frame->function()); + JSFunction* function = frame->function(); ASSERT(frame->LookupCode()->kind() == Code::FUNCTION); active_functions->Add(Handle(function)); function->shared()->code()->set_gc_metadata(active_code_marker); @@ -1933,7 +1931,7 @@ static void RedirectActivationsToRecompiledCodeOnThread( if (frame->is_optimized() || !frame->function()->IsJSFunction()) continue; - JSFunction* function = JSFunction::cast(frame->function()); + JSFunction* function = frame->function(); ASSERT(frame->LookupCode()->kind() == Code::FUNCTION); diff --git a/src/deoptimizer.cc b/src/deoptimizer.cc index f322e85..54c8f75 100644 --- a/src/deoptimizer.cc +++ b/src/deoptimizer.cc @@ -186,7 +186,7 @@ DeoptimizedFrameInfo* Deoptimizer::DebuggerInspectableFrame( ASSERT(isolate->deoptimizer_data()->deoptimized_frame_info_ == NULL); // Get the function and code from the frame. - JSFunction* function = JSFunction::cast(frame->function()); + JSFunction* function = frame->function(); Code* code = frame->LookupCode(); // Locate the deoptimization point in the code. As we are at a call the @@ -1609,7 +1609,7 @@ void Deoptimizer::MaterializeHeapObjects(JavaScriptFrameIterator* it) { for (int frame_index = 0; frame_index < jsframe_count(); ++frame_index) { if (frame_index != 0) it->Advance(); JavaScriptFrame* frame = it->frame(); - Handle function(JSFunction::cast(frame->function()), isolate_); + Handle function(frame->function(), isolate_); Handle arguments; for (int i = frame->ComputeExpressionsCount() - 1; i >= 0; --i) { if (frame->GetExpression(i) == isolate_->heap()->arguments_marker()) { diff --git a/src/frames-inl.h b/src/frames-inl.h index 8d10645..d097ed1 100644 --- a/src/frames-inl.h +++ b/src/frames-inl.h @@ -274,10 +274,8 @@ inline bool JavaScriptFrame::has_adapted_arguments() const { } -inline Object* JavaScriptFrame::function() const { - Object* result = function_slot_object(); - ASSERT(result->IsJSFunction()); - return result; +inline JSFunction* JavaScriptFrame::function() const { + return JSFunction::cast(function_slot_object()); } diff --git a/src/frames.cc b/src/frames.cc index b20a7ea..29d3456 100644 --- a/src/frames.cc +++ b/src/frames.cc @@ -205,7 +205,7 @@ void StackTraceFrameIterator::Advance() { bool StackTraceFrameIterator::IsValidFrame() { if (!frame()->function()->IsJSFunction()) return false; - Object* script = JSFunction::cast(frame()->function())->shared()->script(); + Object* script = frame()->function()->shared()->script(); // Don't show functions from native scripts to user. return (script->IsScript() && Script::TYPE_NATIVE != Script::cast(script)->type()->value()); @@ -724,8 +724,7 @@ int JavaScriptFrame::GetArgumentsLength() const { Code* JavaScriptFrame::unchecked_code() const { - JSFunction* function = JSFunction::cast(this->function()); - return function->code(); + return function()->code(); } @@ -733,8 +732,7 @@ int JavaScriptFrame::GetNumberOfIncomingArguments() const { ASSERT(can_access_heap_objects() && isolate()->heap()->gc_state() == Heap::NOT_IN_GC); - JSFunction* function = JSFunction::cast(this->function()); - return function->shared()->formal_parameter_count(); + return function()->shared()->formal_parameter_count(); } @@ -745,7 +743,7 @@ Address JavaScriptFrame::GetCallerStackPointer() const { void JavaScriptFrame::GetFunctions(List* functions) { ASSERT(functions->length() == 0); - functions->Add(JSFunction::cast(function())); + functions->Add(function()); } @@ -754,7 +752,7 @@ void JavaScriptFrame::Summarize(List* functions) { Code* code_pointer = LookupCode(); int offset = static_cast(pc() - code_pointer->address()); FrameSummary summary(receiver(), - JSFunction::cast(function()), + function(), code_pointer, offset, IsConstructor()); @@ -775,40 +773,35 @@ void JavaScriptFrame::PrintTop(Isolate* isolate, JavaScriptFrame* frame = it.frame(); if (frame->IsConstructor()) PrintF(file, "new "); // function name - Object* maybe_fun = frame->function(); - if (maybe_fun->IsJSFunction()) { - JSFunction* fun = JSFunction::cast(maybe_fun); - fun->PrintName(); - Code* js_code = frame->unchecked_code(); - Address pc = frame->pc(); - int code_offset = - static_cast(pc - js_code->instruction_start()); - PrintF("+%d", code_offset); - SharedFunctionInfo* shared = fun->shared(); - if (print_line_number) { - Code* code = Code::cast( - v8::internal::Isolate::Current()->heap()->FindCodeObject(pc)); - int source_pos = code->SourcePosition(pc); - Object* maybe_script = shared->script(); - if (maybe_script->IsScript()) { - Handle