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_DEFERRED_OBJECTS_H_ | 5 #ifndef RUNTIME_VM_DEFERRED_OBJECTS_H_ |
6 #define RUNTIME_VM_DEFERRED_OBJECTS_H_ | 6 #define RUNTIME_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 Object; | 13 class Object; |
14 class RawObject; | 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(RawObject** 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 RawObject** 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 RawObject** 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, RawObject** 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, RawObject** 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, RawObject** slot, | 75 DeferredFloat32x4(simd128_value_t value, RawObject** slot, DeferredSlot* next) |
76 DeferredSlot* next) | 76 : DeferredSlot(slot, next), value_(value) {} |
77 : DeferredSlot(slot, next), value_(value) { } | |
78 | 77 |
79 virtual void Materialize(DeoptContext* deopt_context); | 78 virtual void Materialize(DeoptContext* deopt_context); |
80 | 79 |
81 simd128_value_t value() const { return value_; } | 80 simd128_value_t value() const { return value_; } |
82 | 81 |
83 private: | 82 private: |
84 const simd128_value_t value_; | 83 const simd128_value_t value_; |
85 | 84 |
86 DISALLOW_COPY_AND_ASSIGN(DeferredFloat32x4); | 85 DISALLOW_COPY_AND_ASSIGN(DeferredFloat32x4); |
87 }; | 86 }; |
88 | 87 |
89 | 88 |
90 class DeferredFloat64x2 : public DeferredSlot { | 89 class DeferredFloat64x2 : public DeferredSlot { |
91 public: | 90 public: |
92 DeferredFloat64x2(simd128_value_t value, RawObject** slot, | 91 DeferredFloat64x2(simd128_value_t value, RawObject** slot, DeferredSlot* next) |
93 DeferredSlot* next) | 92 : DeferredSlot(slot, next), value_(value) {} |
94 : DeferredSlot(slot, next), value_(value) { } | |
95 | 93 |
96 virtual void Materialize(DeoptContext* deopt_context); | 94 virtual void Materialize(DeoptContext* deopt_context); |
97 | 95 |
98 simd128_value_t value() const { return value_; } | 96 simd128_value_t value() const { return value_; } |
99 | 97 |
100 private: | 98 private: |
101 const simd128_value_t value_; | 99 const simd128_value_t value_; |
102 | 100 |
103 DISALLOW_COPY_AND_ASSIGN(DeferredFloat64x2); | 101 DISALLOW_COPY_AND_ASSIGN(DeferredFloat64x2); |
104 }; | 102 }; |
105 | 103 |
106 | 104 |
107 class DeferredInt32x4 : public DeferredSlot { | 105 class DeferredInt32x4 : public DeferredSlot { |
108 public: | 106 public: |
109 DeferredInt32x4(simd128_value_t value, RawObject** slot, | 107 DeferredInt32x4(simd128_value_t value, RawObject** slot, DeferredSlot* next) |
110 DeferredSlot* next) | 108 : DeferredSlot(slot, next), value_(value) {} |
111 : DeferredSlot(slot, next), value_(value) { } | |
112 | 109 |
113 virtual void Materialize(DeoptContext* deopt_context); | 110 virtual void Materialize(DeoptContext* deopt_context); |
114 | 111 |
115 simd128_value_t value() const { return value_; } | 112 simd128_value_t value() const { return value_; } |
116 | 113 |
117 private: | 114 private: |
118 const simd128_value_t value_; | 115 const simd128_value_t value_; |
119 | 116 |
120 DISALLOW_COPY_AND_ASSIGN(DeferredInt32x4); | 117 DISALLOW_COPY_AND_ASSIGN(DeferredInt32x4); |
121 }; | 118 }; |
122 | 119 |
123 | 120 |
124 // Describes a slot that contains a reference to an object that had its | 121 // Describes a slot that contains a reference to an object that had its |
125 // allocation removed by AllocationSinking pass. | 122 // allocation removed by AllocationSinking pass. |
126 // Object itself is described and materialized by DeferredObject. | 123 // Object itself is described and materialized by DeferredObject. |
127 class DeferredObjectRef : public DeferredSlot { | 124 class DeferredObjectRef : public DeferredSlot { |
128 public: | 125 public: |
129 DeferredObjectRef(intptr_t index, RawObject** slot, DeferredSlot* next) | 126 DeferredObjectRef(intptr_t index, RawObject** slot, DeferredSlot* next) |
130 : DeferredSlot(slot, next), index_(index) { } | 127 : DeferredSlot(slot, next), index_(index) {} |
131 | 128 |
132 virtual void Materialize(DeoptContext* deopt_context); | 129 virtual void Materialize(DeoptContext* deopt_context); |
133 | 130 |
134 intptr_t index() const { return index_; } | 131 intptr_t index() const { return index_; } |
135 | 132 |
136 private: | 133 private: |
137 const intptr_t index_; | 134 const intptr_t index_; |
138 | 135 |
139 DISALLOW_COPY_AND_ASSIGN(DeferredObjectRef); | 136 DISALLOW_COPY_AND_ASSIGN(DeferredObjectRef); |
140 }; | 137 }; |
141 | 138 |
142 | 139 |
143 class DeferredRetAddr : public DeferredSlot { | 140 class DeferredRetAddr : public DeferredSlot { |
144 public: | 141 public: |
145 DeferredRetAddr(intptr_t index, | 142 DeferredRetAddr(intptr_t index, |
146 intptr_t deopt_id, | 143 intptr_t deopt_id, |
147 RawObject** slot, | 144 RawObject** slot, |
148 DeferredSlot* next) | 145 DeferredSlot* next) |
149 : DeferredSlot(slot, next), index_(index), deopt_id_(deopt_id) { } | 146 : DeferredSlot(slot, next), index_(index), deopt_id_(deopt_id) {} |
150 | 147 |
151 virtual void Materialize(DeoptContext* deopt_context); | 148 virtual void Materialize(DeoptContext* deopt_context); |
152 | 149 |
153 intptr_t index() const { return index_; } | 150 intptr_t index() const { return index_; } |
154 | 151 |
155 private: | 152 private: |
156 const intptr_t index_; | 153 const intptr_t index_; |
157 const intptr_t deopt_id_; | 154 const intptr_t deopt_id_; |
158 | 155 |
159 DISALLOW_COPY_AND_ASSIGN(DeferredRetAddr); | 156 DISALLOW_COPY_AND_ASSIGN(DeferredRetAddr); |
160 }; | 157 }; |
161 | 158 |
162 | 159 |
163 class DeferredPcMarker : public DeferredSlot { | 160 class DeferredPcMarker : public DeferredSlot { |
164 public: | 161 public: |
165 DeferredPcMarker(intptr_t index, RawObject** slot, DeferredSlot* next) | 162 DeferredPcMarker(intptr_t index, RawObject** slot, DeferredSlot* next) |
166 : DeferredSlot(slot, next), index_(index) { } | 163 : DeferredSlot(slot, next), index_(index) {} |
167 | 164 |
168 virtual void Materialize(DeoptContext* deopt_context); | 165 virtual void Materialize(DeoptContext* deopt_context); |
169 | 166 |
170 intptr_t index() const { return index_; } | 167 intptr_t index() const { return index_; } |
171 | 168 |
172 private: | 169 private: |
173 const intptr_t index_; | 170 const intptr_t index_; |
174 | 171 |
175 DISALLOW_COPY_AND_ASSIGN(DeferredPcMarker); | 172 DISALLOW_COPY_AND_ASSIGN(DeferredPcMarker); |
176 }; | 173 }; |
177 | 174 |
178 | 175 |
179 class DeferredPp : public DeferredSlot { | 176 class DeferredPp : public DeferredSlot { |
180 public: | 177 public: |
181 DeferredPp(intptr_t index, RawObject** slot, DeferredSlot* next) | 178 DeferredPp(intptr_t index, RawObject** slot, DeferredSlot* next) |
182 : DeferredSlot(slot, next), index_(index) { } | 179 : DeferredSlot(slot, next), index_(index) {} |
183 | 180 |
184 virtual void Materialize(DeoptContext* deopt_context); | 181 virtual void Materialize(DeoptContext* deopt_context); |
185 | 182 |
186 intptr_t index() const { return index_; } | 183 intptr_t index() const { return index_; } |
187 | 184 |
188 private: | 185 private: |
189 const intptr_t index_; | 186 const intptr_t index_; |
190 | 187 |
191 DISALLOW_COPY_AND_ASSIGN(DeferredPp); | 188 DISALLOW_COPY_AND_ASSIGN(DeferredPp); |
192 }; | 189 }; |
193 | 190 |
194 | 191 |
195 // Describes an object which allocation was removed by AllocationSinking pass. | 192 // Describes an object which allocation was removed by AllocationSinking pass. |
196 // Arguments for materialization are stored as a part of expression stack | 193 // Arguments for materialization are stored as a part of expression stack |
197 // for the bottommost deoptimized frame so that GC could discover them. | 194 // for the bottommost deoptimized frame so that GC could discover them. |
198 // They will be removed from the stack at the very end of deoptimization. | 195 // They will be removed from the stack at the very end of deoptimization. |
199 class DeferredObject { | 196 class DeferredObject { |
200 public: | 197 public: |
201 DeferredObject(intptr_t field_count, intptr_t* args) | 198 DeferredObject(intptr_t field_count, intptr_t* args) |
202 : field_count_(field_count), | 199 : field_count_(field_count), |
203 args_(reinterpret_cast<RawObject**>(args)), | 200 args_(reinterpret_cast<RawObject**>(args)), |
204 object_(NULL) { } | 201 object_(NULL) {} |
205 | 202 |
206 intptr_t ArgumentCount() const { | 203 intptr_t ArgumentCount() const { |
207 return kFieldsStartIndex + kFieldEntrySize * field_count_; | 204 return kFieldsStartIndex + kFieldEntrySize * field_count_; |
208 } | 205 } |
209 | 206 |
210 RawObject* object(); | 207 RawObject* object(); |
211 | 208 |
212 // Fill object with actual field values. | 209 // Fill object with actual field values. |
213 void Fill(); | 210 void Fill(); |
214 | 211 |
(...skipping 17 matching lines...) Expand all Loading... |
232 void Create(); | 229 void Create(); |
233 | 230 |
234 RawObject* GetArg(intptr_t index) const { | 231 RawObject* GetArg(intptr_t index) const { |
235 #if !defined(TARGET_ARCH_DBC) | 232 #if !defined(TARGET_ARCH_DBC) |
236 return args_[index]; | 233 return args_[index]; |
237 #else | 234 #else |
238 return args_[-index]; | 235 return args_[-index]; |
239 #endif | 236 #endif |
240 } | 237 } |
241 | 238 |
242 RawObject* GetClass() const { | 239 RawObject* GetClass() const { return GetArg(kClassIndex); } |
243 return GetArg(kClassIndex); | |
244 } | |
245 | 240 |
246 RawObject* GetLength() const { | 241 RawObject* GetLength() const { return GetArg(kLengthIndex); } |
247 return GetArg(kLengthIndex); | |
248 } | |
249 | 242 |
250 RawObject* GetFieldOffset(intptr_t index) const { | 243 RawObject* GetFieldOffset(intptr_t index) const { |
251 return GetArg(kFieldsStartIndex + kFieldEntrySize * index + kOffsetIndex); | 244 return GetArg(kFieldsStartIndex + kFieldEntrySize * index + kOffsetIndex); |
252 } | 245 } |
253 | 246 |
254 RawObject* GetValue(intptr_t index) const { | 247 RawObject* GetValue(intptr_t index) const { |
255 return GetArg(kFieldsStartIndex + kFieldEntrySize * index + kValueIndex); | 248 return GetArg(kFieldsStartIndex + kFieldEntrySize * index + kValueIndex); |
256 } | 249 } |
257 | 250 |
258 // Amount of fields that have to be initialized. | 251 // Amount of fields that have to be initialized. |
259 const intptr_t field_count_; | 252 const intptr_t field_count_; |
260 | 253 |
261 // Pointer to the first materialization argument on the stack. | 254 // Pointer to the first materialization argument on the stack. |
262 // The first argument is Class of the instance to materialize followed by | 255 // The first argument is Class of the instance to materialize followed by |
263 // Field, value pairs. | 256 // Field, value pairs. |
264 RawObject** args_; | 257 RawObject** args_; |
265 | 258 |
266 // Object materialized from this description. | 259 // Object materialized from this description. |
267 const Object* object_; | 260 const Object* object_; |
268 | 261 |
269 DISALLOW_COPY_AND_ASSIGN(DeferredObject); | 262 DISALLOW_COPY_AND_ASSIGN(DeferredObject); |
270 }; | 263 }; |
271 | 264 |
272 } // namespace dart | 265 } // namespace dart |
273 | 266 |
274 #endif // RUNTIME_VM_DEFERRED_OBJECTS_H_ | 267 #endif // RUNTIME_VM_DEFERRED_OBJECTS_H_ |
OLD | NEW |