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

Unified Diff: runtime/vm/class_table.cc

Issue 816773005: Copy-on-write class table for concurrent reading. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/class_table.h ('k') | runtime/vm/pages.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/class_table.cc
===================================================================
--- runtime/vm/class_table.cc (revision 42760)
+++ runtime/vm/class_table.cc (working copy)
@@ -5,6 +5,7 @@
#include "vm/class_table.h"
#include "vm/flags.h"
#include "vm/freelist.h"
+#include "vm/growable_array.h"
#include "vm/heap.h"
#include "vm/object.h"
#include "vm/raw_object.h"
@@ -16,6 +17,7 @@
ClassTable::ClassTable()
: top_(kNumPredefinedCids), capacity_(0), table_(NULL),
+ old_tables_(new MallocGrowableArray<RawClass**>()),
Ivan Posva 2015/01/20 22:46:45 Wondering why you decided on MallocGrowableArray v
koda 2015/01/21 14:36:09 1. To avoid yet another ad hoc linked list impleme
class_heap_stats_table_(NULL),
predefined_class_heap_stats_table_(NULL) {
if (Dart::vm_isolate() == NULL) {
@@ -51,23 +53,35 @@
ClassTable::ClassTable(ClassTable* original)
: top_(original->top_),
capacity_(original->top_),
- table_(reinterpret_cast<RawClass**>(
- calloc(original->top_, sizeof(RawClass*)))),
+ table_(original->table_),
+ old_tables_(NULL),
class_heap_stats_table_(NULL),
predefined_class_heap_stats_table_(NULL) {
- for (intptr_t i = 1; i < top_; i++) {
- table_[i] = original->At(i);
- }
}
ClassTable::~ClassTable() {
- free(table_);
- free(predefined_class_heap_stats_table_);
- free(class_heap_stats_table_);
+ if (old_tables_ != NULL) {
+ FreeOldTables();
+ delete old_tables_;
+ free(table_);
+ free(predefined_class_heap_stats_table_);
+ free(class_heap_stats_table_);
+ } else {
+ // This instance was a shallow copy. It doesn't own any memory.
+ ASSERT(predefined_class_heap_stats_table_ == NULL);
+ ASSERT(class_heap_stats_table_ == NULL);
+ }
}
+void ClassTable::FreeOldTables() {
+ while (old_tables_->length() > 0) {
+ free(old_tables_->RemoveLast());
+ }
+}
+
+
void ClassTable::Register(const Class& cls) {
intptr_t index = cls.id();
if (index != kIllegalCid) {
@@ -87,9 +101,11 @@
} else {
if (top_ == capacity_) {
// Grow the capacity of the class table.
+ // TODO(koda): Add ClassTable::Grow to share code.
intptr_t new_capacity = capacity_ + capacity_increment_;
RawClass** new_table = reinterpret_cast<RawClass**>(
- realloc(table_, new_capacity * sizeof(RawClass*))); // NOLINT
+ malloc(new_capacity * sizeof(RawClass*))); // NOLINT
+ memmove(new_table, table_, capacity_ * sizeof(RawClass*));
ClassHeapStats* new_stats_table = reinterpret_cast<ClassHeapStats*>(
realloc(class_heap_stats_table_,
new_capacity * sizeof(ClassHeapStats))); // NOLINT
@@ -98,7 +114,8 @@
new_stats_table[i].Initialize();
}
capacity_ = new_capacity;
- table_ = new_table;
+ old_tables_->Add(table_);
+ table_ = new_table; // TODO(koda): This should use atomics.
class_heap_stats_table_ = new_stats_table;
}
ASSERT(top_ < capacity_);
@@ -118,6 +135,7 @@
ASSERT(index >= kNumPredefinedCids);
if (index >= capacity_) {
// Grow the capacity of the class table.
+ // TODO(koda): Add ClassTable::Grow to share code.
intptr_t new_capacity = index + capacity_increment_;
if (!Class::is_valid_id(index) || new_capacity < capacity_) {
FATAL1("Fatal error in ClassTable::Register: invalid index %" Pd "\n",
@@ -124,7 +142,8 @@
index);
}
RawClass** new_table = reinterpret_cast<RawClass**>(
- realloc(table_, new_capacity * sizeof(RawClass*))); // NOLINT
+ malloc(new_capacity * sizeof(RawClass*))); // NOLINT
+ memmove(new_table, table_, capacity_ * sizeof(RawClass*));
ClassHeapStats* new_stats_table = reinterpret_cast<ClassHeapStats*>(
realloc(class_heap_stats_table_,
new_capacity * sizeof(ClassHeapStats))); // NOLINT
@@ -133,7 +152,8 @@
new_stats_table[i].Initialize();
}
capacity_ = new_capacity;
- table_ = new_table;
+ old_tables_->Add(table_);
+ table_ = new_table; // TODO(koda): This should use atomics.
class_heap_stats_table_ = new_stats_table;
ASSERT(capacity_increment_ >= 1);
}
« no previous file with comments | « runtime/vm/class_table.h ('k') | runtime/vm/pages.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698