Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: runtime/vm/precompiler.h

Issue 1387613003: Dedup stackmaps. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 SymbolPair {
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 SymbolPair Pair;
29 29
30 SymbolPair() : key_(NULL), value_(false) {} 30 SymbolPair() : key_(NULL) {}
31 SymbolPair(Key key, Value value) : key_(key), value_(value) { 31 SymbolPair(Key key, Value value) : key_(key) {
32 ASSERT(key->IsNotTemporaryScopedHandle()); 32 ASSERT(key->IsNotTemporaryScopedHandle());
33 ASSERT(key == value);
33 } 34 }
34 35
35 static Key KeyOf(Pair kv) { return kv.key_; } 36 static Key KeyOf(Pair kv) { return kv.key_; }
36 37
37 static Value ValueOf(Pair kv) { return kv.value_; } 38 static Value ValueOf(Pair kv) { return kv.key_; }
38 39
39 static inline intptr_t Hashcode(Key key) { 40 static inline intptr_t Hashcode(Key key) {
40 return key->Hash(); 41 return key->Hash();
41 } 42 }
42 43
43 static inline bool IsKeyEqual(Pair pair, Key key) { 44 static inline bool IsKeyEqual(Pair pair, Key key) {
44 return pair.key_->raw() == key->raw(); 45 return pair.key_->raw() == key->raw();
45 } 46 }
46 47
47 private: 48 private:
48 Key key_; 49 Key key_;
Florian Schneider 2015/10/07 10:40:07 No need for key_ either. This is basicaly the sam
rmacnak 2015/10/07 22:19:06 Oh, I misunderstood this to be used as the backing
49 Value value_;
50 }; 50 };
51 51
52 52
53 class SymbolSet : public ValueObject { 53 class SymbolSet : public ValueObject {
54 public: 54 public:
55 explicit SymbolSet(Zone* zone) : zone_(zone), map_() {} 55 explicit SymbolSet(Zone* zone) : zone_(zone), map_() {}
56 56
57 void Add(const String& symbol) { 57 void Add(const String& symbol) {
58 ASSERT(symbol.IsSymbol()); 58 ASSERT(symbol.IsSymbol());
59 if (symbol.IsNotTemporaryScopedHandle()) { 59 if (symbol.IsNotTemporaryScopedHandle()) {
60 SymbolPair pair(&symbol, true); 60 SymbolPair pair(&symbol, &symbol);
61 map_.Insert(pair); 61 map_.Insert(pair);
62 } else { 62 } else {
63 SymbolPair pair(&String::ZoneHandle(zone_, symbol.raw()), true); 63 const String* zone_symbol = &String::ZoneHandle(zone_, symbol.raw());
64 SymbolPair pair(zone_symbol, zone_symbol);
64 map_.Insert(pair); 65 map_.Insert(pair);
65 } 66 }
66 } 67 }
67 68
68 bool Includes(const String& symbol) { 69 bool Includes(const String& symbol) {
69 ASSERT(symbol.IsSymbol()); 70 ASSERT(symbol.IsSymbol());
70 return map_.Lookup(&symbol); 71 return map_.Lookup(&symbol) != NULL;
71 } 72 }
72 73
73 private: 74 private:
74 Zone* zone_; 75 Zone* zone_;
75 DirectChainedHashMap<SymbolPair> map_; 76 DirectChainedHashMap<SymbolPair> map_;
76 }; 77 };
77 78
78 79
80 class StackmapPair {
81 public:
82 // Typedefs needed for the DirectChainedHashMap template.
83 typedef const Stackmap* Key;
84 typedef const Stackmap* Value;
85 typedef StackmapPair Pair;
86
87 StackmapPair() : key_(NULL) {}
88 StackmapPair(Key key, Value value) : key_(key) {
89 ASSERT(key->IsNotTemporaryScopedHandle());
90 ASSERT(key == value);
91 }
92
93 static Key KeyOf(Pair kv) { return kv.key_; }
94
95 static Value ValueOf(Pair kv) { return kv.key_; }
96
97 static inline intptr_t Hashcode(Key key) {
Florian Schneider 2015/10/07 10:40:07 Can you avoid this class and use PointerKeyValueTr
rmacnak 2015/10/07 22:19:06 Not quite. It wants Stackmap::Equals(Stackmap*&) i
98 return key->PcOffset();
99 }
100
101 static inline bool IsKeyEqual(Pair pair, Key key) {
102 return pair.key_->Equals(*key);
103 }
104
105 private:
106 Key key_;
107 };
108
109
110 class StackmapSet : public ValueObject {
Florian Schneider 2015/10/07 10:40:07 typedef DirectChainedHashmap<PointerKeyValueTrait<
rmacnak 2015/10/07 22:19:06 Dropped StackmapSet and SymbolsSet for typedefs.
111 public:
112 explicit StackmapSet(Zone* zone) : zone_(zone), map_() {}
113
114 void Add(const Stackmap& stackmap) {
115 StackmapPair pair(&stackmap, &stackmap);
116 map_.Insert(pair);
117 }
118
119 const Stackmap* Lookup(const Stackmap& stackmap) {
120 return map_.Lookup(&stackmap);
121 }
122
123 private:
124 Zone* zone_;
125 DirectChainedHashMap<StackmapPair> map_;
126 };
127
128
79 class Precompiler : public ValueObject { 129 class Precompiler : public ValueObject {
80 public: 130 public:
81 static RawError* CompileAll( 131 static RawError* CompileAll(
82 Dart_QualifiedFunctionName embedder_entry_points[], 132 Dart_QualifiedFunctionName embedder_entry_points[],
83 bool reset_fields); 133 bool reset_fields);
84 134
85 private: 135 private:
86 Precompiler(Thread* thread, bool reset_fields); 136 Precompiler(Thread* thread, bool reset_fields);
87 137
88 void DoCompileAll(Dart_QualifiedFunctionName embedder_entry_points[]); 138 void DoCompileAll(Dart_QualifiedFunctionName embedder_entry_points[]);
(...skipping 10 matching lines...) Expand all
99 void AddClass(const Class& cls); 149 void AddClass(const Class& cls);
100 void AddSelector(const String& selector); 150 void AddSelector(const String& selector);
101 bool IsSent(const String& selector); 151 bool IsSent(const String& selector);
102 152
103 void ProcessFunction(const Function& function); 153 void ProcessFunction(const Function& function);
104 void CheckForNewDynamicFunctions(); 154 void CheckForNewDynamicFunctions();
105 155
106 void DropUncompiledFunctions(); 156 void DropUncompiledFunctions();
107 void BindStaticCalls(); 157 void BindStaticCalls();
108 void BindStaticCalls(const Function& function); 158 void BindStaticCalls(const Function& function);
159 void DedupStackmaps();
160 void DedupStackmaps(const Function& function);
161 RawStackmap* DedupStackmap(const Stackmap& stackmap);
109 162
110 Thread* thread() const { return thread_; } 163 Thread* thread() const { return thread_; }
111 Zone* zone() const { return zone_; } 164 Zone* zone() const { return zone_; }
112 Isolate* isolate() const { return isolate_; } 165 Isolate* isolate() const { return isolate_; }
113 166
114 Thread* thread_; 167 Thread* thread_;
115 Zone* zone_; 168 Zone* zone_;
116 Isolate* isolate_; 169 Isolate* isolate_;
117 170
118 const bool reset_fields_; 171 const bool reset_fields_;
119 172
120 bool changed_; 173 bool changed_;
121 intptr_t function_count_; 174 intptr_t function_count_;
122 intptr_t class_count_; 175 intptr_t class_count_;
123 intptr_t selector_count_; 176 intptr_t selector_count_;
124 intptr_t dropped_function_count_; 177 intptr_t dropped_function_count_;
125 178
126 const GrowableObjectArray& libraries_; 179 const GrowableObjectArray& libraries_;
127 const GrowableObjectArray& pending_functions_; 180 const GrowableObjectArray& pending_functions_;
128 const GrowableObjectArray& collected_closures_; 181 const GrowableObjectArray& collected_closures_;
129 SymbolSet sent_selectors_; 182 SymbolSet sent_selectors_;
183 StackmapSet stackmaps_;
130 Error& error_; 184 Error& error_;
131 }; 185 };
132 186
133 } // namespace dart 187 } // namespace dart
134 188
135 #endif // VM_PRECOMPILER_H_ 189 #endif // VM_PRECOMPILER_H_
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/precompiler.cc » ('j') | runtime/vm/precompiler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698