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 VM_PRECOMPILER_H_ | 5 #ifndef VM_PRECOMPILER_H_ |
6 #define VM_PRECOMPILER_H_ | 6 #define 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 } | 252 } |
253 | 253 |
254 static inline bool IsKeyEqual(Pair pair, Key key) { | 254 static inline bool IsKeyEqual(Pair pair, Key key) { |
255 return pair->raw() == key->raw(); | 255 return pair->raw() == key->raw(); |
256 } | 256 } |
257 }; | 257 }; |
258 | 258 |
259 typedef DirectChainedHashMap<InstanceKeyValueTrait> InstanceSet; | 259 typedef DirectChainedHashMap<InstanceKeyValueTrait> InstanceSet; |
260 | 260 |
261 | 261 |
| 262 struct FieldTypePair { |
| 263 // Typedefs needed for the DirectChainedHashMap template. |
| 264 typedef const Field* Key; |
| 265 typedef intptr_t Value; |
| 266 typedef FieldTypePair Pair; |
| 267 |
| 268 static Key KeyOf(Pair kv) { return kv.field_; } |
| 269 |
| 270 static Value ValueOf(Pair kv) { return kv.cid_; } |
| 271 |
| 272 static inline intptr_t Hashcode(Key key) { |
| 273 return key->token_pos().value(); |
| 274 } |
| 275 |
| 276 static inline bool IsKeyEqual(Pair pair, Key key) { |
| 277 return pair.field_->raw() == key->raw(); |
| 278 } |
| 279 |
| 280 FieldTypePair(const Field* f, intptr_t cid) : field_(f), cid_(cid) { } |
| 281 |
| 282 FieldTypePair() : field_(NULL), cid_(-1) { } |
| 283 |
| 284 void Print() const; |
| 285 |
| 286 const Field* field_; |
| 287 intptr_t cid_; |
| 288 }; |
| 289 |
| 290 typedef DirectChainedHashMap<FieldTypePair> FieldTypeMap; |
| 291 |
| 292 |
262 class Precompiler : public ValueObject { | 293 class Precompiler : public ValueObject { |
263 public: | 294 public: |
264 static RawError* CompileAll( | 295 static RawError* CompileAll( |
265 Dart_QualifiedFunctionName embedder_entry_points[], | 296 Dart_QualifiedFunctionName embedder_entry_points[], |
266 bool reset_fields); | 297 bool reset_fields); |
267 | 298 |
268 static RawError* CompileFunction(Thread* thread, const Function& function); | 299 static RawError* CompileFunction(Thread* thread, |
| 300 Zone* zone, |
| 301 const Function& function, |
| 302 FieldTypeMap* field_type_map = NULL); |
269 | 303 |
270 static RawObject* EvaluateStaticInitializer(const Field& field); | 304 static RawObject* EvaluateStaticInitializer(const Field& field); |
271 static RawObject* ExecuteOnce(SequenceNode* fragment); | 305 static RawObject* ExecuteOnce(SequenceNode* fragment); |
272 | 306 |
273 static RawFunction* CompileStaticInitializer(const Field& field, | 307 static RawFunction* CompileStaticInitializer(const Field& field, |
274 bool compute_type); | 308 bool compute_type); |
275 | 309 |
276 private: | 310 private: |
277 Precompiler(Thread* thread, bool reset_fields); | 311 Precompiler(Thread* thread, bool reset_fields); |
278 | 312 |
279 | |
280 void DoCompileAll(Dart_QualifiedFunctionName embedder_entry_points[]); | 313 void DoCompileAll(Dart_QualifiedFunctionName embedder_entry_points[]); |
281 void ClearAllCode(); | 314 void ClearAllCode(); |
282 void AddRoots(Dart_QualifiedFunctionName embedder_entry_points[]); | 315 void AddRoots(Dart_QualifiedFunctionName embedder_entry_points[]); |
283 void AddEntryPoints(Dart_QualifiedFunctionName entry_points[]); | 316 void AddEntryPoints(Dart_QualifiedFunctionName entry_points[]); |
284 void Iterate(); | 317 void Iterate(); |
285 | 318 |
286 void AddType(const AbstractType& type); | 319 void AddType(const AbstractType& type); |
287 void AddTypesOf(const Class& cls); | 320 void AddTypesOf(const Class& cls); |
288 void AddTypesOf(const Function& function); | 321 void AddTypesOf(const Function& function); |
289 void AddTypeArguments(const TypeArguments& args); | 322 void AddTypeArguments(const TypeArguments& args); |
(...skipping 24 matching lines...) Expand all Loading... |
314 void BindStaticCalls(); | 347 void BindStaticCalls(); |
315 void SwitchICCalls(); | 348 void SwitchICCalls(); |
316 void DedupStackmaps(); | 349 void DedupStackmaps(); |
317 void DedupStackmapLists(); | 350 void DedupStackmapLists(); |
318 void DedupInstructions(); | 351 void DedupInstructions(); |
319 void ResetPrecompilerState(); | 352 void ResetPrecompilerState(); |
320 | 353 |
321 void CollectDynamicFunctionNames(); | 354 void CollectDynamicFunctionNames(); |
322 | 355 |
323 void PrecompileStaticInitializers(); | 356 void PrecompileStaticInitializers(); |
| 357 void PrecompileConstructors(); |
324 | 358 |
325 template<typename T> | 359 template<typename T> |
326 class Visitor : public ValueObject { | 360 class Visitor : public ValueObject { |
327 public: | 361 public: |
328 virtual ~Visitor() {} | 362 virtual ~Visitor() {} |
329 virtual void Visit(const T& obj) = 0; | 363 virtual void Visit(const T& obj) = 0; |
330 }; | 364 }; |
331 typedef Visitor<Function> FunctionVisitor; | 365 typedef Visitor<Function> FunctionVisitor; |
332 typedef Visitor<Class> ClassVisitor; | 366 typedef Visitor<Class> ClassVisitor; |
333 | 367 |
(...skipping 28 matching lines...) Expand all Loading... |
362 GrowableObjectArray& libraries_; | 396 GrowableObjectArray& libraries_; |
363 const GrowableObjectArray& pending_functions_; | 397 const GrowableObjectArray& pending_functions_; |
364 SymbolSet sent_selectors_; | 398 SymbolSet sent_selectors_; |
365 FunctionSet enqueued_functions_; | 399 FunctionSet enqueued_functions_; |
366 FieldSet fields_to_retain_; | 400 FieldSet fields_to_retain_; |
367 FunctionSet functions_to_retain_; | 401 FunctionSet functions_to_retain_; |
368 ClassSet classes_to_retain_; | 402 ClassSet classes_to_retain_; |
369 TypeArgumentsSet typeargs_to_retain_; | 403 TypeArgumentsSet typeargs_to_retain_; |
370 AbstractTypeSet types_to_retain_; | 404 AbstractTypeSet types_to_retain_; |
371 InstanceSet consts_to_retain_; | 405 InstanceSet consts_to_retain_; |
| 406 FieldTypeMap field_type_map_; |
372 Error& error_; | 407 Error& error_; |
373 }; | 408 }; |
374 | 409 |
375 | 410 |
376 class FunctionsTraits { | 411 class FunctionsTraits { |
377 public: | 412 public: |
378 static const char* Name() { return "FunctionsTraits"; } | 413 static const char* Name() { return "FunctionsTraits"; } |
379 static bool ReportStats() { return false; } | 414 static bool ReportStats() { return false; } |
380 | 415 |
381 static bool IsMatch(const Object& a, const Object& b) { | 416 static bool IsMatch(const Object& a, const Object& b) { |
(...skipping 17 matching lines...) Expand all Loading... |
399 return function.raw(); | 434 return function.raw(); |
400 } | 435 } |
401 }; | 436 }; |
402 | 437 |
403 typedef UnorderedHashSet<FunctionsTraits> UniqueFunctionsSet; | 438 typedef UnorderedHashSet<FunctionsTraits> UniqueFunctionsSet; |
404 | 439 |
405 | 440 |
406 } // namespace dart | 441 } // namespace dart |
407 | 442 |
408 #endif // VM_PRECOMPILER_H_ | 443 #endif // VM_PRECOMPILER_H_ |
OLD | NEW |