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

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

Issue 1275653002: Tree-shaking: use a hash set for tracking live selectors, drop uncompiled functions. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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"
10 #include "vm/object.h"
9 11
10 namespace dart { 12 namespace dart {
11 13
12 // Forward declarations. 14 // Forward declarations.
13 class Class; 15 class Class;
14 class Error; 16 class Error;
15 class Field; 17 class Field;
16 class Function; 18 class Function;
17 class GrowableObjectArray; 19 class GrowableObjectArray;
18 class RawError; 20 class RawError;
19 class String; 21 class String;
20 22
23 class SymbolPair {
srdjan 2015/08/05 18:20:08 : public ValueObject ?
rmacnak 2015/08/05 19:51:50 DirectChainedHashMap uses the assignment operator.
24 public:
25 // Typedefs needed for the DirectChainedHashMap template.
26 typedef const String* Key;
27 typedef bool Value;
28 typedef SymbolPair Pair;
29
30 SymbolPair() : key_(NULL), value_(false) {}
31 SymbolPair(Key key, Value value) : key_(key), value_(value) {
32 ASSERT(key->IsNotTemporaryScopedHandle());
33 }
34
35 static Key KeyOf(Pair kv) { return kv.key_; }
36
37 static Value ValueOf(Pair kv) { return kv.value_; }
38
39 static inline intptr_t Hashcode(Key key) {
40 return key->Hash();
41 }
42
43 static inline bool IsKeyEqual(Pair pair, Key key) {
44 return pair.key_->raw() == key->raw();
45 }
46
47 private:
48 Key key_;
49 Value value_;
50 };
51
52
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
78
21 class Precompiler : public ValueObject { 79 class Precompiler : public ValueObject {
22 public: 80 public:
23 static RawError* CompileAll(); 81 static RawError* CompileAll();
24 82
25 private: 83 private:
26 explicit Precompiler(Thread* thread); 84 explicit Precompiler(Thread* thread);
27 85
28 void DoCompileAll(); 86 void DoCompileAll();
29 void ClearAllCode(); 87 void ClearAllCode();
30 void AddRoots(); 88 void AddRoots();
31 void Iterate(); 89 void Iterate();
32 void CleanUp(); 90 void CleanUp();
33 91
34 void AddCalleesOf(const Function& function); 92 void AddCalleesOf(const Function& function);
35 void AddField(const Field& field); 93 void AddField(const Field& field);
36 void AddFunction(const Function& function); 94 void AddFunction(const Function& function);
37 void AddClass(const Class& cls); 95 void AddClass(const Class& cls);
38 void AddSelector(const String& selector); 96 void AddSelector(const String& selector);
39 bool IsSent(const String& selector); 97 bool IsSent(const String& selector);
40 98
41 void ProcessFunction(const Function& function); 99 void ProcessFunction(const Function& function);
42 void CheckForNewDynamicFunctions(); 100 void CheckForNewDynamicFunctions();
43 101
102 void DropUncompiledFunctions();
103
44 Thread* thread() const { return thread_; } 104 Thread* thread() const { return thread_; }
45 Zone* zone() const { return zone_; } 105 Zone* zone() const { return zone_; }
46 Isolate* isolate() const { return isolate_; } 106 Isolate* isolate() const { return isolate_; }
47 107
48 Thread* thread_; 108 Thread* thread_;
49 Zone* zone_; 109 Zone* zone_;
50 Isolate* isolate_; 110 Isolate* isolate_;
51 111
52 bool changed_; 112 bool changed_;
53 intptr_t function_count_; 113 intptr_t function_count_;
54 intptr_t class_count_; 114 intptr_t class_count_;
115 intptr_t selector_count_;
116 intptr_t dropped_function_count_;
55 117
56 const GrowableObjectArray& libraries_; 118 const GrowableObjectArray& libraries_;
57 const GrowableObjectArray& pending_functions_; 119 const GrowableObjectArray& pending_functions_;
58 const GrowableObjectArray& collected_closures_; 120 const GrowableObjectArray& collected_closures_;
59 const GrowableObjectArray& sent_selectors_; 121 SymbolSet sent_selectors_;
60 Error& error_; 122 Error& error_;
61 }; 123 };
62 124
63 } // namespace dart 125 } // namespace dart
64 126
65 #endif // VM_PRECOMPILER_H_ 127 #endif // VM_PRECOMPILER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698