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.
|
|
|
|
|
|
|
|
#ifndef V8_DEOPTIMIZER_H_
|
|
|
|
#define V8_DEOPTIMIZER_H_
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
2011-05-06 06:50:20 +00:00
|
|
|
#include "allocation.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "macro-assembler.h"
|
|
|
|
#include "zone-inl.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
class FrameDescription;
|
|
|
|
class TranslationIterator;
|
|
|
|
class DeoptimizingCodeListNode;
|
2011-06-29 13:02:00 +00:00
|
|
|
class DeoptimizedFrameInfo;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-04-06 14:23:27 +00:00
|
|
|
class HeapNumberMaterializationDescriptor BASE_EMBEDDED {
|
2010-12-07 11:31:57 +00:00
|
|
|
public:
|
2011-04-06 14:23:27 +00:00
|
|
|
HeapNumberMaterializationDescriptor(Address slot_address, double val)
|
|
|
|
: slot_address_(slot_address), val_(val) { }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-04-06 14:23:27 +00:00
|
|
|
Address slot_address() const { return slot_address_; }
|
|
|
|
double value() const { return val_; }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
private:
|
2011-04-06 14:23:27 +00:00
|
|
|
Address slot_address_;
|
|
|
|
double val_;
|
2010-12-07 11:31:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class OptimizedFunctionVisitor BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
virtual ~OptimizedFunctionVisitor() {}
|
|
|
|
|
|
|
|
// Function which is called before iteration of any optimized functions
|
|
|
|
// from given global context.
|
|
|
|
virtual void EnterContext(Context* context) = 0;
|
|
|
|
|
|
|
|
virtual void VisitFunction(JSFunction* function) = 0;
|
|
|
|
|
|
|
|
// Function which is called after iteration of all optimized functions
|
|
|
|
// from given global context.
|
|
|
|
virtual void LeaveContext(Context* context) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
class Deoptimizer;
|
|
|
|
|
|
|
|
|
|
|
|
class DeoptimizerData {
|
|
|
|
public:
|
|
|
|
DeoptimizerData();
|
|
|
|
~DeoptimizerData();
|
|
|
|
|
2011-06-29 13:02:00 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
|
|
|
void Iterate(ObjectVisitor* v);
|
|
|
|
#endif
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
private:
|
2011-09-19 18:36:47 +00:00
|
|
|
MemoryChunk* eager_deoptimization_entry_code_;
|
|
|
|
MemoryChunk* lazy_deoptimization_entry_code_;
|
2011-03-18 20:35:07 +00:00
|
|
|
Deoptimizer* current_;
|
|
|
|
|
2011-06-29 13:02:00 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
|
|
|
DeoptimizedFrameInfo* deoptimized_frame_info_;
|
|
|
|
#endif
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
// List of deoptimized code which still have references from active stack
|
|
|
|
// frames. These code objects are needed by the deoptimizer when deoptimizing
|
|
|
|
// a frame for which the code object for the function function has been
|
|
|
|
// changed from the code present when deoptimizing was done.
|
|
|
|
DeoptimizingCodeListNode* deoptimizing_code_list_;
|
|
|
|
|
|
|
|
friend class Deoptimizer;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(DeoptimizerData);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
class Deoptimizer : public Malloced {
|
|
|
|
public:
|
|
|
|
enum BailoutType {
|
|
|
|
EAGER,
|
|
|
|
LAZY,
|
2011-06-29 13:02:00 +00:00
|
|
|
OSR,
|
|
|
|
// This last bailout type is not really a bailout, but used by the
|
|
|
|
// debugger to deoptimize stack frames to allow inspection.
|
|
|
|
DEBUGGER
|
2010-12-07 11:31:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int output_count() const { return output_count_; }
|
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
// Number of created JS frames. Not all created frames are necessarily JS.
|
|
|
|
int jsframe_count() const { return jsframe_count_; }
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
static 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);
|
|
|
|
static Deoptimizer* Grab(Isolate* isolate);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-06-29 13:02:00 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
|
|
|
// The returned object with information on the optimized frame needs to be
|
|
|
|
// freed before another one can be generated.
|
|
|
|
static DeoptimizedFrameInfo* DebuggerInspectableFrame(JavaScriptFrame* frame,
|
2012-01-24 08:43:12 +00:00
|
|
|
int jsframe_index,
|
2011-06-29 13:02:00 +00:00
|
|
|
Isolate* isolate);
|
|
|
|
static void DeleteDebuggerInspectableFrame(DeoptimizedFrameInfo* info,
|
|
|
|
Isolate* isolate);
|
|
|
|
#endif
|
|
|
|
|
2011-03-25 10:29:34 +00:00
|
|
|
// Makes sure that there is enough room in the relocation
|
|
|
|
// information of a code object to perform lazy deoptimization
|
|
|
|
// patching. If there is not enough room a new relocation
|
|
|
|
// information object is allocated and comments are added until it
|
|
|
|
// is big enough.
|
|
|
|
static void EnsureRelocSpaceForLazyDeoptimization(Handle<Code> code);
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Deoptimize the function now. Its current optimized code will never be run
|
|
|
|
// again and any activations of the optimized code will get deoptimized when
|
|
|
|
// execution returns.
|
|
|
|
static void DeoptimizeFunction(JSFunction* function);
|
|
|
|
|
|
|
|
// Deoptimize all functions in the heap.
|
|
|
|
static void DeoptimizeAll();
|
|
|
|
|
|
|
|
static void DeoptimizeGlobalObject(JSObject* object);
|
|
|
|
|
|
|
|
static void VisitAllOptimizedFunctionsForContext(
|
|
|
|
Context* context, OptimizedFunctionVisitor* visitor);
|
|
|
|
|
|
|
|
static void VisitAllOptimizedFunctionsForGlobalObject(
|
|
|
|
JSObject* object, OptimizedFunctionVisitor* visitor);
|
|
|
|
|
|
|
|
static void VisitAllOptimizedFunctions(OptimizedFunctionVisitor* visitor);
|
|
|
|
|
2011-02-02 13:55:29 +00:00
|
|
|
// The size in bytes of the code required at a lazy deopt patch site.
|
|
|
|
static int patch_size();
|
|
|
|
|
2011-01-24 14:54:45 +00:00
|
|
|
// Patch all stack guard checks in the unoptimized code to
|
|
|
|
// unconditionally call replacement_code.
|
|
|
|
static void PatchStackCheckCode(Code* unoptimized_code,
|
|
|
|
Code* check_code,
|
|
|
|
Code* replacement_code);
|
|
|
|
|
2011-02-01 11:18:45 +00:00
|
|
|
// Patch stack guard check at instruction before pc_after in
|
|
|
|
// the unoptimized code to unconditionally call replacement_code.
|
2011-09-19 18:36:47 +00:00
|
|
|
static void PatchStackCheckCodeAt(Code* unoptimized_code,
|
|
|
|
Address pc_after,
|
2011-02-02 11:58:24 +00:00
|
|
|
Code* check_code,
|
|
|
|
Code* replacement_code);
|
2011-02-01 11:18:45 +00:00
|
|
|
|
2011-01-24 14:54:45 +00:00
|
|
|
// Change all patched stack guard checks in the unoptimized code
|
|
|
|
// back to a normal stack guard check.
|
|
|
|
static void RevertStackCheckCode(Code* unoptimized_code,
|
|
|
|
Code* check_code,
|
|
|
|
Code* replacement_code);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-02-02 11:58:24 +00:00
|
|
|
// Change all patched stack guard checks in the unoptimized code
|
|
|
|
// back to a normal stack guard check.
|
2011-10-18 15:07:42 +00:00
|
|
|
static void RevertStackCheckCodeAt(Code* unoptimized_code,
|
|
|
|
Address pc_after,
|
2011-02-02 11:58:24 +00:00
|
|
|
Code* check_code,
|
|
|
|
Code* replacement_code);
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
~Deoptimizer();
|
|
|
|
|
2011-04-06 14:23:27 +00:00
|
|
|
void MaterializeHeapNumbers();
|
2011-06-29 13:02:00 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
|
|
|
void 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
|
|
|
#endif
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-03-30 18:05:16 +00:00
|
|
|
static void ComputeOutputFrames(Deoptimizer* deoptimizer);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
static Address GetDeoptimizationEntry(int id, BailoutType type);
|
|
|
|
static int GetDeoptimizationId(Address addr, BailoutType type);
|
2010-12-22 09:49:26 +00:00
|
|
|
static int GetOutputInfo(DeoptimizationOutputData* data,
|
|
|
|
unsigned node_id,
|
|
|
|
SharedFunctionInfo* shared);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Code generation support.
|
|
|
|
static int input_offset() { return OFFSET_OF(Deoptimizer, input_); }
|
|
|
|
static int output_count_offset() {
|
|
|
|
return OFFSET_OF(Deoptimizer, output_count_);
|
|
|
|
}
|
|
|
|
static int output_offset() { return OFFSET_OF(Deoptimizer, output_); }
|
|
|
|
|
2012-06-12 10:22:33 +00:00
|
|
|
static int has_alignment_padding_offset() {
|
|
|
|
return OFFSET_OF(Deoptimizer, has_alignment_padding_);
|
|
|
|
}
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
static int GetDeoptimizedCodeCount(Isolate* isolate);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
static const int kNotDeoptimizationEntry = -1;
|
|
|
|
|
|
|
|
// Generators for the deoptimization entry code.
|
|
|
|
class EntryGenerator BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
EntryGenerator(MacroAssembler* masm, BailoutType type)
|
|
|
|
: masm_(masm), type_(type) { }
|
|
|
|
virtual ~EntryGenerator() { }
|
|
|
|
|
|
|
|
void Generate();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
MacroAssembler* masm() const { return masm_; }
|
|
|
|
BailoutType type() const { return type_; }
|
|
|
|
|
|
|
|
virtual void GeneratePrologue() { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
MacroAssembler* masm_;
|
|
|
|
Deoptimizer::BailoutType type_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class TableEntryGenerator : public EntryGenerator {
|
|
|
|
public:
|
|
|
|
TableEntryGenerator(MacroAssembler* masm, BailoutType type, int count)
|
|
|
|
: EntryGenerator(masm, type), count_(count) { }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void GeneratePrologue();
|
|
|
|
|
|
|
|
private:
|
|
|
|
int count() const { return count_; }
|
|
|
|
|
|
|
|
int count_;
|
|
|
|
};
|
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
int ConvertJSFrameIndexToFrameIndex(int jsframe_index);
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
private:
|
2012-02-03 12:05:08 +00:00
|
|
|
static const int kNumberOfEntries = 16384;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
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);
|
2010-12-07 11:31:57 +00:00
|
|
|
void DeleteFrameDescriptions();
|
|
|
|
|
|
|
|
void DoComputeOutputFrames();
|
|
|
|
void DoComputeOsrOutputFrame();
|
2012-01-24 08:43:12 +00:00
|
|
|
void DoComputeJSFrame(TranslationIterator* iterator, int frame_index);
|
|
|
|
void DoComputeArgumentsAdaptorFrame(TranslationIterator* iterator,
|
|
|
|
int frame_index);
|
2012-02-28 09:05:55 +00:00
|
|
|
void DoComputeConstructStubFrame(TranslationIterator* iterator,
|
|
|
|
int frame_index);
|
2010-12-07 11:31:57 +00:00
|
|
|
void DoTranslateCommand(TranslationIterator* iterator,
|
|
|
|
int frame_index,
|
|
|
|
unsigned output_offset);
|
|
|
|
// Translate a command for OSR. Updates the input offset to be used for
|
|
|
|
// the next command. Returns false if translation of the command failed
|
|
|
|
// (e.g., a number conversion failed) and may or may not have updated the
|
|
|
|
// input offset.
|
|
|
|
bool DoOsrTranslateCommand(TranslationIterator* iterator,
|
|
|
|
int* input_offset);
|
|
|
|
|
|
|
|
unsigned ComputeInputFrameSize() const;
|
|
|
|
unsigned ComputeFixedSize(JSFunction* function) const;
|
|
|
|
|
|
|
|
unsigned ComputeIncomingArgumentSize(JSFunction* function) const;
|
|
|
|
unsigned ComputeOutgoingArgumentSize() const;
|
|
|
|
|
|
|
|
Object* ComputeLiteral(int index) const;
|
|
|
|
|
2011-04-06 14:23:27 +00:00
|
|
|
void AddDoubleValue(intptr_t slot_address, double value);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
static MemoryChunk* CreateCode(BailoutType type);
|
2010-12-07 11:31:57 +00:00
|
|
|
static void GenerateDeoptimizationEntries(
|
|
|
|
MacroAssembler* masm, int count, BailoutType type);
|
|
|
|
|
|
|
|
// Weak handle callback for deoptimizing code objects.
|
|
|
|
static void HandleWeakDeoptimizedCode(
|
|
|
|
v8::Persistent<v8::Value> obj, void* data);
|
|
|
|
static Code* FindDeoptimizingCodeFromAddress(Address addr);
|
|
|
|
static void RemoveDeoptimizingCode(Code* code);
|
|
|
|
|
2011-06-29 13:02:00 +00:00
|
|
|
// Fill the input from from a JavaScript frame. This is used when
|
|
|
|
// the debugger needs to inspect an optimized frame. For normal
|
|
|
|
// deoptimizations the input frame is filled in generated code.
|
|
|
|
void FillInputFrame(Address tos, JavaScriptFrame* frame);
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate_;
|
2010-12-07 11:31:57 +00:00
|
|
|
JSFunction* function_;
|
|
|
|
Code* optimized_code_;
|
|
|
|
unsigned bailout_id_;
|
|
|
|
BailoutType bailout_type_;
|
|
|
|
Address from_;
|
|
|
|
int fp_to_sp_delta_;
|
2012-06-12 10:22:33 +00:00
|
|
|
int has_alignment_padding_;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Input frame description.
|
|
|
|
FrameDescription* input_;
|
|
|
|
// Number of output frames.
|
|
|
|
int output_count_;
|
2012-01-24 08:43:12 +00:00
|
|
|
// Number of output js frames.
|
|
|
|
int jsframe_count_;
|
2010-12-07 11:31:57 +00:00
|
|
|
// Array of output frame descriptions.
|
|
|
|
FrameDescription** output_;
|
|
|
|
|
2011-04-06 14:23:27 +00:00
|
|
|
List<HeapNumberMaterializationDescriptor> deferred_heap_numbers_;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-08-05 11:32:46 +00:00
|
|
|
static const int table_entry_size_;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
friend class FrameDescription;
|
|
|
|
friend class DeoptimizingCodeListNode;
|
2011-06-29 13:02:00 +00:00
|
|
|
friend class DeoptimizedFrameInfo;
|
2010-12-07 11:31:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FrameDescription {
|
|
|
|
public:
|
|
|
|
FrameDescription(uint32_t frame_size,
|
|
|
|
JSFunction* function);
|
|
|
|
|
|
|
|
void* operator new(size_t size, uint32_t frame_size) {
|
2011-03-25 13:26:55 +00:00
|
|
|
// Subtracts kPointerSize, as the member frame_content_ already supplies
|
|
|
|
// the first element of the area to store the frame.
|
|
|
|
return malloc(size + frame_size - kPointerSize);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2011-08-29 09:14:59 +00:00
|
|
|
void operator delete(void* pointer, uint32_t frame_size) {
|
|
|
|
free(pointer);
|
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void operator delete(void* description) {
|
|
|
|
free(description);
|
|
|
|
}
|
|
|
|
|
2011-06-30 15:57:56 +00:00
|
|
|
uint32_t GetFrameSize() const {
|
|
|
|
ASSERT(static_cast<uint32_t>(frame_size_) == frame_size_);
|
|
|
|
return static_cast<uint32_t>(frame_size_);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
JSFunction* GetFunction() const { return function_; }
|
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
unsigned GetOffsetFromSlotIndex(int slot_index);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2010-12-07 11:53:19 +00:00
|
|
|
intptr_t GetFrameSlot(unsigned offset) {
|
2010-12-07 11:31:57 +00:00
|
|
|
return *GetFrameSlotPointer(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
double GetDoubleFrameSlot(unsigned offset) {
|
2011-10-28 08:14:46 +00:00
|
|
|
intptr_t* ptr = GetFrameSlotPointer(offset);
|
|
|
|
#if V8_TARGET_ARCH_MIPS
|
|
|
|
// Prevent gcc from using load-double (mips ldc1) on (possibly)
|
|
|
|
// non-64-bit aligned double. Uses two lwc1 instructions.
|
|
|
|
union conversion {
|
|
|
|
double d;
|
|
|
|
uint32_t u[2];
|
|
|
|
} c;
|
|
|
|
c.u[0] = *reinterpret_cast<uint32_t*>(ptr);
|
|
|
|
c.u[1] = *(reinterpret_cast<uint32_t*>(ptr) + 1);
|
|
|
|
return c.d;
|
|
|
|
#else
|
|
|
|
return *reinterpret_cast<double*>(ptr);
|
|
|
|
#endif
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2010-12-07 11:53:19 +00:00
|
|
|
void SetFrameSlot(unsigned offset, intptr_t value) {
|
2010-12-07 11:31:57 +00:00
|
|
|
*GetFrameSlotPointer(offset) = value;
|
|
|
|
}
|
|
|
|
|
2010-12-07 11:53:19 +00:00
|
|
|
intptr_t GetRegister(unsigned n) const {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(n < ARRAY_SIZE(registers_));
|
|
|
|
return registers_[n];
|
|
|
|
}
|
|
|
|
|
|
|
|
double GetDoubleRegister(unsigned n) const {
|
|
|
|
ASSERT(n < ARRAY_SIZE(double_registers_));
|
|
|
|
return double_registers_[n];
|
|
|
|
}
|
|
|
|
|
2010-12-07 11:53:19 +00:00
|
|
|
void SetRegister(unsigned n, intptr_t value) {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(n < ARRAY_SIZE(registers_));
|
|
|
|
registers_[n] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetDoubleRegister(unsigned n, double value) {
|
|
|
|
ASSERT(n < ARRAY_SIZE(double_registers_));
|
|
|
|
double_registers_[n] = value;
|
|
|
|
}
|
|
|
|
|
2010-12-07 11:53:19 +00:00
|
|
|
intptr_t GetTop() const { return top_; }
|
|
|
|
void SetTop(intptr_t top) { top_ = top; }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2010-12-07 11:53:19 +00:00
|
|
|
intptr_t GetPc() const { return pc_; }
|
|
|
|
void SetPc(intptr_t pc) { pc_ = pc; }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2010-12-07 11:53:19 +00:00
|
|
|
intptr_t GetFp() const { return fp_; }
|
|
|
|
void SetFp(intptr_t fp) { fp_ = fp; }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-02-28 09:05:55 +00:00
|
|
|
intptr_t GetContext() const { return context_; }
|
|
|
|
void SetContext(intptr_t context) { context_ = context; }
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
Smi* GetState() const { return state_; }
|
|
|
|
void SetState(Smi* state) { state_ = state; }
|
|
|
|
|
2010-12-07 11:53:19 +00:00
|
|
|
void SetContinuation(intptr_t pc) { continuation_ = pc; }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
StackFrame::Type GetFrameType() const { return type_; }
|
|
|
|
void SetFrameType(StackFrame::Type type) { type_ = type; }
|
2011-06-29 13:02:00 +00:00
|
|
|
|
2011-07-07 14:29:16 +00:00
|
|
|
// Get the incoming arguments count.
|
|
|
|
int ComputeParametersCount();
|
|
|
|
|
|
|
|
// Get a parameter value for an unoptimized frame.
|
2012-01-24 08:43:12 +00:00
|
|
|
Object* GetParameter(int index);
|
2011-07-07 14:29:16 +00:00
|
|
|
|
2011-06-29 13:02:00 +00:00
|
|
|
// Get the expression stack height for a unoptimized frame.
|
2012-01-24 08:43:12 +00:00
|
|
|
unsigned GetExpressionCount();
|
2011-06-29 13:02:00 +00:00
|
|
|
|
|
|
|
// Get the expression stack value for an unoptimized frame.
|
2012-01-24 08:43:12 +00:00
|
|
|
Object* GetExpression(int index);
|
2011-06-29 13:02:00 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
static int registers_offset() {
|
|
|
|
return OFFSET_OF(FrameDescription, registers_);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int double_registers_offset() {
|
|
|
|
return OFFSET_OF(FrameDescription, double_registers_);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int frame_size_offset() {
|
|
|
|
return OFFSET_OF(FrameDescription, frame_size_);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pc_offset() {
|
|
|
|
return OFFSET_OF(FrameDescription, pc_);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int state_offset() {
|
|
|
|
return OFFSET_OF(FrameDescription, state_);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int continuation_offset() {
|
|
|
|
return OFFSET_OF(FrameDescription, continuation_);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int frame_content_offset() {
|
2011-03-25 13:26:55 +00:00
|
|
|
return OFFSET_OF(FrameDescription, frame_content_);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const uint32_t kZapUint32 = 0xbeeddead;
|
|
|
|
|
2011-06-30 15:57:56 +00:00
|
|
|
// Frame_size_ must hold a uint32_t value. It is only a uintptr_t to
|
|
|
|
// keep the variable-size array frame_content_ of type intptr_t at
|
|
|
|
// the end of the structure aligned.
|
2010-12-07 11:53:19 +00:00
|
|
|
uintptr_t frame_size_; // Number of bytes.
|
2010-12-07 11:31:57 +00:00
|
|
|
JSFunction* function_;
|
2010-12-07 11:53:19 +00:00
|
|
|
intptr_t registers_[Register::kNumRegisters];
|
2010-12-07 11:31:57 +00:00
|
|
|
double double_registers_[DoubleRegister::kNumAllocatableRegisters];
|
2010-12-07 11:53:19 +00:00
|
|
|
intptr_t top_;
|
|
|
|
intptr_t pc_;
|
|
|
|
intptr_t fp_;
|
2012-02-28 09:05:55 +00:00
|
|
|
intptr_t context_;
|
2012-01-24 08:43:12 +00:00
|
|
|
StackFrame::Type type_;
|
2010-12-07 11:31:57 +00:00
|
|
|
Smi* state_;
|
2011-06-29 13:02:00 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
Code::Kind kind_;
|
|
|
|
#endif
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Continuation is the PC where the execution continues after
|
|
|
|
// deoptimizing.
|
2010-12-07 11:53:19 +00:00
|
|
|
intptr_t continuation_;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-03-25 13:26:55 +00:00
|
|
|
// This must be at the end of the object as the object is allocated larger
|
|
|
|
// than it's definition indicate to extend this array.
|
|
|
|
intptr_t frame_content_[1];
|
|
|
|
|
2010-12-07 11:53:19 +00:00
|
|
|
intptr_t* GetFrameSlotPointer(unsigned offset) {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(offset < frame_size_);
|
2010-12-07 11:53:19 +00:00
|
|
|
return reinterpret_cast<intptr_t*>(
|
2010-12-07 11:31:57 +00:00
|
|
|
reinterpret_cast<Address>(this) + frame_content_offset() + offset);
|
|
|
|
}
|
2012-01-24 08:43:12 +00:00
|
|
|
|
|
|
|
int ComputeFixedSize();
|
2010-12-07 11:31:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class TranslationBuffer BASE_EMBEDDED {
|
|
|
|
public:
|
2012-06-04 14:42:58 +00:00
|
|
|
explicit TranslationBuffer(Zone* zone) : contents_(256, zone) { }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
int CurrentIndex() const { return contents_.length(); }
|
2012-06-04 14:42:58 +00:00
|
|
|
void Add(int32_t value, Zone* zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
Handle<ByteArray> CreateByteArray();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ZoneList<uint8_t> contents_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class TranslationIterator BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
TranslationIterator(ByteArray* buffer, int index)
|
|
|
|
: buffer_(buffer), index_(index) {
|
|
|
|
ASSERT(index >= 0 && index < buffer->length());
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t Next();
|
|
|
|
|
2011-08-08 07:17:01 +00:00
|
|
|
bool HasNext() const { return index_ < buffer_->length(); }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
void Skip(int n) {
|
|
|
|
for (int i = 0; i < n; i++) Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ByteArray* buffer_;
|
|
|
|
int index_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Translation BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
enum Opcode {
|
|
|
|
BEGIN,
|
2012-01-24 08:43:12 +00:00
|
|
|
JS_FRAME,
|
2012-02-28 09:05:55 +00:00
|
|
|
CONSTRUCT_STUB_FRAME,
|
2012-01-24 08:43:12 +00:00
|
|
|
ARGUMENTS_ADAPTOR_FRAME,
|
2010-12-07 11:31:57 +00:00
|
|
|
REGISTER,
|
|
|
|
INT32_REGISTER,
|
|
|
|
DOUBLE_REGISTER,
|
|
|
|
STACK_SLOT,
|
|
|
|
INT32_STACK_SLOT,
|
|
|
|
DOUBLE_STACK_SLOT,
|
|
|
|
LITERAL,
|
|
|
|
ARGUMENTS_OBJECT,
|
|
|
|
|
|
|
|
// A prefix indicating that the next command is a duplicate of the one
|
|
|
|
// that follows it.
|
|
|
|
DUPLICATE
|
|
|
|
};
|
|
|
|
|
2012-06-04 14:42:58 +00:00
|
|
|
Translation(TranslationBuffer* buffer, int frame_count, int jsframe_count,
|
|
|
|
Zone* zone)
|
2010-12-07 11:31:57 +00:00
|
|
|
: buffer_(buffer),
|
2012-06-04 14:42:58 +00:00
|
|
|
index_(buffer->CurrentIndex()),
|
|
|
|
zone_(zone) {
|
|
|
|
buffer_->Add(BEGIN, zone);
|
|
|
|
buffer_->Add(frame_count, zone);
|
|
|
|
buffer_->Add(jsframe_count, zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int index() const { return index_; }
|
|
|
|
|
|
|
|
// Commands.
|
2012-01-24 08:43:12 +00:00
|
|
|
void BeginJSFrame(int node_id, int literal_id, unsigned height);
|
|
|
|
void BeginArgumentsAdaptorFrame(int literal_id, unsigned height);
|
2012-02-28 09:05:55 +00:00
|
|
|
void BeginConstructStubFrame(int literal_id, unsigned height);
|
2010-12-07 11:31:57 +00:00
|
|
|
void StoreRegister(Register reg);
|
|
|
|
void StoreInt32Register(Register reg);
|
|
|
|
void StoreDoubleRegister(DoubleRegister reg);
|
|
|
|
void StoreStackSlot(int index);
|
|
|
|
void StoreInt32StackSlot(int index);
|
|
|
|
void StoreDoubleStackSlot(int index);
|
|
|
|
void StoreLiteral(int literal_id);
|
|
|
|
void StoreArgumentsObject();
|
|
|
|
void MarkDuplicate();
|
|
|
|
|
2012-06-11 12:42:31 +00:00
|
|
|
Zone* zone() const { return zone_; }
|
2012-06-04 14:42:58 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
static int NumberOfOperandsFor(Opcode opcode);
|
|
|
|
|
2011-06-16 07:58:47 +00:00
|
|
|
#if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER)
|
2010-12-07 11:31:57 +00:00
|
|
|
static const char* StringFor(Opcode opcode);
|
|
|
|
#endif
|
|
|
|
|
2012-06-14 14:06:22 +00:00
|
|
|
// A literal id which refers to the JSFunction itself.
|
|
|
|
static const int kSelfLiteralId = -239;
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
private:
|
|
|
|
TranslationBuffer* buffer_;
|
|
|
|
int index_;
|
2012-06-04 14:42:58 +00:00
|
|
|
Zone* zone_;
|
2010-12-07 11:31:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Linked list holding deoptimizing code objects. The deoptimizing code objects
|
|
|
|
// are kept as weak handles until they are no longer activated on the stack.
|
|
|
|
class DeoptimizingCodeListNode : public Malloced {
|
|
|
|
public:
|
|
|
|
explicit DeoptimizingCodeListNode(Code* code);
|
|
|
|
~DeoptimizingCodeListNode();
|
|
|
|
|
|
|
|
DeoptimizingCodeListNode* next() const { return next_; }
|
|
|
|
void set_next(DeoptimizingCodeListNode* next) { next_ = next; }
|
|
|
|
Handle<Code> code() const { return code_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Global (weak) handle to the deoptimizing code object.
|
|
|
|
Handle<Code> code_;
|
|
|
|
|
|
|
|
// Next pointer for linked list.
|
|
|
|
DeoptimizingCodeListNode* next_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-04-01 11:41:36 +00:00
|
|
|
class SlotRef BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
enum SlotRepresentation {
|
|
|
|
UNKNOWN,
|
|
|
|
TAGGED,
|
|
|
|
INT32,
|
|
|
|
DOUBLE,
|
|
|
|
LITERAL
|
|
|
|
};
|
|
|
|
|
|
|
|
SlotRef()
|
|
|
|
: addr_(NULL), representation_(UNKNOWN) { }
|
|
|
|
|
|
|
|
SlotRef(Address addr, SlotRepresentation representation)
|
|
|
|
: addr_(addr), representation_(representation) { }
|
|
|
|
|
|
|
|
explicit SlotRef(Object* literal)
|
|
|
|
: literal_(literal), representation_(LITERAL) { }
|
|
|
|
|
|
|
|
Handle<Object> GetValue() {
|
|
|
|
switch (representation_) {
|
|
|
|
case TAGGED:
|
|
|
|
return Handle<Object>(Memory::Object_at(addr_));
|
|
|
|
|
|
|
|
case INT32: {
|
|
|
|
int value = Memory::int32_at(addr_);
|
|
|
|
if (Smi::IsValid(value)) {
|
|
|
|
return Handle<Object>(Smi::FromInt(value));
|
|
|
|
} else {
|
|
|
|
return Isolate::Current()->factory()->NewNumberFromInt(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case DOUBLE: {
|
|
|
|
double value = Memory::double_at(addr_);
|
|
|
|
return Isolate::Current()->factory()->NewNumber(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
case LITERAL:
|
|
|
|
return literal_;
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return Handle<Object>::null();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
static Vector<SlotRef> ComputeSlotMappingForArguments(
|
|
|
|
JavaScriptFrame* frame,
|
|
|
|
int inlined_frame_index,
|
|
|
|
int formal_parameter_count);
|
2011-04-01 11:41:36 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Address addr_;
|
|
|
|
Handle<Object> literal_;
|
|
|
|
SlotRepresentation representation_;
|
|
|
|
|
|
|
|
static Address SlotAddress(JavaScriptFrame* frame, int slot_index) {
|
|
|
|
if (slot_index >= 0) {
|
|
|
|
const int offset = JavaScriptFrameConstants::kLocal0Offset;
|
|
|
|
return frame->fp() + offset - (slot_index * kPointerSize);
|
|
|
|
} else {
|
|
|
|
const int offset = JavaScriptFrameConstants::kLastParameterOffset;
|
|
|
|
return frame->fp() + offset - ((slot_index + 1) * kPointerSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static SlotRef ComputeSlotForNextArgument(TranslationIterator* iterator,
|
|
|
|
DeoptimizationInputData* data,
|
|
|
|
JavaScriptFrame* frame);
|
2012-01-24 08:43:12 +00:00
|
|
|
|
|
|
|
static void ComputeSlotsForArguments(
|
|
|
|
Vector<SlotRef>* args_slots,
|
|
|
|
TranslationIterator* iterator,
|
|
|
|
DeoptimizationInputData* data,
|
|
|
|
JavaScriptFrame* frame);
|
2011-04-01 11:41:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-06-29 13:02:00 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
|
|
|
// Class used to represent an unoptimized frame when the debugger
|
|
|
|
// needs to inspect a frame that is part of an optimized frame. The
|
|
|
|
// internally used FrameDescription objects are not GC safe so for use
|
|
|
|
// by the debugger frame information is copied to an object of this type.
|
2012-01-24 08:43:12 +00:00
|
|
|
// Represents parameters in unadapted form so their number might mismatch
|
|
|
|
// formal parameter count.
|
2011-06-29 13:02:00 +00:00
|
|
|
class DeoptimizedFrameInfo : public Malloced {
|
|
|
|
public:
|
2012-01-24 08:43:12 +00:00
|
|
|
DeoptimizedFrameInfo(Deoptimizer* deoptimizer,
|
|
|
|
int frame_index,
|
2012-02-28 09:05:55 +00:00
|
|
|
bool has_arguments_adaptor,
|
|
|
|
bool has_construct_stub);
|
2011-06-29 13:02:00 +00:00
|
|
|
virtual ~DeoptimizedFrameInfo();
|
|
|
|
|
|
|
|
// GC support.
|
|
|
|
void Iterate(ObjectVisitor* v);
|
|
|
|
|
2011-07-07 14:29:16 +00:00
|
|
|
// Return the number of incoming arguments.
|
|
|
|
int parameters_count() { return parameters_count_; }
|
|
|
|
|
2011-06-29 13:02:00 +00:00
|
|
|
// Return the height of the expression stack.
|
|
|
|
int expression_count() { return expression_count_; }
|
|
|
|
|
2011-07-06 13:02:17 +00:00
|
|
|
// Get the frame function.
|
|
|
|
JSFunction* GetFunction() {
|
|
|
|
return function_;
|
|
|
|
}
|
|
|
|
|
2012-02-28 09:05:55 +00:00
|
|
|
// Check if this frame is preceded by construct stub frame. The bottom-most
|
|
|
|
// inlined frame might still be called by an uninlined construct stub.
|
|
|
|
bool HasConstructStub() {
|
|
|
|
return has_construct_stub_;
|
|
|
|
}
|
|
|
|
|
2011-07-07 14:29:16 +00:00
|
|
|
// Get an incoming argument.
|
|
|
|
Object* GetParameter(int index) {
|
|
|
|
ASSERT(0 <= index && index < parameters_count());
|
|
|
|
return parameters_[index];
|
|
|
|
}
|
|
|
|
|
2011-06-29 13:02:00 +00:00
|
|
|
// Get an expression from the expression stack.
|
|
|
|
Object* GetExpression(int index) {
|
|
|
|
ASSERT(0 <= index && index < expression_count());
|
|
|
|
return expression_stack_[index];
|
|
|
|
}
|
|
|
|
|
2012-01-31 12:08:33 +00:00
|
|
|
int GetSourcePosition() {
|
|
|
|
return source_position_;
|
2012-01-30 13:07:01 +00:00
|
|
|
}
|
|
|
|
|
2011-06-29 13:02:00 +00:00
|
|
|
private:
|
2011-07-07 14:29:16 +00:00
|
|
|
// Set an incoming argument.
|
|
|
|
void SetParameter(int index, Object* obj) {
|
|
|
|
ASSERT(0 <= index && index < parameters_count());
|
|
|
|
parameters_[index] = obj;
|
|
|
|
}
|
|
|
|
|
2011-06-29 13:02:00 +00:00
|
|
|
// Set an expression on the expression stack.
|
|
|
|
void SetExpression(int index, Object* obj) {
|
|
|
|
ASSERT(0 <= index && index < expression_count());
|
|
|
|
expression_stack_[index] = obj;
|
|
|
|
}
|
|
|
|
|
2011-07-06 13:02:17 +00:00
|
|
|
JSFunction* function_;
|
2012-02-28 09:05:55 +00:00
|
|
|
bool has_construct_stub_;
|
2011-07-07 14:29:16 +00:00
|
|
|
int parameters_count_;
|
2011-06-29 13:02:00 +00:00
|
|
|
int expression_count_;
|
2011-07-07 14:29:16 +00:00
|
|
|
Object** parameters_;
|
2011-06-29 13:02:00 +00:00
|
|
|
Object** expression_stack_;
|
2012-01-31 12:08:33 +00:00
|
|
|
int source_position_;
|
2011-06-29 13:02:00 +00:00
|
|
|
|
|
|
|
friend class Deoptimizer;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_DEOPTIMIZER_H_
|