OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef RUNTIME_VM_DEOPT_INSTRUCTIONS_H_ | 5 #ifndef RUNTIME_VM_DEOPT_INSTRUCTIONS_H_ |
6 #define RUNTIME_VM_DEOPT_INSTRUCTIONS_H_ | 6 #define RUNTIME_VM_DEOPT_INSTRUCTIONS_H_ |
7 | 7 |
8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/code_descriptors.h" | |
11 #include "vm/code_generator.h" | 10 #include "vm/code_generator.h" |
12 #include "vm/deferred_objects.h" | 11 #include "vm/deferred_objects.h" |
13 #include "vm/flow_graph_compiler.h" | 12 #include "vm/flow_graph_compiler.h" |
14 #include "vm/growable_array.h" | 13 #include "vm/growable_array.h" |
15 #include "vm/locations.h" | 14 #include "vm/locations.h" |
16 #include "vm/object.h" | 15 #include "vm/object.h" |
17 #include "vm/stack_frame.h" | 16 #include "vm/stack_frame.h" |
18 #include "vm/thread.h" | 17 #include "vm/thread.h" |
19 | 18 |
20 namespace dart { | 19 namespace dart { |
(...skipping 30 matching lines...) Expand all Loading... |
51 intptr_t* GetSourceFrameAddressAt(intptr_t index) const { | 50 intptr_t* GetSourceFrameAddressAt(intptr_t index) const { |
52 ASSERT(source_frame_ != NULL); | 51 ASSERT(source_frame_ != NULL); |
53 ASSERT((0 <= index) && (index < source_frame_size_)); | 52 ASSERT((0 <= index) && (index < source_frame_size_)); |
54 #if !defined(TARGET_ARCH_DBC) | 53 #if !defined(TARGET_ARCH_DBC) |
55 // Convert FP relative index to SP relative one. | 54 // Convert FP relative index to SP relative one. |
56 index = source_frame_size_ - 1 - index; | 55 index = source_frame_size_ - 1 - index; |
57 #endif // !defined(TARGET_ARCH_DBC) | 56 #endif // !defined(TARGET_ARCH_DBC) |
58 return &source_frame_[index]; | 57 return &source_frame_[index]; |
59 } | 58 } |
60 | 59 |
61 // Returns index in stack slot notation where -1 is the first argument | |
62 // For DBC returns index directly relative to FP. | |
63 intptr_t GetStackSlot(intptr_t index) const { | |
64 ASSERT((0 <= index) && (index < source_frame_size_)); | |
65 index -= num_args_; | |
66 #if defined(TARGET_ARCH_DBC) | |
67 return index < 0 ? index - kDartFrameFixedSize : index; | |
68 #else | |
69 return index < 0 ? index : index - kDartFrameFixedSize; | |
70 #endif // defined(TARGET_ARCH_DBC) | |
71 } | |
72 | |
73 intptr_t GetSourceFp() const; | 60 intptr_t GetSourceFp() const; |
74 intptr_t GetSourcePp() const; | 61 intptr_t GetSourcePp() const; |
75 intptr_t GetSourcePc() const; | 62 intptr_t GetSourcePc() const; |
76 | 63 |
77 intptr_t GetCallerFp() const; | 64 intptr_t GetCallerFp() const; |
78 void SetCallerFp(intptr_t callers_fp); | 65 void SetCallerFp(intptr_t callers_fp); |
79 | 66 |
80 RawObject* ObjectAt(intptr_t index) const { | 67 RawObject* ObjectAt(intptr_t index) const { |
81 const ObjectPool& object_pool = ObjectPool::Handle(object_pool_); | 68 const ObjectPool& object_pool = ObjectPool::Handle(object_pool_); |
82 return object_pool.ObjectAt(index); | 69 return object_pool.ObjectAt(index); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 bool HasDeoptFlag(ICData::DeoptFlags flag) { | 146 bool HasDeoptFlag(ICData::DeoptFlags flag) { |
160 return (deopt_flags_ & flag) != 0; | 147 return (deopt_flags_ & flag) != 0; |
161 } | 148 } |
162 | 149 |
163 RawTypedData* deopt_info() const { return deopt_info_; } | 150 RawTypedData* deopt_info() const { return deopt_info_; } |
164 | 151 |
165 // Fills the destination frame but defers materialization of | 152 // Fills the destination frame but defers materialization of |
166 // objects. | 153 // objects. |
167 void FillDestFrame(); | 154 void FillDestFrame(); |
168 | 155 |
169 // Allocate and prepare exceptions metadata for TrySync | |
170 intptr_t* CatchEntryState(intptr_t num_vars); | |
171 | |
172 // Materializes all deferred objects. Returns the total number of | 156 // Materializes all deferred objects. Returns the total number of |
173 // artificial arguments used during deoptimization. | 157 // artificial arguments used during deoptimization. |
174 intptr_t MaterializeDeferredObjects(); | 158 intptr_t MaterializeDeferredObjects(); |
175 | 159 |
176 RawArray* DestFrameAsArray(); | 160 RawArray* DestFrameAsArray(); |
177 | 161 |
178 void VisitObjectPointers(ObjectPointerVisitor* visitor); | 162 void VisitObjectPointers(ObjectPointerVisitor* visitor); |
179 | 163 |
180 void DeferMaterializedObjectRef(intptr_t idx, intptr_t* slot) { | 164 void DeferMaterializedObjectRef(intptr_t idx, intptr_t* slot) { |
181 deferred_slots_ = new DeferredObjectRef( | 165 deferred_slots_ = new DeferredObjectRef( |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 | 264 |
281 intptr_t deferred_objects_count_; | 265 intptr_t deferred_objects_count_; |
282 DeferredObject** deferred_objects_; | 266 DeferredObject** deferred_objects_; |
283 | 267 |
284 const bool is_lazy_deopt_; | 268 const bool is_lazy_deopt_; |
285 const bool deoptimizing_code_; | 269 const bool deoptimizing_code_; |
286 | 270 |
287 DISALLOW_COPY_AND_ASSIGN(DeoptContext); | 271 DISALLOW_COPY_AND_ASSIGN(DeoptContext); |
288 }; | 272 }; |
289 | 273 |
| 274 |
290 // Represents one deopt instruction, e.g, setup return address, store object, | 275 // Represents one deopt instruction, e.g, setup return address, store object, |
291 // store register, etc. The target is defined by instruction's position in | 276 // store register, etc. The target is defined by instruction's position in |
292 // the deopt-info array. | 277 // the deopt-info array. |
293 class DeoptInstr : public ZoneAllocated { | 278 class DeoptInstr : public ZoneAllocated { |
294 public: | 279 public: |
295 enum Kind { | 280 enum Kind { |
296 kRetAddress, | 281 kRetAddress, |
297 kConstant, | 282 kConstant, |
298 kWord, | 283 kWord, |
299 kDouble, | 284 kDouble, |
(...skipping 27 matching lines...) Expand all Loading... |
327 if (args != NULL) { | 312 if (args != NULL) { |
328 return Thread::Current()->zone()->PrintToString( | 313 return Thread::Current()->zone()->PrintToString( |
329 "%s(%s)", KindToCString(kind()), args); | 314 "%s(%s)", KindToCString(kind()), args); |
330 } else { | 315 } else { |
331 return KindToCString(kind()); | 316 return KindToCString(kind()); |
332 } | 317 } |
333 } | 318 } |
334 | 319 |
335 virtual void Execute(DeoptContext* deopt_context, intptr_t* dest_addr) = 0; | 320 virtual void Execute(DeoptContext* deopt_context, intptr_t* dest_addr) = 0; |
336 | 321 |
337 // Convert DeoptInstr to TrySync metadata entry. | |
338 virtual CatchEntryStatePair ToCatchEntryStatePair(DeoptContext* deopt_context, | |
339 intptr_t dest_slot) { | |
340 UNREACHABLE(); | |
341 return CatchEntryStatePair(); | |
342 } | |
343 | |
344 virtual DeoptInstr::Kind kind() const = 0; | 322 virtual DeoptInstr::Kind kind() const = 0; |
345 | 323 |
346 bool Equals(const DeoptInstr& other) const { | 324 bool Equals(const DeoptInstr& other) const { |
347 return (kind() == other.kind()) && (source_index() == other.source_index()); | 325 return (kind() == other.kind()) && (source_index() == other.source_index()); |
348 } | 326 } |
349 | 327 |
350 // Get the code and return address which is encoded in this | 328 // Get the code and return address which is encoded in this |
351 // kRetAfterAddress deopt instruction. | 329 // kRetAfterAddress deopt instruction. |
352 static uword GetRetAddress(DeoptInstr* instr, | 330 static uword GetRetAddress(DeoptInstr* instr, |
353 const ObjectPool& object_pool, | 331 const ObjectPool& object_pool, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 T Value(DeoptContext* context) const { | 405 T Value(DeoptContext* context) const { |
428 if (is_register()) { | 406 if (is_register()) { |
429 return static_cast<T>( | 407 return static_cast<T>( |
430 RegisterReader<RegisterType, T>::Read(context, reg())); | 408 RegisterReader<RegisterType, T>::Read(context, reg())); |
431 } else { | 409 } else { |
432 return *reinterpret_cast<T*>( | 410 return *reinterpret_cast<T*>( |
433 context->GetSourceFrameAddressAt(raw_index())); | 411 context->GetSourceFrameAddressAt(raw_index())); |
434 } | 412 } |
435 } | 413 } |
436 | 414 |
437 intptr_t StackSlot(DeoptContext* context) const { | |
438 if (is_register()) { | |
439 return raw_index(); // in DBC stack slots are registers. | |
440 } else { | |
441 return context->GetStackSlot(raw_index()); | |
442 } | |
443 } | |
444 | |
445 intptr_t source_index() const { return source_index_; } | 415 intptr_t source_index() const { return source_index_; } |
446 | 416 |
447 const char* ToCString() const { | 417 const char* ToCString() const { |
448 if (is_register()) { | 418 if (is_register()) { |
449 return Name(reg()); | 419 return Name(reg()); |
450 } else { | 420 } else { |
451 return Thread::Current()->zone()->PrintToString("s%" Pd "", raw_index()); | 421 return Thread::Current()->zone()->PrintToString("s%" Pd "", raw_index()); |
452 } | 422 } |
453 } | 423 } |
454 | 424 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 class ReasonField : public BitField<intptr_t, ICData::DeoptReasonId, 0, 8> {}; | 572 class ReasonField : public BitField<intptr_t, ICData::DeoptReasonId, 0, 8> {}; |
603 class FlagsField : public BitField<intptr_t, uint32_t, 8, 8> {}; | 573 class FlagsField : public BitField<intptr_t, uint32_t, 8, 8> {}; |
604 | 574 |
605 private: | 575 private: |
606 static const intptr_t kEntrySize = 3; | 576 static const intptr_t kEntrySize = 3; |
607 }; | 577 }; |
608 | 578 |
609 } // namespace dart | 579 } // namespace dart |
610 | 580 |
611 #endif // RUNTIME_VM_DEOPT_INSTRUCTIONS_H_ | 581 #endif // RUNTIME_VM_DEOPT_INSTRUCTIONS_H_ |
OLD | NEW |