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

Side by Side Diff: vm/class_table.cc

Issue 10827209: Unify class ids and snapshot object ids list so that we don't have disparate and sometimes confusin… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 4 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 | « vm/class_finalizer.cc ('k') | vm/dart_api_impl.h » ('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/freelist.h" 7 #include "vm/freelist.h"
8 #include "vm/object.h" 8 #include "vm/object.h"
9 #include "vm/raw_object.h" 9 #include "vm/raw_object.h"
10 #include "vm/visitor.h" 10 #include "vm/visitor.h"
11 11
12 namespace dart { 12 namespace dart {
13 13
14 DEFINE_FLAG(bool, print_class_table, false, "Print initial class table."); 14 DEFINE_FLAG(bool, print_class_table, false, "Print initial class table.");
15 15
16 ClassTable::ClassTable() 16 ClassTable::ClassTable()
17 : top_(kNumPredefinedKinds), capacity_(0), table_(NULL) { 17 : top_(kNumPredefinedCids), capacity_(0), table_(NULL) {
18 if (Dart::vm_isolate() == NULL) { 18 if (Dart::vm_isolate() == NULL) {
19 capacity_ = initial_capacity_; 19 capacity_ = initial_capacity_;
20 table_ = reinterpret_cast<RawClass**>( 20 table_ = reinterpret_cast<RawClass**>(
21 calloc(capacity_, sizeof(RawClass*))); // NOLINT 21 calloc(capacity_, sizeof(RawClass*))); // NOLINT
22 } else { 22 } else {
23 // Duplicate the class table from the VM isolate. 23 // Duplicate the class table from the VM isolate.
24 ClassTable* vm_class_table = Dart::vm_isolate()->class_table(); 24 ClassTable* vm_class_table = Dart::vm_isolate()->class_table();
25 capacity_ = vm_class_table->capacity_; 25 capacity_ = vm_class_table->capacity_;
26 table_ = reinterpret_cast<RawClass**>( 26 table_ = reinterpret_cast<RawClass**>(
27 calloc(capacity_, sizeof(RawClass*))); // NOLINT 27 calloc(capacity_, sizeof(RawClass*))); // NOLINT
28 for (intptr_t i = kObject; i < kInstance; i++) { 28 for (intptr_t i = kObjectCid; i < kInstanceCid; i++) {
29 table_[i] = vm_class_table->At(i); 29 table_[i] = vm_class_table->At(i);
30 } 30 }
31 table_[kFreeListElement] = vm_class_table->At(kFreeListElement); 31 table_[kFreeListElement] = vm_class_table->At(kFreeListElement);
32 table_[kNullClassId] = vm_class_table->At(kNullClassId); 32 table_[kNullCid] = vm_class_table->At(kNullCid);
33 table_[kDynamicClassId] = vm_class_table->At(kDynamicClassId); 33 table_[kDynamicCid] = vm_class_table->At(kDynamicCid);
34 table_[kVoidClassId] = vm_class_table->At(kVoidClassId); 34 table_[kVoidCid] = vm_class_table->At(kVoidCid);
35 } 35 }
36 } 36 }
37 37
38 38
39 ClassTable::~ClassTable() { 39 ClassTable::~ClassTable() {
40 free(table_); 40 free(table_);
41 } 41 }
42 42
43 43
44 void ClassTable::Register(const Class& cls) { 44 void ClassTable::Register(const Class& cls) {
45 intptr_t index = cls.id(); 45 intptr_t index = cls.id();
46 if (index != kIllegalObjectKind) { 46 if (index != kIllegalCid) {
47 ASSERT(index > 0); 47 ASSERT(index > 0);
48 ASSERT(index < kNumPredefinedKinds); 48 ASSERT(index < kNumPredefinedCids);
49 ASSERT(table_[index] == 0); 49 ASSERT(table_[index] == 0);
50 ASSERT(index < capacity_); 50 ASSERT(index < capacity_);
51 table_[index] = cls.raw(); 51 table_[index] = cls.raw();
52 // Add the vtable for this predefined class into the static vtable registry 52 // Add the vtable for this predefined class into the static vtable registry
53 // if it has not been setup yet. 53 // if it has not been setup yet.
54 cpp_vtable cls_vtable = cls.handle_vtable(); 54 cpp_vtable cls_vtable = cls.handle_vtable();
55 cpp_vtable table_entry = Object::builtin_vtables_[index]; 55 cpp_vtable table_entry = Object::builtin_vtables_[index];
56 ASSERT((table_entry == 0) || (table_entry == cls_vtable)); 56 ASSERT((table_entry == 0) || (table_entry == cls_vtable));
57 if (table_entry == 0) { 57 if (table_entry == 0) {
58 Object::builtin_vtables_[index] = cls_vtable; 58 Object::builtin_vtables_[index] = cls_vtable;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 for (intptr_t i = 1; i < top_; i++) { 90 for (intptr_t i = 1; i < top_; i++) {
91 cls = At(i); 91 cls = At(i);
92 if (cls.raw() != reinterpret_cast<RawClass*>(0)) { 92 if (cls.raw() != reinterpret_cast<RawClass*>(0)) {
93 name = cls.Name(); 93 name = cls.Name();
94 OS::Print("%d: %s\n", i, name.ToCString()); 94 OS::Print("%d: %s\n", i, name.ToCString());
95 } 95 }
96 } 96 }
97 } 97 }
98 98
99 } // namespace dart 99 } // namespace dart
OLDNEW
« no previous file with comments | « vm/class_finalizer.cc ('k') | vm/dart_api_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698