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

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

Issue 10538022: Do not reuse tags_ field to store next_ pointer of FreeListElement. (Closed) Base URL: https://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 | « no previous file | runtime/vm/freelist.h » ('j') | runtime/vm/freelist.h » ('J')
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/object.h" 8 #include "vm/object.h"
8 #include "vm/raw_object.h" 9 #include "vm/raw_object.h"
9 #include "vm/visitor.h" 10 #include "vm/visitor.h"
10 11
11 namespace dart { 12 namespace dart {
12 13
13 DEFINE_FLAG(bool, print_class_table, false, "Print initial class table."); 14 DEFINE_FLAG(bool, print_class_table, false, "Print initial class table.");
14 15
15 ClassTable::ClassTable() 16 ClassTable::ClassTable()
16 : top_(kNumPredefinedKinds), capacity_(0), table_(NULL) { 17 : top_(kNumPredefinedKinds), capacity_(0), table_(NULL) {
17 if (Dart::vm_isolate() == NULL) { 18 if (Dart::vm_isolate() == NULL) {
18 capacity_ = initial_capacity_; 19 capacity_ = initial_capacity_;
19 table_ = reinterpret_cast<RawClass**>( 20 table_ = reinterpret_cast<RawClass**>(
20 calloc(capacity_, sizeof(RawClass*))); // NOLINT 21 calloc(capacity_, sizeof(RawClass*))); // NOLINT
22 table_[kFreeListElement] = FreeListElement::element_class();
21 } else { 23 } else {
22 // Duplicate the class table from the VM isolate. 24 // Duplicate the class table from the VM isolate.
23 ClassTable* vm_class_table = Dart::vm_isolate()->class_table(); 25 ClassTable* vm_class_table = Dart::vm_isolate()->class_table();
24 capacity_ = vm_class_table->capacity_; 26 capacity_ = vm_class_table->capacity_;
25 table_ = reinterpret_cast<RawClass**>( 27 table_ = reinterpret_cast<RawClass**>(
26 calloc(capacity_, sizeof(RawClass*))); // NOLINT 28 calloc(capacity_, sizeof(RawClass*))); // NOLINT
27 for (intptr_t i = kObject; i < kInstance; i++) { 29 for (intptr_t i = kObject; i < kInstance; i++) {
28 table_[i] = vm_class_table->At(i); 30 table_[i] = vm_class_table->At(i);
29 } 31 }
32 table_[kFreeListElement] = vm_class_table->At(kFreeListElement);
30 table_[kNullClassId] = vm_class_table->At(kNullClassId); 33 table_[kNullClassId] = vm_class_table->At(kNullClassId);
31 table_[kDynamicClassId] = vm_class_table->At(kDynamicClassId); 34 table_[kDynamicClassId] = vm_class_table->At(kDynamicClassId);
32 table_[kVoidClassId] = vm_class_table->At(kVoidClassId); 35 table_[kVoidClassId] = vm_class_table->At(kVoidClassId);
33 } 36 }
34 } 37 }
35 38
36 39
37 ClassTable::~ClassTable() { 40 ClassTable::~ClassTable() {
38 free(table_); 41 free(table_);
39 } 42 }
(...skipping 22 matching lines...) Expand all
62 ASSERT(top_ < capacity_); 65 ASSERT(top_ < capacity_);
63 cls.set_id(top_); 66 cls.set_id(top_);
64 table_[top_] = cls.raw(); 67 table_[top_] = cls.raw();
65 top_++; // Increment next index. 68 top_++; // Increment next index.
66 } 69 }
67 } 70 }
68 71
69 72
70 void ClassTable::VisitObjectPointers(ObjectPointerVisitor* visitor) { 73 void ClassTable::VisitObjectPointers(ObjectPointerVisitor* visitor) {
71 ASSERT(visitor != NULL); 74 ASSERT(visitor != NULL);
72 visitor->VisitPointers(reinterpret_cast<RawObject**>(&table_[0]), top_); 75 // Class stored at the index kFreeListElement is a fake object
76 // residing outside of the heap. Do not visit it.
Ivan Posva 2012/06/08 07:19:20 Does the FreeListElement class have to reside outs
77 visitor->VisitPointers(
78 reinterpret_cast<RawObject**>(&table_[0]),
79 reinterpret_cast<RawObject**>(&table_[kFreeListElement - 1]));
80 visitor->VisitPointers(
81 reinterpret_cast<RawObject**>(&table_[kFreeListElement + 1]),
82 reinterpret_cast<RawObject**>(&table_[top_ - 1]));
73 } 83 }
74 84
75 85
76 void ClassTable::Print() { 86 void ClassTable::Print() {
77 Class& cls = Class::Handle(); 87 Class& cls = Class::Handle();
78 String& name = String::Handle(); 88 String& name = String::Handle();
79 89
80 for (intptr_t i = 1; i < top_; i++) { 90 for (intptr_t i = 1; i < top_; i++) {
81 cls = At(i); 91 cls = At(i);
82 if (cls.raw() != reinterpret_cast<RawClass*>(0)) { 92 if (cls.raw() != reinterpret_cast<RawClass*>(0)) {
83 name = cls.Name(); 93 name = cls.Name();
84 OS::Print("%d: %s\n", i, name.ToCString()); 94 OS::Print("%d: %s\n", i, name.ToCString());
85 } 95 }
86 } 96 }
87 } 97 }
88 98
89 } // namespace dart 99 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/freelist.h » ('j') | runtime/vm/freelist.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698