1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef V8_DEOPTIMIZER_H_
6 #define V8_DEOPTIMIZER_H_
10 #include "src/allocation.h"
11 #include "src/macro-assembler.h"
12 #include "src/zone-inl.h"
19 static inline double read_double_value(Address p) {
21 memcpy(&d, p, sizeof(d));
25 static inline simd128_value_t read_simd128_value(Address p) {
26 return *reinterpret_cast<simd128_value_t*>(p);
29 class FrameDescription;
30 class TranslationIterator;
31 class DeoptimizedFrameInfo;
34 class HeapNumberMaterializationDescriptor BASE_EMBEDDED {
36 HeapNumberMaterializationDescriptor(T destination, double value)
37 : destination_(destination), value_(value) { }
39 T destination() const { return destination_; }
40 double value() const { return value_; }
49 class SIMD128MaterializationDescriptor BASE_EMBEDDED {
51 SIMD128MaterializationDescriptor(T destination, simd128_value_t value)
52 : destination_(destination), value_(value) { }
54 T destination() const { return destination_; }
55 simd128_value_t value() const { return value_; }
59 simd128_value_t value_;
63 class ObjectMaterializationDescriptor BASE_EMBEDDED {
65 ObjectMaterializationDescriptor(
66 Address slot_address, int frame, int length, int duplicate, bool is_args)
67 : slot_address_(slot_address),
68 jsframe_index_(frame),
69 object_length_(length),
70 duplicate_object_(duplicate),
71 is_arguments_(is_args) { }
73 Address slot_address() const { return slot_address_; }
74 int jsframe_index() const { return jsframe_index_; }
75 int object_length() const { return object_length_; }
76 int duplicate_object() const { return duplicate_object_; }
77 bool is_arguments() const { return is_arguments_; }
79 // Only used for allocated receivers in DoComputeConstructStubFrame.
80 void patch_slot_address(intptr_t slot) {
81 slot_address_ = reinterpret_cast<Address>(slot);
85 Address slot_address_;
88 int duplicate_object_;
93 class OptimizedFunctionVisitor BASE_EMBEDDED {
95 virtual ~OptimizedFunctionVisitor() {}
97 // Function which is called before iteration of any optimized functions
98 // from given native context.
99 virtual void EnterContext(Context* context) = 0;
101 virtual void VisitFunction(JSFunction* function) = 0;
103 // Function which is called after iteration of all optimized functions
104 // from given native context.
105 virtual void LeaveContext(Context* context) = 0;
109 class Deoptimizer : public Malloced {
115 // This last bailout type is not really a bailout, but used by the
116 // debugger to deoptimize stack frames to allow inspection.
120 static const int kBailoutTypesWithCodeEntry = SOFT + 1;
123 Reason(int r, const char* m, const char* d)
124 : raw_position(r), mnemonic(m), detail(d) {}
126 bool operator==(const Reason& other) const {
127 return raw_position == other.raw_position &&
128 CStringEquals(mnemonic, other.mnemonic) &&
129 CStringEquals(detail, other.detail);
132 bool operator!=(const Reason& other) const { return !(*this == other); }
135 const char* mnemonic;
139 struct JumpTableEntry : public ZoneObject {
140 inline JumpTableEntry(Address entry, const Reason& the_reason,
141 Deoptimizer::BailoutType type, bool frame)
146 needs_frame(frame) {}
148 bool IsEquivalentTo(const JumpTableEntry& other) const {
149 return address == other.address && bailout_type == other.bailout_type &&
150 needs_frame == other.needs_frame &&
151 (!FLAG_trace_deopt || reason == other.reason);
157 Deoptimizer::BailoutType bailout_type;
161 static bool TraceEnabledFor(BailoutType deopt_type,
162 StackFrame::Type frame_type);
163 static const char* MessageFor(BailoutType type);
165 int output_count() const { return output_count_; }
167 Handle<JSFunction> function() const { return Handle<JSFunction>(function_); }
168 Handle<Code> compiled_code() const { return Handle<Code>(compiled_code_); }
169 BailoutType bailout_type() const { return bailout_type_; }
171 // Number of created JS frames. Not all created frames are necessarily JS.
172 int jsframe_count() const { return jsframe_count_; }
174 static Deoptimizer* New(JSFunction* function,
180 static Deoptimizer* Grab(Isolate* isolate);
182 // The returned object with information on the optimized frame needs to be
183 // freed before another one can be generated.
184 static DeoptimizedFrameInfo* DebuggerInspectableFrame(JavaScriptFrame* frame,
187 static void DeleteDebuggerInspectableFrame(DeoptimizedFrameInfo* info,
190 // Makes sure that there is enough room in the relocation
191 // information of a code object to perform lazy deoptimization
192 // patching. If there is not enough room a new relocation
193 // information object is allocated and comments are added until it
195 static void EnsureRelocSpaceForLazyDeoptimization(Handle<Code> code);
197 // Deoptimize the function now. Its current optimized code will never be run
198 // again and any activations of the optimized code will get deoptimized when
199 // execution returns.
200 static void DeoptimizeFunction(JSFunction* function);
202 // Deoptimize all code in the given isolate.
203 static void DeoptimizeAll(Isolate* isolate);
205 // Deoptimize code associated with the given global object.
206 static void DeoptimizeGlobalObject(JSObject* object);
208 // Deoptimizes all optimized code that has been previously marked
209 // (via code->set_marked_for_deoptimization) and unlinks all functions that
210 // refer to that code.
211 static void DeoptimizeMarkedCode(Isolate* isolate);
213 // Visit all the known optimized functions in a given isolate.
214 static void VisitAllOptimizedFunctions(
215 Isolate* isolate, OptimizedFunctionVisitor* visitor);
217 // The size in bytes of the code required at a lazy deopt patch site.
218 static int patch_size();
222 void MaterializeHeapObjects(JavaScriptFrameIterator* it);
224 void MaterializeHeapNumbersForDebuggerInspectableFrame(
225 Address parameters_top,
226 uint32_t parameters_size,
227 Address expressions_top,
228 uint32_t expressions_size,
229 DeoptimizedFrameInfo* info);
231 static void ComputeOutputFrames(Deoptimizer* deoptimizer);
235 CALCULATE_ENTRY_ADDRESS,
240 static Address GetDeoptimizationEntry(
244 GetEntryMode mode = ENSURE_ENTRY_CODE);
245 static int GetDeoptimizationId(Isolate* isolate,
248 static int GetOutputInfo(DeoptimizationOutputData* data,
250 SharedFunctionInfo* shared);
252 // Code generation support.
253 static int input_offset() { return OFFSET_OF(Deoptimizer, input_); }
254 static int output_count_offset() {
255 return OFFSET_OF(Deoptimizer, output_count_);
257 static int output_offset() { return OFFSET_OF(Deoptimizer, output_); }
259 static int has_alignment_padding_offset() {
260 return OFFSET_OF(Deoptimizer, has_alignment_padding_);
263 static int GetDeoptimizedCodeCount(Isolate* isolate);
265 static const int kNotDeoptimizationEntry = -1;
267 // Generators for the deoptimization entry code.
268 class EntryGenerator BASE_EMBEDDED {
270 EntryGenerator(MacroAssembler* masm, BailoutType type)
271 : masm_(masm), type_(type) { }
272 virtual ~EntryGenerator() { }
277 MacroAssembler* masm() const { return masm_; }
278 BailoutType type() const { return type_; }
279 Isolate* isolate() const { return masm_->isolate(); }
281 virtual void GeneratePrologue() { }
284 MacroAssembler* masm_;
285 Deoptimizer::BailoutType type_;
288 class TableEntryGenerator : public EntryGenerator {
290 TableEntryGenerator(MacroAssembler* masm, BailoutType type, int count)
291 : EntryGenerator(masm, type), count_(count) { }
294 virtual void GeneratePrologue();
297 int count() const { return count_; }
302 int ConvertJSFrameIndexToFrameIndex(int jsframe_index);
304 static size_t GetMaxDeoptTableSize();
306 static void EnsureCodeForDeoptimizationEntry(Isolate* isolate,
310 Isolate* isolate() const { return isolate_; }
313 static const int kMinNumberOfEntries = 64;
314 static const int kMaxNumberOfEntries = 16384;
316 Deoptimizer(Isolate* isolate,
317 JSFunction* function,
322 Code* optimized_code);
323 Code* FindOptimizedCode(JSFunction* function, Code* optimized_code);
324 void PrintFunctionName();
325 void DeleteFrameDescriptions();
327 void DoComputeOutputFrames();
328 void DoComputeJSFrame(TranslationIterator* iterator, int frame_index);
329 void DoComputeArgumentsAdaptorFrame(TranslationIterator* iterator,
331 void DoComputeConstructStubFrame(TranslationIterator* iterator,
333 void DoComputeAccessorStubFrame(TranslationIterator* iterator,
335 bool is_setter_stub_frame);
336 void DoComputeCompiledStubFrame(TranslationIterator* iterator,
339 // Translate object, store the result into an auxiliary array
340 // (deferred_objects_tagged_values_).
341 void DoTranslateObject(TranslationIterator* iterator,
345 // Translate value, store the result into the given frame slot.
346 void DoTranslateCommand(TranslationIterator* iterator,
348 unsigned output_offset);
350 // Translate object, do not store the result anywhere (but do update
351 // the deferred materialization array).
352 void DoTranslateObjectAndSkip(TranslationIterator* iterator);
354 unsigned ComputeInputFrameSize() const;
355 unsigned ComputeFixedSize(JSFunction* function) const;
357 unsigned ComputeIncomingArgumentSize(JSFunction* function) const;
358 unsigned ComputeOutgoingArgumentSize() const;
360 Object* ComputeLiteral(int index) const;
362 void AddObjectStart(intptr_t slot_address, int argc, bool is_arguments);
363 void AddObjectDuplication(intptr_t slot, int object_index);
364 void AddObjectTaggedValue(intptr_t value);
365 void AddObjectDoubleValue(double value);
366 void AddObjectSIMD128Value(simd128_value_t value, int translation_opcode);
367 void AddDoubleValue(intptr_t slot_address, double value);
368 void AddSIMD128Value(intptr_t slot_address, simd128_value_t value,
369 int translation_opcode);
371 bool ArgumentsObjectIsAdapted(int object_index) {
372 ObjectMaterializationDescriptor desc = deferred_objects_.at(object_index);
373 int reverse_jsframe_index = jsframe_count_ - desc.jsframe_index() - 1;
374 return jsframe_has_adapted_arguments_[reverse_jsframe_index];
377 Handle<JSFunction> ArgumentsObjectFunction(int object_index) {
378 ObjectMaterializationDescriptor desc = deferred_objects_.at(object_index);
379 int reverse_jsframe_index = jsframe_count_ - desc.jsframe_index() - 1;
380 return jsframe_functions_[reverse_jsframe_index];
383 // Helper function for heap object materialization.
384 Handle<Object> MaterializeNextHeapObject();
385 Handle<Object> MaterializeNextValue();
387 static void GenerateDeoptimizationEntries(
388 MacroAssembler* masm, int count, BailoutType type);
390 // Marks all the code in the given context for deoptimization.
391 static void MarkAllCodeForContext(Context* native_context);
393 // Visit all the known optimized functions in a given context.
394 static void VisitAllOptimizedFunctionsForContext(
395 Context* context, OptimizedFunctionVisitor* visitor);
397 // Deoptimizes all code marked in the given context.
398 static void DeoptimizeMarkedCodeForContext(Context* native_context);
400 // Patch the given code so that it will deoptimize itself.
401 static void PatchCodeForDeoptimization(Isolate* isolate, Code* code);
403 // Searches the list of known deoptimizing code for a Code object
404 // containing the given address (which is supposedly faster than
405 // searching all code objects).
406 Code* FindDeoptimizingCode(Address addr);
408 // Fill the input from from a JavaScript frame. This is used when
409 // the debugger needs to inspect an optimized frame. For normal
410 // deoptimizations the input frame is filled in generated code.
411 void FillInputFrame(Address tos, JavaScriptFrame* frame);
413 // Fill the given output frame's registers to contain the failure handler
414 // address and the number of parameters for a stub failure trampoline.
415 void SetPlatformCompiledStubRegisters(FrameDescription* output_frame,
416 CodeStubDescriptor* desc);
418 // Fill the given output frame's simd128 registers with the original values
419 // from the input frame's simd128 registers.
420 void CopySIMD128Registers(FrameDescription* output_frame);
422 // Determines whether the input frame contains alignment padding by looking
423 // at the dynamic alignment state slot inside the frame.
424 bool HasAlignmentPadding(JSFunction* function);
427 JSFunction* function_;
428 Code* compiled_code_;
429 unsigned bailout_id_;
430 BailoutType bailout_type_;
433 int has_alignment_padding_;
435 // Input frame description.
436 FrameDescription* input_;
437 // Number of output frames.
439 // Number of output js frames.
441 // Array of output frame descriptions.
442 FrameDescription** output_;
444 // Deferred values to be materialized.
445 List<Object*> deferred_objects_tagged_values_;
446 List<HeapNumberMaterializationDescriptor<int> >
447 deferred_objects_double_values_;
448 List<SIMD128MaterializationDescriptor<int> >
449 deferred_objects_float32x4_values_;
450 List<SIMD128MaterializationDescriptor<int> >
451 deferred_objects_float64x2_values_;
452 List<SIMD128MaterializationDescriptor<int> >
453 deferred_objects_int32x4_values_;
454 List<ObjectMaterializationDescriptor> deferred_objects_;
455 List<HeapNumberMaterializationDescriptor<Address> > deferred_heap_numbers_;
456 List<SIMD128MaterializationDescriptor<Address> > deferred_float32x4s_;
457 List<SIMD128MaterializationDescriptor<Address> > deferred_float64x2s_;
458 List<SIMD128MaterializationDescriptor<Address> > deferred_int32x4s_;
460 // Key for lookup of previously materialized objects
462 Handle<FixedArray> previously_materialized_objects_;
463 int prev_materialized_count_;
465 // Output frame information. Only used during heap object materialization.
466 List<Handle<JSFunction> > jsframe_functions_;
467 List<bool> jsframe_has_adapted_arguments_;
469 // Materialized objects. Only used during heap object materialization.
470 List<Handle<Object> >* materialized_values_;
471 List<Handle<Object> >* materialized_objects_;
472 int materialization_value_index_;
473 int materialization_object_index_;
476 DisallowHeapAllocation* disallow_heap_allocation_;
479 CodeTracer::Scope* trace_scope_;
481 static const int table_entry_size_;
483 friend class FrameDescription;
484 friend class DeoptimizedFrameInfo;
488 class FrameDescription {
490 FrameDescription(uint32_t frame_size,
491 JSFunction* function);
493 void* operator new(size_t size, uint32_t frame_size) {
494 // Subtracts kPointerSize, as the member frame_content_ already supplies
495 // the first element of the area to store the frame.
496 return malloc(size + frame_size - kPointerSize);
499 void operator delete(void* pointer, uint32_t frame_size) {
503 void operator delete(void* description) {
507 uint32_t GetFrameSize() const {
508 DCHECK(static_cast<uint32_t>(frame_size_) == frame_size_);
509 return static_cast<uint32_t>(frame_size_);
512 JSFunction* GetFunction() const { return function_; }
514 unsigned GetOffsetFromSlotIndex(int slot_index);
516 intptr_t GetFrameSlot(unsigned offset) {
517 return *GetFrameSlotPointer(offset);
520 double GetDoubleFrameSlot(unsigned offset) {
521 intptr_t* ptr = GetFrameSlotPointer(offset);
522 return read_double_value(reinterpret_cast<Address>(ptr));
525 simd128_value_t GetSIMD128FrameSlot(unsigned offset) {
526 intptr_t* ptr = GetFrameSlotPointer(offset);
527 return read_simd128_value(reinterpret_cast<Address>(ptr));
530 void SetFrameSlot(unsigned offset, intptr_t value) {
531 *GetFrameSlotPointer(offset) = value;
534 void SetCallerPc(unsigned offset, intptr_t value);
536 void SetCallerFp(unsigned offset, intptr_t value);
538 void SetCallerConstantPool(unsigned offset, intptr_t value);
540 intptr_t GetRegister(unsigned n) const {
542 // This convoluted DCHECK is needed to work around a gcc problem that
543 // improperly detects an array bounds overflow in optimized debug builds
544 // when using a plain DCHECK.
545 if (n >= arraysize(registers_)) {
550 return registers_[n];
553 double GetDoubleRegister(unsigned n) const;
555 simd128_value_t GetSIMD128Register(unsigned n) const {
556 DCHECK(n < arraysize(simd128_registers_));
557 return simd128_registers_[n];
560 void SetRegister(unsigned n, intptr_t value) {
561 DCHECK(n < arraysize(registers_));
562 registers_[n] = value;
565 void SetDoubleRegister(unsigned n, double value);
567 void SetSIMD128Register(unsigned n, simd128_value_t value) {
568 DCHECK(n < arraysize(simd128_registers_));
569 simd128_registers_[n] = value;
572 intptr_t GetTop() const { return top_; }
573 void SetTop(intptr_t top) { top_ = top; }
575 intptr_t GetPc() const { return pc_; }
576 void SetPc(intptr_t pc) { pc_ = pc; }
578 intptr_t GetFp() const { return fp_; }
579 void SetFp(intptr_t fp) { fp_ = fp; }
581 intptr_t GetContext() const { return context_; }
582 void SetContext(intptr_t context) { context_ = context; }
584 intptr_t GetConstantPool() const { return constant_pool_; }
585 void SetConstantPool(intptr_t constant_pool) {
586 constant_pool_ = constant_pool;
589 Smi* GetState() const { return state_; }
590 void SetState(Smi* state) { state_ = state; }
592 void SetContinuation(intptr_t pc) { continuation_ = pc; }
594 StackFrame::Type GetFrameType() const { return type_; }
595 void SetFrameType(StackFrame::Type type) { type_ = type; }
597 // Get the incoming arguments count.
598 int ComputeParametersCount();
600 // Get a parameter value for an unoptimized frame.
601 Object* GetParameter(int index);
603 // Get the expression stack height for a unoptimized frame.
604 unsigned GetExpressionCount();
606 // Get the expression stack value for an unoptimized frame.
607 Object* GetExpression(int index);
609 static int registers_offset() {
610 return OFFSET_OF(FrameDescription, registers_);
613 static int simd128_registers_offset() {
614 return OFFSET_OF(FrameDescription, simd128_registers_);
617 static int frame_size_offset() {
618 return OFFSET_OF(FrameDescription, frame_size_);
621 static int pc_offset() {
622 return OFFSET_OF(FrameDescription, pc_);
625 static int state_offset() {
626 return OFFSET_OF(FrameDescription, state_);
629 static int continuation_offset() {
630 return OFFSET_OF(FrameDescription, continuation_);
633 static int frame_content_offset() {
634 return OFFSET_OF(FrameDescription, frame_content_);
638 static const uint32_t kZapUint32 = 0xbeeddead;
640 // Frame_size_ must hold a uint32_t value. It is only a uintptr_t to
641 // keep the variable-size array frame_content_ of type intptr_t at
642 // the end of the structure aligned.
643 uintptr_t frame_size_; // Number of bytes.
644 JSFunction* function_;
645 intptr_t registers_[Register::kNumRegisters];
646 simd128_value_t simd128_registers_[SIMD128Register::kMaxNumRegisters];
651 intptr_t constant_pool_;
652 StackFrame::Type type_;
655 // Continuation is the PC where the execution continues after
657 intptr_t continuation_;
659 // This must be at the end of the object as the object is allocated larger
660 // than it's definition indicate to extend this array.
661 intptr_t frame_content_[1];
663 intptr_t* GetFrameSlotPointer(unsigned offset) {
664 DCHECK(offset < frame_size_);
665 return reinterpret_cast<intptr_t*>(
666 reinterpret_cast<Address>(this) + frame_content_offset() + offset);
669 int ComputeFixedSize();
673 class DeoptimizerData {
675 explicit DeoptimizerData(MemoryAllocator* allocator);
678 void Iterate(ObjectVisitor* v);
681 MemoryAllocator* allocator_;
682 int deopt_entry_code_entries_[Deoptimizer::kBailoutTypesWithCodeEntry];
683 MemoryChunk* deopt_entry_code_[Deoptimizer::kBailoutTypesWithCodeEntry];
685 DeoptimizedFrameInfo* deoptimized_frame_info_;
687 Deoptimizer* current_;
689 friend class Deoptimizer;
691 DISALLOW_COPY_AND_ASSIGN(DeoptimizerData);
695 class TranslationBuffer BASE_EMBEDDED {
697 explicit TranslationBuffer(Zone* zone) : contents_(256, zone) { }
699 int CurrentIndex() const { return contents_.length(); }
700 void Add(int32_t value, Zone* zone);
702 Handle<ByteArray> CreateByteArray(Factory* factory);
705 ZoneList<uint8_t> contents_;
709 class TranslationIterator BASE_EMBEDDED {
711 TranslationIterator(ByteArray* buffer, int index)
712 : buffer_(buffer), index_(index) {
713 DCHECK(index >= 0 && index < buffer->length());
718 bool HasNext() const { return index_ < buffer_->length(); }
721 for (int i = 0; i < n; i++) Next();
730 #define TRANSLATION_OPCODE_LIST(V) \
733 V(CONSTRUCT_STUB_FRAME) \
734 V(GETTER_STUB_FRAME) \
735 V(SETTER_STUB_FRAME) \
736 V(ARGUMENTS_ADAPTOR_FRAME) \
737 V(COMPILED_STUB_FRAME) \
738 V(DUPLICATED_OBJECT) \
739 V(ARGUMENTS_OBJECT) \
745 V(FLOAT32x4_REGISTER) \
746 V(FLOAT64x2_REGISTER) \
747 V(INT32x4_REGISTER) \
749 V(INT32_STACK_SLOT) \
750 V(UINT32_STACK_SLOT) \
751 V(DOUBLE_STACK_SLOT) \
752 V(FLOAT32x4_STACK_SLOT) \
753 V(FLOAT64x2_STACK_SLOT) \
754 V(INT32x4_STACK_SLOT) \
758 class Translation BASE_EMBEDDED {
760 #define DECLARE_TRANSLATION_OPCODE_ENUM(item) item,
762 TRANSLATION_OPCODE_LIST(DECLARE_TRANSLATION_OPCODE_ENUM)
765 #undef DECLARE_TRANSLATION_OPCODE_ENUM
767 Translation(TranslationBuffer* buffer, int frame_count, int jsframe_count,
770 index_(buffer->CurrentIndex()),
772 buffer_->Add(BEGIN, zone);
773 buffer_->Add(frame_count, zone);
774 buffer_->Add(jsframe_count, zone);
777 int index() const { return index_; }
780 void BeginJSFrame(BailoutId node_id, int literal_id, unsigned height);
781 void BeginCompiledStubFrame();
782 void BeginArgumentsAdaptorFrame(int literal_id, unsigned height);
783 void BeginConstructStubFrame(int literal_id, unsigned height);
784 void BeginGetterStubFrame(int literal_id);
785 void BeginSetterStubFrame(int literal_id);
786 void BeginArgumentsObject(int args_length);
787 void BeginCapturedObject(int length);
788 void DuplicateObject(int object_index);
789 void StoreRegister(Register reg);
790 void StoreInt32Register(Register reg);
791 void StoreUint32Register(Register reg);
792 void StoreDoubleRegister(DoubleRegister reg);
793 void StoreSIMD128Register(SIMD128Register reg, Opcode opcode);
794 void StoreStackSlot(int index);
795 void StoreInt32StackSlot(int index);
796 void StoreUint32StackSlot(int index);
797 void StoreDoubleStackSlot(int index);
798 void StoreSIMD128StackSlot(int index, Opcode opcode);
799 void StoreLiteral(int literal_id);
800 void StoreArgumentsObject(bool args_known, int args_index, int args_length);
802 Zone* zone() const { return zone_; }
804 static int NumberOfOperandsFor(Opcode opcode);
806 #if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER)
807 static const char* StringFor(Opcode opcode);
810 // A literal id which refers to the JSFunction itself.
811 static const int kSelfLiteralId = -239;
814 TranslationBuffer* buffer_;
820 class SlotRef BASE_EMBEDDED {
822 enum SlotRepresentation {
832 DEFERRED_OBJECT, // Object captured by the escape analysis.
833 // The number of nested objects can be obtained
834 // with the DeferredObjectLength() method
835 // (the SlotRefs of the nested objects follow
836 // this SlotRef in the depth-first order.)
837 DUPLICATE_OBJECT, // Duplicated object of a deferred object.
838 ARGUMENTS_OBJECT // Arguments object - only used to keep indexing
839 // in sync, it should not be materialized.
843 : addr_(NULL), representation_(UNKNOWN) { }
845 SlotRef(Address addr, SlotRepresentation representation)
846 : addr_(addr), representation_(representation) { }
848 SlotRef(Isolate* isolate, Object* literal)
849 : literal_(literal, isolate), representation_(LITERAL) { }
851 static SlotRef NewArgumentsObject(int length) {
853 slot.representation_ = ARGUMENTS_OBJECT;
854 slot.deferred_object_length_ = length;
858 static SlotRef NewDeferredObject(int length) {
860 slot.representation_ = DEFERRED_OBJECT;
861 slot.deferred_object_length_ = length;
865 SlotRepresentation Representation() { return representation_; }
867 static SlotRef NewDuplicateObject(int id) {
869 slot.representation_ = DUPLICATE_OBJECT;
870 slot.duplicate_object_id_ = id;
874 int GetChildrenCount() {
875 if (representation_ == DEFERRED_OBJECT ||
876 representation_ == ARGUMENTS_OBJECT) {
877 return deferred_object_length_;
883 int DuplicateObjectId() { return duplicate_object_id_; }
885 Handle<Object> GetValue(Isolate* isolate);
889 Handle<Object> literal_;
890 SlotRepresentation representation_;
891 int deferred_object_length_;
892 int duplicate_object_id_;
895 class SlotRefValueBuilder BASE_EMBEDDED {
898 JavaScriptFrame* frame,
899 int inlined_frame_index,
900 int formal_parameter_count);
902 void Prepare(Isolate* isolate);
903 Handle<Object> GetNext(Isolate* isolate, int level);
904 void Finish(Isolate* isolate);
906 int args_length() { return args_length_; }
909 List<Handle<Object> > materialized_objects_;
910 Handle<FixedArray> previously_materialized_objects_;
911 int prev_materialized_count_;
912 Address stack_frame_id_;
913 List<SlotRef> slot_refs_;
916 int first_slot_index_;
918 static SlotRef ComputeSlotForNextArgument(
919 Translation::Opcode opcode,
920 TranslationIterator* iterator,
921 DeoptimizationInputData* data,
922 JavaScriptFrame* frame);
924 Handle<Object> GetPreviouslyMaterialized(Isolate* isolate, int length);
926 static Address SlotAddress(JavaScriptFrame* frame, int slot_index) {
927 if (slot_index >= 0) {
928 const int offset = JavaScriptFrameConstants::kLocal0Offset;
929 return frame->fp() + offset - (slot_index * kPointerSize);
931 const int offset = JavaScriptFrameConstants::kLastParameterOffset;
932 return frame->fp() + offset - ((slot_index + 1) * kPointerSize);
936 Handle<Object> GetDeferredObject(Isolate* isolate);
939 class MaterializedObjectStore {
941 explicit MaterializedObjectStore(Isolate* isolate) : isolate_(isolate) {
944 Handle<FixedArray> Get(Address fp);
945 void Set(Address fp, Handle<FixedArray> materialized_objects);
946 void Remove(Address fp);
949 Isolate* isolate() { return isolate_; }
950 Handle<FixedArray> GetStackEntries();
951 Handle<FixedArray> EnsureStackEntries(int size);
953 int StackIdToIndex(Address fp);
956 List<Address> frame_fps_;
960 // Class used to represent an unoptimized frame when the debugger
961 // needs to inspect a frame that is part of an optimized frame. The
962 // internally used FrameDescription objects are not GC safe so for use
963 // by the debugger frame information is copied to an object of this type.
964 // Represents parameters in unadapted form so their number might mismatch
965 // formal parameter count.
966 class DeoptimizedFrameInfo : public Malloced {
968 DeoptimizedFrameInfo(Deoptimizer* deoptimizer,
970 bool has_arguments_adaptor,
971 bool has_construct_stub);
972 virtual ~DeoptimizedFrameInfo();
975 void Iterate(ObjectVisitor* v);
977 // Return the number of incoming arguments.
978 int parameters_count() { return parameters_count_; }
980 // Return the height of the expression stack.
981 int expression_count() { return expression_count_; }
983 // Get the frame function.
984 JSFunction* GetFunction() {
988 // Get the frame context.
989 Object* GetContext() { return context_; }
991 // Check if this frame is preceded by construct stub frame. The bottom-most
992 // inlined frame might still be called by an uninlined construct stub.
993 bool HasConstructStub() {
994 return has_construct_stub_;
997 // Get an incoming argument.
998 Object* GetParameter(int index) {
999 DCHECK(0 <= index && index < parameters_count());
1000 return parameters_[index];
1003 // Get an expression from the expression stack.
1004 Object* GetExpression(int index) {
1005 DCHECK(0 <= index && index < expression_count());
1006 return expression_stack_[index];
1009 int GetSourcePosition() {
1010 return source_position_;
1014 // Set an incoming argument.
1015 void SetParameter(int index, Object* obj) {
1016 DCHECK(0 <= index && index < parameters_count());
1017 parameters_[index] = obj;
1020 // Set an expression on the expression stack.
1021 void SetExpression(int index, Object* obj) {
1022 DCHECK(0 <= index && index < expression_count());
1023 expression_stack_[index] = obj;
1026 JSFunction* function_;
1028 bool has_construct_stub_;
1029 int parameters_count_;
1030 int expression_count_;
1031 Object** parameters_;
1032 Object** expression_stack_;
1033 int source_position_;
1035 friend class Deoptimizer;
1038 } } // namespace v8::internal
1040 #endif // V8_DEOPTIMIZER_H_