| 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 VM_DEFERRED_OBJECTS_H_ | 5 #ifndef VM_DEFERRED_OBJECTS_H_ |
| 6 #define VM_DEFERRED_OBJECTS_H_ | 6 #define VM_DEFERRED_OBJECTS_H_ |
| 7 | 7 |
| 8 #include "platform/globals.h" | 8 #include "platform/globals.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| 11 | 11 |
| 12 // Forward declarations. | 12 // Forward declarations. |
| 13 class Instance; | 13 class Object; |
| 14 class RawInstance; | 14 class RawObject; |
| 15 class RawObject; | 15 class RawObject; |
| 16 class DeoptContext; | 16 class DeoptContext; |
| 17 | 17 |
| 18 // Used by the deoptimization infrastructure to defer allocation of | 18 // Used by the deoptimization infrastructure to defer allocation of |
| 19 // unboxed objects until frame is fully rewritten and GC is safe. | 19 // unboxed objects until frame is fully rewritten and GC is safe. |
| 20 // Describes a stack slot that should be populated with a reference to | 20 // Describes a stack slot that should be populated with a reference to |
| 21 // the materialized object. | 21 // the materialized object. |
| 22 class DeferredSlot { | 22 class DeferredSlot { |
| 23 public: | 23 public: |
| 24 DeferredSlot(RawInstance** slot, DeferredSlot* next) | 24 DeferredSlot(RawObject** slot, DeferredSlot* next) |
| 25 : slot_(slot), next_(next) { } | 25 : slot_(slot), next_(next) { } |
| 26 virtual ~DeferredSlot() { } | 26 virtual ~DeferredSlot() { } |
| 27 | 27 |
| 28 RawInstance** slot() const { return slot_; } | 28 RawObject** slot() const { return slot_; } |
| 29 DeferredSlot* next() const { return next_; } | 29 DeferredSlot* next() const { return next_; } |
| 30 | 30 |
| 31 virtual void Materialize(DeoptContext* deopt_context) = 0; | 31 virtual void Materialize(DeoptContext* deopt_context) = 0; |
| 32 | 32 |
| 33 private: | 33 private: |
| 34 RawInstance** const slot_; | 34 RawObject** const slot_; |
| 35 DeferredSlot* const next_; | 35 DeferredSlot* const next_; |
| 36 | 36 |
| 37 DISALLOW_COPY_AND_ASSIGN(DeferredSlot); | 37 DISALLOW_COPY_AND_ASSIGN(DeferredSlot); |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 | 40 |
| 41 class DeferredDouble : public DeferredSlot { | 41 class DeferredDouble : public DeferredSlot { |
| 42 public: | 42 public: |
| 43 DeferredDouble(double value, RawInstance** slot, DeferredSlot* next) | 43 DeferredDouble(double value, RawObject** slot, DeferredSlot* next) |
| 44 : DeferredSlot(slot, next), value_(value) { } | 44 : DeferredSlot(slot, next), value_(value) { } |
| 45 | 45 |
| 46 virtual void Materialize(DeoptContext* deopt_context); | 46 virtual void Materialize(DeoptContext* deopt_context); |
| 47 | 47 |
| 48 double value() const { return value_; } | 48 double value() const { return value_; } |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 const double value_; | 51 const double value_; |
| 52 | 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(DeferredDouble); | 53 DISALLOW_COPY_AND_ASSIGN(DeferredDouble); |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 | 56 |
| 57 class DeferredMint : public DeferredSlot { | 57 class DeferredMint : public DeferredSlot { |
| 58 public: | 58 public: |
| 59 DeferredMint(int64_t value, RawInstance** slot, DeferredSlot* next) | 59 DeferredMint(int64_t value, RawObject** slot, DeferredSlot* next) |
| 60 : DeferredSlot(slot, next), value_(value) { } | 60 : DeferredSlot(slot, next), value_(value) { } |
| 61 | 61 |
| 62 virtual void Materialize(DeoptContext* deopt_context); | 62 virtual void Materialize(DeoptContext* deopt_context); |
| 63 | 63 |
| 64 int64_t value() const { return value_; } | 64 int64_t value() const { return value_; } |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 const int64_t value_; | 67 const int64_t value_; |
| 68 | 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(DeferredMint); | 69 DISALLOW_COPY_AND_ASSIGN(DeferredMint); |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 | 72 |
| 73 class DeferredFloat32x4 : public DeferredSlot { | 73 class DeferredFloat32x4 : public DeferredSlot { |
| 74 public: | 74 public: |
| 75 DeferredFloat32x4(simd128_value_t value, RawInstance** slot, | 75 DeferredFloat32x4(simd128_value_t value, RawObject** slot, |
| 76 DeferredSlot* next) | 76 DeferredSlot* next) |
| 77 : DeferredSlot(slot, next), value_(value) { } | 77 : DeferredSlot(slot, next), value_(value) { } |
| 78 | 78 |
| 79 virtual void Materialize(DeoptContext* deopt_context); | 79 virtual void Materialize(DeoptContext* deopt_context); |
| 80 | 80 |
| 81 simd128_value_t value() const { return value_; } | 81 simd128_value_t value() const { return value_; } |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 const simd128_value_t value_; | 84 const simd128_value_t value_; |
| 85 | 85 |
| 86 DISALLOW_COPY_AND_ASSIGN(DeferredFloat32x4); | 86 DISALLOW_COPY_AND_ASSIGN(DeferredFloat32x4); |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 | 89 |
| 90 class DeferredFloat64x2 : public DeferredSlot { | 90 class DeferredFloat64x2 : public DeferredSlot { |
| 91 public: | 91 public: |
| 92 DeferredFloat64x2(simd128_value_t value, RawInstance** slot, | 92 DeferredFloat64x2(simd128_value_t value, RawObject** slot, |
| 93 DeferredSlot* next) | 93 DeferredSlot* next) |
| 94 : DeferredSlot(slot, next), value_(value) { } | 94 : DeferredSlot(slot, next), value_(value) { } |
| 95 | 95 |
| 96 virtual void Materialize(DeoptContext* deopt_context); | 96 virtual void Materialize(DeoptContext* deopt_context); |
| 97 | 97 |
| 98 simd128_value_t value() const { return value_; } | 98 simd128_value_t value() const { return value_; } |
| 99 | 99 |
| 100 private: | 100 private: |
| 101 const simd128_value_t value_; | 101 const simd128_value_t value_; |
| 102 | 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(DeferredFloat64x2); | 103 DISALLOW_COPY_AND_ASSIGN(DeferredFloat64x2); |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 | 106 |
| 107 class DeferredInt32x4 : public DeferredSlot { | 107 class DeferredInt32x4 : public DeferredSlot { |
| 108 public: | 108 public: |
| 109 DeferredInt32x4(simd128_value_t value, RawInstance** slot, | 109 DeferredInt32x4(simd128_value_t value, RawObject** slot, |
| 110 DeferredSlot* next) | 110 DeferredSlot* next) |
| 111 : DeferredSlot(slot, next), value_(value) { } | 111 : DeferredSlot(slot, next), value_(value) { } |
| 112 | 112 |
| 113 virtual void Materialize(DeoptContext* deopt_context); | 113 virtual void Materialize(DeoptContext* deopt_context); |
| 114 | 114 |
| 115 simd128_value_t value() const { return value_; } | 115 simd128_value_t value() const { return value_; } |
| 116 | 116 |
| 117 private: | 117 private: |
| 118 const simd128_value_t value_; | 118 const simd128_value_t value_; |
| 119 | 119 |
| 120 DISALLOW_COPY_AND_ASSIGN(DeferredInt32x4); | 120 DISALLOW_COPY_AND_ASSIGN(DeferredInt32x4); |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 | 123 |
| 124 // Describes a slot that contains a reference to an object that had its | 124 // Describes a slot that contains a reference to an object that had its |
| 125 // allocation removed by AllocationSinking pass. | 125 // allocation removed by AllocationSinking pass. |
| 126 // Object itself is described and materialized by DeferredObject. | 126 // Object itself is described and materialized by DeferredObject. |
| 127 class DeferredObjectRef : public DeferredSlot { | 127 class DeferredObjectRef : public DeferredSlot { |
| 128 public: | 128 public: |
| 129 DeferredObjectRef(intptr_t index, RawInstance** slot, DeferredSlot* next) | 129 DeferredObjectRef(intptr_t index, RawObject** slot, DeferredSlot* next) |
| 130 : DeferredSlot(slot, next), index_(index) { } | 130 : DeferredSlot(slot, next), index_(index) { } |
| 131 | 131 |
| 132 virtual void Materialize(DeoptContext* deopt_context); | 132 virtual void Materialize(DeoptContext* deopt_context); |
| 133 | 133 |
| 134 intptr_t index() const { return index_; } | 134 intptr_t index() const { return index_; } |
| 135 | 135 |
| 136 private: | 136 private: |
| 137 const intptr_t index_; | 137 const intptr_t index_; |
| 138 | 138 |
| 139 DISALLOW_COPY_AND_ASSIGN(DeferredObjectRef); | 139 DISALLOW_COPY_AND_ASSIGN(DeferredObjectRef); |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 | 142 |
| 143 // Describes an object which allocation was removed by AllocationSinking pass. | 143 // Describes an object which allocation was removed by AllocationSinking pass. |
| 144 // Arguments for materialization are stored as a part of expression stack | 144 // Arguments for materialization are stored as a part of expression stack |
| 145 // for the bottommost deoptimized frame so that GC could discover them. | 145 // for the bottommost deoptimized frame so that GC could discover them. |
| 146 // They will be removed from the stack at the very end of deoptimization. | 146 // They will be removed from the stack at the very end of deoptimization. |
| 147 class DeferredObject { | 147 class DeferredObject { |
| 148 public: | 148 public: |
| 149 DeferredObject(intptr_t field_count, intptr_t* args) | 149 DeferredObject(intptr_t field_count, intptr_t* args) |
| 150 : field_count_(field_count), | 150 : field_count_(field_count), |
| 151 args_(reinterpret_cast<RawObject**>(args)), | 151 args_(reinterpret_cast<RawObject**>(args)), |
| 152 object_(NULL) { } | 152 object_(NULL) { } |
| 153 | 153 |
| 154 intptr_t ArgumentCount() const { | 154 intptr_t ArgumentCount() const { |
| 155 return kFieldsStartIndex + kFieldEntrySize * field_count_; | 155 return kFieldsStartIndex + kFieldEntrySize * field_count_; |
| 156 } | 156 } |
| 157 | 157 |
| 158 RawInstance* object(); | 158 RawObject* object(); |
| 159 | 159 |
| 160 // Fill object with actual field values. | 160 // Fill object with actual field values. |
| 161 void Fill(); | 161 void Fill(); |
| 162 | 162 |
| 163 private: | 163 private: |
| 164 enum { | 164 enum { |
| 165 kClassIndex = 0, | 165 kClassIndex = 0, |
| 166 kFieldsStartIndex = kClassIndex + 1 | 166 kLengthIndex, // Number of context variables for contexts, -1 otherwise. |
| 167 kFieldsStartIndex |
| 167 }; | 168 }; |
| 168 | 169 |
| 169 enum { | 170 enum { |
| 170 kOffsetIndex = 0, | 171 kOffsetIndex = 0, |
| 171 kValueIndex, | 172 kValueIndex, |
| 172 kFieldEntrySize, | 173 kFieldEntrySize, |
| 173 }; | 174 }; |
| 174 | 175 |
| 175 // Allocate the object but keep its fields null-initialized. Actual field | 176 // Allocate the object but keep its fields null-initialized. Actual field |
| 176 // values will be filled later by the Fill method. This separation between | 177 // values will be filled later by the Fill method. This separation between |
| 177 // allocation and filling is needed because dematerialized objects form | 178 // allocation and filling is needed because dematerialized objects form |
| 178 // a graph which can contain cycles. | 179 // a graph which can contain cycles. |
| 179 void Create(); | 180 void Create(); |
| 180 | 181 |
| 181 RawObject* GetClass() const { | 182 RawObject* GetClass() const { |
| 182 return args_[kClassIndex]; | 183 return args_[kClassIndex]; |
| 183 } | 184 } |
| 184 | 185 |
| 186 RawObject* GetLength() const { |
| 187 return args_[kLengthIndex]; |
| 188 } |
| 189 |
| 185 RawObject* GetFieldOffset(intptr_t index) const { | 190 RawObject* GetFieldOffset(intptr_t index) const { |
| 186 return args_[kFieldsStartIndex + kFieldEntrySize * index + kOffsetIndex]; | 191 return args_[kFieldsStartIndex + kFieldEntrySize * index + kOffsetIndex]; |
| 187 } | 192 } |
| 188 | 193 |
| 189 RawObject* GetValue(intptr_t index) const { | 194 RawObject* GetValue(intptr_t index) const { |
| 190 return args_[kFieldsStartIndex + kFieldEntrySize * index + kValueIndex]; | 195 return args_[kFieldsStartIndex + kFieldEntrySize * index + kValueIndex]; |
| 191 } | 196 } |
| 192 | 197 |
| 193 // Amount of fields that have to be initialized. | 198 // Amount of fields that have to be initialized. |
| 194 const intptr_t field_count_; | 199 const intptr_t field_count_; |
| 195 | 200 |
| 196 // Pointer to the first materialization argument on the stack. | 201 // Pointer to the first materialization argument on the stack. |
| 197 // The first argument is Class of the instance to materialize followed by | 202 // The first argument is Class of the instance to materialize followed by |
| 198 // Field, value pairs. | 203 // Field, value pairs. |
| 199 RawObject** args_; | 204 RawObject** args_; |
| 200 | 205 |
| 201 // Object materialized from this description. | 206 // Object materialized from this description. |
| 202 const Instance* object_; | 207 const Object* object_; |
| 203 | 208 |
| 204 DISALLOW_COPY_AND_ASSIGN(DeferredObject); | 209 DISALLOW_COPY_AND_ASSIGN(DeferredObject); |
| 205 }; | 210 }; |
| 206 | 211 |
| 207 } // namespace dart | 212 } // namespace dart |
| 208 | 213 |
| 209 #endif // VM_DEFERRED_OBJECTS_H_ | 214 #endif // VM_DEFERRED_OBJECTS_H_ |
| OLD | NEW |