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

Side by Side Diff: vm/class_table.cc

Issue 9965042: - Add a class index to the classes. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 7 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_table.h ('k') | vm/dart.cc » ('j') | vm/raw_object.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "vm/class_table.h"
6 #include "vm/flags.h"
7 #include "vm/object.h"
8 #include "vm/raw_object.h"
9 #include "vm/visitor.h"
10
11 namespace dart {
12
13 DEFINE_FLAG(bool, print_class_table, false, "Print initial class table.");
14
15 ClassTable::ClassTable()
16 : top_(kNumPredefinedKinds), capacity_(initial_capacity_), table_(NULL) {
17 table_ = reinterpret_cast<RawClass**>(calloc(capacity_,
18 sizeof(RawClass*))); // NOLINT
19 // Duplicate the class table from the VM isolate.
20 if (Dart::vm_isolate() != NULL) {
21 ClassTable* vm_class_table = Dart::vm_isolate()->class_table();
22 for (int i = kObject; i < kInstance; i++) {
23 table_[i] = vm_class_table->At(i);
24 }
25 table_[kNullClassIndex] = vm_class_table->At(kNullClassIndex);
26 table_[kDynamicClassIndex] = vm_class_table->At(kDynamicClassIndex);
27 table_[kVoidClassIndex] = vm_class_table->At(kVoidClassIndex);
28 }
29 }
30
31
32 ClassTable::~ClassTable() {
33 free(table_);
34 }
35
36
37 void ClassTable::Register(const Class& cls) {
38 intptr_t index = cls.index();
39 if (index != kIllegalObjectKind) {
40 ASSERT(index > 0);
41 ASSERT(index < kNumPredefinedKinds);
42 ASSERT(table_[index] == 0);
43 table_[index] = cls.raw();
44 } else {
45 cls.set_index(top_);
46 table_[top_] = cls.raw();
47 top_++; // Increment next index.
48 ASSERT(top_ < capacity_);
49 }
50 }
51
52
53 void ClassTable::VisitObjectPointers(ObjectPointerVisitor* visitor) {
54 ASSERT(visitor != NULL);
55 visitor->VisitPointers(reinterpret_cast<RawObject**>(&table_[0]), top_);
56 }
57
58
59 void ClassTable::Print() {
60 Class& cls = Class::Handle();
61 String& name = String::Handle();
62
63 for (intptr_t i = 1; i < top_; i++) {
64 cls = At(i);
65 if (cls.raw() != reinterpret_cast<RawClass*>(0)) {
66 name = cls.Name();
67 OS::Print("%d: %s\n", i, name.ToCString());
68 }
69 }
70 }
71
72 } // namespace dart
OLDNEW
« no previous file with comments | « vm/class_table.h ('k') | vm/dart.cc » ('j') | vm/raw_object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698