Skip to content

Commit

Permalink
Add deletion of unused VMs
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Phoenix committed Mar 10, 2009
1 parent f5260b5 commit 17b1959
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
3 changes: 1 addition & 2 deletions vm/native_thread.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ namespace rubinius {
Object* ret = vm_->thread.get()->send(vm_, &cf, vm_->symbol("initialize"), Object* ret = vm_->thread.get()->send(vm_, &cf, vm_->symbol("initialize"),
args_.get(), block_.get()); args_.get(), block_.get());


vm_->set_call_frame(0);

if(!ret) { if(!ret) {
if(Exception* exc = try_as<Exception>(vm_->thread_state()->raise_value())) { if(Exception* exc = try_as<Exception>(vm_->thread_state()->raise_value())) {
std::cout << "Exception at thread toplevel:\n"; std::cout << "Exception at thread toplevel:\n";
Expand All @@ -57,5 +55,6 @@ namespace rubinius {
} }
} }


vm_->discard();
} }
} }
8 changes: 8 additions & 0 deletions vm/vm.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace rubinius {
VM::VM(SharedState& shared, int id) VM::VM(SharedState& shared, int id)
: id_(id) : id_(id)
, saved_call_frame_(0) , saved_call_frame_(0)
, alive_(true)
, shared(shared) , shared(shared)
, globals(shared.globals) , globals(shared.globals)
, om(shared.om) , om(shared.om)
Expand All @@ -82,6 +83,11 @@ namespace rubinius {
, use_safe_position(false) , use_safe_position(false)
{} {}


void VM::discard() {
alive_ = false;
saved_call_frame_ = 0;
}

void VM::initialize(size_t bytes) void VM::initialize(size_t bytes)
{ {
config.compile_up_front = false; config.compile_up_front = false;
Expand Down Expand Up @@ -290,6 +296,8 @@ namespace rubinius {
om->collect_mature(globals.roots, frames); om->collect_mature(globals.roots, frames);


global_cache->clear(); global_cache->clear();

shared.manager().prune();
} }
} }


Expand Down
11 changes: 11 additions & 0 deletions vm/vm.hpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ namespace rubinius {
return id_; return id_;
} }


VMManager& manager() {
return manager_;
}

void set_initialized() { void set_initialized() {
initialized_ = true; initialized_ = true;
} }
Expand Down Expand Up @@ -157,6 +161,7 @@ namespace rubinius {
CallFrame* saved_call_frame_; CallFrame* saved_call_frame_;
ASyncMessageMailbox mailbox_; ASyncMessageMailbox mailbox_;
void* stack_start_; void* stack_start_;
bool alive_;


public: public:
/* Data members */ /* Data members */
Expand Down Expand Up @@ -221,6 +226,10 @@ namespace rubinius {
return id_; return id_;
} }


bool alive_p() {
return alive_;
}

ThreadState* thread_state() { ThreadState* thread_state() {
return &thread_state_; return &thread_state_;
} }
Expand Down Expand Up @@ -278,6 +287,8 @@ namespace rubinius {
// Registers a VM* object as the current state. // Registers a VM* object as the current state.
static void register_state(VM*); static void register_state(VM*);


void discard();

void bootstrap_class(); void bootstrap_class();
void bootstrap_ontology(); void bootstrap_ontology();
void bootstrap_symbol(); void bootstrap_symbol();
Expand Down
21 changes: 21 additions & 0 deletions vm/vm_manager.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,4 +40,25 @@ namespace rubinius {
delete shared; delete shared;
} }
} }

void VMManager::prune() {
VMMap::iterator i = vms_.begin();
while(i != vms_.end()) {
VM* vm = i->second;
if(!vm->alive_p()) {
SharedState* shared = &vm->shared;
shared->remove_vm(vm);

vms_.erase(i);
delete vm;
if(shared->deref()) {
ShareMap::iterator si = shares_.find(shared->id());
assert(si != shares_.end());
shares_.erase(si);
delete shared;
}
}
i++;
}
}
} }
1 change: 1 addition & 0 deletions vm/vm_manager.hpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ namespace rubinius {
VM* create_vm(SharedState*); VM* create_vm(SharedState*);


void destroy_vm(VM*); void destroy_vm(VM*);
void prune();
}; };
} }

0 comments on commit 17b1959

Please sign in to comment.