Browse files

remove member<T>; not necessary for a stop-the-world gc

  • Loading branch information...
1 parent 04aa573 commit e3072a858130bfc95aaff9e49a9135c7baf01606 @kazuho committed Mar 26, 2012
Showing with 7 additions and 41 deletions.
  1. +2 −2 picogc.cpp
  2. +2 −36 picogc.h
  3. +1 −1 t/gc_in_ctor.cpp
  4. +2 −2 t/simple.cpp
View
4 picogc.cpp
@@ -72,7 +72,7 @@ void gc::trigger_gc()
// setup local
for (std::vector<gc_object*>::iterator i = stack_.begin(); i != stack_.end();
++i)
- _mark_object(*i);
+ mark(*i);
// setup root
_setup_roots(stats);
@@ -135,7 +135,7 @@ void gc::_setup_roots(gc_stats& stats)
gc_root* root = roots_;
do {
gc_object* obj = **root;
- _mark_object(obj);
+ mark(obj);
stats.on_stack++;
} while ((root = root->next_) != roots_);
}
View
38 picogc.h
@@ -75,16 +75,6 @@ namespace picogc {
static gc_emitter default_;
};
- template <typename T> class member {
- T* obj_;
- public:
- member() {} // slots are zero-filled by the allocator
- explicit member(T* obj);
- member& operator=(T* obj);
- operator T*() const { return obj_; }
- T* operator->() const { return obj_; }
- };
-
template <typename T> class local {
T* obj_;
public:
@@ -128,8 +118,7 @@ namespace picogc {
void* allocate(size_t sz);
void trigger_gc();
void _register(gc_object* obj, bool has_gc_members);
- template <typename T> void mark(member<T>& _obj);
- void _mark_object(gc_object* obj);
+ void mark(gc_object* obj);
void _register(gc_root* root);
void _unregister(gc_root* root);
void _assign_barrier(gc_object*) {} // for concurrent GC
@@ -174,23 +163,6 @@ namespace picogc {
static void* operator new(size_t sz);
};
- template <typename T> member<T>::member(T* obj) : obj_(obj)
- {
- gc_object* o = obj; // all GC-able objects should be inheriting gc_object
- scope::top()->_assign_barrier(o);
- }
-
- template <typename T> member<T>& member<T>::operator=(T* obj)
- {
- if (obj_ != obj) {
- gc_object* o = obj; // all GC-able objects should be inheriting gc_object
- scope::top()->_assign_barrier(o);
- scope::top()->_unassign_barrier(obj_);
- obj_ = obj;
- }
- return *this;
- }
-
template <typename T> local<T>::local(T* obj) : obj_(obj)
{
gc* gc = scope::top();
@@ -249,7 +221,7 @@ namespace picogc {
// NOTE: not marked
}
- inline void gc::_mark_object(gc_object* obj)
+ inline void gc::mark(gc_object* obj)
{
if (obj == NULL)
return;
@@ -263,12 +235,6 @@ namespace picogc {
pending_.push_back(obj);
}
- template <typename T> void gc::mark(member<T>& _obj)
- {
- gc_object* obj = &*_obj; // members should conform this type conversion
- _mark_object(obj);
- }
-
inline gc_object::gc_object(bool has_gc_members)
{
gc* gc = scope::top();
View
2 t/gc_in_ctor.cpp
@@ -11,7 +11,7 @@ static size_t num_created = 0;
struct Linked : public picogc::gc_object {
typedef picogc::gc_object super;
- picogc::member<Linked> linked_;
+ Linked* linked_;
Linked() : super(true) {
gc->trigger_gc();
is(last_stats.collected, 0UL);
View
4 t/simple.cpp
@@ -13,8 +13,8 @@ static vector<string> destroyed;
struct Label : public picogc::gc_object {
typedef picogc::gc_object super;
string label_;
- picogc::member<Label> linked_;
- Label(const string& label) : super(true), label_(label), linked_(NULL) {}
+ Label* linked_;
+ Label(const string& label) : super(true), label_(label) {}
virtual void gc_mark(picogc::gc* gc) {
super::gc_mark(gc);
gc->mark(linked_);

0 comments on commit e3072a8

Please sign in to comment.