Skip to content

Commit

Permalink
Enable configuring some young generation parameters.
Browse files Browse the repository at this point in the history
-Xrbx.gc.lifetime=N sets the lifetime before an object is promoted to N.
-Xrbx.gc.large_object=B sets the large object allocation threshold to B bytes.
-Xrbx.gc.young_space=B sets the size of each young space heap to B bytes.
  • Loading branch information
Brian Ford committed Mar 10, 2009
1 parent 17b1959 commit d722e15
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 26 deletions.
8 changes: 7 additions & 1 deletion kernel/delta/stats.rb
Expand Up @@ -107,30 +107,36 @@ def show
format = "%-#{col1}s%#{col2}s%#{col3}s\n"
n_a = "n/a"


total = ay[:total] + cy[:total] + am[:total] + cm[:total]

puts "\nGarbage collector stats:"

printf header, "Stats \\ Generation", "Young", "Mature"
young = "Young (%d)" % (Rubinius::RUBY_CONFIG["rbx.gc.lifetime"] || 6)
printf header, "Stats \\ Generation", young, "Mature"

puts "-" * (col1 + col2 + col3)
printf format, "Collections", comma(cy[:timings]), comma(cm[:timings])
printf format, "total time", auto_time(cy[:total]), auto_time(cm[:total])
printf format, " max", auto_time(cy[:max]), auto_time(cm[:max])
printf format, " min", auto_time(cy[:min]), auto_time(cm[:min])
printf format, " average", auto_time(cy[:average]), auto_time(cm[:average])

puts "--"
printf format, "objects copied/seen", comma(oc[:total]), comma(os[:total])
printf format, " max", comma(oc[:max]), comma(os[:max])
printf format, " min", comma(oc[:min]), comma(os[:min])
printf format, " average", comma(oc[:average].to_i), comma(os[:average].to_i)
printf format, "bytes copied", auto_bytes(cy[:bytes_copied]), n_a

puts "--"
printf format, "objects promoted", comma(op[:total]), n_a
printf format, " max", comma(op[:max]), n_a
printf format, " min", comma(op[:min]), n_a
printf format, " average", comma(op[:average].to_i), n_a
printf format, "% of GC time",
"(#{percentage(cy[:total], total)})", "(#{percentage(cm[:total], total)})"

puts "---"
printf format, "Allocations", comma(ay[:timings]), comma(am[:timings])
printf format, "total time", auto_time(ay[:total]), auto_time(am[:total])
Expand Down
16 changes: 16 additions & 0 deletions vm/config_parser.cpp
Expand Up @@ -27,6 +27,18 @@ namespace rubinius {
return str;
}

void ConfigParser::process_argv(int argc, char** argv) {
for(int i=1; i < argc; i++) {
char* arg = argv[i];
if(strncmp(arg, "-X", 2) == 0) {
import_line(arg + 2);
continue;
}

if(arg[0] != '-' || strcmp(arg, "--") == 0) return;
}
}

ConfigParser::Entry* ConfigParser::parse_line(const char* line) {
char* var = strdup(line);
char* equals = strstr(var, "=");
Expand Down Expand Up @@ -94,6 +106,10 @@ namespace rubinius {
return value == "true";
}

long ConfigParser::Entry::to_i() {
return strtol(value.c_str(), NULL, 10);
}

bool ConfigParser::Entry::in_section(std::string prefix) {
return variable.find(prefix) == 0;
}
Expand Down
2 changes: 2 additions & 0 deletions vm/config_parser.hpp
Expand Up @@ -14,6 +14,7 @@ namespace rubinius {
bool is_number();
bool is_true();
bool in_section(std::string prefix);
long to_i();
};

typedef std::map<std::string, Entry*> ConfigMap;
Expand All @@ -23,6 +24,7 @@ namespace rubinius {

virtual ~ConfigParser();

void process_argv(int argc, char** argv);
Entry* parse_line(const char* line);
void import_line(const char* line);
void import_stream(std::istream&);
Expand Down
3 changes: 1 addition & 2 deletions vm/drivers/cli.cpp
Expand Up @@ -60,8 +60,7 @@ static void load_runtime_kernel(Environment& env, std::string root) {
* function does not deal with that subject.
*/
int main(int argc, char** argv) {
Environment env;
env.load_config_argv(argc, argv);
Environment env(argc, argv);
env.state->init_stack_size();
env.state->set_stack_start(&env);

Expand Down
2 changes: 1 addition & 1 deletion vm/drivers/compile.cpp
Expand Up @@ -59,7 +59,7 @@ int main(int argc, char** argv) {
string input(argv[1]);
string output(argv[2]);

Environment env;
Environment env(argc, argv);

ifstream stream(input.c_str());

Expand Down
21 changes: 7 additions & 14 deletions vm/environment.cpp
Expand Up @@ -27,9 +27,14 @@

namespace rubinius {

Environment::Environment() {
Environment::Environment(int argc, char** argv) {
ConfigParser* config = new ConfigParser();
config->process_argv(argc, argv);

shared = manager.create_shared_state();
state = shared->new_vm();
shared->user_config = config;

state = shared->new_vm();
state->initialize(VM::default_bytes);

TaskProbe* probe = TaskProbe::create(state);
Expand Down Expand Up @@ -59,18 +64,6 @@ namespace rubinius {
shared->set_signal_thread(st);
}

void Environment::load_config_argv(int argc, char** argv) {
for(int i=1; i < argc; i++) {
char* arg = argv[i];
if(strncmp(arg, "-X", 2) == 0) {
state->user_config->import_line(arg + 2);
continue;
}

if(arg[0] != '-' || strcmp(arg, "--") == 0) return;
}
}

void Environment::load_argv(int argc, char** argv) {
bool process_xflags = true;
state->set_const("ARG0", String::create(state, argv[0]));
Expand Down
2 changes: 1 addition & 1 deletion vm/environment.hpp
Expand Up @@ -15,7 +15,7 @@ namespace rubinius {
SharedState* shared;
VM* state;

Environment();
Environment(int argc, char** argv);
~Environment();

void load_config_argv(int argc, char** argv);
Expand Down
17 changes: 15 additions & 2 deletions vm/objectmemory.cpp
Expand Up @@ -4,6 +4,8 @@
#include "vm.hpp"
#include "objectmemory.hpp"
#include "gc_marksweep.hpp"
#include "config_parser.hpp"

#include "builtin/class.hpp"
#include "builtin/fixnum.hpp"
#include "builtin/tuple.hpp"
Expand All @@ -30,10 +32,21 @@ namespace rubinius {

collect_young_now = false;
collect_mature_now = false;
large_object_threshold = 2700;
young.lifetime = 6;
last_object_id = 0;

ConfigParser::Entry* entry;
if((entry = state->user_config->find("rbx.gc.large_object"))) {
large_object_threshold = entry->to_i();
} else {
large_object_threshold = 2700;
}

if((entry = state->user_config->find("rbx.gc.lifetime"))) {
young.lifetime = entry->to_i();
} else {
young.lifetime = 6;
}

for(size_t i = 0; i < LastObjectType; i++) {
type_info[i] = NULL;
}
Expand Down
8 changes: 4 additions & 4 deletions vm/vm.cpp
Expand Up @@ -68,13 +68,13 @@ namespace rubinius {
, saved_call_frame_(0)
, alive_(true)
, shared(shared)
, user_config(shared.user_config)
, globals(shared.globals)
, om(shared.om)
, global_cache(shared.global_cache)
, config(shared.config)
, interrupts(shared.interrupts)
, symbols(shared.symbols)
, user_config(shared.user_config)
, check_local_interrupts(false)
, thread_state_(this)
, thread(this, (Thread*)Qnil)
Expand All @@ -96,9 +96,9 @@ namespace rubinius {

VM::register_state(this);

user_config = new ConfigParser();
shared.user_config = user_config;

if(ConfigParser::Entry* entry = user_config->find("rbx.gc.young_space")) {
bytes = entry->to_i();
}
om = new ObjectMemory(this, bytes);
shared.om = om;

Expand Down
2 changes: 1 addition & 1 deletion vm/vm.hpp
Expand Up @@ -169,6 +169,7 @@ namespace rubinius {
thread::Mutex local_lock_;
Waiter* waiter_;

ConfigParser *user_config;
Globals& globals;
ObjectMemory* om;
event::Loop* events;
Expand All @@ -178,7 +179,6 @@ namespace rubinius {
Configuration& config;
Interrupts& interrupts;
SymbolTable& symbols;
ConfigParser *user_config;

bool check_local_interrupts;

Expand Down

0 comments on commit d722e15

Please sign in to comment.