OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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_PRECOMPILER_H_ | 5 #ifndef RUNTIME_VM_PRECOMPILER_H_ |
6 #define RUNTIME_VM_PRECOMPILER_H_ | 6 #define RUNTIME_VM_PRECOMPILER_H_ |
7 | 7 |
8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
9 #include "vm/hash_map.h" | 9 #include "vm/hash_map.h" |
10 #include "vm/hash_table.h" | 10 #include "vm/hash_table.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 private: | 38 private: |
39 static const intptr_t kNotComputed = -1; | 39 static const intptr_t kNotComputed = -1; |
40 static const intptr_t kNotContiguous = -2; | 40 static const intptr_t kNotContiguous = -2; |
41 | 41 |
42 Precompiler* precompiler_; | 42 Precompiler* precompiler_; |
43 Thread* thread_; | 43 Thread* thread_; |
44 intptr_t* lower_limits_; | 44 intptr_t* lower_limits_; |
45 intptr_t* upper_limits_; | 45 intptr_t* upper_limits_; |
46 }; | 46 }; |
47 | 47 |
48 | |
49 class SymbolKeyValueTrait { | 48 class SymbolKeyValueTrait { |
50 public: | 49 public: |
51 // Typedefs needed for the DirectChainedHashMap template. | 50 // Typedefs needed for the DirectChainedHashMap template. |
52 typedef const String* Key; | 51 typedef const String* Key; |
53 typedef const String* Value; | 52 typedef const String* Value; |
54 typedef const String* Pair; | 53 typedef const String* Pair; |
55 | 54 |
56 static Key KeyOf(Pair kv) { return kv; } | 55 static Key KeyOf(Pair kv) { return kv; } |
57 | 56 |
58 static Value ValueOf(Pair kv) { return kv; } | 57 static Value ValueOf(Pair kv) { return kv; } |
59 | 58 |
60 static inline intptr_t Hashcode(Key key) { return key->Hash(); } | 59 static inline intptr_t Hashcode(Key key) { return key->Hash(); } |
61 | 60 |
62 static inline bool IsKeyEqual(Pair pair, Key key) { | 61 static inline bool IsKeyEqual(Pair pair, Key key) { |
63 return pair->raw() == key->raw(); | 62 return pair->raw() == key->raw(); |
64 } | 63 } |
65 }; | 64 }; |
66 | 65 |
67 typedef DirectChainedHashMap<SymbolKeyValueTrait> SymbolSet; | 66 typedef DirectChainedHashMap<SymbolKeyValueTrait> SymbolSet; |
68 | 67 |
69 | |
70 class UnlinkedCallKeyValueTrait { | 68 class UnlinkedCallKeyValueTrait { |
71 public: | 69 public: |
72 // Typedefs needed for the DirectChainedHashMap template. | 70 // Typedefs needed for the DirectChainedHashMap template. |
73 typedef const UnlinkedCall* Key; | 71 typedef const UnlinkedCall* Key; |
74 typedef const UnlinkedCall* Value; | 72 typedef const UnlinkedCall* Value; |
75 typedef const UnlinkedCall* Pair; | 73 typedef const UnlinkedCall* Pair; |
76 | 74 |
77 static Key KeyOf(Pair kv) { return kv; } | 75 static Key KeyOf(Pair kv) { return kv; } |
78 | 76 |
79 static Value ValueOf(Pair kv) { return kv; } | 77 static Value ValueOf(Pair kv) { return kv; } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 113 } |
116 } | 114 } |
117 | 115 |
118 static inline bool IsKeyEqual(Pair pair, Key key) { | 116 static inline bool IsKeyEqual(Pair pair, Key key) { |
119 return pair->raw() == key->raw(); | 117 return pair->raw() == key->raw(); |
120 } | 118 } |
121 }; | 119 }; |
122 | 120 |
123 typedef DirectChainedHashMap<FunctionKeyValueTrait> FunctionSet; | 121 typedef DirectChainedHashMap<FunctionKeyValueTrait> FunctionSet; |
124 | 122 |
125 | |
126 class FieldKeyValueTrait { | 123 class FieldKeyValueTrait { |
127 public: | 124 public: |
128 // Typedefs needed for the DirectChainedHashMap template. | 125 // Typedefs needed for the DirectChainedHashMap template. |
129 typedef const Field* Key; | 126 typedef const Field* Key; |
130 typedef const Field* Value; | 127 typedef const Field* Value; |
131 typedef const Field* Pair; | 128 typedef const Field* Pair; |
132 | 129 |
133 static Key KeyOf(Pair kv) { return kv; } | 130 static Key KeyOf(Pair kv) { return kv; } |
134 | 131 |
135 static Value ValueOf(Pair kv) { return kv; } | 132 static Value ValueOf(Pair kv) { return kv; } |
136 | 133 |
137 static inline intptr_t Hashcode(Key key) { | 134 static inline intptr_t Hashcode(Key key) { |
138 // We are using pointer hash for objects originating from Kernel because | 135 // We are using pointer hash for objects originating from Kernel because |
139 // Fasta currently does not assign any position information to them. | 136 // Fasta currently does not assign any position information to them. |
140 if (key->kernel_offset() > 0) { | 137 if (key->kernel_offset() > 0) { |
141 return key->kernel_offset(); | 138 return key->kernel_offset(); |
142 } else { | 139 } else { |
143 return key->token_pos().value(); | 140 return key->token_pos().value(); |
144 } | 141 } |
145 } | 142 } |
146 | 143 |
147 static inline bool IsKeyEqual(Pair pair, Key key) { | 144 static inline bool IsKeyEqual(Pair pair, Key key) { |
148 return pair->raw() == key->raw(); | 145 return pair->raw() == key->raw(); |
149 } | 146 } |
150 }; | 147 }; |
151 | 148 |
152 typedef DirectChainedHashMap<FieldKeyValueTrait> FieldSet; | 149 typedef DirectChainedHashMap<FieldKeyValueTrait> FieldSet; |
153 | 150 |
154 | |
155 class ClassKeyValueTrait { | 151 class ClassKeyValueTrait { |
156 public: | 152 public: |
157 // Typedefs needed for the DirectChainedHashMap template. | 153 // Typedefs needed for the DirectChainedHashMap template. |
158 typedef const Class* Key; | 154 typedef const Class* Key; |
159 typedef const Class* Value; | 155 typedef const Class* Value; |
160 typedef const Class* Pair; | 156 typedef const Class* Pair; |
161 | 157 |
162 static Key KeyOf(Pair kv) { return kv; } | 158 static Key KeyOf(Pair kv) { return kv; } |
163 | 159 |
164 static Value ValueOf(Pair kv) { return kv; } | 160 static Value ValueOf(Pair kv) { return kv; } |
165 | 161 |
166 static inline intptr_t Hashcode(Key key) { return key->token_pos().value(); } | 162 static inline intptr_t Hashcode(Key key) { return key->token_pos().value(); } |
167 | 163 |
168 static inline bool IsKeyEqual(Pair pair, Key key) { | 164 static inline bool IsKeyEqual(Pair pair, Key key) { |
169 return pair->raw() == key->raw(); | 165 return pair->raw() == key->raw(); |
170 } | 166 } |
171 }; | 167 }; |
172 | 168 |
173 typedef DirectChainedHashMap<ClassKeyValueTrait> ClassSet; | 169 typedef DirectChainedHashMap<ClassKeyValueTrait> ClassSet; |
174 | 170 |
175 | |
176 class AbstractTypeKeyValueTrait { | 171 class AbstractTypeKeyValueTrait { |
177 public: | 172 public: |
178 // Typedefs needed for the DirectChainedHashMap template. | 173 // Typedefs needed for the DirectChainedHashMap template. |
179 typedef const AbstractType* Key; | 174 typedef const AbstractType* Key; |
180 typedef const AbstractType* Value; | 175 typedef const AbstractType* Value; |
181 typedef const AbstractType* Pair; | 176 typedef const AbstractType* Pair; |
182 | 177 |
183 static Key KeyOf(Pair kv) { return kv; } | 178 static Key KeyOf(Pair kv) { return kv; } |
184 | 179 |
185 static Value ValueOf(Pair kv) { return kv; } | 180 static Value ValueOf(Pair kv) { return kv; } |
186 | 181 |
187 static inline intptr_t Hashcode(Key key) { return key->Hash(); } | 182 static inline intptr_t Hashcode(Key key) { return key->Hash(); } |
188 | 183 |
189 static inline bool IsKeyEqual(Pair pair, Key key) { | 184 static inline bool IsKeyEqual(Pair pair, Key key) { |
190 return pair->raw() == key->raw(); | 185 return pair->raw() == key->raw(); |
191 } | 186 } |
192 }; | 187 }; |
193 | 188 |
194 typedef DirectChainedHashMap<AbstractTypeKeyValueTrait> AbstractTypeSet; | 189 typedef DirectChainedHashMap<AbstractTypeKeyValueTrait> AbstractTypeSet; |
195 | 190 |
196 | |
197 class TypeArgumentsKeyValueTrait { | 191 class TypeArgumentsKeyValueTrait { |
198 public: | 192 public: |
199 // Typedefs needed for the DirectChainedHashMap template. | 193 // Typedefs needed for the DirectChainedHashMap template. |
200 typedef const TypeArguments* Key; | 194 typedef const TypeArguments* Key; |
201 typedef const TypeArguments* Value; | 195 typedef const TypeArguments* Value; |
202 typedef const TypeArguments* Pair; | 196 typedef const TypeArguments* Pair; |
203 | 197 |
204 static Key KeyOf(Pair kv) { return kv; } | 198 static Key KeyOf(Pair kv) { return kv; } |
205 | 199 |
206 static Value ValueOf(Pair kv) { return kv; } | 200 static Value ValueOf(Pair kv) { return kv; } |
207 | 201 |
208 static inline intptr_t Hashcode(Key key) { return key->Hash(); } | 202 static inline intptr_t Hashcode(Key key) { return key->Hash(); } |
209 | 203 |
210 static inline bool IsKeyEqual(Pair pair, Key key) { | 204 static inline bool IsKeyEqual(Pair pair, Key key) { |
211 return pair->raw() == key->raw(); | 205 return pair->raw() == key->raw(); |
212 } | 206 } |
213 }; | 207 }; |
214 | 208 |
215 typedef DirectChainedHashMap<TypeArgumentsKeyValueTrait> TypeArgumentsSet; | 209 typedef DirectChainedHashMap<TypeArgumentsKeyValueTrait> TypeArgumentsSet; |
216 | 210 |
217 | |
218 class InstanceKeyValueTrait { | 211 class InstanceKeyValueTrait { |
219 public: | 212 public: |
220 // Typedefs needed for the DirectChainedHashMap template. | 213 // Typedefs needed for the DirectChainedHashMap template. |
221 typedef const Instance* Key; | 214 typedef const Instance* Key; |
222 typedef const Instance* Value; | 215 typedef const Instance* Value; |
223 typedef const Instance* Pair; | 216 typedef const Instance* Pair; |
224 | 217 |
225 static Key KeyOf(Pair kv) { return kv; } | 218 static Key KeyOf(Pair kv) { return kv; } |
226 | 219 |
227 static Value ValueOf(Pair kv) { return kv; } | 220 static Value ValueOf(Pair kv) { return kv; } |
228 | 221 |
229 static inline intptr_t Hashcode(Key key) { return key->GetClassId(); } | 222 static inline intptr_t Hashcode(Key key) { return key->GetClassId(); } |
230 | 223 |
231 static inline bool IsKeyEqual(Pair pair, Key key) { | 224 static inline bool IsKeyEqual(Pair pair, Key key) { |
232 return pair->raw() == key->raw(); | 225 return pair->raw() == key->raw(); |
233 } | 226 } |
234 }; | 227 }; |
235 | 228 |
236 typedef DirectChainedHashMap<InstanceKeyValueTrait> InstanceSet; | 229 typedef DirectChainedHashMap<InstanceKeyValueTrait> InstanceSet; |
237 | 230 |
238 | |
239 struct FieldTypePair { | 231 struct FieldTypePair { |
240 // Typedefs needed for the DirectChainedHashMap template. | 232 // Typedefs needed for the DirectChainedHashMap template. |
241 typedef const Field* Key; | 233 typedef const Field* Key; |
242 typedef intptr_t Value; | 234 typedef intptr_t Value; |
243 typedef FieldTypePair Pair; | 235 typedef FieldTypePair Pair; |
244 | 236 |
245 static Key KeyOf(Pair kv) { return kv.field_; } | 237 static Key KeyOf(Pair kv) { return kv.field_; } |
246 | 238 |
247 static Value ValueOf(Pair kv) { return kv.cid_; } | 239 static Value ValueOf(Pair kv) { return kv.cid_; } |
248 | 240 |
249 static inline intptr_t Hashcode(Key key) { return key->token_pos().value(); } | 241 static inline intptr_t Hashcode(Key key) { return key->token_pos().value(); } |
250 | 242 |
251 static inline bool IsKeyEqual(Pair pair, Key key) { | 243 static inline bool IsKeyEqual(Pair pair, Key key) { |
252 return pair.field_->raw() == key->raw(); | 244 return pair.field_->raw() == key->raw(); |
253 } | 245 } |
254 | 246 |
255 FieldTypePair(const Field* f, intptr_t cid) : field_(f), cid_(cid) {} | 247 FieldTypePair(const Field* f, intptr_t cid) : field_(f), cid_(cid) {} |
256 | 248 |
257 FieldTypePair() : field_(NULL), cid_(-1) {} | 249 FieldTypePair() : field_(NULL), cid_(-1) {} |
258 | 250 |
259 void Print() const; | 251 void Print() const; |
260 | 252 |
261 const Field* field_; | 253 const Field* field_; |
262 intptr_t cid_; | 254 intptr_t cid_; |
263 }; | 255 }; |
264 | 256 |
265 typedef DirectChainedHashMap<FieldTypePair> FieldTypeMap; | 257 typedef DirectChainedHashMap<FieldTypePair> FieldTypeMap; |
266 | 258 |
267 | |
268 struct IntptrPair { | 259 struct IntptrPair { |
269 // Typedefs needed for the DirectChainedHashMap template. | 260 // Typedefs needed for the DirectChainedHashMap template. |
270 typedef intptr_t Key; | 261 typedef intptr_t Key; |
271 typedef intptr_t Value; | 262 typedef intptr_t Value; |
272 typedef IntptrPair Pair; | 263 typedef IntptrPair Pair; |
273 | 264 |
274 static Key KeyOf(Pair kv) { return kv.key_; } | 265 static Key KeyOf(Pair kv) { return kv.key_; } |
275 | 266 |
276 static Value ValueOf(Pair kv) { return kv.value_; } | 267 static Value ValueOf(Pair kv) { return kv.value_; } |
277 | 268 |
278 static inline intptr_t Hashcode(Key key) { return key; } | 269 static inline intptr_t Hashcode(Key key) { return key; } |
279 | 270 |
280 static inline bool IsKeyEqual(Pair pair, Key key) { return pair.key_ == key; } | 271 static inline bool IsKeyEqual(Pair pair, Key key) { return pair.key_ == key; } |
281 | 272 |
282 IntptrPair(intptr_t key, intptr_t value) : key_(key), value_(value) {} | 273 IntptrPair(intptr_t key, intptr_t value) : key_(key), value_(value) {} |
283 | 274 |
284 IntptrPair() : key_(kIllegalCid), value_(kIllegalCid) {} | 275 IntptrPair() : key_(kIllegalCid), value_(kIllegalCid) {} |
285 | 276 |
286 Key key_; | 277 Key key_; |
287 Value value_; | 278 Value value_; |
288 }; | 279 }; |
289 | 280 |
290 typedef DirectChainedHashMap<IntptrPair> CidMap; | 281 typedef DirectChainedHashMap<IntptrPair> CidMap; |
291 | 282 |
292 | |
293 struct FunctionFeedbackKey { | 283 struct FunctionFeedbackKey { |
294 FunctionFeedbackKey() : owner_cid_(kIllegalCid), token_(0), kind_(0) {} | 284 FunctionFeedbackKey() : owner_cid_(kIllegalCid), token_(0), kind_(0) {} |
295 FunctionFeedbackKey(intptr_t owner_cid, intptr_t token, intptr_t kind) | 285 FunctionFeedbackKey(intptr_t owner_cid, intptr_t token, intptr_t kind) |
296 : owner_cid_(owner_cid), token_(token), kind_(kind) {} | 286 : owner_cid_(owner_cid), token_(token), kind_(kind) {} |
297 | 287 |
298 intptr_t owner_cid_; | 288 intptr_t owner_cid_; |
299 intptr_t token_; | 289 intptr_t token_; |
300 intptr_t kind_; | 290 intptr_t kind_; |
301 }; | 291 }; |
302 | 292 |
303 | |
304 struct FunctionFeedbackPair { | 293 struct FunctionFeedbackPair { |
305 // Typedefs needed for the DirectChainedHashMap template. | 294 // Typedefs needed for the DirectChainedHashMap template. |
306 typedef FunctionFeedbackKey Key; | 295 typedef FunctionFeedbackKey Key; |
307 typedef ParsedJSONObject* Value; | 296 typedef ParsedJSONObject* Value; |
308 typedef FunctionFeedbackPair Pair; | 297 typedef FunctionFeedbackPair Pair; |
309 | 298 |
310 static Key KeyOf(Pair kv) { return kv.key_; } | 299 static Key KeyOf(Pair kv) { return kv.key_; } |
311 | 300 |
312 static Value ValueOf(Pair kv) { return kv.value_; } | 301 static Value ValueOf(Pair kv) { return kv.value_; } |
313 | 302 |
314 static inline intptr_t Hashcode(Key key) { | 303 static inline intptr_t Hashcode(Key key) { |
315 return key.token_ ^ key.owner_cid_ ^ key.kind_; | 304 return key.token_ ^ key.owner_cid_ ^ key.kind_; |
316 } | 305 } |
317 | 306 |
318 static inline bool IsKeyEqual(Pair pair, Key key) { | 307 static inline bool IsKeyEqual(Pair pair, Key key) { |
319 return (pair.key_.owner_cid_ == key.owner_cid_) && | 308 return (pair.key_.owner_cid_ == key.owner_cid_) && |
320 (pair.key_.token_ == key.token_) && (pair.key_.kind_ == key.kind_); | 309 (pair.key_.token_ == key.token_) && (pair.key_.kind_ == key.kind_); |
321 } | 310 } |
322 | 311 |
323 FunctionFeedbackPair(Key key, Value value) : key_(key), value_(value) {} | 312 FunctionFeedbackPair(Key key, Value value) : key_(key), value_(value) {} |
324 | 313 |
325 FunctionFeedbackPair() : key_(), value_(NULL) {} | 314 FunctionFeedbackPair() : key_(), value_(NULL) {} |
326 | 315 |
327 Key key_; | 316 Key key_; |
328 Value value_; | 317 Value value_; |
329 }; | 318 }; |
330 | 319 |
331 typedef DirectChainedHashMap<FunctionFeedbackPair> FunctionFeedbackMap; | 320 typedef DirectChainedHashMap<FunctionFeedbackPair> FunctionFeedbackMap; |
332 | 321 |
333 | |
334 class Precompiler : public ValueObject { | 322 class Precompiler : public ValueObject { |
335 public: | 323 public: |
336 static RawError* CompileAll( | 324 static RawError* CompileAll( |
337 Dart_QualifiedFunctionName embedder_entry_points[], | 325 Dart_QualifiedFunctionName embedder_entry_points[], |
338 uint8_t* jit_feedback, | 326 uint8_t* jit_feedback, |
339 intptr_t jit_feedback_length); | 327 intptr_t jit_feedback_length); |
340 | 328 |
341 static RawError* CompileFunction(Precompiler* precompiler, | 329 static RawError* CompileFunction(Precompiler* precompiler, |
342 Thread* thread, | 330 Thread* thread, |
343 Zone* zone, | 331 Zone* zone, |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 InstanceSet consts_to_retain_; | 442 InstanceSet consts_to_retain_; |
455 FieldTypeMap field_type_map_; | 443 FieldTypeMap field_type_map_; |
456 TypeRangeCache* type_range_cache_; | 444 TypeRangeCache* type_range_cache_; |
457 CidMap feedback_cid_map_; | 445 CidMap feedback_cid_map_; |
458 FunctionFeedbackMap function_feedback_map_; | 446 FunctionFeedbackMap function_feedback_map_; |
459 Error& error_; | 447 Error& error_; |
460 | 448 |
461 bool get_runtime_type_is_unique_; | 449 bool get_runtime_type_is_unique_; |
462 }; | 450 }; |
463 | 451 |
464 | |
465 class FunctionsTraits { | 452 class FunctionsTraits { |
466 public: | 453 public: |
467 static const char* Name() { return "FunctionsTraits"; } | 454 static const char* Name() { return "FunctionsTraits"; } |
468 static bool ReportStats() { return false; } | 455 static bool ReportStats() { return false; } |
469 | 456 |
470 static bool IsMatch(const Object& a, const Object& b) { | 457 static bool IsMatch(const Object& a, const Object& b) { |
471 Zone* zone = Thread::Current()->zone(); | 458 Zone* zone = Thread::Current()->zone(); |
472 String& a_s = String::Handle(zone); | 459 String& a_s = String::Handle(zone); |
473 String& b_s = String::Handle(zone); | 460 String& b_s = String::Handle(zone); |
474 a_s = a.IsFunction() ? Function::Cast(a).name() : String::Cast(a).raw(); | 461 a_s = a.IsFunction() ? Function::Cast(a).name() : String::Cast(a).raw(); |
475 b_s = b.IsFunction() ? Function::Cast(b).name() : String::Cast(b).raw(); | 462 b_s = b.IsFunction() ? Function::Cast(b).name() : String::Cast(b).raw(); |
476 ASSERT(a_s.IsSymbol() && b_s.IsSymbol()); | 463 ASSERT(a_s.IsSymbol() && b_s.IsSymbol()); |
477 return a_s.raw() == b_s.raw(); | 464 return a_s.raw() == b_s.raw(); |
478 } | 465 } |
479 static uword Hash(const Object& obj) { | 466 static uword Hash(const Object& obj) { |
480 if (obj.IsFunction()) { | 467 if (obj.IsFunction()) { |
481 return String::Handle(Function::Cast(obj).name()).Hash(); | 468 return String::Handle(Function::Cast(obj).name()).Hash(); |
482 } else { | 469 } else { |
483 ASSERT(String::Cast(obj).IsSymbol()); | 470 ASSERT(String::Cast(obj).IsSymbol()); |
484 return String::Cast(obj).Hash(); | 471 return String::Cast(obj).Hash(); |
485 } | 472 } |
486 } | 473 } |
487 static RawObject* NewKey(const Function& function) { return function.raw(); } | 474 static RawObject* NewKey(const Function& function) { return function.raw(); } |
488 }; | 475 }; |
489 | 476 |
490 typedef UnorderedHashSet<FunctionsTraits> UniqueFunctionsSet; | 477 typedef UnorderedHashSet<FunctionsTraits> UniqueFunctionsSet; |
491 | 478 |
492 | |
493 } // namespace dart | 479 } // namespace dart |
494 | 480 |
495 #endif // RUNTIME_VM_PRECOMPILER_H_ | 481 #endif // RUNTIME_VM_PRECOMPILER_H_ |
OLD | NEW |