Permalink
Browse files

Unify write barrier access

This ensures we only have one implementation for the write barrier.
Before Object had it's own implementation and the write barrier itself
as well.

Also removes the aux barrier mechanism for now, since we don't need it.
If we want / need it, we can introduce it again in the future.
  • Loading branch information...
1 parent 8455690 commit c426e7bdfea54a742fc598d104a5fd756db27a6a @dbussink dbussink committed May 28, 2013
View
@@ -860,31 +860,8 @@ namespace rubinius {
return RBOOL(dis.resolve(state, name, lookup));
}
- /**
- * We use void* as the type for obj to work around C++'s type system
- * that requires full definitions of classes to be present for it
- * figure out if you can properly pass an object (the superclass
- * has to be known).
- *
- * If we have Object* obj here, then we either have to cast to call
- * write_barrier (which means we lose the ability to have type specific
- * write_barrier versions, which we do), or we have to include
- * every header up front. We opt for the former.
- */
- void Object::inline_write_barrier_passed(STATE, void* obj) {
- if(!remembered_p()) {
- state->memory()->remember_object(this);
- }
- }
-
- void Object::inline_write_barrier_passed(VM* vm, void* obj) {
- if(!remembered_p()) {
- vm->om->remember_object(this);
- }
- }
-
- void Object::write_barrier(gc::WriteBarrier* wb, void* obj) {
- wb->write_barrier(this, reinterpret_cast<Object*>(obj));
+ void Object::write_barrier(ObjectMemory* om, void* obj) {
+ om->write_barrier(this, reinterpret_cast<Object*>(obj));
}
void Object::setup_allocation_site(STATE, CallFrame* call_frame) {
View
@@ -7,6 +7,7 @@
#include "oop.hpp"
#include "type_info.hpp"
#include "executor.hpp"
+#include "objectmemory.hpp"
namespace rubinius {
@@ -49,12 +50,8 @@ namespace rubinius {
class Module;
class Executable;
class Array;
-
class Object;
- typedef std::vector<Object*> ObjectArray;
-
-
/**
* Object is the basic Ruby object.
*
@@ -95,17 +92,14 @@ namespace rubinius {
/** Provides access to the GC write barrier from any object. */
void write_barrier(STATE, void* obj);
- void inline_write_barrier_passed(STATE, void* obj);
-
void write_barrier(VM*, void* obj);
- void inline_write_barrier_passed(VM*, void* obj);
/** Special-case write_barrier() for Fixnums. */
void write_barrier(STATE, Fixnum* obj);
/** Special-case write_barrier() for Symbols. */
void write_barrier(STATE, Symbol* obj);
- void write_barrier(gc::WriteBarrier* wb, void* obj);
+ void write_barrier(ObjectMemory* om, void* obj);
void setup_allocation_site(STATE, CallFrame* call_frame = NULL);
@@ -447,20 +441,12 @@ namespace rubinius {
inline void Object::write_barrier(STATE, void* ptr) {
Object* obj = reinterpret_cast<Object*>(ptr);
- if(!obj->reference_p() ||
- this->young_object_p() ||
- !obj->young_object_p()) return;
-
- inline_write_barrier_passed(state, ptr);
+ state->memory()->write_barrier(this, obj);
}
inline void Object::write_barrier(VM* vm, void* ptr) {
Object* obj = reinterpret_cast<Object*>(ptr);
- if(!obj->reference_p() ||
- this->young_object_p() ||
- !obj->young_object_p()) return;
-
- inline_write_barrier_passed(vm, ptr);
+ vm->om->write_barrier(this, obj);
}
// Used in filtering APIs
View
@@ -20,9 +20,9 @@ namespace rubinius {
return object_;
}
- void set_object(gc::WriteBarrier* wb, Object* obj) {
+ void set_object(ObjectMemory* om, Object* obj) {
object_ = obj;
- write_barrier(wb, obj);
+ write_barrier(om, obj);
}
// Rubinius.primitive :weakref_set_object
View
@@ -1,4 +1,5 @@
#include "vm.hpp"
+#include "objectmemory.hpp"
#include "capi/19/include/ruby/ruby.h"
#include "capi/19/include/ruby/encoding.h"
View
@@ -174,25 +174,6 @@ namespace rubinius {
delete current_rs;
- for(std::list<gc::WriteBarrier*>::iterator wbi = object_memory_->aux_barriers().begin();
- wbi != object_memory_->aux_barriers().end();
- ++wbi) {
- gc::WriteBarrier* wb = *wbi;
- ObjectArray* rs = wb->swap_remember_set();
- for(ObjectArray::iterator oi = rs->begin();
- oi != rs->end();
- ++oi) {
- tmp = *oi;
-
- if(tmp) {
- tmp->clear_remember();
- scan_object(tmp);
- }
- }
-
- delete rs;
- }
-
for(Roots::Iterator i(data.roots()); i.more(); i.advance()) {
i->set(saw_object(i->get()));
}
View
@@ -215,12 +215,6 @@ namespace rubinius {
int cleared = 0;
unsigned int mark = object_memory_->mark();
cleared = object_memory_->unremember_objects(mark);
- for(std::list<gc::WriteBarrier*>::iterator wbi = object_memory_->aux_barriers().begin();
- wbi != object_memory_->aux_barriers().end();
- ++wbi) {
- gc::WriteBarrier* wb = *wbi;
- cleared += wb->unremember_objects(mark);
- }
// Sweep up the garbage
gc_.sweep_blocks();
View
@@ -32,20 +32,6 @@ namespace rubinius {
if(tmp) saw_object(tmp);
}
- for(std::list<gc::WriteBarrier*>::iterator wbi = object_memory_->aux_barriers().begin();
- wbi != object_memory_->aux_barriers().end();
- ++wbi) {
- gc::WriteBarrier* wb = *wbi;
- ObjectArray* rs = wb->remember_set();
- for(ObjectArray::iterator oi = rs->begin();
- oi != rs->end();
- ++oi) {
- tmp = *oi;
-
- if(tmp) saw_object(tmp);
- }
- }
-
for(Roots::Iterator i(data.roots()); i.more(); i.advance()) {
saw_object(i->get());
}
View
@@ -2,10 +2,11 @@
#define RBX_GC_WRITE_BARRIER_HPP
#include "util/thread.hpp"
-#include "builtin/object.hpp"
namespace rubinius {
+ class Object;
+
namespace gc {
/**
@@ -68,13 +69,13 @@ namespace gc {
* @param target The object holding the reference (i.e. the referer).
* @param val The object being referenced (i.e. the referee).
*/
- void write_barrier(Object* target, Object* val) {
+ void write_barrier(ObjectHeader* target, ObjectHeader* val) {
if(target->remembered_p()) return;
if(!val->reference_p()) return;
if(target->young_object_p()) return;
if(!val->young_object_p()) return;
- remember_object(target);
+ remember_object(reinterpret_cast<Object*>(target));
}
// Adds the target object directly to the remembered set.
View
@@ -71,22 +71,22 @@ namespace jit {
}
}
- void RuntimeDataHolder::run_write_barrier(gc::WriteBarrier* wb, Object* obj) {
+ void RuntimeDataHolder::run_write_barrier(ObjectMemory* om, Object* obj) {
for(std::vector<jit::RuntimeData*>::iterator i = runtime_data_.begin();
i != runtime_data_.end();
++i) {
jit::RuntimeData* rd = *i;
if(rd->method()) {
- obj->write_barrier(wb, rd->method());
+ obj->write_barrier(om, rd->method());
}
if(rd->name()) {
- obj->write_barrier(wb, rd->name());
+ obj->write_barrier(om, rd->name());
}
if(rd->module()) {
- obj->write_barrier(wb, rd->module());
+ obj->write_barrier(om, rd->module());
}
}
View
@@ -16,12 +16,9 @@ namespace rubinius {
class GarbageCollector;
class RuntimeDataHolder;
class ObjectMark;
+ class ObjectMemory;
class VM;
- namespace gc {
- class WriteBarrier;
- }
-
namespace jit {
class RuntimeData {
@@ -102,7 +99,7 @@ namespace rubinius {
}
void mark_all(Object* obj, ObjectMark& mark);
- void run_write_barrier(gc::WriteBarrier* wb, Object* obj);
+ void run_write_barrier(ObjectMemory* om, Object* obj);
};
}
}
View
@@ -370,7 +370,7 @@ namespace rubinius {
ls_->end_method_update();
- rd->run_write_barrier(ls_->write_barrier(), req->method());
+ rd->run_write_barrier(ls_->shared().om, req->method());
ls_->shared().stats.jitted_methods++;
@@ -454,7 +454,6 @@ namespace rubinius {
state->shared().auxiliary_threads()->register_thread(this);
state->shared().add_managed_thread(this);
- state->shared().om->add_aux_barrier(state, &write_barrier_);
if(state->shared().config.jit_log.value.size() == 0) {
log_ = &std::cerr;
@@ -506,7 +505,6 @@ namespace rubinius {
shared_.auxiliary_threads()->unregister_thread(this);
shared_.remove_managed_thread(this);
- shared_.om->del_aux_barrier(&write_barrier_);
delete background_thread_;
delete memory_;
delete jit_event_listener_;
View
@@ -40,7 +40,6 @@
#include "llvm/local_info.hpp"
#include "gc/managed.hpp"
-#include "gc/write_barrier.hpp"
#include "auxiliary_threads.hpp"
#include "configuration.hpp"
#include "util/thread.hpp"
@@ -59,6 +58,7 @@ namespace rubinius {
class BackgroundCompilerThread;
class BlockEnvironment;
class Context;
+ class Symbol;
enum JitDebug {
cSimple = 1,
@@ -87,8 +87,6 @@ namespace rubinius {
std::ostream* log_;
- gc::WriteBarrier write_barrier_;
-
uint32_t fixnum_class_id_;
uint32_t integer_class_id_;
uint32_t numeric_class_id_;
@@ -185,10 +183,6 @@ namespace rubinius {
return *log_;
}
- gc::WriteBarrier* write_barrier() {
- return &write_barrier_;
- }
-
uint32_t fixnum_class_id() {
return fixnum_class_id_;
}
View
@@ -6,20 +6,23 @@
#include "object_position.hpp"
-#include "builtin/object.hpp"
+#include "oop.hpp"
#include "gc/code_manager.hpp"
#include "gc/finalize.hpp"
#include "gc/write_barrier.hpp"
#include "util/thread.hpp"
#include "lock.hpp"
+#include "shared_state.hpp"
+
class TestObjectMemory; // So we can friend it properly
class TestVM; // So we can friend it properly
namespace rubinius {
class Object;
+ class Integer;
struct CallFrame;
class GCData;
@@ -35,6 +38,12 @@ namespace rubinius {
class Slab;
}
+ namespace capi {
+ class Handle;
+ class Handles;
+ class GlobalHandle;
+ }
+
struct YoungCollectStats {
int bytes_copied;
double percentage_used;
@@ -159,10 +168,6 @@ namespace rubinius {
/// Flag controlling whether garbage collections are allowed
bool allow_gc_;
- /// List of additional write-barriers that may hold objects with references
- /// to young objects.
- std::list<gc::WriteBarrier*> aux_barriers_;
-
/// Size of slabs to be allocated to threads for lockless thread-local
/// allocations.
size_t slab_size_;
@@ -247,30 +252,6 @@ namespace rubinius {
void add_global_capi_handle_location(STATE, capi::Handle** loc, const char* file, int line);
void del_global_capi_handle_location(STATE, capi::Handle** loc);
- /**
- * Adds an additional write-barrier to the auxiliary write-barriers list.
- */
- void add_aux_barrier(STATE, gc::WriteBarrier* wb) {
- SYNC(state);
- aux_barriers_.push_back(wb);
- }
-
- /**
- * Removes a write-barrier from the auxiliary write-barriers list.
- */
- void del_aux_barrier(STATE, gc::WriteBarrier* wb) {
- SYNC(state);
- aux_barriers_.remove(wb);
- }
-
- void del_aux_barrier(gc::WriteBarrier* wb) {
- aux_barriers_.remove(wb);
- }
-
- std::list<gc::WriteBarrier*>& aux_barriers() {
- return aux_barriers_;
- }
-
public:
ObjectMemory(VM* state, Configuration& config);
~ObjectMemory();
Oops, something went wrong.

0 comments on commit c426e7b

Please sign in to comment.