Permalink
Browse files

Add deletion of unused VMs

  • Loading branch information...
1 parent f5260b5 commit 17b1959a380fd42fb354d9631d1f9af0c9064e82 Evan Phoenix committed Mar 10, 2009
Showing with 42 additions and 2 deletions.
  1. +1 −2 vm/native_thread.cpp
  2. +8 −0 vm/vm.cpp
  3. +11 −0 vm/vm.hpp
  4. +21 −0 vm/vm_manager.cpp
  5. +1 −0 vm/vm_manager.hpp
View
3 vm/native_thread.cpp
@@ -40,8 +40,6 @@ namespace rubinius {
Object* ret = vm_->thread.get()->send(vm_, &cf, vm_->symbol("initialize"),
args_.get(), block_.get());
- vm_->set_call_frame(0);
-
if(!ret) {
if(Exception* exc = try_as<Exception>(vm_->thread_state()->raise_value())) {
std::cout << "Exception at thread toplevel:\n";
@@ -57,5 +55,6 @@ namespace rubinius {
}
}
+ vm_->discard();
}
}
View
8 vm/vm.cpp
@@ -66,6 +66,7 @@ namespace rubinius {
VM::VM(SharedState& shared, int id)
: id_(id)
, saved_call_frame_(0)
+ , alive_(true)
, shared(shared)
, globals(shared.globals)
, om(shared.om)
@@ -82,6 +83,11 @@ namespace rubinius {
, use_safe_position(false)
{}
+ void VM::discard() {
+ alive_ = false;
+ saved_call_frame_ = 0;
+ }
+
void VM::initialize(size_t bytes)
{
config.compile_up_front = false;
@@ -290,6 +296,8 @@ namespace rubinius {
om->collect_mature(globals.roots, frames);
global_cache->clear();
+
+ shared.manager().prune();
}
}
View
11 vm/vm.hpp
@@ -126,6 +126,10 @@ namespace rubinius {
return id_;
}
+ VMManager& manager() {
+ return manager_;
+ }
+
void set_initialized() {
initialized_ = true;
}
@@ -157,6 +161,7 @@ namespace rubinius {
CallFrame* saved_call_frame_;
ASyncMessageMailbox mailbox_;
void* stack_start_;
+ bool alive_;
public:
/* Data members */
@@ -221,6 +226,10 @@ namespace rubinius {
return id_;
}
+ bool alive_p() {
+ return alive_;
+ }
+
ThreadState* thread_state() {
return &thread_state_;
}
@@ -278,6 +287,8 @@ namespace rubinius {
// Registers a VM* object as the current state.
static void register_state(VM*);
+ void discard();
+
void bootstrap_class();
void bootstrap_ontology();
void bootstrap_symbol();
View
21 vm/vm_manager.cpp
@@ -40,4 +40,25 @@ namespace rubinius {
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++;
+ }
+ }
}
View
1 vm/vm_manager.hpp
@@ -22,5 +22,6 @@ namespace rubinius {
VM* create_vm(SharedState*);
void destroy_vm(VM*);
+ void prune();
};
}

0 comments on commit 17b1959

Please sign in to comment.