OLD | NEW |
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/atomic.h" | 5 #include "vm/atomic.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/growable_array.h" | 9 #include "vm/growable_array.h" |
10 #include "vm/heap.h" | 10 #include "vm/heap.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 FATAL1("Fatal error in ClassTable::Register: invalid index %" Pd "\n", | 136 FATAL1("Fatal error in ClassTable::Register: invalid index %" Pd "\n", |
137 top_); | 137 top_); |
138 } | 138 } |
139 cls.set_id(top_); | 139 cls.set_id(top_); |
140 table_[top_] = cls.raw(); | 140 table_[top_] = cls.raw(); |
141 top_++; // Increment next index. | 141 top_++; // Increment next index. |
142 } | 142 } |
143 } | 143 } |
144 | 144 |
145 | 145 |
146 void ClassTable::RegisterAt(intptr_t index, const Class& cls) { | 146 void ClassTable::AllocateIndex(intptr_t index) { |
147 ASSERT(Thread::Current()->IsMutatorThread()); | |
148 ASSERT(index != kIllegalCid); | |
149 ASSERT(index >= kNumPredefinedCids); | |
150 if (index >= capacity_) { | 147 if (index >= capacity_) { |
151 // Grow the capacity of the class table. | 148 // Grow the capacity of the class table. |
152 // TODO(koda): Add ClassTable::Grow to share code. | 149 // TODO(koda): Add ClassTable::Grow to share code. |
153 intptr_t new_capacity = index + capacity_increment_; | 150 intptr_t new_capacity = index + capacity_increment_; |
154 if (!Class::is_valid_id(index) || new_capacity < capacity_) { | 151 if (!Class::is_valid_id(index) || new_capacity < capacity_) { |
155 FATAL1("Fatal error in ClassTable::Register: invalid index %" Pd "\n", | 152 FATAL1("Fatal error in ClassTable::Register: invalid index %" Pd "\n", |
156 index); | 153 index); |
157 } | 154 } |
158 RawClass** new_table = reinterpret_cast<RawClass**>( | 155 RawClass** new_table = reinterpret_cast<RawClass**>( |
159 malloc(new_capacity * sizeof(RawClass*))); // NOLINT | 156 malloc(new_capacity * sizeof(RawClass*))); // NOLINT |
160 memmove(new_table, table_, capacity_ * sizeof(RawClass*)); | 157 memmove(new_table, table_, capacity_ * sizeof(RawClass*)); |
161 ClassHeapStats* new_stats_table = reinterpret_cast<ClassHeapStats*>( | 158 ClassHeapStats* new_stats_table = reinterpret_cast<ClassHeapStats*>( |
162 realloc(class_heap_stats_table_, | 159 realloc(class_heap_stats_table_, |
163 new_capacity * sizeof(ClassHeapStats))); // NOLINT | 160 new_capacity * sizeof(ClassHeapStats))); // NOLINT |
164 for (intptr_t i = capacity_; i < new_capacity; i++) { | 161 for (intptr_t i = capacity_; i < new_capacity; i++) { |
165 new_table[i] = NULL; | 162 new_table[i] = NULL; |
166 new_stats_table[i].Initialize(); | 163 new_stats_table[i].Initialize(); |
167 } | 164 } |
168 capacity_ = new_capacity; | 165 capacity_ = new_capacity; |
169 old_tables_->Add(table_); | 166 old_tables_->Add(table_); |
170 table_ = new_table; // TODO(koda): This should use atomics. | 167 table_ = new_table; // TODO(koda): This should use atomics. |
171 class_heap_stats_table_ = new_stats_table; | 168 class_heap_stats_table_ = new_stats_table; |
172 ASSERT(capacity_increment_ >= 1); | 169 ASSERT(capacity_increment_ >= 1); |
173 } | 170 } |
| 171 |
174 ASSERT(table_[index] == 0); | 172 ASSERT(table_[index] == 0); |
175 cls.set_id(index); | |
176 table_[index] = cls.raw(); | |
177 if (index >= top_) { | 173 if (index >= top_) { |
178 top_ = index + 1; | 174 top_ = index + 1; |
179 } | 175 } |
180 } | 176 } |
181 | 177 |
182 | 178 |
| 179 void ClassTable::RegisterAt(intptr_t index, const Class& cls) { |
| 180 ASSERT(Thread::Current()->IsMutatorThread()); |
| 181 ASSERT(index != kIllegalCid); |
| 182 ASSERT(index >= kNumPredefinedCids); |
| 183 AllocateIndex(index); |
| 184 cls.set_id(index); |
| 185 table_[index] = cls.raw(); |
| 186 } |
| 187 |
| 188 |
183 #if defined(DEBUG) | 189 #if defined(DEBUG) |
184 void ClassTable::Unregister(intptr_t index) { | 190 void ClassTable::Unregister(intptr_t index) { |
185 table_[index] = 0; | 191 table_[index] = 0; |
186 } | 192 } |
187 #endif | 193 #endif |
188 | 194 |
189 | 195 |
190 void ClassTable::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 196 void ClassTable::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
191 ASSERT(visitor != NULL); | 197 ASSERT(visitor != NULL); |
192 visitor->VisitPointers(reinterpret_cast<RawObject**>(&table_[0]), top_); | 198 visitor->VisitPointers(reinterpret_cast<RawObject**>(&table_[0]), top_); |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 | 555 |
550 void ClassTable::UpdateLiveNew(intptr_t cid, intptr_t size) { | 556 void ClassTable::UpdateLiveNew(intptr_t cid, intptr_t size) { |
551 ClassHeapStats* stats = PreliminaryStatsAt(cid); | 557 ClassHeapStats* stats = PreliminaryStatsAt(cid); |
552 ASSERT(stats != NULL); | 558 ASSERT(stats != NULL); |
553 ASSERT(size >= 0); | 559 ASSERT(size >= 0); |
554 stats->post_gc.AddNew(size); | 560 stats->post_gc.AddNew(size); |
555 } | 561 } |
556 | 562 |
557 | 563 |
558 } // namespace dart | 564 } // namespace dart |
OLD | NEW |