Chromium Code Reviews| 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/class_table.h" | 5 #include "vm/class_table.h" |
| 6 #include "vm/flags.h" | 6 #include "vm/flags.h" |
| 7 #include "vm/freelist.h" | 7 #include "vm/freelist.h" |
| 8 #include "vm/heap.h" | 8 #include "vm/heap.h" |
| 9 #include "vm/object.h" | 9 #include "vm/object.h" |
| 10 #include "vm/raw_object.h" | 10 #include "vm/raw_object.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 class_heap_stats_table_ = new_stats_table; | 89 class_heap_stats_table_ = new_stats_table; |
| 90 } | 90 } |
| 91 ASSERT(top_ < capacity_); | 91 ASSERT(top_ < capacity_); |
| 92 cls.set_id(top_); | 92 cls.set_id(top_); |
| 93 table_[top_] = cls.raw(); | 93 table_[top_] = cls.raw(); |
| 94 top_++; // Increment next index. | 94 top_++; // Increment next index. |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 | 98 |
| 99 void ClassTable::RegisterAt(intptr_t index, const Class& cls) { | |
| 100 ASSERT(index != kIllegalCid); | |
| 101 ASSERT(index >= kNumPredefinedCids); | |
| 102 if (index >= capacity_) { | |
| 103 // Grow the capacity of the class table. | |
| 104 intptr_t new_capacity = index + capacity_increment_; | |
| 105 if (new_capacity < capacity_) { | |
| 106 FATAL1("Fatal error in ClassTable::Register: invalid index %" Pd "\n", | |
| 107 index); | |
| 108 } | |
| 109 RawClass** new_table = reinterpret_cast<RawClass**>( | |
| 110 realloc(table_, new_capacity * sizeof(RawClass*))); // NOLINT | |
| 111 ClassHeapStats* new_stats_table = reinterpret_cast<ClassHeapStats*>( | |
| 112 realloc(class_heap_stats_table_, | |
| 113 new_capacity * sizeof(ClassHeapStats))); // NOLINT | |
| 114 for (intptr_t i = capacity_; i < new_capacity; i++) { | |
| 115 new_table[i] = NULL; | |
| 116 new_stats_table[i].Initialize(); | |
| 117 } | |
| 118 capacity_ = new_capacity; | |
| 119 table_ = new_table; | |
| 120 class_heap_stats_table_ = new_stats_table; | |
| 121 ASSERT(capacity_increment_ >= 1); | |
| 122 } | |
| 123 ASSERT(table_[index] == 0); | |
| 124 cls.set_id(index); | |
| 125 table_[index] = cls.raw(); | |
| 126 if (index >= top_) { | |
| 127 top_ = index + 1; | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 | |
| 99 void ClassTable::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 132 void ClassTable::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
| 100 ASSERT(visitor != NULL); | 133 ASSERT(visitor != NULL); |
| 101 visitor->VisitPointers(reinterpret_cast<RawObject**>(&table_[0]), top_); | 134 visitor->VisitPointers(reinterpret_cast<RawObject**>(&table_[0]), top_); |
| 102 } | 135 } |
| 103 | 136 |
| 104 | 137 |
| 138 void ClassTable::Validate() { | |
| 139 Class& cls = Class::Handle(); | |
| 140 for (intptr_t i = kNumPredefinedCids; i < top_; i++) { | |
| 141 // Some of the class table entries maybe NULL as we create some | |
|
regis
2014/03/05 00:21:32
maybe -> may be
| |
| 142 // top level classes but do not add them to the list of anonymous | |
| 143 // classes in a library if there are no top level fields or functions. | |
| 144 // Since there are no references to these top level classes they are | |
| 145 // not written into a full snapshot and will not be recreated when | |
| 146 // we read back the full snapshot. These class slots end up with NULL | |
| 147 // entries. | |
| 148 if (HasValidClassAt(i)) { | |
| 149 cls = At(i); | |
| 150 ASSERT(cls.IsClass()); | |
| 151 } | |
| 152 } | |
| 153 } | |
| 154 | |
| 155 | |
| 105 void ClassTable::Print() { | 156 void ClassTable::Print() { |
| 106 Class& cls = Class::Handle(); | 157 Class& cls = Class::Handle(); |
| 107 String& name = String::Handle(); | 158 String& name = String::Handle(); |
| 108 | 159 |
| 109 for (intptr_t i = 1; i < top_; i++) { | 160 for (intptr_t i = 1; i < top_; i++) { |
| 110 cls = At(i); | 161 cls = At(i); |
| 111 if (cls.raw() != reinterpret_cast<RawClass*>(0)) { | 162 if (cls.raw() != reinterpret_cast<RawClass*>(0)) { |
| 112 name = cls.Name(); | 163 name = cls.Name(); |
| 113 OS::Print("%" Pd ": %s\n", i, name.ToCString()); | 164 OS::Print("%" Pd ": %s\n", i, name.ToCString()); |
| 114 } | 165 } |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 | 424 |
| 374 void ClassTable::UpdateLiveNew(intptr_t cid, intptr_t size) { | 425 void ClassTable::UpdateLiveNew(intptr_t cid, intptr_t size) { |
| 375 ClassHeapStats* stats = StatsAt(cid); | 426 ClassHeapStats* stats = StatsAt(cid); |
| 376 ASSERT(stats != NULL); | 427 ASSERT(stats != NULL); |
| 377 ASSERT(size >= 0); | 428 ASSERT(size >= 0); |
| 378 stats->post_gc.AddNew(size); | 429 stats->post_gc.AddNew(size); |
| 379 } | 430 } |
| 380 | 431 |
| 381 | 432 |
| 382 } // namespace dart | 433 } // namespace dart |
| OLD | NEW |