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

Side by Side Diff: runtime/vm/cha.cc

Issue 2974233002: VM: Re-format to use at most one newline between functions (Closed)
Patch Set: Rebase and merge Created 3 years, 5 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
« no previous file with comments | « runtime/vm/branch_optimizer.cc ('k') | runtime/vm/cha_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #include "vm/cha.h" 5 #include "vm/cha.h"
6 #include "vm/class_table.h" 6 #include "vm/class_table.h"
7 #include "vm/flags.h" 7 #include "vm/flags.h"
8 #include "vm/freelist.h" 8 #include "vm/freelist.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 #include "vm/raw_object.h" 10 #include "vm/raw_object.h"
11 #include "vm/visitor.h" 11 #include "vm/visitor.h"
12 12
13 namespace dart { 13 namespace dart {
14 14
15 void CHA::AddToGuardedClasses(const Class& cls, intptr_t subclass_count) { 15 void CHA::AddToGuardedClasses(const Class& cls, intptr_t subclass_count) {
16 for (intptr_t i = 0; i < guarded_classes_.length(); i++) { 16 for (intptr_t i = 0; i < guarded_classes_.length(); i++) {
17 if (guarded_classes_[i].cls->raw() == cls.raw()) { 17 if (guarded_classes_[i].cls->raw() == cls.raw()) {
18 return; 18 return;
19 } 19 }
20 } 20 }
21 GuardedClassInfo info = {&Class::ZoneHandle(thread_->zone(), cls.raw()), 21 GuardedClassInfo info = {&Class::ZoneHandle(thread_->zone(), cls.raw()),
22 subclass_count}; 22 subclass_count};
23 guarded_classes_.Add(info); 23 guarded_classes_.Add(info);
24 return; 24 return;
25 } 25 }
26 26
27
28 bool CHA::IsGuardedClass(intptr_t cid) const { 27 bool CHA::IsGuardedClass(intptr_t cid) const {
29 for (intptr_t i = 0; i < guarded_classes_.length(); ++i) { 28 for (intptr_t i = 0; i < guarded_classes_.length(); ++i) {
30 if (guarded_classes_[i].cls->id() == cid) return true; 29 if (guarded_classes_[i].cls->id() == cid) return true;
31 } 30 }
32 return false; 31 return false;
33 } 32 }
34 33
35
36 bool CHA::HasSubclasses(const Class& cls) { 34 bool CHA::HasSubclasses(const Class& cls) {
37 ASSERT(!cls.IsNull()); 35 ASSERT(!cls.IsNull());
38 ASSERT(cls.id() >= kInstanceCid); 36 ASSERT(cls.id() >= kInstanceCid);
39 // Can't track dependencies for classes on the VM heap since those are 37 // Can't track dependencies for classes on the VM heap since those are
40 // read-only. 38 // read-only.
41 // TODO(fschneider): Enable tracking of CHA dependent code for VM heap 39 // TODO(fschneider): Enable tracking of CHA dependent code for VM heap
42 // classes. 40 // classes.
43 if (cls.InVMHeap()) return true; 41 if (cls.InVMHeap()) return true;
44 42
45 if (cls.IsObjectClass()) { 43 if (cls.IsObjectClass()) {
46 // Class Object has subclasses, although we do not keep track of them. 44 // Class Object has subclasses, although we do not keep track of them.
47 return true; 45 return true;
48 } 46 }
49 const GrowableObjectArray& direct_subclasses = 47 const GrowableObjectArray& direct_subclasses =
50 GrowableObjectArray::Handle(cls.direct_subclasses()); 48 GrowableObjectArray::Handle(cls.direct_subclasses());
51 return !direct_subclasses.IsNull() && (direct_subclasses.Length() > 0); 49 return !direct_subclasses.IsNull() && (direct_subclasses.Length() > 0);
52 } 50 }
53 51
54
55 bool CHA::HasSubclasses(intptr_t cid) const { 52 bool CHA::HasSubclasses(intptr_t cid) const {
56 const ClassTable& class_table = *thread_->isolate()->class_table(); 53 const ClassTable& class_table = *thread_->isolate()->class_table();
57 Class& cls = Class::Handle(thread_->zone(), class_table.At(cid)); 54 Class& cls = Class::Handle(thread_->zone(), class_table.At(cid));
58 return HasSubclasses(cls); 55 return HasSubclasses(cls);
59 } 56 }
60 57
61
62 bool CHA::ConcreteSubclasses(const Class& cls, 58 bool CHA::ConcreteSubclasses(const Class& cls,
63 GrowableArray<intptr_t>* class_ids) { 59 GrowableArray<intptr_t>* class_ids) {
64 if (cls.InVMHeap()) return false; 60 if (cls.InVMHeap()) return false;
65 if (cls.IsObjectClass()) return false; 61 if (cls.IsObjectClass()) return false;
66 62
67 if (!cls.is_abstract()) { 63 if (!cls.is_abstract()) {
68 class_ids->Add(cls.id()); 64 class_ids->Add(cls.id());
69 } 65 }
70 66
71 const GrowableObjectArray& direct_subclasses = 67 const GrowableObjectArray& direct_subclasses =
72 GrowableObjectArray::Handle(cls.direct_subclasses()); 68 GrowableObjectArray::Handle(cls.direct_subclasses());
73 if (direct_subclasses.IsNull()) { 69 if (direct_subclasses.IsNull()) {
74 return true; 70 return true;
75 } 71 }
76 Class& subclass = Class::Handle(); 72 Class& subclass = Class::Handle();
77 for (intptr_t i = 0; i < direct_subclasses.Length(); i++) { 73 for (intptr_t i = 0; i < direct_subclasses.Length(); i++) {
78 subclass ^= direct_subclasses.At(i); 74 subclass ^= direct_subclasses.At(i);
79 if (!ConcreteSubclasses(subclass, class_ids)) { 75 if (!ConcreteSubclasses(subclass, class_ids)) {
80 return false; 76 return false;
81 } 77 }
82 } 78 }
83 return true; 79 return true;
84 } 80 }
85 81
86
87 bool CHA::IsImplemented(const Class& cls) { 82 bool CHA::IsImplemented(const Class& cls) {
88 // Function type aliases have different type checking rules. 83 // Function type aliases have different type checking rules.
89 ASSERT(!cls.IsTypedefClass()); 84 ASSERT(!cls.IsTypedefClass());
90 // Can't track dependencies for classes on the VM heap since those are 85 // Can't track dependencies for classes on the VM heap since those are
91 // read-only. 86 // read-only.
92 // TODO(fschneider): Enable tracking of CHA dependent code for VM heap 87 // TODO(fschneider): Enable tracking of CHA dependent code for VM heap
93 // classes. 88 // classes.
94 if (cls.InVMHeap()) return true; 89 if (cls.InVMHeap()) return true;
95 90
96 return cls.is_implemented(); 91 return cls.is_implemented();
97 } 92 }
98 93
99
100 static intptr_t CountFinalizedSubclasses(Thread* thread, const Class& cls) { 94 static intptr_t CountFinalizedSubclasses(Thread* thread, const Class& cls) {
101 intptr_t count = 0; 95 intptr_t count = 0;
102 const GrowableObjectArray& cls_direct_subclasses = 96 const GrowableObjectArray& cls_direct_subclasses =
103 GrowableObjectArray::Handle(thread->zone(), cls.direct_subclasses()); 97 GrowableObjectArray::Handle(thread->zone(), cls.direct_subclasses());
104 if (cls_direct_subclasses.IsNull()) return count; 98 if (cls_direct_subclasses.IsNull()) return count;
105 Class& direct_subclass = Class::Handle(thread->zone()); 99 Class& direct_subclass = Class::Handle(thread->zone());
106 for (intptr_t i = 0; i < cls_direct_subclasses.Length(); i++) { 100 for (intptr_t i = 0; i < cls_direct_subclasses.Length(); i++) {
107 direct_subclass ^= cls_direct_subclasses.At(i); 101 direct_subclass ^= cls_direct_subclasses.At(i);
108 // Unfinalized classes are treated as non-existent for CHA purposes, 102 // Unfinalized classes are treated as non-existent for CHA purposes,
109 // as that means that no instance of that class exists at runtime. 103 // as that means that no instance of that class exists at runtime.
110 if (!direct_subclass.is_finalized()) { 104 if (!direct_subclass.is_finalized()) {
111 continue; 105 continue;
112 } 106 }
113 107
114 count += 1 + CountFinalizedSubclasses(thread, direct_subclass); 108 count += 1 + CountFinalizedSubclasses(thread, direct_subclass);
115 } 109 }
116 return count; 110 return count;
117 } 111 }
118 112
119
120 bool CHA::IsConsistentWithCurrentHierarchy() const { 113 bool CHA::IsConsistentWithCurrentHierarchy() const {
121 for (intptr_t i = 0; i < guarded_classes_.length(); i++) { 114 for (intptr_t i = 0; i < guarded_classes_.length(); i++) {
122 const intptr_t subclass_count = 115 const intptr_t subclass_count =
123 CountFinalizedSubclasses(thread_, *guarded_classes_[i].cls); 116 CountFinalizedSubclasses(thread_, *guarded_classes_[i].cls);
124 if (guarded_classes_[i].subclass_count != subclass_count) { 117 if (guarded_classes_[i].subclass_count != subclass_count) {
125 return false; 118 return false;
126 } 119 }
127 } 120 }
128 return true; 121 return true;
129 } 122 }
130 123
131
132 bool CHA::HasOverride(const Class& cls, 124 bool CHA::HasOverride(const Class& cls,
133 const String& function_name, 125 const String& function_name,
134 intptr_t* subclasses_count) { 126 intptr_t* subclasses_count) {
135 // Can't track dependencies for classes on the VM heap since those are 127 // Can't track dependencies for classes on the VM heap since those are
136 // read-only. 128 // read-only.
137 // TODO(fschneider): Enable tracking of CHA dependent code for VM heap 129 // TODO(fschneider): Enable tracking of CHA dependent code for VM heap
138 // classes. 130 // classes.
139 if (cls.InVMHeap()) return true; 131 if (cls.InVMHeap()) return true;
140 132
141 // Subclasses of Object are not tracked by CHA. Safely assume that overrides 133 // Subclasses of Object are not tracked by CHA. Safely assume that overrides
(...skipping 24 matching lines...) Expand all
166 if (HasOverride(direct_subclass, function_name, subclasses_count)) { 158 if (HasOverride(direct_subclass, function_name, subclasses_count)) {
167 return true; 159 return true;
168 } 160 }
169 161
170 (*subclasses_count)++; 162 (*subclasses_count)++;
171 } 163 }
172 164
173 return false; 165 return false;
174 } 166 }
175 167
176
177 void CHA::RegisterDependencies(const Code& code) const { 168 void CHA::RegisterDependencies(const Code& code) const {
178 for (intptr_t i = 0; i < guarded_classes_.length(); ++i) { 169 for (intptr_t i = 0; i < guarded_classes_.length(); ++i) {
179 guarded_classes_[i].cls->RegisterCHACode(code); 170 guarded_classes_[i].cls->RegisterCHACode(code);
180 } 171 }
181 } 172 }
182 173
183
184 } // namespace dart 174 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/branch_optimizer.cc ('k') | runtime/vm/cha_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698