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

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

Issue 10441111: - Rename class index to class id. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/code_generator_ia32.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/class_table.h" 5 #include "vm/class_table.h"
6 #include "vm/flags.h" 6 #include "vm/flags.h"
7 #include "vm/object.h" 7 #include "vm/object.h"
8 #include "vm/raw_object.h" 8 #include "vm/raw_object.h"
9 #include "vm/visitor.h" 9 #include "vm/visitor.h"
10 10
11 namespace dart { 11 namespace dart {
12 12
13 DEFINE_FLAG(bool, print_class_table, false, "Print initial class table."); 13 DEFINE_FLAG(bool, print_class_table, false, "Print initial class table.");
14 14
15 ClassTable::ClassTable() 15 ClassTable::ClassTable()
16 : top_(kNumPredefinedKinds), capacity_(0), table_(NULL) { 16 : top_(kNumPredefinedKinds), capacity_(0), table_(NULL) {
17 if (Dart::vm_isolate() == NULL) { 17 if (Dart::vm_isolate() == NULL) {
18 capacity_ = initial_capacity_; 18 capacity_ = initial_capacity_;
19 table_ = reinterpret_cast<RawClass**>( 19 table_ = reinterpret_cast<RawClass**>(
20 calloc(capacity_, sizeof(RawClass*))); // NOLINT 20 calloc(capacity_, sizeof(RawClass*))); // NOLINT
21 } else { 21 } else {
22 // Duplicate the class table from the VM isolate. 22 // Duplicate the class table from the VM isolate.
23 ClassTable* vm_class_table = Dart::vm_isolate()->class_table(); 23 ClassTable* vm_class_table = Dart::vm_isolate()->class_table();
24 capacity_ = vm_class_table->capacity_; 24 capacity_ = vm_class_table->capacity_;
25 table_ = reinterpret_cast<RawClass**>( 25 table_ = reinterpret_cast<RawClass**>(
26 calloc(capacity_, sizeof(RawClass*))); // NOLINT 26 calloc(capacity_, sizeof(RawClass*))); // NOLINT
27 for (intptr_t i = kObject; i < kInstance; i++) { 27 for (intptr_t i = kObject; i < kInstance; i++) {
28 table_[i] = vm_class_table->At(i); 28 table_[i] = vm_class_table->At(i);
29 } 29 }
30 table_[kNullClassIndex] = vm_class_table->At(kNullClassIndex); 30 table_[kNullClassId] = vm_class_table->At(kNullClassId);
31 table_[kDynamicClassIndex] = vm_class_table->At(kDynamicClassIndex); 31 table_[kDynamicClassId] = vm_class_table->At(kDynamicClassId);
32 table_[kVoidClassIndex] = vm_class_table->At(kVoidClassIndex); 32 table_[kVoidClassId] = vm_class_table->At(kVoidClassId);
33 } 33 }
34 } 34 }
35 35
36 36
37 ClassTable::~ClassTable() { 37 ClassTable::~ClassTable() {
38 free(table_); 38 free(table_);
39 } 39 }
40 40
41 41
42 void ClassTable::Register(const Class& cls) { 42 void ClassTable::Register(const Class& cls) {
43 intptr_t index = cls.index(); 43 intptr_t index = cls.id();
44 if (index != kIllegalObjectKind) { 44 if (index != kIllegalObjectKind) {
45 ASSERT(index > 0); 45 ASSERT(index > 0);
46 ASSERT(index < kNumPredefinedKinds); 46 ASSERT(index < kNumPredefinedKinds);
47 ASSERT(table_[index] == 0); 47 ASSERT(table_[index] == 0);
48 ASSERT(index < capacity_); 48 ASSERT(index < capacity_);
49 table_[index] = cls.raw(); 49 table_[index] = cls.raw();
50 } else { 50 } else {
51 if (top_ == capacity_) { 51 if (top_ == capacity_) {
52 // Grow the capacity of the class table. 52 // Grow the capacity of the class table.
53 intptr_t new_capacity = capacity_ + capacity_increment_; 53 intptr_t new_capacity = capacity_ + capacity_increment_;
54 RawClass** new_table = reinterpret_cast<RawClass**>( 54 RawClass** new_table = reinterpret_cast<RawClass**>(
55 realloc(table_, new_capacity * sizeof(RawClass*))); // NOLINT 55 realloc(table_, new_capacity * sizeof(RawClass*))); // NOLINT
56 for (intptr_t i = capacity_; i < new_capacity; i++) { 56 for (intptr_t i = capacity_; i < new_capacity; i++) {
57 new_table[i] = NULL; 57 new_table[i] = NULL;
58 } 58 }
59 capacity_ = new_capacity; 59 capacity_ = new_capacity;
60 table_ = new_table; 60 table_ = new_table;
61 } 61 }
62 ASSERT(top_ < capacity_); 62 ASSERT(top_ < capacity_);
63 cls.set_index(top_); 63 cls.set_id(top_);
64 table_[top_] = cls.raw(); 64 table_[top_] = cls.raw();
65 top_++; // Increment next index. 65 top_++; // Increment next index.
66 } 66 }
67 } 67 }
68 68
69 69
70 void ClassTable::VisitObjectPointers(ObjectPointerVisitor* visitor) { 70 void ClassTable::VisitObjectPointers(ObjectPointerVisitor* visitor) {
71 ASSERT(visitor != NULL); 71 ASSERT(visitor != NULL);
72 visitor->VisitPointers(reinterpret_cast<RawObject**>(&table_[0]), top_); 72 visitor->VisitPointers(reinterpret_cast<RawObject**>(&table_[0]), top_);
73 } 73 }
74 74
75 75
76 void ClassTable::Print() { 76 void ClassTable::Print() {
77 Class& cls = Class::Handle(); 77 Class& cls = Class::Handle();
78 String& name = String::Handle(); 78 String& name = String::Handle();
79 79
80 for (intptr_t i = 1; i < top_; i++) { 80 for (intptr_t i = 1; i < top_; i++) {
81 cls = At(i); 81 cls = At(i);
82 if (cls.raw() != reinterpret_cast<RawClass*>(0)) { 82 if (cls.raw() != reinterpret_cast<RawClass*>(0)) {
83 name = cls.Name(); 83 name = cls.Name();
84 OS::Print("%d: %s\n", i, name.ToCString()); 84 OS::Print("%d: %s\n", i, name.ToCString());
85 } 85 }
86 } 86 }
87 } 87 }
88 88
89 } // namespace dart 89 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/code_generator_ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698