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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 } | 173 } |
174 ASSERT(table_[index] == 0); | 174 ASSERT(table_[index] == 0); |
175 cls.set_id(index); | 175 cls.set_id(index); |
176 table_[index] = cls.raw(); | 176 table_[index] = cls.raw(); |
177 if (index >= top_) { | 177 if (index >= top_) { |
178 top_ = index + 1; | 178 top_ = index + 1; |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 | 182 |
| 183 void ClassTable::RegisterAt(intptr_t index, RawClass* cls) { |
| 184 ASSERT(Thread::Current()->IsMutatorThread()); |
| 185 ASSERT(index != kIllegalCid); |
| 186 ASSERT(index >= kNumPredefinedCids); |
| 187 if (index >= capacity_) { |
| 188 // Grow the capacity of the class table. |
| 189 // TODO(koda): Add ClassTable::Grow to share code. |
| 190 intptr_t new_capacity = index + capacity_increment_; |
| 191 if (!Class::is_valid_id(index) || new_capacity < capacity_) { |
| 192 FATAL1("Fatal error in ClassTable::Register: invalid index %" Pd "\n", |
| 193 index); |
| 194 } |
| 195 RawClass** new_table = reinterpret_cast<RawClass**>( |
| 196 malloc(new_capacity * sizeof(RawClass*))); // NOLINT |
| 197 memmove(new_table, table_, capacity_ * sizeof(RawClass*)); |
| 198 ClassHeapStats* new_stats_table = reinterpret_cast<ClassHeapStats*>( |
| 199 realloc(class_heap_stats_table_, |
| 200 new_capacity * sizeof(ClassHeapStats))); // NOLINT |
| 201 for (intptr_t i = capacity_; i < new_capacity; i++) { |
| 202 new_table[i] = NULL; |
| 203 new_stats_table[i].Initialize(); |
| 204 } |
| 205 capacity_ = new_capacity; |
| 206 old_tables_->Add(table_); |
| 207 table_ = new_table; // TODO(koda): This should use atomics. |
| 208 class_heap_stats_table_ = new_stats_table; |
| 209 ASSERT(capacity_increment_ >= 1); |
| 210 } |
| 211 ASSERT(table_[index] == 0); |
| 212 table_[index] = cls; |
| 213 if (index >= top_) { |
| 214 top_ = index + 1; |
| 215 } |
| 216 } |
| 217 |
| 218 |
183 #if defined(DEBUG) | 219 #if defined(DEBUG) |
184 void ClassTable::Unregister(intptr_t index) { | 220 void ClassTable::Unregister(intptr_t index) { |
185 table_[index] = 0; | 221 table_[index] = 0; |
186 } | 222 } |
187 #endif | 223 #endif |
188 | 224 |
189 | 225 |
190 void ClassTable::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 226 void ClassTable::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
191 ASSERT(visitor != NULL); | 227 ASSERT(visitor != NULL); |
192 visitor->VisitPointers(reinterpret_cast<RawObject**>(&table_[0]), top_); | 228 visitor->VisitPointers(reinterpret_cast<RawObject**>(&table_[0]), top_); |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 | 585 |
550 void ClassTable::UpdateLiveNew(intptr_t cid, intptr_t size) { | 586 void ClassTable::UpdateLiveNew(intptr_t cid, intptr_t size) { |
551 ClassHeapStats* stats = PreliminaryStatsAt(cid); | 587 ClassHeapStats* stats = PreliminaryStatsAt(cid); |
552 ASSERT(stats != NULL); | 588 ASSERT(stats != NULL); |
553 ASSERT(size >= 0); | 589 ASSERT(size >= 0); |
554 stats->post_gc.AddNew(size); | 590 stats->post_gc.AddNew(size); |
555 } | 591 } |
556 | 592 |
557 | 593 |
558 } // namespace dart | 594 } // namespace dart |
OLD | NEW |