Browse files

Merge pull request #2225 from ryoqun/compiled-code-leak

Trigger full GC from CodeManager to fix memory use
  • Loading branch information...
2 parents baab48d + dff83c1 commit cbe57a78b2702bbd8ab4cd03ca6cc3a11f072fdf @dbussink dbussink committed Mar 25, 2013
Showing with 21 additions and 7 deletions.
  1. +7 −3 vm/builtin/compiledcode.cpp
  2. +3 −1 vm/builtin/compiledcode.hpp
  3. +7 −1 vm/gc/code_manager.cpp
  4. +3 −1 vm/gc/code_manager.hpp
  5. +1 −1 vm/objectmemory.cpp
View
10 vm/builtin/compiledcode.cpp
@@ -48,11 +48,11 @@ namespace rubinius {
CompiledCode* CompiledCode::create(STATE) {
CompiledCode* code = state->new_object<CompiledCode>(G(compiled_code));
code->local_count(state, Fixnum::from(0));
- code->set_executor(CompiledCode::default_executor);
- code->machine_code_ = NULL;
code->inliners_ = 0;
code->prim_index_ = -1;
+ code->set_executor(CompiledCode::default_executor);
+ code->machine_code_ = NULL;
#ifdef ENABLE_LLVM
code->jit_data_ = NULL;
#endif
@@ -65,8 +65,10 @@ namespace rubinius {
code->copy_object(state, this);
code->set_executor(CompiledCode::default_executor);
- code->jit_data_ = NULL;
code->machine_code_ = NULL;
+#ifdef ENABLE_LLVM
+ code->jit_data_ = NULL;
+#endif
return code;
}
@@ -251,7 +253,9 @@ namespace rubinius {
machine_code_->set_execute_status(MachineCode::eJIT);
+#ifdef ENABLE_LLVM
jit_data_ = rd;
+#endif
machine_code_->unspecialized = exec;
// See if we can also just make this the normal execute
View
4 vm/builtin/compiledcode.hpp
@@ -33,12 +33,14 @@ namespace rubinius {
Tuple* lines_; // slot
Tuple* local_names_; // slot
Symbol* file_; // slot
- ConstantScope* scope_; // slot
+ ConstantScope* scope_; // slot
LookupTable* breakpoints_; // slot
MachineCode* machine_code_;
+#ifdef ENABLE_LLVM
jit::RuntimeDataHolder* jit_data_;
+#endif
public:
// Access directly from assembly, so has to be public.
View
8 vm/gc/code_manager.cpp
@@ -26,6 +26,7 @@ namespace rubinius {
, freed_resources_(0)
, total_allocated_(0)
, total_freed_(0)
+ , gc_triggered_(0)
, bytes_used_(0)
{
first_chunk_ = new Chunk(chunk_size_);
@@ -58,12 +59,17 @@ namespace rubinius {
current_chunk_ = c;
}
- void CodeManager::add_resource(CodeResource* cr) {
+ void CodeManager::add_resource(CodeResource* cr, bool* collect_now) {
utilities::thread::Mutex::LockGuard guard(mutex_);
total_allocated_ += cr->size();
bytes_used_ += cr->size();
+ if(total_allocated_ - gc_triggered_ > cGCTriggerThreshold) {
+ gc_triggered_ = total_allocated_;
+ *collect_now = true;
+ }
+
for(;;) {
while(current_index_ < chunk_size_) {
if(current_chunk_->resources[current_index_] == 0) {
View
4 vm/gc/code_manager.hpp
@@ -25,6 +25,7 @@ namespace rubinius {
class CodeManager {
const static int cDefaultChunkSize = 64;
+ const static int cGCTriggerThreshold = 64 * 1024 * 1024;
/**
* A chunk of memory used to store an array of references to CodeResource
@@ -55,6 +56,7 @@ namespace rubinius {
int freed_resources_;
int total_allocated_;
int total_freed_;
+ int gc_triggered_;
size_t bytes_used_;
@@ -83,7 +85,7 @@ namespace rubinius {
CodeManager(SharedState* shared, int chunk_size=cDefaultChunkSize);
~CodeManager();
- void add_resource(CodeResource* cr);
+ void add_resource(CodeResource* cr, bool* collect_now);
void clear_marks();
void sweep();
int calculate_size();
View
2 vm/objectmemory.cpp
@@ -902,7 +902,7 @@ namespace rubinius {
void ObjectMemory::add_code_resource(CodeResource* cr) {
SYNC_TL;
- code_manager_.add_resource(cr);
+ code_manager_.add_resource(cr, &collect_mature_now);
}
void* ObjectMemory::young_start() {

0 comments on commit cbe57a7

Please sign in to comment.