| 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/object.h" | 10 #include "vm/object.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 // Forward declarations. | 14 // Forward declarations. |
| 15 class Class; | 15 class Class; |
| 16 class Error; | 16 class Error; |
| 17 class Field; | 17 class Field; |
| 18 class Function; | 18 class Function; |
| 19 class GrowableObjectArray; | 19 class GrowableObjectArray; |
| 20 class RawError; | 20 class RawError; |
| 21 class String; | 21 class String; |
| 22 | 22 |
| 23 class SymbolPair { | 23 class SymbolKeyValueTrait { |
| 24 public: | 24 public: |
| 25 // Typedefs needed for the DirectChainedHashMap template. | 25 // Typedefs needed for the DirectChainedHashMap template. |
| 26 typedef const String* Key; | 26 typedef const String* Key; |
| 27 typedef bool Value; | 27 typedef const String* Value; |
| 28 typedef SymbolPair Pair; | 28 typedef const String* Pair; |
| 29 | 29 |
| 30 SymbolPair() : key_(NULL), value_(false) {} | 30 static Key KeyOf(Pair kv) { return kv; } |
| 31 SymbolPair(Key key, Value value) : key_(key), value_(value) { | |
| 32 ASSERT(key->IsNotTemporaryScopedHandle()); | |
| 33 } | |
| 34 | 31 |
| 35 static Key KeyOf(Pair kv) { return kv.key_; } | 32 static Value ValueOf(Pair kv) { return kv; } |
| 36 | |
| 37 static Value ValueOf(Pair kv) { return kv.value_; } | |
| 38 | 33 |
| 39 static inline intptr_t Hashcode(Key key) { | 34 static inline intptr_t Hashcode(Key key) { |
| 40 return key->Hash(); | 35 return key->Hash(); |
| 41 } | 36 } |
| 42 | 37 |
| 43 static inline bool IsKeyEqual(Pair pair, Key key) { | 38 static inline bool IsKeyEqual(Pair pair, Key key) { |
| 44 return pair.key_->raw() == key->raw(); | 39 return pair->raw() == key->raw(); |
| 40 } |
| 41 }; |
| 42 |
| 43 typedef DirectChainedHashMap<SymbolKeyValueTrait> SymbolSet; |
| 44 |
| 45 class StackmapKeyValueTrait { |
| 46 public: |
| 47 // Typedefs needed for the DirectChainedHashMap template. |
| 48 typedef const Stackmap* Key; |
| 49 typedef const Stackmap* Value; |
| 50 typedef const Stackmap* Pair; |
| 51 |
| 52 static Key KeyOf(Pair kv) { return kv; } |
| 53 |
| 54 static Value ValueOf(Pair kv) { return kv; } |
| 55 |
| 56 static inline intptr_t Hashcode(Key key) { |
| 57 return key->PcOffset(); |
| 45 } | 58 } |
| 46 | 59 |
| 47 private: | 60 static inline bool IsKeyEqual(Pair pair, Key key) { |
| 48 Key key_; | 61 return pair->Equals(*key); |
| 49 Value value_; | 62 } |
| 50 }; | 63 }; |
| 51 | 64 |
| 52 | 65 typedef DirectChainedHashMap<StackmapKeyValueTrait> StackmapSet; |
| 53 class SymbolSet : public ValueObject { | |
| 54 public: | |
| 55 explicit SymbolSet(Zone* zone) : zone_(zone), map_() {} | |
| 56 | |
| 57 void Add(const String& symbol) { | |
| 58 ASSERT(symbol.IsSymbol()); | |
| 59 if (symbol.IsNotTemporaryScopedHandle()) { | |
| 60 SymbolPair pair(&symbol, true); | |
| 61 map_.Insert(pair); | |
| 62 } else { | |
| 63 SymbolPair pair(&String::ZoneHandle(zone_, symbol.raw()), true); | |
| 64 map_.Insert(pair); | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 bool Includes(const String& symbol) { | |
| 69 ASSERT(symbol.IsSymbol()); | |
| 70 return map_.Lookup(&symbol); | |
| 71 } | |
| 72 | |
| 73 private: | |
| 74 Zone* zone_; | |
| 75 DirectChainedHashMap<SymbolPair> map_; | |
| 76 }; | |
| 77 | 66 |
| 78 | 67 |
| 79 class Precompiler : public ValueObject { | 68 class Precompiler : public ValueObject { |
| 80 public: | 69 public: |
| 81 static RawError* CompileAll( | 70 static RawError* CompileAll( |
| 82 Dart_QualifiedFunctionName embedder_entry_points[], | 71 Dart_QualifiedFunctionName embedder_entry_points[], |
| 83 bool reset_fields); | 72 bool reset_fields); |
| 84 | 73 |
| 85 private: | 74 private: |
| 86 Precompiler(Thread* thread, bool reset_fields); | 75 Precompiler(Thread* thread, bool reset_fields); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 98 void AddFunction(const Function& function); | 87 void AddFunction(const Function& function); |
| 99 void AddClass(const Class& cls); | 88 void AddClass(const Class& cls); |
| 100 void AddSelector(const String& selector); | 89 void AddSelector(const String& selector); |
| 101 bool IsSent(const String& selector); | 90 bool IsSent(const String& selector); |
| 102 | 91 |
| 103 void ProcessFunction(const Function& function); | 92 void ProcessFunction(const Function& function); |
| 104 void CheckForNewDynamicFunctions(); | 93 void CheckForNewDynamicFunctions(); |
| 105 | 94 |
| 106 void DropUncompiledFunctions(); | 95 void DropUncompiledFunctions(); |
| 107 void BindStaticCalls(); | 96 void BindStaticCalls(); |
| 108 void BindStaticCalls(const Function& function); | 97 void DedupStackmaps(); |
| 98 |
| 99 class FunctionVisitor : public ValueObject { |
| 100 public: |
| 101 virtual ~FunctionVisitor() { } |
| 102 virtual void VisitFunction(const Function& function) = 0; |
| 103 }; |
| 104 |
| 105 void VisitFunctions(FunctionVisitor* visitor); |
| 109 | 106 |
| 110 Thread* thread() const { return thread_; } | 107 Thread* thread() const { return thread_; } |
| 111 Zone* zone() const { return zone_; } | 108 Zone* zone() const { return zone_; } |
| 112 Isolate* isolate() const { return isolate_; } | 109 Isolate* isolate() const { return isolate_; } |
| 113 | 110 |
| 114 Thread* thread_; | 111 Thread* thread_; |
| 115 Zone* zone_; | 112 Zone* zone_; |
| 116 Isolate* isolate_; | 113 Isolate* isolate_; |
| 117 | 114 |
| 118 const bool reset_fields_; | 115 const bool reset_fields_; |
| 119 | 116 |
| 120 bool changed_; | 117 bool changed_; |
| 121 intptr_t function_count_; | 118 intptr_t function_count_; |
| 122 intptr_t class_count_; | 119 intptr_t class_count_; |
| 123 intptr_t selector_count_; | 120 intptr_t selector_count_; |
| 124 intptr_t dropped_function_count_; | 121 intptr_t dropped_function_count_; |
| 125 | 122 |
| 126 const GrowableObjectArray& libraries_; | 123 const GrowableObjectArray& libraries_; |
| 127 const GrowableObjectArray& pending_functions_; | 124 const GrowableObjectArray& pending_functions_; |
| 128 const GrowableObjectArray& collected_closures_; | 125 const GrowableObjectArray& collected_closures_; |
| 129 SymbolSet sent_selectors_; | 126 SymbolSet sent_selectors_; |
| 130 Error& error_; | 127 Error& error_; |
| 131 }; | 128 }; |
| 132 | 129 |
| 133 } // namespace dart | 130 } // namespace dart |
| 134 | 131 |
| 135 #endif // VM_PRECOMPILER_H_ | 132 #endif // VM_PRECOMPILER_H_ |
| OLD | NEW |