| 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_trace.h" |
| 8 #include "vm/object.h" | 9 #include "vm/object.h" |
| 9 #include "vm/raw_object.h" | 10 #include "vm/raw_object.h" |
| 10 #include "vm/visitor.h" | 11 #include "vm/visitor.h" |
| 11 | 12 |
| 12 namespace dart { | 13 namespace dart { |
| 13 | 14 |
| 14 DEFINE_FLAG(bool, print_class_table, false, "Print initial class table."); | 15 DEFINE_FLAG(bool, print_class_table, false, "Print initial class table."); |
| 15 | 16 |
| 16 ClassTable::ClassTable() | 17 ClassTable::ClassTable() |
| 17 : top_(kNumPredefinedCids), capacity_(0), table_(NULL) { | 18 : top_(kNumPredefinedCids), capacity_(0), table_(NULL) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 42 | 43 |
| 43 | 44 |
| 44 void ClassTable::Register(const Class& cls) { | 45 void ClassTable::Register(const Class& cls) { |
| 45 intptr_t index = cls.id(); | 46 intptr_t index = cls.id(); |
| 46 if (index != kIllegalCid) { | 47 if (index != kIllegalCid) { |
| 47 ASSERT(index > 0); | 48 ASSERT(index > 0); |
| 48 ASSERT(index < kNumPredefinedCids); | 49 ASSERT(index < kNumPredefinedCids); |
| 49 ASSERT(table_[index] == 0); | 50 ASSERT(table_[index] == 0); |
| 50 ASSERT(index < capacity_); | 51 ASSERT(index < capacity_); |
| 51 table_[index] = cls.raw(); | 52 table_[index] = cls.raw(); |
| 53 if (HeapTrace::is_enabled()) { |
| 54 Isolate::Current()->heap()->trace()->TraceRegisterClass(cls); |
| 55 } |
| 52 // Add the vtable for this predefined class into the static vtable registry | 56 // Add the vtable for this predefined class into the static vtable registry |
| 53 // if it has not been setup yet. | 57 // if it has not been setup yet. |
| 54 cpp_vtable cls_vtable = cls.handle_vtable(); | 58 cpp_vtable cls_vtable = cls.handle_vtable(); |
| 55 cpp_vtable table_entry = Object::builtin_vtables_[index]; | 59 cpp_vtable table_entry = Object::builtin_vtables_[index]; |
| 56 ASSERT((table_entry == 0) || (table_entry == cls_vtable)); | 60 ASSERT((table_entry == 0) || (table_entry == cls_vtable)); |
| 57 if (table_entry == 0) { | 61 if (table_entry == 0) { |
| 58 Object::builtin_vtables_[index] = cls_vtable; | 62 Object::builtin_vtables_[index] = cls_vtable; |
| 59 } | 63 } |
| 60 } else { | 64 } else { |
| 61 if (top_ == capacity_) { | 65 if (top_ == capacity_) { |
| 62 // Grow the capacity of the class table. | 66 // Grow the capacity of the class table. |
| 63 intptr_t new_capacity = capacity_ + capacity_increment_; | 67 intptr_t new_capacity = capacity_ + capacity_increment_; |
| 64 RawClass** new_table = reinterpret_cast<RawClass**>( | 68 RawClass** new_table = reinterpret_cast<RawClass**>( |
| 65 realloc(table_, new_capacity * sizeof(RawClass*))); // NOLINT | 69 realloc(table_, new_capacity * sizeof(RawClass*))); // NOLINT |
| 66 for (intptr_t i = capacity_; i < new_capacity; i++) { | 70 for (intptr_t i = capacity_; i < new_capacity; i++) { |
| 67 new_table[i] = NULL; | 71 new_table[i] = NULL; |
| 68 } | 72 } |
| 69 capacity_ = new_capacity; | 73 capacity_ = new_capacity; |
| 70 table_ = new_table; | 74 table_ = new_table; |
| 71 } | 75 } |
| 72 ASSERT(top_ < capacity_); | 76 ASSERT(top_ < capacity_); |
| 73 cls.set_id(top_); | 77 cls.set_id(top_); |
| 74 table_[top_] = cls.raw(); | 78 table_[top_] = cls.raw(); |
| 79 if (HeapTrace::is_enabled()) { |
| 80 Isolate::Current()->heap()->trace()->TraceRegisterClass(cls); |
| 81 } |
| 75 top_++; // Increment next index. | 82 top_++; // Increment next index. |
| 76 } | 83 } |
| 77 } | 84 } |
| 78 | 85 |
| 79 | 86 |
| 80 void ClassTable::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 87 void ClassTable::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
| 81 ASSERT(visitor != NULL); | 88 ASSERT(visitor != NULL); |
| 82 visitor->VisitPointers(reinterpret_cast<RawObject**>(&table_[0]), top_); | 89 visitor->VisitPointers(reinterpret_cast<RawObject**>(&table_[0]), top_); |
| 83 } | 90 } |
| 84 | 91 |
| 85 | 92 |
| 86 void ClassTable::Print() { | 93 void ClassTable::Print() { |
| 87 Class& cls = Class::Handle(); | 94 Class& cls = Class::Handle(); |
| 88 String& name = String::Handle(); | 95 String& name = String::Handle(); |
| 89 | 96 |
| 90 for (intptr_t i = 1; i < top_; i++) { | 97 for (intptr_t i = 1; i < top_; i++) { |
| 91 cls = At(i); | 98 cls = At(i); |
| 92 if (cls.raw() != reinterpret_cast<RawClass*>(0)) { | 99 if (cls.raw() != reinterpret_cast<RawClass*>(0)) { |
| 93 name = cls.Name(); | 100 name = cls.Name(); |
| 94 OS::Print("%"Pd": %s\n", i, name.ToCString()); | 101 OS::Print("%"Pd": %s\n", i, name.ToCString()); |
| 95 } | 102 } |
| 96 } | 103 } |
| 97 } | 104 } |
| 98 | 105 |
| 99 } // namespace dart | 106 } // namespace dart |
| OLD | NEW |