Skip to content
This repository
Browse code

Add deletion of unused VMs

  • Loading branch information...
commit 17b1959a380fd42fb354d9631d1f9af0c9064e82 1 parent f5260b5
Evan Phoenix authored
3  vm/native_thread.cpp
@@ -40,8 +40,6 @@ namespace rubinius {
40 40 Object* ret = vm_->thread.get()->send(vm_, &cf, vm_->symbol("initialize"),
41 41 args_.get(), block_.get());
42 42
43   - vm_->set_call_frame(0);
44   -
45 43 if(!ret) {
46 44 if(Exception* exc = try_as<Exception>(vm_->thread_state()->raise_value())) {
47 45 std::cout << "Exception at thread toplevel:\n";
@@ -57,5 +55,6 @@ namespace rubinius {
57 55 }
58 56 }
59 57
  58 + vm_->discard();
60 59 }
61 60 }
8 vm/vm.cpp
@@ -66,6 +66,7 @@ namespace rubinius {
66 66 VM::VM(SharedState& shared, int id)
67 67 : id_(id)
68 68 , saved_call_frame_(0)
  69 + , alive_(true)
69 70 , shared(shared)
70 71 , globals(shared.globals)
71 72 , om(shared.om)
@@ -82,6 +83,11 @@ namespace rubinius {
82 83 , use_safe_position(false)
83 84 {}
84 85
  86 + void VM::discard() {
  87 + alive_ = false;
  88 + saved_call_frame_ = 0;
  89 + }
  90 +
85 91 void VM::initialize(size_t bytes)
86 92 {
87 93 config.compile_up_front = false;
@@ -290,6 +296,8 @@ namespace rubinius {
290 296 om->collect_mature(globals.roots, frames);
291 297
292 298 global_cache->clear();
  299 +
  300 + shared.manager().prune();
293 301 }
294 302 }
295 303
11 vm/vm.hpp
@@ -126,6 +126,10 @@ namespace rubinius {
126 126 return id_;
127 127 }
128 128
  129 + VMManager& manager() {
  130 + return manager_;
  131 + }
  132 +
129 133 void set_initialized() {
130 134 initialized_ = true;
131 135 }
@@ -157,6 +161,7 @@ namespace rubinius {
157 161 CallFrame* saved_call_frame_;
158 162 ASyncMessageMailbox mailbox_;
159 163 void* stack_start_;
  164 + bool alive_;
160 165
161 166 public:
162 167 /* Data members */
@@ -221,6 +226,10 @@ namespace rubinius {
221 226 return id_;
222 227 }
223 228
  229 + bool alive_p() {
  230 + return alive_;
  231 + }
  232 +
224 233 ThreadState* thread_state() {
225 234 return &thread_state_;
226 235 }
@@ -278,6 +287,8 @@ namespace rubinius {
278 287 // Registers a VM* object as the current state.
279 288 static void register_state(VM*);
280 289
  290 + void discard();
  291 +
281 292 void bootstrap_class();
282 293 void bootstrap_ontology();
283 294 void bootstrap_symbol();
21 vm/vm_manager.cpp
@@ -40,4 +40,25 @@ namespace rubinius {
40 40 delete shared;
41 41 }
42 42 }
  43 +
  44 + void VMManager::prune() {
  45 + VMMap::iterator i = vms_.begin();
  46 + while(i != vms_.end()) {
  47 + VM* vm = i->second;
  48 + if(!vm->alive_p()) {
  49 + SharedState* shared = &vm->shared;
  50 + shared->remove_vm(vm);
  51 +
  52 + vms_.erase(i);
  53 + delete vm;
  54 + if(shared->deref()) {
  55 + ShareMap::iterator si = shares_.find(shared->id());
  56 + assert(si != shares_.end());
  57 + shares_.erase(si);
  58 + delete shared;
  59 + }
  60 + }
  61 + i++;
  62 + }
  63 + }
43 64 }
1  vm/vm_manager.hpp
@@ -22,5 +22,6 @@ namespace rubinius {
22 22 VM* create_vm(SharedState*);
23 23
24 24 void destroy_vm(VM*);
  25 + void prune();
25 26 };
26 27 }

0 comments on commit 17b1959

Please sign in to comment.
Something went wrong with that request. Please try again.