Permalink
Browse files

Move capi::Handles into separate files

  • Loading branch information...
1 parent 0f2e708 commit 1f6af7cd1fdc4a4aa0d9db598c0399d671420d64 @dbussink dbussink committed May 19, 2012
Showing with 163 additions and 139 deletions.
  1. +2 −101 vm/capi/handle.cpp
  2. +0 −33 vm/capi/handle.hpp
  3. +106 −0 vm/capi/handles.cpp
  4. +49 −0 vm/capi/handles.hpp
  5. +1 −1 vm/gc/baker.cpp
  6. +1 −1 vm/gc/immix.cpp
  7. +1 −1 vm/gc/walker.cpp
  8. +1 −1 vm/objectmemory.cpp
  9. +1 −1 vm/shared_state.cpp
  10. +1 −0 vm/test/test_objectmemory.hpp
View
103 vm/capi/handle.cpp
@@ -1,8 +1,10 @@
#include "builtin/nativemethod.hpp"
#include "objectmemory.hpp"
#include "gc/baker.hpp"
+#include "util/allocator.hpp"
#include "capi/capi.hpp"
#include "capi/handle.hpp"
+#include "capi/handles.hpp"
#include "capi/18/include/ruby.h"
namespace rubinius {
@@ -57,107 +59,6 @@ namespace rubinius {
std::cerr << " object: " << object_ << std::endl;
}
- Handles::~Handles() {
- delete allocator_;
- }
-
-
- Handle* Handles::allocate(STATE, Object* obj) {
- bool needs_gc = false;
- Handle* handle = allocator_->allocate(&needs_gc);
- handle->set_object(obj);
- handle->validate();
- if(needs_gc) {
- state->memory()->collect_mature_now = true;
- }
- return handle;
- }
-
- void Handles::deallocate_handles(std::list<Handle*>* cached, int mark, BakerGC* young) {
-
- std::vector<bool> chunk_marks(allocator_->chunks_.size(), false);
-
- size_t i = 0;
-
- for(std::vector<Handle*>::iterator it = allocator_->chunks_.begin();
- it != allocator_->chunks_.end(); ++it) {
- Handle* chunk = *it;
-
- for(size_t j = 0; j < allocator_->cChunkSize; j++) {
- Handle* handle = &chunk[j];
-
- Object* obj = handle->object();
-
- if(!handle->in_use_p()) {
- continue;
- }
-
- // Strong references will already have been updated.
- if(!handle->weak_p()) {
- chunk_marks[i] = true;
- continue;
- }
-
- if(young) {
- if(obj->young_object_p()) {
-
- // A weakref pointing to a valid young object
- //
- // TODO this only works because we run prune_handles right after
- // a collection. In this state, valid objects are only in current.
- if(young->in_current_p(obj)) {
- chunk_marks[i] = true;
- // A weakref pointing to a forwarded young object
- } else if(obj->forwarded_p()) {
- handle->set_object(obj->forward());
- chunk_marks[i] = true;
- // A weakref pointing to a dead young object
- } else {
- handle->clear();
- }
- } else {
- // Not a young object, so won't be GC'd so mark
- // chunk as still active
- chunk_marks[i] = true;
- }
-
- // A weakref pointing to a dead mature object
- } else if(!obj->marked_p(mark)) {
- handle->clear();
- } else {
- chunk_marks[i] = true;
- }
- }
- ++i;
- }
-
- // Cleanup cached handles
- for(std::list<Handle*>::iterator i = cached->begin(); i != cached->end();) {
- Handle* handle = *i;
- if(handle->in_use_p()) {
- ++i;
- } else {
- i = cached->erase(i);
- }
- }
-
- i = 0;
- for(std::vector<Handle*>::iterator it = allocator_->chunks_.begin();
- it != allocator_->chunks_.end();) {
- // No header was marked, so it's completely empty. Free it.
- if(!chunk_marks[i]) {
- Handle* chunk = *it;
- delete[] chunk;
- it = allocator_->chunks_.erase(it);
- } else {
- ++it;
- }
- ++i;
- }
-
- allocator_->rebuild_freelist();
- }
-
HandleSet::HandleSet()
: slow_(0)
{
View
33 vm/capi/handle.hpp
@@ -5,10 +5,8 @@
#include "gc/root.hpp"
#include "capi/value.hpp"
-#include "util/allocator.hpp"
#include <tr1/unordered_set>
-#include <vector>
#ifndef RIO
#define RIO rb_io_t
@@ -23,7 +21,6 @@ struct RFile;
namespace rubinius {
class NativeMethodEnvironment;
- class BakerGC;
namespace capi {
@@ -202,36 +199,6 @@ namespace rubinius {
bool rio_close();
};
- class Handles {
-
- private:
- Allocator<Handle>* allocator_;
-
- public:
-
- Handles()
- : allocator_(new Allocator<Handle>())
- {}
-
- ~Handles();
-
- Handle* allocate(STATE, Object* obj);
-
- void deallocate_handles(std::list<Handle*>* cached, int mark, BakerGC* young);
-
- void flush_all(NativeMethodEnvironment* env);
-
- Allocator<Handle>* allocator() const {
- return allocator_;
- }
-
- int size() const {
- return allocator_->in_use_;
- }
-
- };
-
-
typedef std::tr1::unordered_set<Handle*> SlowHandleSet;
class HandleSet {
View
106 vm/capi/handles.cpp
@@ -0,0 +1,106 @@
+#include "builtin/nativemethod.hpp"
+#include "objectmemory.hpp"
+#include "gc/baker.hpp"
+#include "capi/capi.hpp"
+#include "capi/handles.hpp"
+
+namespace rubinius {
+ namespace capi {
+
+ Handle* Handles::allocate(STATE, Object* obj) {
+ bool needs_gc = false;
+ Handle* handle = allocator_->allocate(&needs_gc);
+ handle->set_object(obj);
+ handle->validate();
+ if(needs_gc) {
+ state->memory()->collect_mature_now = true;
+ }
+ return handle;
+ }
+
+ void Handles::deallocate_handles(std::list<Handle*>* cached, int mark, BakerGC* young) {
+
+ std::vector<bool> chunk_marks(allocator_->chunks_.size(), false);
+
+ size_t i = 0;
+
+ for(std::vector<Handle*>::iterator it = allocator_->chunks_.begin();
+ it != allocator_->chunks_.end(); ++it) {
+ Handle* chunk = *it;
+
+ for(size_t j = 0; j < allocator_->cChunkSize; j++) {
+ Handle* handle = &chunk[j];
+
+ Object* obj = handle->object();
+
+ if(!handle->in_use_p()) {
+ continue;
+ }
+
+ // Strong references will already have been updated.
+ if(!handle->weak_p()) {
+ chunk_marks[i] = true;
+ continue;
+ }
+
+ if(young) {
+ if(obj->young_object_p()) {
+
+ // A weakref pointing to a valid young object
+ //
+ // TODO this only works because we run prune_handles right after
+ // a collection. In this state, valid objects are only in current.
+ if(young->in_current_p(obj)) {
+ chunk_marks[i] = true;
+ // A weakref pointing to a forwarded young object
+ } else if(obj->forwarded_p()) {
+ handle->set_object(obj->forward());
+ chunk_marks[i] = true;
+ // A weakref pointing to a dead young object
+ } else {
+ handle->clear();
+ }
+ } else {
+ // Not a young object, so won't be GC'd so mark
+ // chunk as still active
+ chunk_marks[i] = true;
+ }
+
+ // A weakref pointing to a dead mature object
+ } else if(!obj->marked_p(mark)) {
+ handle->clear();
+ } else {
+ chunk_marks[i] = true;
+ }
+ }
+ ++i;
+ }
+
+ // Cleanup cached handles
+ for(std::list<Handle*>::iterator i = cached->begin(); i != cached->end();) {
+ Handle* handle = *i;
+ if(handle->in_use_p()) {
+ ++i;
+ } else {
+ i = cached->erase(i);
+ }
+ }
+
+ i = 0;
+ for(std::vector<Handle*>::iterator it = allocator_->chunks_.begin();
+ it != allocator_->chunks_.end();) {
+ // No header was marked, so it's completely empty. Free it.
+ if(!chunk_marks[i]) {
+ Handle* chunk = *it;
+ delete[] chunk;
+ it = allocator_->chunks_.erase(it);
+ } else {
+ ++it;
+ }
+ ++i;
+ }
+
+ allocator_->rebuild_freelist();
+ }
+ }
+}
View
49 vm/capi/handles.hpp
@@ -0,0 +1,49 @@
+#ifndef RBX_CAPI_HANDLES_HPP
+#define RBX_CAPI_HANDLES_HPP
+
+#include "vm.hpp"
+#include "gc/root.hpp"
+#include "util/allocator.hpp"
+#include "capi/handle.hpp"
+
+#include <vector>
+
+namespace rubinius {
+ class BakerGC;
+
+ namespace capi {
+
+ class Handles {
+
+ private:
+ Allocator<Handle>* allocator_;
+
+ public:
+
+ Handles()
+ : allocator_(new Allocator<Handle>())
+ {}
+
+ ~Handles() {
+ delete allocator_;
+ }
+
+ Handle* allocate(STATE, Object* obj);
+
+ void deallocate_handles(std::list<Handle*>* cached, int mark, BakerGC* young);
+
+ void flush_all(NativeMethodEnvironment* env);
+
+ Allocator<Handle>* allocator() const {
+ return allocator_;
+ }
+
+ int size() const {
+ return allocator_->in_use_;
+ }
+
+ };
+ }
+}
+
+#endif
View
2 vm/gc/baker.cpp
@@ -13,7 +13,7 @@
#include "gc/gc.hpp"
-#include "capi/handle.hpp"
+#include "capi/handles.hpp"
#include "capi/tag.hpp"
#ifdef ENABLE_LLVM
View
2 vm/gc/immix.cpp
@@ -3,7 +3,7 @@
#include "instruments/stats.hpp"
-#include "capi/handle.hpp"
+#include "capi/handles.hpp"
#include "capi/tag.hpp"
#include "object_watch.hpp"
View
2 vm/gc/walker.cpp
@@ -1,7 +1,7 @@
#include "gc/walker.hpp"
#include "objectmemory.hpp"
-#include "capi/handle.hpp"
+#include "capi/handles.hpp"
namespace rubinius {
ObjectWalker::~ObjectWalker() {
View
2 vm/objectmemory.cpp
@@ -28,7 +28,7 @@
#include "builtin/array.hpp"
#include "builtin/thread.hpp"
-#include "capi/handle.hpp"
+#include "capi/handles.hpp"
#include "configuration.hpp"
#include "global_cache.hpp"
View
2 vm/shared_state.cpp
@@ -7,7 +7,7 @@
#include "instruments/tooling.hpp"
#include "instruments/timing.hpp"
#include "global_cache.hpp"
-#include "capi/handle.hpp"
+#include "capi/handles.hpp"
#include "util/thread.hpp"
#include "inline_cache.hpp"
View
1 vm/test/test_objectmemory.hpp
@@ -6,6 +6,7 @@
#include "gc/root.hpp"
#include "gc/baker.hpp"
#include "gc/marksweep.hpp"
+#include "capi/handles.hpp"
#include "object_utils.hpp"

0 comments on commit 1f6af7c

Please sign in to comment.