2012-01-24 08:43:12 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2010-12-07 11:31:57 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
|
|
|
#include "codegen.h"
|
|
|
|
#include "deoptimizer.h"
|
|
|
|
#include "disasm.h"
|
|
|
|
#include "full-codegen.h"
|
|
|
|
#include "global-handles.h"
|
|
|
|
#include "macro-assembler.h"
|
|
|
|
#include "prettyprinter.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
DeoptimizerData::DeoptimizerData() {
|
|
|
|
eager_deoptimization_entry_code_ = NULL;
|
|
|
|
lazy_deoptimization_entry_code_ = NULL;
|
|
|
|
current_ = NULL;
|
|
|
|
deoptimizing_code_list_ = NULL;
|
2011-06-29 13:02:00 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
|
|
|
deoptimized_frame_info_ = NULL;
|
|
|
|
#endif
|
2011-03-18 20:35:07 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
DeoptimizerData::~DeoptimizerData() {
|
|
|
|
if (eager_deoptimization_entry_code_ != NULL) {
|
2011-09-19 18:36:47 +00:00
|
|
|
Isolate::Current()->memory_allocator()->Free(
|
|
|
|
eager_deoptimization_entry_code_);
|
2011-03-18 20:35:07 +00:00
|
|
|
eager_deoptimization_entry_code_ = NULL;
|
|
|
|
}
|
|
|
|
if (lazy_deoptimization_entry_code_ != NULL) {
|
2011-09-19 18:36:47 +00:00
|
|
|
Isolate::Current()->memory_allocator()->Free(
|
|
|
|
lazy_deoptimization_entry_code_);
|
2011-03-18 20:35:07 +00:00
|
|
|
lazy_deoptimization_entry_code_ = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-29 13:02:00 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
|
|
|
void DeoptimizerData::Iterate(ObjectVisitor* v) {
|
|
|
|
if (deoptimized_frame_info_ != NULL) {
|
|
|
|
deoptimized_frame_info_->Iterate(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2011-09-15 11:30:45 +00:00
|
|
|
// We rely on this function not causing a GC. It is called from generated code
|
|
|
|
// without having a real stack frame in place.
|
2010-12-07 11:31:57 +00:00
|
|
|
Deoptimizer* Deoptimizer::New(JSFunction* function,
|
|
|
|
BailoutType type,
|
|
|
|
unsigned bailout_id,
|
|
|
|
Address from,
|
2011-03-18 20:35:07 +00:00
|
|
|
int fp_to_sp_delta,
|
|
|
|
Isolate* isolate) {
|
|
|
|
ASSERT(isolate == Isolate::Current());
|
|
|
|
Deoptimizer* deoptimizer = new Deoptimizer(isolate,
|
|
|
|
function,
|
|
|
|
type,
|
|
|
|
bailout_id,
|
|
|
|
from,
|
2011-06-29 13:02:00 +00:00
|
|
|
fp_to_sp_delta,
|
|
|
|
NULL);
|
2011-03-18 20:35:07 +00:00
|
|
|
ASSERT(isolate->deoptimizer_data()->current_ == NULL);
|
|
|
|
isolate->deoptimizer_data()->current_ = deoptimizer;
|
2010-12-07 11:31:57 +00:00
|
|
|
return deoptimizer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Deoptimizer* Deoptimizer::Grab(Isolate* isolate) {
|
|
|
|
ASSERT(isolate == Isolate::Current());
|
|
|
|
Deoptimizer* result = isolate->deoptimizer_data()->current_;
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(result != NULL);
|
|
|
|
result->DeleteFrameDescriptions();
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->deoptimizer_data()->current_ = NULL;
|
2010-12-07 11:31:57 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
|
|
|
|
int Deoptimizer::ConvertJSFrameIndexToFrameIndex(int jsframe_index) {
|
|
|
|
if (jsframe_index == 0) return 0;
|
|
|
|
|
|
|
|
int frame_index = 0;
|
|
|
|
while (jsframe_index >= 0) {
|
|
|
|
FrameDescription* frame = output_[frame_index];
|
|
|
|
if (frame->GetFrameType() == StackFrame::JAVA_SCRIPT) {
|
|
|
|
jsframe_index--;
|
|
|
|
}
|
|
|
|
frame_index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return frame_index - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-29 13:02:00 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
|
|
|
DeoptimizedFrameInfo* Deoptimizer::DebuggerInspectableFrame(
|
|
|
|
JavaScriptFrame* frame,
|
2012-01-24 08:43:12 +00:00
|
|
|
int jsframe_index,
|
2011-06-29 13:02:00 +00:00
|
|
|
Isolate* isolate) {
|
|
|
|
ASSERT(isolate == Isolate::Current());
|
|
|
|
ASSERT(frame->is_optimized());
|
|
|
|
ASSERT(isolate->deoptimizer_data()->deoptimized_frame_info_ == NULL);
|
|
|
|
|
|
|
|
// Get the function and code from the frame.
|
|
|
|
JSFunction* function = JSFunction::cast(frame->function());
|
|
|
|
Code* code = frame->LookupCode();
|
|
|
|
|
|
|
|
// Locate the deoptimization point in the code. As we are at a call the
|
|
|
|
// return address must be at a place in the code with deoptimization support.
|
2011-11-16 08:44:30 +00:00
|
|
|
SafepointEntry safepoint_entry = code->GetSafepointEntry(frame->pc());
|
|
|
|
int deoptimization_index = safepoint_entry.deoptimization_index();
|
2011-06-29 13:02:00 +00:00
|
|
|
ASSERT(deoptimization_index != Safepoint::kNoDeoptimizationIndex);
|
|
|
|
|
|
|
|
// Always use the actual stack slots when calculating the fp to sp
|
|
|
|
// delta adding two for the function and context.
|
|
|
|
unsigned stack_slots = code->stack_slots();
|
|
|
|
unsigned fp_to_sp_delta = ((stack_slots + 2) * kPointerSize);
|
|
|
|
|
|
|
|
Deoptimizer* deoptimizer = new Deoptimizer(isolate,
|
|
|
|
function,
|
|
|
|
Deoptimizer::DEBUGGER,
|
|
|
|
deoptimization_index,
|
|
|
|
frame->pc(),
|
|
|
|
fp_to_sp_delta,
|
|
|
|
code);
|
|
|
|
Address tos = frame->fp() - fp_to_sp_delta;
|
|
|
|
deoptimizer->FillInputFrame(tos, frame);
|
|
|
|
|
|
|
|
// Calculate the output frames.
|
|
|
|
Deoptimizer::ComputeOutputFrames(deoptimizer);
|
|
|
|
|
|
|
|
// Create the GC safe output frame information and register it for GC
|
|
|
|
// handling.
|
2012-01-24 08:43:12 +00:00
|
|
|
ASSERT_LT(jsframe_index, deoptimizer->jsframe_count());
|
|
|
|
|
|
|
|
// Convert JS frame index into frame index.
|
|
|
|
int frame_index = deoptimizer->ConvertJSFrameIndexToFrameIndex(jsframe_index);
|
|
|
|
|
|
|
|
bool has_arguments_adaptor =
|
|
|
|
frame_index > 0 &&
|
|
|
|
deoptimizer->output_[frame_index - 1]->GetFrameType() ==
|
|
|
|
StackFrame::ARGUMENTS_ADAPTOR;
|
|
|
|
|
2012-02-28 09:05:55 +00:00
|
|
|
int construct_offset = has_arguments_adaptor ? 2 : 1;
|
|
|
|
bool has_construct_stub =
|
|
|
|
frame_index >= construct_offset &&
|
|
|
|
deoptimizer->output_[frame_index - construct_offset]->GetFrameType() ==
|
|
|
|
StackFrame::CONSTRUCT;
|
|
|
|
|
|
|
|
DeoptimizedFrameInfo* info = new DeoptimizedFrameInfo(deoptimizer,
|
|
|
|
frame_index,
|
|
|
|
has_arguments_adaptor,
|
|
|
|
has_construct_stub);
|
2011-06-29 13:02:00 +00:00
|
|
|
isolate->deoptimizer_data()->deoptimized_frame_info_ = info;
|
|
|
|
|
|
|
|
// Get the "simulated" top and size for the requested frame.
|
2012-01-24 08:43:12 +00:00
|
|
|
FrameDescription* parameters_frame =
|
|
|
|
deoptimizer->output_[
|
|
|
|
has_arguments_adaptor ? (frame_index - 1) : frame_index];
|
|
|
|
|
|
|
|
uint32_t parameters_size = (info->parameters_count() + 1) * kPointerSize;
|
|
|
|
Address parameters_top = reinterpret_cast<Address>(
|
|
|
|
parameters_frame->GetTop() + (parameters_frame->GetFrameSize() -
|
|
|
|
parameters_size));
|
|
|
|
|
|
|
|
uint32_t expressions_size = info->expression_count() * kPointerSize;
|
|
|
|
Address expressions_top = reinterpret_cast<Address>(
|
|
|
|
deoptimizer->output_[frame_index]->GetTop());
|
2011-06-29 13:02:00 +00:00
|
|
|
|
|
|
|
// Done with the GC-unsafe frame descriptions. This re-enables allocation.
|
|
|
|
deoptimizer->DeleteFrameDescriptions();
|
|
|
|
|
|
|
|
// Allocate a heap number for the doubles belonging to this frame.
|
|
|
|
deoptimizer->MaterializeHeapNumbersForDebuggerInspectableFrame(
|
2012-01-24 08:43:12 +00:00
|
|
|
parameters_top, parameters_size, expressions_top, expressions_size, info);
|
2011-06-29 13:02:00 +00:00
|
|
|
|
|
|
|
// Finished using the deoptimizer instance.
|
|
|
|
delete deoptimizer;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Deoptimizer::DeleteDebuggerInspectableFrame(DeoptimizedFrameInfo* info,
|
|
|
|
Isolate* isolate) {
|
|
|
|
ASSERT(isolate == Isolate::Current());
|
|
|
|
ASSERT(isolate->deoptimizer_data()->deoptimized_frame_info_ == info);
|
|
|
|
delete info;
|
|
|
|
isolate->deoptimizer_data()->deoptimized_frame_info_ = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
void Deoptimizer::GenerateDeoptimizationEntries(MacroAssembler* masm,
|
|
|
|
int count,
|
|
|
|
BailoutType type) {
|
|
|
|
TableEntryGenerator generator(masm, type, count);
|
|
|
|
generator.Generate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class DeoptimizingVisitor : public OptimizedFunctionVisitor {
|
|
|
|
public:
|
|
|
|
virtual void EnterContext(Context* context) {
|
|
|
|
if (FLAG_trace_deopt) {
|
|
|
|
PrintF("[deoptimize context: %" V8PRIxPTR "]\n",
|
|
|
|
reinterpret_cast<intptr_t>(context));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void VisitFunction(JSFunction* function) {
|
|
|
|
Deoptimizer::DeoptimizeFunction(function);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void LeaveContext(Context* context) {
|
|
|
|
context->ClearOptimizedFunctions();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void Deoptimizer::DeoptimizeAll() {
|
|
|
|
AssertNoAllocation no_allocation;
|
|
|
|
|
|
|
|
if (FLAG_trace_deopt) {
|
|
|
|
PrintF("[deoptimize all contexts]\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
DeoptimizingVisitor visitor;
|
|
|
|
VisitAllOptimizedFunctions(&visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Deoptimizer::DeoptimizeGlobalObject(JSObject* object) {
|
|
|
|
AssertNoAllocation no_allocation;
|
|
|
|
|
|
|
|
DeoptimizingVisitor visitor;
|
|
|
|
VisitAllOptimizedFunctionsForGlobalObject(object, &visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Deoptimizer::VisitAllOptimizedFunctionsForContext(
|
|
|
|
Context* context, OptimizedFunctionVisitor* visitor) {
|
2012-06-15 10:36:45 +00:00
|
|
|
Isolate* isolate = context->GetIsolate();
|
|
|
|
ZoneScope zone_scope(isolate, DELETE_ON_EXIT);
|
2010-12-07 11:31:57 +00:00
|
|
|
AssertNoAllocation no_allocation;
|
|
|
|
|
|
|
|
ASSERT(context->IsGlobalContext());
|
|
|
|
|
|
|
|
visitor->EnterContext(context);
|
2012-06-15 10:36:45 +00:00
|
|
|
|
|
|
|
// Create a snapshot of the optimized functions list. This is needed because
|
|
|
|
// visitors might remove more than one link from the list at once.
|
|
|
|
ZoneList<JSFunction*> snapshot(1, isolate->zone());
|
2010-12-07 11:31:57 +00:00
|
|
|
Object* element = context->OptimizedFunctionsListHead();
|
|
|
|
while (!element->IsUndefined()) {
|
|
|
|
JSFunction* element_function = JSFunction::cast(element);
|
2012-06-15 10:36:45 +00:00
|
|
|
snapshot.Add(element_function, isolate->zone());
|
2010-12-07 11:31:57 +00:00
|
|
|
element = element_function->next_function_link();
|
|
|
|
}
|
2012-06-15 10:36:45 +00:00
|
|
|
|
|
|
|
// Run through the snapshot of optimized functions and visit them.
|
|
|
|
for (int i = 0; i < snapshot.length(); ++i) {
|
|
|
|
visitor->VisitFunction(snapshot.at(i));
|
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
visitor->LeaveContext(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Deoptimizer::VisitAllOptimizedFunctionsForGlobalObject(
|
|
|
|
JSObject* object, OptimizedFunctionVisitor* visitor) {
|
|
|
|
AssertNoAllocation no_allocation;
|
|
|
|
|
|
|
|
if (object->IsJSGlobalProxy()) {
|
|
|
|
Object* proto = object->GetPrototype();
|
|
|
|
ASSERT(proto->IsJSGlobalObject());
|
|
|
|
VisitAllOptimizedFunctionsForContext(
|
|
|
|
GlobalObject::cast(proto)->global_context(), visitor);
|
|
|
|
} else if (object->IsGlobalObject()) {
|
|
|
|
VisitAllOptimizedFunctionsForContext(
|
|
|
|
GlobalObject::cast(object)->global_context(), visitor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Deoptimizer::VisitAllOptimizedFunctions(
|
|
|
|
OptimizedFunctionVisitor* visitor) {
|
|
|
|
AssertNoAllocation no_allocation;
|
|
|
|
|
|
|
|
// Run through the list of all global contexts and deoptimize.
|
2011-12-13 14:20:03 +00:00
|
|
|
Object* context = Isolate::Current()->heap()->global_contexts_list();
|
|
|
|
while (!context->IsUndefined()) {
|
|
|
|
// GC can happen when the context is not fully initialized,
|
|
|
|
// so the global field of the context can be undefined.
|
|
|
|
Object* global = Context::cast(context)->get(Context::GLOBAL_INDEX);
|
|
|
|
if (!global->IsUndefined()) {
|
|
|
|
VisitAllOptimizedFunctionsForGlobalObject(JSObject::cast(global),
|
|
|
|
visitor);
|
|
|
|
}
|
|
|
|
context = Context::cast(context)->get(Context::NEXT_CONTEXT_LINK);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Deoptimizer::HandleWeakDeoptimizedCode(
|
|
|
|
v8::Persistent<v8::Value> obj, void* data) {
|
|
|
|
DeoptimizingCodeListNode* node =
|
|
|
|
reinterpret_cast<DeoptimizingCodeListNode*>(data);
|
|
|
|
RemoveDeoptimizingCode(*node->code());
|
|
|
|
#ifdef DEBUG
|
2011-03-18 20:35:07 +00:00
|
|
|
node = Isolate::Current()->deoptimizer_data()->deoptimizing_code_list_;
|
2010-12-07 11:31:57 +00:00
|
|
|
while (node != NULL) {
|
|
|
|
ASSERT(node != reinterpret_cast<DeoptimizingCodeListNode*>(data));
|
|
|
|
node = node->next();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-30 18:05:16 +00:00
|
|
|
void Deoptimizer::ComputeOutputFrames(Deoptimizer* deoptimizer) {
|
2010-12-07 11:31:57 +00:00
|
|
|
deoptimizer->DoComputeOutputFrames();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Deoptimizer::Deoptimizer(Isolate* isolate,
|
|
|
|
JSFunction* function,
|
2010-12-07 11:31:57 +00:00
|
|
|
BailoutType type,
|
|
|
|
unsigned bailout_id,
|
|
|
|
Address from,
|
2011-06-29 13:02:00 +00:00
|
|
|
int fp_to_sp_delta,
|
|
|
|
Code* optimized_code)
|
2011-03-18 20:35:07 +00:00
|
|
|
: isolate_(isolate),
|
|
|
|
function_(function),
|
2010-12-07 11:31:57 +00:00
|
|
|
bailout_id_(bailout_id),
|
|
|
|
bailout_type_(type),
|
|
|
|
from_(from),
|
|
|
|
fp_to_sp_delta_(fp_to_sp_delta),
|
2012-06-12 10:22:33 +00:00
|
|
|
has_alignment_padding_(0),
|
2011-06-29 13:02:00 +00:00
|
|
|
input_(NULL),
|
2010-12-07 11:31:57 +00:00
|
|
|
output_count_(0),
|
2012-01-24 08:43:12 +00:00
|
|
|
jsframe_count_(0),
|
2010-12-07 11:31:57 +00:00
|
|
|
output_(NULL),
|
2011-04-06 14:23:27 +00:00
|
|
|
deferred_heap_numbers_(0) {
|
2010-12-07 11:31:57 +00:00
|
|
|
if (FLAG_trace_deopt && type != OSR) {
|
2011-06-29 13:02:00 +00:00
|
|
|
if (type == DEBUGGER) {
|
|
|
|
PrintF("**** DEOPT FOR DEBUGGER: ");
|
|
|
|
} else {
|
|
|
|
PrintF("**** DEOPT: ");
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
function->PrintName();
|
|
|
|
PrintF(" at bailout #%u, address 0x%" V8PRIxPTR ", frame size %d\n",
|
|
|
|
bailout_id,
|
|
|
|
reinterpret_cast<intptr_t>(from),
|
|
|
|
fp_to_sp_delta - (2 * kPointerSize));
|
|
|
|
} else if (FLAG_trace_osr && type == OSR) {
|
|
|
|
PrintF("**** OSR: ");
|
|
|
|
function->PrintName();
|
|
|
|
PrintF(" at ast id #%u, address 0x%" V8PRIxPTR ", frame size %d\n",
|
|
|
|
bailout_id,
|
|
|
|
reinterpret_cast<intptr_t>(from),
|
|
|
|
fp_to_sp_delta - (2 * kPointerSize));
|
|
|
|
}
|
2012-06-11 16:57:27 +00:00
|
|
|
function->shared()->increment_deopt_count();
|
2010-12-07 11:31:57 +00:00
|
|
|
// Find the optimized code.
|
|
|
|
if (type == EAGER) {
|
|
|
|
ASSERT(from == NULL);
|
|
|
|
optimized_code_ = function_->code();
|
2011-09-23 12:13:27 +00:00
|
|
|
if (FLAG_trace_deopt && FLAG_code_comments) {
|
|
|
|
// Print instruction associated with this bailout.
|
|
|
|
const char* last_comment = NULL;
|
|
|
|
int mask = RelocInfo::ModeMask(RelocInfo::COMMENT)
|
|
|
|
| RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY);
|
|
|
|
for (RelocIterator it(optimized_code_, mask); !it.done(); it.next()) {
|
|
|
|
RelocInfo* info = it.rinfo();
|
|
|
|
if (info->rmode() == RelocInfo::COMMENT) {
|
|
|
|
last_comment = reinterpret_cast<const char*>(info->data());
|
|
|
|
}
|
|
|
|
if (info->rmode() == RelocInfo::RUNTIME_ENTRY) {
|
|
|
|
unsigned id = Deoptimizer::GetDeoptimizationId(
|
|
|
|
info->target_address(), Deoptimizer::EAGER);
|
|
|
|
if (id == bailout_id && last_comment != NULL) {
|
|
|
|
PrintF(" %s\n", last_comment);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
} else if (type == LAZY) {
|
|
|
|
optimized_code_ = FindDeoptimizingCodeFromAddress(from);
|
|
|
|
ASSERT(optimized_code_ != NULL);
|
|
|
|
} else if (type == OSR) {
|
|
|
|
// The function has already been optimized and we're transitioning
|
|
|
|
// from the unoptimized shared version to the optimized one in the
|
|
|
|
// function. The return address (from) points to unoptimized code.
|
|
|
|
optimized_code_ = function_->code();
|
|
|
|
ASSERT(optimized_code_->kind() == Code::OPTIMIZED_FUNCTION);
|
|
|
|
ASSERT(!optimized_code_->contains(from));
|
2011-06-29 13:02:00 +00:00
|
|
|
} else if (type == DEBUGGER) {
|
|
|
|
optimized_code_ = optimized_code;
|
|
|
|
ASSERT(optimized_code_->contains(from));
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
ASSERT(HEAP->allow_allocation(false));
|
2010-12-07 11:31:57 +00:00
|
|
|
unsigned size = ComputeInputFrameSize();
|
|
|
|
input_ = new(size) FrameDescription(size, function);
|
2012-01-24 08:43:12 +00:00
|
|
|
input_->SetFrameType(StackFrame::JAVA_SCRIPT);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Deoptimizer::~Deoptimizer() {
|
|
|
|
ASSERT(input_ == NULL && output_ == NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Deoptimizer::DeleteFrameDescriptions() {
|
|
|
|
delete input_;
|
|
|
|
for (int i = 0; i < output_count_; ++i) {
|
|
|
|
if (output_[i] != input_) delete output_[i];
|
|
|
|
}
|
|
|
|
delete[] output_;
|
|
|
|
input_ = NULL;
|
|
|
|
output_ = NULL;
|
2011-03-18 20:35:07 +00:00
|
|
|
ASSERT(!HEAP->allow_allocation(true));
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Address Deoptimizer::GetDeoptimizationEntry(int id, BailoutType type) {
|
|
|
|
ASSERT(id >= 0);
|
|
|
|
if (id >= kNumberOfEntries) return NULL;
|
2011-09-19 18:36:47 +00:00
|
|
|
MemoryChunk* base = NULL;
|
2011-03-18 20:35:07 +00:00
|
|
|
DeoptimizerData* data = Isolate::Current()->deoptimizer_data();
|
2010-12-07 11:31:57 +00:00
|
|
|
if (type == EAGER) {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (data->eager_deoptimization_entry_code_ == NULL) {
|
|
|
|
data->eager_deoptimization_entry_code_ = CreateCode(type);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
base = data->eager_deoptimization_entry_code_;
|
2010-12-07 11:31:57 +00:00
|
|
|
} else {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (data->lazy_deoptimization_entry_code_ == NULL) {
|
|
|
|
data->lazy_deoptimization_entry_code_ = CreateCode(type);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
base = data->lazy_deoptimization_entry_code_;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
return
|
2012-02-23 12:11:24 +00:00
|
|
|
static_cast<Address>(base->area_start()) + (id * table_entry_size_);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Deoptimizer::GetDeoptimizationId(Address addr, BailoutType type) {
|
2011-09-19 18:36:47 +00:00
|
|
|
MemoryChunk* base = NULL;
|
2011-03-18 20:35:07 +00:00
|
|
|
DeoptimizerData* data = Isolate::Current()->deoptimizer_data();
|
2010-12-07 11:31:57 +00:00
|
|
|
if (type == EAGER) {
|
2011-03-18 20:35:07 +00:00
|
|
|
base = data->eager_deoptimization_entry_code_;
|
2010-12-07 11:31:57 +00:00
|
|
|
} else {
|
2011-03-18 20:35:07 +00:00
|
|
|
base = data->lazy_deoptimization_entry_code_;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
if (base == NULL ||
|
2012-02-23 12:11:24 +00:00
|
|
|
addr < base->area_start() ||
|
|
|
|
addr >= base->area_start() +
|
2010-12-07 11:31:57 +00:00
|
|
|
(kNumberOfEntries * table_entry_size_)) {
|
|
|
|
return kNotDeoptimizationEntry;
|
|
|
|
}
|
|
|
|
ASSERT_EQ(0,
|
2012-02-23 12:11:24 +00:00
|
|
|
static_cast<int>(addr - base->area_start()) % table_entry_size_);
|
|
|
|
return static_cast<int>(addr - base->area_start()) / table_entry_size_;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-22 09:49:26 +00:00
|
|
|
int Deoptimizer::GetOutputInfo(DeoptimizationOutputData* data,
|
|
|
|
unsigned id,
|
|
|
|
SharedFunctionInfo* shared) {
|
2010-12-07 11:31:57 +00:00
|
|
|
// TODO(kasperl): For now, we do a simple linear search for the PC
|
|
|
|
// offset associated with the given node id. This should probably be
|
|
|
|
// changed to a binary search.
|
|
|
|
int length = data->DeoptPoints();
|
|
|
|
Smi* smi_id = Smi::FromInt(id);
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
if (data->AstId(i) == smi_id) {
|
|
|
|
return data->PcAndState(i)->value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PrintF("[couldn't find pc offset for node=%u]\n", id);
|
|
|
|
PrintF("[method: %s]\n", *shared->DebugName()->ToCString());
|
|
|
|
// Print the source code if available.
|
|
|
|
HeapStringAllocator string_allocator;
|
|
|
|
StringStream stream(&string_allocator);
|
|
|
|
shared->SourceCodePrint(&stream, -1);
|
|
|
|
PrintF("[source:\n%s\n]", *stream.ToCString());
|
|
|
|
|
|
|
|
UNREACHABLE();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
int Deoptimizer::GetDeoptimizedCodeCount(Isolate* isolate) {
|
2010-12-07 11:31:57 +00:00
|
|
|
int length = 0;
|
2011-03-18 20:35:07 +00:00
|
|
|
DeoptimizingCodeListNode* node =
|
|
|
|
isolate->deoptimizer_data()->deoptimizing_code_list_;
|
2010-12-07 11:31:57 +00:00
|
|
|
while (node != NULL) {
|
|
|
|
length++;
|
|
|
|
node = node->next();
|
|
|
|
}
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-15 11:30:45 +00:00
|
|
|
// We rely on this function not causing a GC. It is called from generated code
|
|
|
|
// without having a real stack frame in place.
|
2010-12-07 11:31:57 +00:00
|
|
|
void Deoptimizer::DoComputeOutputFrames() {
|
|
|
|
if (bailout_type_ == OSR) {
|
|
|
|
DoComputeOsrOutputFrame();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print some helpful diagnostic information.
|
|
|
|
int64_t start = OS::Ticks();
|
|
|
|
if (FLAG_trace_deopt) {
|
|
|
|
PrintF("[deoptimizing%s: begin 0x%08" V8PRIxPTR " ",
|
|
|
|
(bailout_type_ == LAZY ? " (lazy)" : ""),
|
|
|
|
reinterpret_cast<intptr_t>(function_));
|
|
|
|
function_->PrintName();
|
|
|
|
PrintF(" @%d]\n", bailout_id_);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine basic deoptimization information. The optimized frame is
|
|
|
|
// described by the input data.
|
|
|
|
DeoptimizationInputData* input_data =
|
|
|
|
DeoptimizationInputData::cast(optimized_code_->deoptimization_data());
|
|
|
|
unsigned node_id = input_data->AstId(bailout_id_)->value();
|
|
|
|
ByteArray* translations = input_data->TranslationByteArray();
|
|
|
|
unsigned translation_index =
|
|
|
|
input_data->TranslationIndex(bailout_id_)->value();
|
|
|
|
|
|
|
|
// Do the input frame to output frame(s) translation.
|
|
|
|
TranslationIterator iterator(translations, translation_index);
|
|
|
|
Translation::Opcode opcode =
|
|
|
|
static_cast<Translation::Opcode>(iterator.Next());
|
|
|
|
ASSERT(Translation::BEGIN == opcode);
|
|
|
|
USE(opcode);
|
|
|
|
// Read the number of output frames and allocate an array for their
|
|
|
|
// descriptions.
|
|
|
|
int count = iterator.Next();
|
2012-01-24 08:43:12 +00:00
|
|
|
iterator.Next(); // Drop JS frames count.
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(output_ == NULL);
|
|
|
|
output_ = new FrameDescription*[count];
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
output_[i] = NULL;
|
|
|
|
}
|
|
|
|
output_count_ = count;
|
|
|
|
|
|
|
|
// Translate each output frame.
|
|
|
|
for (int i = 0; i < count; ++i) {
|
2012-01-24 08:43:12 +00:00
|
|
|
// Read the ast node id, function, and frame height for this output frame.
|
|
|
|
Translation::Opcode opcode =
|
|
|
|
static_cast<Translation::Opcode>(iterator.Next());
|
|
|
|
switch (opcode) {
|
|
|
|
case Translation::JS_FRAME:
|
|
|
|
DoComputeJSFrame(&iterator, i);
|
|
|
|
jsframe_count_++;
|
|
|
|
break;
|
|
|
|
case Translation::ARGUMENTS_ADAPTOR_FRAME:
|
|
|
|
DoComputeArgumentsAdaptorFrame(&iterator, i);
|
|
|
|
break;
|
2012-02-28 09:05:55 +00:00
|
|
|
case Translation::CONSTRUCT_STUB_FRAME:
|
|
|
|
DoComputeConstructStubFrame(&iterator, i);
|
|
|
|
break;
|
2012-01-24 08:43:12 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Print some helpful diagnostic information.
|
|
|
|
if (FLAG_trace_deopt) {
|
|
|
|
double ms = static_cast<double>(OS::Ticks() - start) / 1000;
|
|
|
|
int index = output_count_ - 1; // Index of the topmost frame.
|
|
|
|
JSFunction* function = output_[index]->GetFunction();
|
|
|
|
PrintF("[deoptimizing: end 0x%08" V8PRIxPTR " ",
|
|
|
|
reinterpret_cast<intptr_t>(function));
|
|
|
|
function->PrintName();
|
2012-06-12 10:22:33 +00:00
|
|
|
PrintF(" => node=%u, pc=0x%08" V8PRIxPTR ", state=%s, alignment=%s,"
|
|
|
|
" took %0.3f ms]\n",
|
2010-12-07 11:31:57 +00:00
|
|
|
node_id,
|
|
|
|
output_[index]->GetPc(),
|
|
|
|
FullCodeGenerator::State2String(
|
|
|
|
static_cast<FullCodeGenerator::State>(
|
|
|
|
output_[index]->GetState()->value())),
|
2012-06-12 10:22:33 +00:00
|
|
|
has_alignment_padding_ ? "with padding" : "no padding",
|
2010-12-07 11:31:57 +00:00
|
|
|
ms);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-06 14:23:27 +00:00
|
|
|
void Deoptimizer::MaterializeHeapNumbers() {
|
2011-06-29 13:02:00 +00:00
|
|
|
ASSERT_NE(DEBUGGER, bailout_type_);
|
2011-04-06 14:23:27 +00:00
|
|
|
for (int i = 0; i < deferred_heap_numbers_.length(); i++) {
|
|
|
|
HeapNumberMaterializationDescriptor d = deferred_heap_numbers_[i];
|
|
|
|
Handle<Object> num = isolate_->factory()->NewNumber(d.value());
|
|
|
|
if (FLAG_trace_deopt) {
|
|
|
|
PrintF("Materializing a new heap number %p [%e] in slot %p\n",
|
|
|
|
reinterpret_cast<void*>(*num),
|
|
|
|
d.value(),
|
|
|
|
d.slot_address());
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-04-06 14:23:27 +00:00
|
|
|
Memory::Object_at(d.slot_address()) = *num;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-29 13:02:00 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
|
|
|
void Deoptimizer::MaterializeHeapNumbersForDebuggerInspectableFrame(
|
2012-01-24 08:43:12 +00:00
|
|
|
Address parameters_top,
|
|
|
|
uint32_t parameters_size,
|
|
|
|
Address expressions_top,
|
|
|
|
uint32_t expressions_size,
|
|
|
|
DeoptimizedFrameInfo* info) {
|
2011-06-29 13:02:00 +00:00
|
|
|
ASSERT_EQ(DEBUGGER, bailout_type_);
|
2012-01-24 08:43:12 +00:00
|
|
|
Address parameters_bottom = parameters_top + parameters_size;
|
|
|
|
Address expressions_bottom = expressions_top + expressions_size;
|
2011-06-29 13:02:00 +00:00
|
|
|
for (int i = 0; i < deferred_heap_numbers_.length(); i++) {
|
|
|
|
HeapNumberMaterializationDescriptor d = deferred_heap_numbers_[i];
|
|
|
|
|
|
|
|
// Check of the heap number to materialize actually belong to the frame
|
|
|
|
// being extracted.
|
|
|
|
Address slot = d.slot_address();
|
2012-01-24 08:43:12 +00:00
|
|
|
if (parameters_top <= slot && slot < parameters_bottom) {
|
2011-06-29 13:02:00 +00:00
|
|
|
Handle<Object> num = isolate_->factory()->NewNumber(d.value());
|
2012-01-24 08:43:12 +00:00
|
|
|
|
|
|
|
int index = (info->parameters_count() - 1) -
|
2012-01-24 09:05:15 +00:00
|
|
|
static_cast<int>(slot - parameters_top) / kPointerSize;
|
2012-01-24 08:43:12 +00:00
|
|
|
|
2011-06-29 13:02:00 +00:00
|
|
|
if (FLAG_trace_deopt) {
|
|
|
|
PrintF("Materializing a new heap number %p [%e] in slot %p"
|
2012-01-24 08:43:12 +00:00
|
|
|
"for parameter slot #%d\n",
|
2011-06-29 13:02:00 +00:00
|
|
|
reinterpret_cast<void*>(*num),
|
|
|
|
d.value(),
|
|
|
|
d.slot_address(),
|
2011-07-07 14:29:16 +00:00
|
|
|
index);
|
|
|
|
}
|
2012-01-24 08:43:12 +00:00
|
|
|
|
|
|
|
info->SetParameter(index, *num);
|
|
|
|
} else if (expressions_top <= slot && slot < expressions_bottom) {
|
|
|
|
Handle<Object> num = isolate_->factory()->NewNumber(d.value());
|
|
|
|
|
|
|
|
int index = info->expression_count() - 1 -
|
2012-01-24 09:05:15 +00:00
|
|
|
static_cast<int>(slot - expressions_top) / kPointerSize;
|
2012-01-24 08:43:12 +00:00
|
|
|
|
|
|
|
if (FLAG_trace_deopt) {
|
|
|
|
PrintF("Materializing a new heap number %p [%e] in slot %p"
|
|
|
|
"for expression slot #%d\n",
|
|
|
|
reinterpret_cast<void*>(*num),
|
|
|
|
d.value(),
|
|
|
|
d.slot_address(),
|
|
|
|
index);
|
2011-06-29 13:02:00 +00:00
|
|
|
}
|
2012-01-24 08:43:12 +00:00
|
|
|
|
|
|
|
info->SetExpression(index, *num);
|
2011-06-29 13:02:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void Deoptimizer::DoTranslateCommand(TranslationIterator* iterator,
|
|
|
|
int frame_index,
|
|
|
|
unsigned output_offset) {
|
|
|
|
disasm::NameConverter converter;
|
|
|
|
// A GC-safe temporary placeholder that we can put in the output frame.
|
|
|
|
const intptr_t kPlaceholder = reinterpret_cast<intptr_t>(Smi::FromInt(0));
|
|
|
|
|
|
|
|
// Ignore commands marked as duplicate and act on the first non-duplicate.
|
|
|
|
Translation::Opcode opcode =
|
|
|
|
static_cast<Translation::Opcode>(iterator->Next());
|
|
|
|
while (opcode == Translation::DUPLICATE) {
|
|
|
|
opcode = static_cast<Translation::Opcode>(iterator->Next());
|
|
|
|
iterator->Skip(Translation::NumberOfOperandsFor(opcode));
|
|
|
|
opcode = static_cast<Translation::Opcode>(iterator->Next());
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (opcode) {
|
|
|
|
case Translation::BEGIN:
|
2012-01-24 08:43:12 +00:00
|
|
|
case Translation::JS_FRAME:
|
|
|
|
case Translation::ARGUMENTS_ADAPTOR_FRAME:
|
2012-02-28 09:05:55 +00:00
|
|
|
case Translation::CONSTRUCT_STUB_FRAME:
|
2010-12-07 11:31:57 +00:00
|
|
|
case Translation::DUPLICATE:
|
|
|
|
UNREACHABLE();
|
|
|
|
return;
|
|
|
|
|
|
|
|
case Translation::REGISTER: {
|
|
|
|
int input_reg = iterator->Next();
|
2010-12-07 11:53:19 +00:00
|
|
|
intptr_t input_value = input_->GetRegister(input_reg);
|
2010-12-07 11:31:57 +00:00
|
|
|
if (FLAG_trace_deopt) {
|
2010-12-07 11:53:19 +00:00
|
|
|
PrintF(
|
2011-09-20 07:14:30 +00:00
|
|
|
" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" V8PRIxPTR " ; %s ",
|
2010-12-07 11:53:19 +00:00
|
|
|
output_[frame_index]->GetTop() + output_offset,
|
|
|
|
output_offset,
|
|
|
|
input_value,
|
|
|
|
converter.NameOfCPURegister(input_reg));
|
2011-09-20 07:14:30 +00:00
|
|
|
reinterpret_cast<Object*>(input_value)->ShortPrint();
|
|
|
|
PrintF("\n");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
output_[frame_index]->SetFrameSlot(output_offset, input_value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Translation::INT32_REGISTER: {
|
|
|
|
int input_reg = iterator->Next();
|
2010-12-07 11:53:19 +00:00
|
|
|
intptr_t value = input_->GetRegister(input_reg);
|
2010-12-07 11:31:57 +00:00
|
|
|
bool is_smi = Smi::IsValid(value);
|
|
|
|
if (FLAG_trace_deopt) {
|
2010-12-07 11:53:19 +00:00
|
|
|
PrintF(
|
|
|
|
" 0x%08" V8PRIxPTR ": [top + %d] <- %" V8PRIdPTR " ; %s (%s)\n",
|
|
|
|
output_[frame_index]->GetTop() + output_offset,
|
|
|
|
output_offset,
|
|
|
|
value,
|
|
|
|
converter.NameOfCPURegister(input_reg),
|
|
|
|
is_smi ? "smi" : "heap number");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
if (is_smi) {
|
|
|
|
intptr_t tagged_value =
|
2010-12-07 11:53:19 +00:00
|
|
|
reinterpret_cast<intptr_t>(Smi::FromInt(static_cast<int>(value)));
|
2010-12-07 11:31:57 +00:00
|
|
|
output_[frame_index]->SetFrameSlot(output_offset, tagged_value);
|
|
|
|
} else {
|
|
|
|
// We save the untagged value on the side and store a GC-safe
|
|
|
|
// temporary placeholder in the frame.
|
2011-04-06 14:23:27 +00:00
|
|
|
AddDoubleValue(output_[frame_index]->GetTop() + output_offset,
|
|
|
|
static_cast<double>(static_cast<int32_t>(value)));
|
2010-12-07 11:31:57 +00:00
|
|
|
output_[frame_index]->SetFrameSlot(output_offset, kPlaceholder);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Translation::DOUBLE_REGISTER: {
|
|
|
|
int input_reg = iterator->Next();
|
|
|
|
double value = input_->GetDoubleRegister(input_reg);
|
|
|
|
if (FLAG_trace_deopt) {
|
2010-12-07 11:53:19 +00:00
|
|
|
PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- %e ; %s\n",
|
2010-12-07 11:31:57 +00:00
|
|
|
output_[frame_index]->GetTop() + output_offset,
|
|
|
|
output_offset,
|
|
|
|
value,
|
|
|
|
DoubleRegister::AllocationIndexToString(input_reg));
|
|
|
|
}
|
|
|
|
// We save the untagged value on the side and store a GC-safe
|
|
|
|
// temporary placeholder in the frame.
|
2011-04-06 14:23:27 +00:00
|
|
|
AddDoubleValue(output_[frame_index]->GetTop() + output_offset, value);
|
2010-12-07 11:31:57 +00:00
|
|
|
output_[frame_index]->SetFrameSlot(output_offset, kPlaceholder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Translation::STACK_SLOT: {
|
|
|
|
int input_slot_index = iterator->Next();
|
|
|
|
unsigned input_offset =
|
2012-01-24 08:43:12 +00:00
|
|
|
input_->GetOffsetFromSlotIndex(input_slot_index);
|
2010-12-07 11:53:19 +00:00
|
|
|
intptr_t input_value = input_->GetFrameSlot(input_offset);
|
2010-12-07 11:31:57 +00:00
|
|
|
if (FLAG_trace_deopt) {
|
2010-12-07 11:53:19 +00:00
|
|
|
PrintF(" 0x%08" V8PRIxPTR ": ",
|
|
|
|
output_[frame_index]->GetTop() + output_offset);
|
2012-06-12 10:22:33 +00:00
|
|
|
PrintF("[top + %d] <- 0x%08" V8PRIxPTR " ; [sp + %d] ",
|
2010-12-07 11:31:57 +00:00
|
|
|
output_offset,
|
|
|
|
input_value,
|
|
|
|
input_offset);
|
2011-09-20 07:14:30 +00:00
|
|
|
reinterpret_cast<Object*>(input_value)->ShortPrint();
|
|
|
|
PrintF("\n");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
output_[frame_index]->SetFrameSlot(output_offset, input_value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Translation::INT32_STACK_SLOT: {
|
|
|
|
int input_slot_index = iterator->Next();
|
|
|
|
unsigned input_offset =
|
2012-01-24 08:43:12 +00:00
|
|
|
input_->GetOffsetFromSlotIndex(input_slot_index);
|
2010-12-07 11:53:19 +00:00
|
|
|
intptr_t value = input_->GetFrameSlot(input_offset);
|
2010-12-07 11:31:57 +00:00
|
|
|
bool is_smi = Smi::IsValid(value);
|
|
|
|
if (FLAG_trace_deopt) {
|
2010-12-07 11:53:19 +00:00
|
|
|
PrintF(" 0x%08" V8PRIxPTR ": ",
|
|
|
|
output_[frame_index]->GetTop() + output_offset);
|
2012-06-12 10:22:33 +00:00
|
|
|
PrintF("[top + %d] <- %" V8PRIdPTR " ; [sp + %d] (%s)\n",
|
2010-12-07 11:31:57 +00:00
|
|
|
output_offset,
|
|
|
|
value,
|
|
|
|
input_offset,
|
|
|
|
is_smi ? "smi" : "heap number");
|
|
|
|
}
|
|
|
|
if (is_smi) {
|
|
|
|
intptr_t tagged_value =
|
2010-12-07 11:53:19 +00:00
|
|
|
reinterpret_cast<intptr_t>(Smi::FromInt(static_cast<int>(value)));
|
2010-12-07 11:31:57 +00:00
|
|
|
output_[frame_index]->SetFrameSlot(output_offset, tagged_value);
|
|
|
|
} else {
|
|
|
|
// We save the untagged value on the side and store a GC-safe
|
|
|
|
// temporary placeholder in the frame.
|
2011-04-06 14:23:27 +00:00
|
|
|
AddDoubleValue(output_[frame_index]->GetTop() + output_offset,
|
|
|
|
static_cast<double>(static_cast<int32_t>(value)));
|
2010-12-07 11:31:57 +00:00
|
|
|
output_[frame_index]->SetFrameSlot(output_offset, kPlaceholder);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Translation::DOUBLE_STACK_SLOT: {
|
|
|
|
int input_slot_index = iterator->Next();
|
|
|
|
unsigned input_offset =
|
2012-01-24 08:43:12 +00:00
|
|
|
input_->GetOffsetFromSlotIndex(input_slot_index);
|
2010-12-07 11:31:57 +00:00
|
|
|
double value = input_->GetDoubleFrameSlot(input_offset);
|
|
|
|
if (FLAG_trace_deopt) {
|
2012-06-12 10:22:33 +00:00
|
|
|
PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- %e ; [sp + %d]\n",
|
2010-12-07 11:31:57 +00:00
|
|
|
output_[frame_index]->GetTop() + output_offset,
|
|
|
|
output_offset,
|
|
|
|
value,
|
|
|
|
input_offset);
|
|
|
|
}
|
|
|
|
// We save the untagged value on the side and store a GC-safe
|
|
|
|
// temporary placeholder in the frame.
|
2011-04-06 14:23:27 +00:00
|
|
|
AddDoubleValue(output_[frame_index]->GetTop() + output_offset, value);
|
2010-12-07 11:31:57 +00:00
|
|
|
output_[frame_index]->SetFrameSlot(output_offset, kPlaceholder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Translation::LITERAL: {
|
|
|
|
Object* literal = ComputeLiteral(iterator->Next());
|
|
|
|
if (FLAG_trace_deopt) {
|
2010-12-07 11:53:19 +00:00
|
|
|
PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- ",
|
2010-12-07 11:31:57 +00:00
|
|
|
output_[frame_index]->GetTop() + output_offset,
|
|
|
|
output_offset);
|
|
|
|
literal->ShortPrint();
|
|
|
|
PrintF(" ; literal\n");
|
|
|
|
}
|
|
|
|
intptr_t value = reinterpret_cast<intptr_t>(literal);
|
|
|
|
output_[frame_index]->SetFrameSlot(output_offset, value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Translation::ARGUMENTS_OBJECT: {
|
2011-01-06 15:53:56 +00:00
|
|
|
// Use the arguments marker value as a sentinel and fill in the arguments
|
|
|
|
// object after the deoptimized frame is built.
|
2010-12-07 11:31:57 +00:00
|
|
|
if (FLAG_trace_deopt) {
|
2010-12-07 11:53:19 +00:00
|
|
|
PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- ",
|
2010-12-07 11:31:57 +00:00
|
|
|
output_[frame_index]->GetTop() + output_offset,
|
|
|
|
output_offset);
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate_->heap()->arguments_marker()->ShortPrint();
|
2010-12-07 11:31:57 +00:00
|
|
|
PrintF(" ; arguments object\n");
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
intptr_t value = reinterpret_cast<intptr_t>(
|
|
|
|
isolate_->heap()->arguments_marker());
|
2010-12-07 11:31:57 +00:00
|
|
|
output_[frame_index]->SetFrameSlot(output_offset, value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Deoptimizer::DoOsrTranslateCommand(TranslationIterator* iterator,
|
|
|
|
int* input_offset) {
|
|
|
|
disasm::NameConverter converter;
|
|
|
|
FrameDescription* output = output_[0];
|
|
|
|
|
|
|
|
// The input values are all part of the unoptimized frame so they
|
|
|
|
// are all tagged pointers.
|
2010-12-07 11:53:19 +00:00
|
|
|
uintptr_t input_value = input_->GetFrameSlot(*input_offset);
|
2010-12-07 11:31:57 +00:00
|
|
|
Object* input_object = reinterpret_cast<Object*>(input_value);
|
|
|
|
|
|
|
|
Translation::Opcode opcode =
|
|
|
|
static_cast<Translation::Opcode>(iterator->Next());
|
|
|
|
bool duplicate = (opcode == Translation::DUPLICATE);
|
|
|
|
if (duplicate) {
|
|
|
|
opcode = static_cast<Translation::Opcode>(iterator->Next());
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (opcode) {
|
|
|
|
case Translation::BEGIN:
|
2012-01-24 08:43:12 +00:00
|
|
|
case Translation::JS_FRAME:
|
|
|
|
case Translation::ARGUMENTS_ADAPTOR_FRAME:
|
2012-02-28 09:05:55 +00:00
|
|
|
case Translation::CONSTRUCT_STUB_FRAME:
|
2010-12-07 11:31:57 +00:00
|
|
|
case Translation::DUPLICATE:
|
|
|
|
UNREACHABLE(); // Malformed input.
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case Translation::REGISTER: {
|
|
|
|
int output_reg = iterator->Next();
|
|
|
|
if (FLAG_trace_osr) {
|
2011-02-13 10:24:39 +00:00
|
|
|
PrintF(" %s <- 0x%08" V8PRIxPTR " ; [sp + %d]\n",
|
2010-12-07 11:31:57 +00:00
|
|
|
converter.NameOfCPURegister(output_reg),
|
|
|
|
input_value,
|
|
|
|
*input_offset);
|
|
|
|
}
|
|
|
|
output->SetRegister(output_reg, input_value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Translation::INT32_REGISTER: {
|
|
|
|
// Abort OSR if we don't have a number.
|
|
|
|
if (!input_object->IsNumber()) return false;
|
|
|
|
|
|
|
|
int output_reg = iterator->Next();
|
|
|
|
int int32_value = input_object->IsSmi()
|
|
|
|
? Smi::cast(input_object)->value()
|
|
|
|
: FastD2I(input_object->Number());
|
|
|
|
// Abort the translation if the conversion lost information.
|
|
|
|
if (!input_object->IsSmi() &&
|
|
|
|
FastI2D(int32_value) != input_object->Number()) {
|
|
|
|
if (FLAG_trace_osr) {
|
|
|
|
PrintF("**** %g could not be converted to int32 ****\n",
|
|
|
|
input_object->Number());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (FLAG_trace_osr) {
|
2011-02-13 10:24:39 +00:00
|
|
|
PrintF(" %s <- %d (int32) ; [sp + %d]\n",
|
2010-12-07 11:31:57 +00:00
|
|
|
converter.NameOfCPURegister(output_reg),
|
|
|
|
int32_value,
|
|
|
|
*input_offset);
|
|
|
|
}
|
|
|
|
output->SetRegister(output_reg, int32_value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Translation::DOUBLE_REGISTER: {
|
|
|
|
// Abort OSR if we don't have a number.
|
|
|
|
if (!input_object->IsNumber()) return false;
|
|
|
|
|
|
|
|
int output_reg = iterator->Next();
|
|
|
|
double double_value = input_object->Number();
|
|
|
|
if (FLAG_trace_osr) {
|
2011-02-13 10:24:39 +00:00
|
|
|
PrintF(" %s <- %g (double) ; [sp + %d]\n",
|
2010-12-07 11:31:57 +00:00
|
|
|
DoubleRegister::AllocationIndexToString(output_reg),
|
|
|
|
double_value,
|
|
|
|
*input_offset);
|
|
|
|
}
|
|
|
|
output->SetDoubleRegister(output_reg, double_value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Translation::STACK_SLOT: {
|
|
|
|
int output_index = iterator->Next();
|
|
|
|
unsigned output_offset =
|
2012-01-24 08:43:12 +00:00
|
|
|
output->GetOffsetFromSlotIndex(output_index);
|
2010-12-07 11:31:57 +00:00
|
|
|
if (FLAG_trace_osr) {
|
2011-10-24 13:53:08 +00:00
|
|
|
PrintF(" [sp + %d] <- 0x%08" V8PRIxPTR " ; [sp + %d] ",
|
2010-12-07 11:31:57 +00:00
|
|
|
output_offset,
|
|
|
|
input_value,
|
|
|
|
*input_offset);
|
2011-10-24 13:53:08 +00:00
|
|
|
reinterpret_cast<Object*>(input_value)->ShortPrint();
|
|
|
|
PrintF("\n");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
output->SetFrameSlot(output_offset, input_value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Translation::INT32_STACK_SLOT: {
|
|
|
|
// Abort OSR if we don't have a number.
|
|
|
|
if (!input_object->IsNumber()) return false;
|
|
|
|
|
|
|
|
int output_index = iterator->Next();
|
|
|
|
unsigned output_offset =
|
2012-01-24 08:43:12 +00:00
|
|
|
output->GetOffsetFromSlotIndex(output_index);
|
2010-12-07 11:31:57 +00:00
|
|
|
int int32_value = input_object->IsSmi()
|
|
|
|
? Smi::cast(input_object)->value()
|
|
|
|
: DoubleToInt32(input_object->Number());
|
|
|
|
// Abort the translation if the conversion lost information.
|
|
|
|
if (!input_object->IsSmi() &&
|
|
|
|
FastI2D(int32_value) != input_object->Number()) {
|
|
|
|
if (FLAG_trace_osr) {
|
|
|
|
PrintF("**** %g could not be converted to int32 ****\n",
|
|
|
|
input_object->Number());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (FLAG_trace_osr) {
|
2011-02-13 10:24:39 +00:00
|
|
|
PrintF(" [sp + %d] <- %d (int32) ; [sp + %d]\n",
|
2010-12-07 11:31:57 +00:00
|
|
|
output_offset,
|
|
|
|
int32_value,
|
|
|
|
*input_offset);
|
|
|
|
}
|
|
|
|
output->SetFrameSlot(output_offset, int32_value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Translation::DOUBLE_STACK_SLOT: {
|
|
|
|
static const int kLowerOffset = 0 * kPointerSize;
|
|
|
|
static const int kUpperOffset = 1 * kPointerSize;
|
|
|
|
|
|
|
|
// Abort OSR if we don't have a number.
|
|
|
|
if (!input_object->IsNumber()) return false;
|
|
|
|
|
|
|
|
int output_index = iterator->Next();
|
|
|
|
unsigned output_offset =
|
2012-01-24 08:43:12 +00:00
|
|
|
output->GetOffsetFromSlotIndex(output_index);
|
2010-12-07 11:31:57 +00:00
|
|
|
double double_value = input_object->Number();
|
|
|
|
uint64_t int_value = BitCast<uint64_t, double>(double_value);
|
|
|
|
int32_t lower = static_cast<int32_t>(int_value);
|
|
|
|
int32_t upper = static_cast<int32_t>(int_value >> kBitsPerInt);
|
|
|
|
if (FLAG_trace_osr) {
|
2011-02-13 10:24:39 +00:00
|
|
|
PrintF(" [sp + %d] <- 0x%08x (upper bits of %g) ; [sp + %d]\n",
|
2010-12-07 11:31:57 +00:00
|
|
|
output_offset + kUpperOffset,
|
|
|
|
upper,
|
|
|
|
double_value,
|
|
|
|
*input_offset);
|
2011-02-13 10:24:39 +00:00
|
|
|
PrintF(" [sp + %d] <- 0x%08x (lower bits of %g) ; [sp + %d]\n",
|
2010-12-07 11:31:57 +00:00
|
|
|
output_offset + kLowerOffset,
|
|
|
|
lower,
|
|
|
|
double_value,
|
|
|
|
*input_offset);
|
|
|
|
}
|
|
|
|
output->SetFrameSlot(output_offset + kLowerOffset, lower);
|
|
|
|
output->SetFrameSlot(output_offset + kUpperOffset, upper);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Translation::LITERAL: {
|
|
|
|
// Just ignore non-materialized literals.
|
|
|
|
iterator->Next();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Translation::ARGUMENTS_OBJECT: {
|
|
|
|
// Optimized code assumes that the argument object has not been
|
|
|
|
// materialized and so bypasses it when doing arguments access.
|
|
|
|
// We should have bailed out before starting the frame
|
|
|
|
// translation.
|
|
|
|
UNREACHABLE();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!duplicate) *input_offset -= kPointerSize;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-01 11:18:45 +00:00
|
|
|
void Deoptimizer::PatchStackCheckCode(Code* unoptimized_code,
|
|
|
|
Code* check_code,
|
|
|
|
Code* replacement_code) {
|
|
|
|
// Iterate over the stack check table and patch every stack check
|
|
|
|
// call to an unconditional call to the replacement code.
|
|
|
|
ASSERT(unoptimized_code->kind() == Code::FUNCTION);
|
|
|
|
Address stack_check_cursor = unoptimized_code->instruction_start() +
|
2011-02-03 10:07:22 +00:00
|
|
|
unoptimized_code->stack_check_table_offset();
|
2011-02-01 11:18:45 +00:00
|
|
|
uint32_t table_length = Memory::uint32_at(stack_check_cursor);
|
|
|
|
stack_check_cursor += kIntSize;
|
|
|
|
for (uint32_t i = 0; i < table_length; ++i) {
|
|
|
|
uint32_t pc_offset = Memory::uint32_at(stack_check_cursor + kIntSize);
|
|
|
|
Address pc_after = unoptimized_code->instruction_start() + pc_offset;
|
2011-09-19 18:36:47 +00:00
|
|
|
PatchStackCheckCodeAt(unoptimized_code,
|
|
|
|
pc_after,
|
|
|
|
check_code,
|
|
|
|
replacement_code);
|
2011-02-02 11:58:24 +00:00
|
|
|
stack_check_cursor += 2 * kIntSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Deoptimizer::RevertStackCheckCode(Code* unoptimized_code,
|
|
|
|
Code* check_code,
|
|
|
|
Code* replacement_code) {
|
|
|
|
// Iterate over the stack check table and revert the patched
|
|
|
|
// stack check calls.
|
|
|
|
ASSERT(unoptimized_code->kind() == Code::FUNCTION);
|
|
|
|
Address stack_check_cursor = unoptimized_code->instruction_start() +
|
2011-02-03 10:07:22 +00:00
|
|
|
unoptimized_code->stack_check_table_offset();
|
2011-02-02 11:58:24 +00:00
|
|
|
uint32_t table_length = Memory::uint32_at(stack_check_cursor);
|
|
|
|
stack_check_cursor += kIntSize;
|
|
|
|
for (uint32_t i = 0; i < table_length; ++i) {
|
|
|
|
uint32_t pc_offset = Memory::uint32_at(stack_check_cursor + kIntSize);
|
|
|
|
Address pc_after = unoptimized_code->instruction_start() + pc_offset;
|
2011-10-18 15:07:42 +00:00
|
|
|
RevertStackCheckCodeAt(unoptimized_code,
|
|
|
|
pc_after,
|
|
|
|
check_code,
|
|
|
|
replacement_code);
|
2011-02-01 11:18:45 +00:00
|
|
|
stack_check_cursor += 2 * kIntSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
unsigned Deoptimizer::ComputeInputFrameSize() const {
|
|
|
|
unsigned fixed_size = ComputeFixedSize(function_);
|
|
|
|
// The fp-to-sp delta already takes the context and the function
|
|
|
|
// into account so we have to avoid double counting them (-2).
|
|
|
|
unsigned result = fixed_size + fp_to_sp_delta_ - (2 * kPointerSize);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (bailout_type_ == OSR) {
|
|
|
|
// TODO(kasperl): It would be nice if we could verify that the
|
|
|
|
// size matches with the stack height we can compute based on the
|
|
|
|
// environment at the OSR entry. The code for that his built into
|
|
|
|
// the DoComputeOsrOutputFrame function for now.
|
|
|
|
} else {
|
|
|
|
unsigned stack_slots = optimized_code_->stack_slots();
|
|
|
|
unsigned outgoing_size = ComputeOutgoingArgumentSize();
|
|
|
|
ASSERT(result == fixed_size + (stack_slots * kPointerSize) + outgoing_size);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned Deoptimizer::ComputeFixedSize(JSFunction* function) const {
|
|
|
|
// The fixed part of the frame consists of the return address, frame
|
|
|
|
// pointer, function, context, and all the incoming arguments.
|
2012-01-24 08:43:12 +00:00
|
|
|
return ComputeIncomingArgumentSize(function) +
|
|
|
|
StandardFrameConstants::kFixedFrameSize;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned Deoptimizer::ComputeIncomingArgumentSize(JSFunction* function) const {
|
|
|
|
// The incoming arguments is the values for formal parameters and
|
|
|
|
// the receiver. Every slot contains a pointer.
|
|
|
|
unsigned arguments = function->shared()->formal_parameter_count() + 1;
|
|
|
|
return arguments * kPointerSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned Deoptimizer::ComputeOutgoingArgumentSize() const {
|
|
|
|
DeoptimizationInputData* data = DeoptimizationInputData::cast(
|
|
|
|
optimized_code_->deoptimization_data());
|
|
|
|
unsigned height = data->ArgumentsStackHeight(bailout_id_)->value();
|
|
|
|
return height * kPointerSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Object* Deoptimizer::ComputeLiteral(int index) const {
|
|
|
|
DeoptimizationInputData* data = DeoptimizationInputData::cast(
|
|
|
|
optimized_code_->deoptimization_data());
|
|
|
|
FixedArray* literals = data->LiteralArray();
|
|
|
|
return literals->get(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-06 14:23:27 +00:00
|
|
|
void Deoptimizer::AddDoubleValue(intptr_t slot_address,
|
2010-12-07 11:31:57 +00:00
|
|
|
double value) {
|
2011-04-06 14:23:27 +00:00
|
|
|
HeapNumberMaterializationDescriptor value_desc(
|
|
|
|
reinterpret_cast<Address>(slot_address), value);
|
|
|
|
deferred_heap_numbers_.Add(value_desc);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
MemoryChunk* Deoptimizer::CreateCode(BailoutType type) {
|
2010-12-07 11:31:57 +00:00
|
|
|
// We cannot run this if the serializer is enabled because this will
|
|
|
|
// cause us to emit relocation information for the external
|
|
|
|
// references. This is fine because the deoptimizer's code section
|
|
|
|
// isn't meant to be serialized at all.
|
|
|
|
ASSERT(!Serializer::enabled());
|
|
|
|
|
2011-04-01 14:46:30 +00:00
|
|
|
MacroAssembler masm(Isolate::Current(), NULL, 16 * KB);
|
2011-03-15 14:49:10 +00:00
|
|
|
masm.set_emit_debug_code(false);
|
2010-12-07 11:31:57 +00:00
|
|
|
GenerateDeoptimizationEntries(&masm, kNumberOfEntries, type);
|
|
|
|
CodeDesc desc;
|
|
|
|
masm.GetCode(&desc);
|
|
|
|
ASSERT(desc.reloc_size == 0);
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
MemoryChunk* chunk =
|
|
|
|
Isolate::Current()->memory_allocator()->AllocateChunk(desc.instr_size,
|
|
|
|
EXECUTABLE,
|
|
|
|
NULL);
|
2012-02-23 12:11:24 +00:00
|
|
|
ASSERT(chunk->area_size() >= desc.instr_size);
|
2011-06-03 10:11:10 +00:00
|
|
|
if (chunk == NULL) {
|
|
|
|
V8::FatalProcessOutOfMemory("Not enough memory for deoptimization table");
|
|
|
|
}
|
2012-02-23 12:11:24 +00:00
|
|
|
memcpy(chunk->area_start(), desc.buffer, desc.instr_size);
|
|
|
|
CPU::FlushICache(chunk->area_start(), desc.instr_size);
|
2010-12-07 11:31:57 +00:00
|
|
|
return chunk;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Code* Deoptimizer::FindDeoptimizingCodeFromAddress(Address addr) {
|
2011-03-18 20:35:07 +00:00
|
|
|
DeoptimizingCodeListNode* node =
|
|
|
|
Isolate::Current()->deoptimizer_data()->deoptimizing_code_list_;
|
2010-12-07 11:31:57 +00:00
|
|
|
while (node != NULL) {
|
|
|
|
if (node->code()->contains(addr)) return *node->code();
|
|
|
|
node = node->next();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Deoptimizer::RemoveDeoptimizingCode(Code* code) {
|
2011-03-18 20:35:07 +00:00
|
|
|
DeoptimizerData* data = Isolate::Current()->deoptimizer_data();
|
|
|
|
ASSERT(data->deoptimizing_code_list_ != NULL);
|
2010-12-07 11:31:57 +00:00
|
|
|
// Run through the code objects to find this one and remove it.
|
|
|
|
DeoptimizingCodeListNode* prev = NULL;
|
2011-03-18 20:35:07 +00:00
|
|
|
DeoptimizingCodeListNode* current = data->deoptimizing_code_list_;
|
2010-12-07 11:31:57 +00:00
|
|
|
while (current != NULL) {
|
|
|
|
if (*current->code() == code) {
|
|
|
|
// Unlink from list. If prev is NULL we are looking at the first element.
|
|
|
|
if (prev == NULL) {
|
2011-03-18 20:35:07 +00:00
|
|
|
data->deoptimizing_code_list_ = current->next();
|
2010-12-07 11:31:57 +00:00
|
|
|
} else {
|
|
|
|
prev->set_next(current->next());
|
|
|
|
}
|
|
|
|
delete current;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Move to next in list.
|
|
|
|
prev = current;
|
|
|
|
current = current->next();
|
|
|
|
}
|
|
|
|
// Deoptimizing code is removed through weak callback. Each object is expected
|
|
|
|
// to be removed once and only once.
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FrameDescription::FrameDescription(uint32_t frame_size,
|
|
|
|
JSFunction* function)
|
|
|
|
: frame_size_(frame_size),
|
|
|
|
function_(function),
|
|
|
|
top_(kZapUint32),
|
|
|
|
pc_(kZapUint32),
|
2012-02-28 09:05:55 +00:00
|
|
|
fp_(kZapUint32),
|
|
|
|
context_(kZapUint32) {
|
2010-12-07 11:31:57 +00:00
|
|
|
// Zap all the registers.
|
|
|
|
for (int r = 0; r < Register::kNumRegisters; r++) {
|
|
|
|
SetRegister(r, kZapUint32);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Zap all the slots.
|
|
|
|
for (unsigned o = 0; o < frame_size; o += kPointerSize) {
|
|
|
|
SetFrameSlot(o, kZapUint32);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
int FrameDescription::ComputeFixedSize() {
|
|
|
|
return StandardFrameConstants::kFixedFrameSize +
|
|
|
|
(ComputeParametersCount() + 1) * kPointerSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned FrameDescription::GetOffsetFromSlotIndex(int slot_index) {
|
2010-12-07 11:31:57 +00:00
|
|
|
if (slot_index >= 0) {
|
|
|
|
// Local or spill slots. Skip the fixed part of the frame
|
|
|
|
// including all arguments.
|
2012-01-24 08:43:12 +00:00
|
|
|
unsigned base = GetFrameSize() - ComputeFixedSize();
|
2010-12-07 11:31:57 +00:00
|
|
|
return base - ((slot_index + 1) * kPointerSize);
|
|
|
|
} else {
|
|
|
|
// Incoming parameter.
|
2012-01-24 08:43:12 +00:00
|
|
|
int arg_size = (ComputeParametersCount() + 1) * kPointerSize;
|
|
|
|
unsigned base = GetFrameSize() - arg_size;
|
2010-12-07 11:31:57 +00:00
|
|
|
return base - ((slot_index + 1) * kPointerSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-07 14:29:16 +00:00
|
|
|
int FrameDescription::ComputeParametersCount() {
|
2012-01-24 08:43:12 +00:00
|
|
|
switch (type_) {
|
|
|
|
case StackFrame::JAVA_SCRIPT:
|
|
|
|
return function_->shared()->formal_parameter_count();
|
|
|
|
case StackFrame::ARGUMENTS_ADAPTOR: {
|
|
|
|
// Last slot contains number of incomming arguments as a smi.
|
|
|
|
// Can't use GetExpression(0) because it would cause infinite recursion.
|
|
|
|
return reinterpret_cast<Smi*>(*GetFrameSlotPointer(0))->value();
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return 0;
|
|
|
|
}
|
2011-07-07 14:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
Object* FrameDescription::GetParameter(int index) {
|
2011-07-07 14:29:16 +00:00
|
|
|
ASSERT(index >= 0);
|
|
|
|
ASSERT(index < ComputeParametersCount());
|
|
|
|
// The slot indexes for incoming arguments are negative.
|
2012-01-24 08:43:12 +00:00
|
|
|
unsigned offset = GetOffsetFromSlotIndex(index - ComputeParametersCount());
|
2011-07-07 14:29:16 +00:00
|
|
|
return reinterpret_cast<Object*>(*GetFrameSlotPointer(offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
unsigned FrameDescription::GetExpressionCount() {
|
|
|
|
ASSERT_EQ(StackFrame::JAVA_SCRIPT, type_);
|
|
|
|
unsigned size = GetFrameSize() - ComputeFixedSize();
|
2011-06-30 15:57:56 +00:00
|
|
|
return size / kPointerSize;
|
2011-06-29 13:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
Object* FrameDescription::GetExpression(int index) {
|
|
|
|
ASSERT_EQ(StackFrame::JAVA_SCRIPT, type_);
|
|
|
|
unsigned offset = GetOffsetFromSlotIndex(index);
|
2011-06-29 13:02:00 +00:00
|
|
|
return reinterpret_cast<Object*>(*GetFrameSlotPointer(offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-04 14:42:58 +00:00
|
|
|
void TranslationBuffer::Add(int32_t value, Zone* zone) {
|
2010-12-07 11:31:57 +00:00
|
|
|
// Encode the sign bit in the least significant bit.
|
|
|
|
bool is_negative = (value < 0);
|
|
|
|
uint32_t bits = ((is_negative ? -value : value) << 1) |
|
|
|
|
static_cast<int32_t>(is_negative);
|
|
|
|
// Encode the individual bytes using the least significant bit of
|
|
|
|
// each byte to indicate whether or not more bytes follow.
|
|
|
|
do {
|
|
|
|
uint32_t next = bits >> 7;
|
2012-06-04 14:42:58 +00:00
|
|
|
contents_.Add(((bits << 1) & 0xFF) | (next != 0), zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
bits = next;
|
|
|
|
} while (bits != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32_t TranslationIterator::Next() {
|
|
|
|
// Run through the bytes until we reach one with a least significant
|
|
|
|
// bit of zero (marks the end).
|
|
|
|
uint32_t bits = 0;
|
|
|
|
for (int i = 0; true; i += 7) {
|
2011-08-08 07:17:01 +00:00
|
|
|
ASSERT(HasNext());
|
2010-12-07 11:31:57 +00:00
|
|
|
uint8_t next = buffer_->get(index_++);
|
|
|
|
bits |= (next >> 1) << i;
|
|
|
|
if ((next & 1) == 0) break;
|
|
|
|
}
|
|
|
|
// The bits encode the sign in the least significant bit.
|
|
|
|
bool is_negative = (bits & 1) == 1;
|
|
|
|
int32_t result = bits >> 1;
|
|
|
|
return is_negative ? -result : result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<ByteArray> TranslationBuffer::CreateByteArray() {
|
|
|
|
int length = contents_.length();
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<ByteArray> result =
|
|
|
|
Isolate::Current()->factory()->NewByteArray(length, TENURED);
|
2010-12-07 11:31:57 +00:00
|
|
|
memcpy(result->GetDataStartAddress(), contents_.ToVector().start(), length);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 09:05:55 +00:00
|
|
|
void Translation::BeginConstructStubFrame(int literal_id, unsigned height) {
|
2012-06-04 14:42:58 +00:00
|
|
|
buffer_->Add(CONSTRUCT_STUB_FRAME, zone());
|
|
|
|
buffer_->Add(literal_id, zone());
|
|
|
|
buffer_->Add(height, zone());
|
2012-02-28 09:05:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
void Translation::BeginArgumentsAdaptorFrame(int literal_id, unsigned height) {
|
2012-06-04 14:42:58 +00:00
|
|
|
buffer_->Add(ARGUMENTS_ADAPTOR_FRAME, zone());
|
|
|
|
buffer_->Add(literal_id, zone());
|
|
|
|
buffer_->Add(height, zone());
|
2012-01-24 08:43:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Translation::BeginJSFrame(int node_id, int literal_id, unsigned height) {
|
2012-06-04 14:42:58 +00:00
|
|
|
buffer_->Add(JS_FRAME, zone());
|
|
|
|
buffer_->Add(node_id, zone());
|
|
|
|
buffer_->Add(literal_id, zone());
|
|
|
|
buffer_->Add(height, zone());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Translation::StoreRegister(Register reg) {
|
2012-06-04 14:42:58 +00:00
|
|
|
buffer_->Add(REGISTER, zone());
|
|
|
|
buffer_->Add(reg.code(), zone());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Translation::StoreInt32Register(Register reg) {
|
2012-06-04 14:42:58 +00:00
|
|
|
buffer_->Add(INT32_REGISTER, zone());
|
|
|
|
buffer_->Add(reg.code(), zone());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Translation::StoreDoubleRegister(DoubleRegister reg) {
|
2012-06-04 14:42:58 +00:00
|
|
|
buffer_->Add(DOUBLE_REGISTER, zone());
|
|
|
|
buffer_->Add(DoubleRegister::ToAllocationIndex(reg), zone());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Translation::StoreStackSlot(int index) {
|
2012-06-04 14:42:58 +00:00
|
|
|
buffer_->Add(STACK_SLOT, zone());
|
|
|
|
buffer_->Add(index, zone());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Translation::StoreInt32StackSlot(int index) {
|
2012-06-04 14:42:58 +00:00
|
|
|
buffer_->Add(INT32_STACK_SLOT, zone());
|
|
|
|
buffer_->Add(index, zone());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Translation::StoreDoubleStackSlot(int index) {
|
2012-06-04 14:42:58 +00:00
|
|
|
buffer_->Add(DOUBLE_STACK_SLOT, zone());
|
|
|
|
buffer_->Add(index, zone());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Translation::StoreLiteral(int literal_id) {
|
2012-06-04 14:42:58 +00:00
|
|
|
buffer_->Add(LITERAL, zone());
|
|
|
|
buffer_->Add(literal_id, zone());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Translation::StoreArgumentsObject() {
|
2012-06-04 14:42:58 +00:00
|
|
|
buffer_->Add(ARGUMENTS_OBJECT, zone());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Translation::MarkDuplicate() {
|
2012-06-04 14:42:58 +00:00
|
|
|
buffer_->Add(DUPLICATE, zone());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Translation::NumberOfOperandsFor(Opcode opcode) {
|
|
|
|
switch (opcode) {
|
|
|
|
case ARGUMENTS_OBJECT:
|
|
|
|
case DUPLICATE:
|
|
|
|
return 0;
|
|
|
|
case REGISTER:
|
|
|
|
case INT32_REGISTER:
|
|
|
|
case DOUBLE_REGISTER:
|
|
|
|
case STACK_SLOT:
|
|
|
|
case INT32_STACK_SLOT:
|
|
|
|
case DOUBLE_STACK_SLOT:
|
|
|
|
case LITERAL:
|
|
|
|
return 1;
|
2012-01-24 08:43:12 +00:00
|
|
|
case BEGIN:
|
|
|
|
case ARGUMENTS_ADAPTOR_FRAME:
|
2012-02-28 09:05:55 +00:00
|
|
|
case CONSTRUCT_STUB_FRAME:
|
2012-01-24 08:43:12 +00:00
|
|
|
return 2;
|
|
|
|
case JS_FRAME:
|
2010-12-07 11:31:57 +00:00
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-16 07:58:47 +00:00
|
|
|
#if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER)
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
const char* Translation::StringFor(Opcode opcode) {
|
|
|
|
switch (opcode) {
|
|
|
|
case BEGIN:
|
|
|
|
return "BEGIN";
|
2012-01-24 08:43:12 +00:00
|
|
|
case JS_FRAME:
|
|
|
|
return "JS_FRAME";
|
|
|
|
case ARGUMENTS_ADAPTOR_FRAME:
|
|
|
|
return "ARGUMENTS_ADAPTOR_FRAME";
|
2012-02-28 09:05:55 +00:00
|
|
|
case CONSTRUCT_STUB_FRAME:
|
|
|
|
return "CONSTRUCT_STUB_FRAME";
|
2010-12-07 11:31:57 +00:00
|
|
|
case REGISTER:
|
|
|
|
return "REGISTER";
|
|
|
|
case INT32_REGISTER:
|
|
|
|
return "INT32_REGISTER";
|
|
|
|
case DOUBLE_REGISTER:
|
|
|
|
return "DOUBLE_REGISTER";
|
|
|
|
case STACK_SLOT:
|
|
|
|
return "STACK_SLOT";
|
|
|
|
case INT32_STACK_SLOT:
|
|
|
|
return "INT32_STACK_SLOT";
|
|
|
|
case DOUBLE_STACK_SLOT:
|
|
|
|
return "DOUBLE_STACK_SLOT";
|
|
|
|
case LITERAL:
|
|
|
|
return "LITERAL";
|
|
|
|
case ARGUMENTS_OBJECT:
|
|
|
|
return "ARGUMENTS_OBJECT";
|
|
|
|
case DUPLICATE:
|
|
|
|
return "DUPLICATE";
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
DeoptimizingCodeListNode::DeoptimizingCodeListNode(Code* code): next_(NULL) {
|
2011-03-18 20:35:07 +00:00
|
|
|
GlobalHandles* global_handles = Isolate::Current()->global_handles();
|
2010-12-07 11:31:57 +00:00
|
|
|
// Globalize the code object and make it weak.
|
2011-03-18 20:35:07 +00:00
|
|
|
code_ = Handle<Code>::cast(global_handles->Create(code));
|
|
|
|
global_handles->MakeWeak(reinterpret_cast<Object**>(code_.location()),
|
|
|
|
this,
|
|
|
|
Deoptimizer::HandleWeakDeoptimizedCode);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DeoptimizingCodeListNode::~DeoptimizingCodeListNode() {
|
2011-03-18 20:35:07 +00:00
|
|
|
GlobalHandles* global_handles = Isolate::Current()->global_handles();
|
|
|
|
global_handles->Destroy(reinterpret_cast<Object**>(code_.location()));
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-01 11:41:36 +00:00
|
|
|
// We can't intermix stack decoding and allocations because
|
|
|
|
// deoptimization infrastracture is not GC safe.
|
|
|
|
// Thus we build a temporary structure in malloced space.
|
|
|
|
SlotRef SlotRef::ComputeSlotForNextArgument(TranslationIterator* iterator,
|
|
|
|
DeoptimizationInputData* data,
|
|
|
|
JavaScriptFrame* frame) {
|
|
|
|
Translation::Opcode opcode =
|
|
|
|
static_cast<Translation::Opcode>(iterator->Next());
|
|
|
|
|
|
|
|
switch (opcode) {
|
|
|
|
case Translation::BEGIN:
|
2012-01-24 08:43:12 +00:00
|
|
|
case Translation::JS_FRAME:
|
|
|
|
case Translation::ARGUMENTS_ADAPTOR_FRAME:
|
2012-02-28 09:05:55 +00:00
|
|
|
case Translation::CONSTRUCT_STUB_FRAME:
|
2011-04-01 11:41:36 +00:00
|
|
|
// Peeled off before getting here.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Translation::ARGUMENTS_OBJECT:
|
|
|
|
// This can be only emitted for local slots not for argument slots.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Translation::REGISTER:
|
|
|
|
case Translation::INT32_REGISTER:
|
|
|
|
case Translation::DOUBLE_REGISTER:
|
|
|
|
case Translation::DUPLICATE:
|
|
|
|
// We are at safepoint which corresponds to call. All registers are
|
|
|
|
// saved by caller so there would be no live registers at this
|
|
|
|
// point. Thus these translation commands should not be used.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Translation::STACK_SLOT: {
|
|
|
|
int slot_index = iterator->Next();
|
|
|
|
Address slot_addr = SlotAddress(frame, slot_index);
|
|
|
|
return SlotRef(slot_addr, SlotRef::TAGGED);
|
|
|
|
}
|
|
|
|
|
|
|
|
case Translation::INT32_STACK_SLOT: {
|
|
|
|
int slot_index = iterator->Next();
|
|
|
|
Address slot_addr = SlotAddress(frame, slot_index);
|
|
|
|
return SlotRef(slot_addr, SlotRef::INT32);
|
|
|
|
}
|
|
|
|
|
|
|
|
case Translation::DOUBLE_STACK_SLOT: {
|
|
|
|
int slot_index = iterator->Next();
|
|
|
|
Address slot_addr = SlotAddress(frame, slot_index);
|
|
|
|
return SlotRef(slot_addr, SlotRef::DOUBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
case Translation::LITERAL: {
|
|
|
|
int literal_index = iterator->Next();
|
|
|
|
return SlotRef(data->LiteralArray()->get(literal_index));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UNREACHABLE();
|
|
|
|
return SlotRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
void SlotRef::ComputeSlotsForArguments(Vector<SlotRef>* args_slots,
|
|
|
|
TranslationIterator* it,
|
|
|
|
DeoptimizationInputData* data,
|
|
|
|
JavaScriptFrame* frame) {
|
|
|
|
// Process the translation commands for the arguments.
|
|
|
|
|
|
|
|
// Skip the translation command for the receiver.
|
|
|
|
it->Skip(Translation::NumberOfOperandsFor(
|
|
|
|
static_cast<Translation::Opcode>(it->Next())));
|
|
|
|
|
|
|
|
// Compute slots for arguments.
|
|
|
|
for (int i = 0; i < args_slots->length(); ++i) {
|
|
|
|
(*args_slots)[i] = ComputeSlotForNextArgument(it, data, frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Vector<SlotRef> SlotRef::ComputeSlotMappingForArguments(
|
|
|
|
JavaScriptFrame* frame,
|
|
|
|
int inlined_jsframe_index,
|
|
|
|
int formal_parameter_count) {
|
2011-04-01 11:41:36 +00:00
|
|
|
AssertNoAllocation no_gc;
|
|
|
|
int deopt_index = AstNode::kNoNumber;
|
|
|
|
DeoptimizationInputData* data =
|
|
|
|
static_cast<OptimizedFrame*>(frame)->GetDeoptimizationData(&deopt_index);
|
|
|
|
TranslationIterator it(data->TranslationByteArray(),
|
|
|
|
data->TranslationIndex(deopt_index)->value());
|
|
|
|
Translation::Opcode opcode = static_cast<Translation::Opcode>(it.Next());
|
|
|
|
ASSERT(opcode == Translation::BEGIN);
|
2012-01-24 08:43:12 +00:00
|
|
|
it.Next(); // Drop frame count.
|
|
|
|
int jsframe_count = it.Next();
|
|
|
|
USE(jsframe_count);
|
|
|
|
ASSERT(jsframe_count > inlined_jsframe_index);
|
|
|
|
int jsframes_to_skip = inlined_jsframe_index;
|
2011-04-01 11:41:36 +00:00
|
|
|
while (true) {
|
|
|
|
opcode = static_cast<Translation::Opcode>(it.Next());
|
2012-01-24 08:43:12 +00:00
|
|
|
if (opcode == Translation::ARGUMENTS_ADAPTOR_FRAME) {
|
|
|
|
if (jsframes_to_skip == 0) {
|
|
|
|
ASSERT(Translation::NumberOfOperandsFor(opcode) == 2);
|
|
|
|
|
|
|
|
it.Skip(1); // literal id
|
|
|
|
int height = it.Next();
|
|
|
|
|
|
|
|
// We reached the arguments adaptor frame corresponding to the
|
|
|
|
// inlined function in question. Number of arguments is height - 1.
|
|
|
|
Vector<SlotRef> args_slots =
|
|
|
|
Vector<SlotRef>::New(height - 1); // Minus receiver.
|
|
|
|
ComputeSlotsForArguments(&args_slots, &it, data, frame);
|
|
|
|
return args_slots;
|
|
|
|
}
|
|
|
|
} else if (opcode == Translation::JS_FRAME) {
|
|
|
|
if (jsframes_to_skip == 0) {
|
|
|
|
// Skip over operands to advance to the next opcode.
|
|
|
|
it.Skip(Translation::NumberOfOperandsFor(opcode));
|
|
|
|
|
2011-04-01 11:41:36 +00:00
|
|
|
// We reached the frame corresponding to the inlined function
|
|
|
|
// in question. Process the translation commands for the
|
2012-01-24 08:43:12 +00:00
|
|
|
// arguments. Number of arguments is equal to the number of
|
|
|
|
// format parameter count.
|
|
|
|
Vector<SlotRef> args_slots =
|
|
|
|
Vector<SlotRef>::New(formal_parameter_count);
|
|
|
|
ComputeSlotsForArguments(&args_slots, &it, data, frame);
|
|
|
|
return args_slots;
|
2011-04-01 11:41:36 +00:00
|
|
|
}
|
2012-01-24 08:43:12 +00:00
|
|
|
jsframes_to_skip--;
|
2011-04-01 11:41:36 +00:00
|
|
|
}
|
2012-01-24 08:43:12 +00:00
|
|
|
|
|
|
|
// Skip over operands to advance to the next opcode.
|
|
|
|
it.Skip(Translation::NumberOfOperandsFor(opcode));
|
2011-04-01 11:41:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UNREACHABLE();
|
2012-01-24 08:43:12 +00:00
|
|
|
return Vector<SlotRef>();
|
2011-04-01 11:41:36 +00:00
|
|
|
}
|
|
|
|
|
2011-08-05 09:44:30 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2011-04-01 11:41:36 +00:00
|
|
|
|
2012-02-28 09:05:55 +00:00
|
|
|
DeoptimizedFrameInfo::DeoptimizedFrameInfo(Deoptimizer* deoptimizer,
|
|
|
|
int frame_index,
|
|
|
|
bool has_arguments_adaptor,
|
|
|
|
bool has_construct_stub) {
|
2011-06-29 13:02:00 +00:00
|
|
|
FrameDescription* output_frame = deoptimizer->output_[frame_index];
|
2012-02-28 09:05:55 +00:00
|
|
|
function_ = output_frame->GetFunction();
|
|
|
|
has_construct_stub_ = has_construct_stub;
|
2012-01-24 08:43:12 +00:00
|
|
|
expression_count_ = output_frame->GetExpressionCount();
|
|
|
|
expression_stack_ = new Object*[expression_count_];
|
2012-01-31 12:08:33 +00:00
|
|
|
// Get the source position using the unoptimized code.
|
|
|
|
Address pc = reinterpret_cast<Address>(output_frame->GetPc());
|
|
|
|
Code* code = Code::cast(Isolate::Current()->heap()->FindCodeObject(pc));
|
|
|
|
source_position_ = code->SourcePosition(pc);
|
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
for (int i = 0; i < expression_count_; i++) {
|
|
|
|
SetExpression(i, output_frame->GetExpression(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_arguments_adaptor) {
|
|
|
|
output_frame = deoptimizer->output_[frame_index - 1];
|
|
|
|
ASSERT(output_frame->GetFrameType() == StackFrame::ARGUMENTS_ADAPTOR);
|
|
|
|
}
|
|
|
|
|
2011-07-07 14:29:16 +00:00
|
|
|
parameters_count_ = output_frame->ComputeParametersCount();
|
2011-07-11 09:35:18 +00:00
|
|
|
parameters_ = new Object*[parameters_count_];
|
2011-07-07 14:29:16 +00:00
|
|
|
for (int i = 0; i < parameters_count_; i++) {
|
2012-01-24 08:43:12 +00:00
|
|
|
SetParameter(i, output_frame->GetParameter(i));
|
2011-06-29 13:02:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DeoptimizedFrameInfo::~DeoptimizedFrameInfo() {
|
2011-07-11 09:35:18 +00:00
|
|
|
delete[] expression_stack_;
|
|
|
|
delete[] parameters_;
|
2011-06-29 13:02:00 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 12:08:33 +00:00
|
|
|
|
2011-06-29 13:02:00 +00:00
|
|
|
void DeoptimizedFrameInfo::Iterate(ObjectVisitor* v) {
|
2011-07-18 10:51:28 +00:00
|
|
|
v->VisitPointer(BitCast<Object**>(&function_));
|
2011-07-07 14:29:16 +00:00
|
|
|
v->VisitPointers(parameters_, parameters_ + parameters_count_);
|
2011-06-29 13:02:00 +00:00
|
|
|
v->VisitPointers(expression_stack_, expression_stack_ + expression_count_);
|
|
|
|
}
|
|
|
|
|
2011-08-05 09:44:30 +00:00
|
|
|
#endif // ENABLE_DEBUGGER_SUPPORT
|
2011-06-29 13:02:00 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
} } // namespace v8::internal
|