Permalink
Browse files

Add real Configuration infrastructure

Pass -Xconfig.print to have the config printed out before rbx starts.
  • Loading branch information...
1 parent 72d5ffe commit 37dc48942cc0b10894ff33ef32a798106c0d8ffb Evan Phoenix committed Apr 30, 2009
View
@@ -44,6 +44,8 @@
#include "instruments/stats.hpp"
+#include "configuration.hpp"
+
namespace rubinius {
@@ -174,7 +176,7 @@ namespace rubinius {
}
Object* System::vm_get_config_item(STATE, String* var) {
- ConfigParser::Entry* ent = state->user_config->find(var->c_str());
+ ConfigParser::Entry* ent = state->shared.user_variables.find(var->c_str());
if(!ent) return Qnil;
if(ent->is_number()) {
@@ -189,7 +191,7 @@ namespace rubinius {
Object* System::vm_get_config_section(STATE, String* section) {
ConfigParser::EntryList* list;
- list = state->user_config->get_section(section->byte_address());
+ list = state->shared.user_variables.get_section(section->byte_address());
Array* ary = Array::create(state, list->size());
for(size_t i = 0; i < list->size(); i++) {
@@ -268,7 +270,7 @@ namespace rubinius {
}
Object* System::vm_jit_info(STATE) {
- if(!state->config.jit_enabled) {
+ if(!state->shared.config.jit_enabled) {
return Qnil;
}
View
@@ -1,7 +1,9 @@
#include <cstring>
#include <cstdlib>
#include <string>
+
#include "config_parser.hpp"
+#include "configuration.hpp"
namespace rubinius {
/* utility: checks whether string contains only digits */
@@ -27,6 +29,15 @@ namespace rubinius {
return str;
}
+ ConfigParser::~ConfigParser() {
+ ConfigParser::ConfigMap::iterator i = variables.begin();
+ while(i != variables.end()) {
+ delete i->second;
+ i++;
+ }
+ }
+
+
void ConfigParser::process_argv(int argc, char** argv) {
for(int i=1; i < argc; i++) {
char* arg = argv[i];
@@ -90,14 +101,6 @@ namespace rubinius {
return i->second;
}
- ConfigParser::~ConfigParser() {
- ConfigParser::ConfigMap::iterator i = variables.begin();
- while(i != variables.end()) {
- delete i->second;
- i++;
- }
- }
-
bool ConfigParser::Entry::is_number() {
return rubinius::is_number(value.c_str());
}
@@ -127,4 +130,12 @@ namespace rubinius {
return list;
}
+
+ void ConfigParser::update_configuration(Configuration& config) {
+ for(ConfigParser::ConfigMap::iterator i = variables.begin();
+ i != variables.end();
+ i++) {
+ config.import(i->first.c_str(), i->second->value.c_str());
+ }
+ }
}
View
@@ -7,6 +7,8 @@
#include <vector>
namespace rubinius {
+ class Configuration;
+
class ConfigParser {
public:
class Entry {
@@ -33,6 +35,8 @@ namespace rubinius {
void import_stream(std::istream&);
Entry* find(std::string variable);
EntryList* get_section(std::string prefix);
+
+ void update_configuration(Configuration&);
};
}
View
@@ -0,0 +1,37 @@
+#ifndef RBX_CONFIGURATION_HPP
+#define RBX_CONFIGURATION_HPP
+
+#include "util/configuration.hpp"
+
+namespace rubinius {
+ class Configuration : public config::Configuration {
+ public:
+ // GC
+ config::Integer gc_bytes;
+ config::Integer gc_large_object;
+ config::Integer gc_lifetime;
+
+ // JIT/Interpreter
+ config::Bool jit_enabled;
+ config::Bool dynamic_interpreter_enabled;
+
+ // Debug
+ config::Bool print_config;
+
+ // defaults
+ static const int default_gc_bytes = 1048576 * 3;
+ static const int default_gc_large_object = 2700;
+ static const int default_gc_lifetime = 6;
+
+ Configuration()
+ : gc_bytes(this, "rbx.gc.bytes", default_gc_bytes)
+ , gc_large_object(this, "rbx.gc.large_object", default_gc_large_object)
+ , gc_lifetime(this, "rbx.gc.lifetime", default_gc_lifetime)
+ , jit_enabled(this, "rbx.jit.enabled")
+ , dynamic_interpreter_enabled(this, "rbx.interpreter.dynamic")
+ , print_config(this, "config.print")
+ {}
+ };
+}
+
+#endif
View
@@ -28,14 +28,16 @@
namespace rubinius {
Environment::Environment(int argc, char** argv) {
- ConfigParser* config = new ConfigParser();
- config->process_argv(argc, argv);
+ config_parser.process_argv(argc, argv);
- shared = new SharedState();
- shared->user_config = config;
+ config_parser.update_configuration(config);
+
+ shared = new SharedState(config, config_parser);
state = shared->new_vm();
- state->initialize(VM::default_bytes);
+ state->initialize();
+
+ if(config.print_config) config.print();
}
Environment::~Environment() {
@@ -110,7 +112,7 @@ namespace rubinius {
throw std::runtime_error(error);
}
- state->user_config->import_stream(stream);
+ config_parser.import_stream(stream);
}
void Environment::boot_vm() {
View
@@ -5,14 +5,21 @@
#include <stdexcept>
#include "vm.hpp"
+#include "config_parser.hpp"
+#include "configuration.hpp"
namespace rubinius {
+ class ConfigParser;
+
class Environment {
public:
SharedState* shared;
VM* state;
+ ConfigParser config_parser;
+ Configuration config;
+
Environment(int argc, char** argv);
~Environment();
View
@@ -11,15 +11,16 @@
#include "builtin/tuple.hpp"
#include "capi/handle.hpp"
+#include "configuration.hpp"
namespace rubinius {
Object* object_watch = 0;
/* ObjectMemory methods */
- ObjectMemory::ObjectMemory(STATE, size_t young_bytes)
+ ObjectMemory::ObjectMemory(STATE, Configuration& config)
: state(state)
- , young(this, young_bytes)
+ , young(this, config.gc_bytes)
, mark_sweep_(this)
, immix_(this)
{
@@ -36,23 +37,8 @@ namespace rubinius {
collect_mature_now = false;
last_object_id = 0;
- if(state->user_config) {
- 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;
- }
- } else {
- large_object_threshold = 2700;
- young.lifetime = 6;
- }
+ large_object_threshold = config.gc_large_object;
+ young.lifetime = config.gc_lifetime;
for(size_t i = 0; i < LastObjectType; i++) {
type_info[i] = NULL;
View
@@ -36,6 +36,7 @@ namespace rubinius {
class CallFrame;
class GCData;
+ class Configuration;
class ObjectMemory {
public:
@@ -56,7 +57,7 @@ namespace rubinius {
/* Config variables */
size_t large_object_threshold;
- ObjectMemory(STATE, size_t young_bytes);
+ ObjectMemory(STATE, Configuration& config);
~ObjectMemory();
void remember_object(Object* target);
View
@@ -41,6 +41,7 @@
#include "builtin/location.hpp"
#include "builtin/global_cache_entry.hpp"
+#include "configuration.hpp"
#include "config.h"
#define SPECIAL_CLASS_MASK 0x1f
@@ -399,7 +400,7 @@ namespace rubinius {
}
#ifdef USE_DYNAMIC_INTERPRETER
- if(config.dynamic_interpreter_enabled) {
+ if(shared.config.dynamic_interpreter_enabled) {
G(rubinius)->set_const(state, "INTERPRETER", symbol("dynamic"));
} else {
G(rubinius)->set_const(state, "INTERPRETER", symbol("static"));
@@ -409,7 +410,7 @@ namespace rubinius {
#endif
#ifdef USE_USAGE_JIT
- if(config.jit_enabled) {
+ if(shared.config.jit_enabled) {
G(rubinius)->set_const(state, "JIT", symbol("usage"));
} else {
G(rubinius)->set_const(state, "JIT", Qfalse);
View
@@ -7,15 +7,16 @@
#include "capi/handle.hpp"
namespace rubinius {
- SharedState::SharedState()
+ SharedState::SharedState(Configuration& config, ConfigParser& cp)
: initialized_(false)
, global_handles_(new capi::Handles)
, profiling_(false)
, profiler_collection_(0)
, global_serial_(0)
, om(0)
, global_cache(0)
- , user_config(0)
+ , config(config)
+ , user_variables(cp)
{
ref();
}
@@ -25,7 +26,6 @@ namespace rubinius {
delete om;
delete global_cache;
- delete user_config;
delete global_handles_;
#ifdef ENABLE_LLVM
View
@@ -25,12 +25,7 @@ namespace rubinius {
class GlobalCache;
class ConfigParser;
class VM;
-
- struct Configuration {
- bool compile_up_front;
- bool jit_enabled;
- bool dynamic_interpreter_enabled;
- };
+ class Configuration;
struct Interrupts {
bool check;
@@ -70,13 +65,13 @@ namespace rubinius {
Globals globals;
ObjectMemory* om;
GlobalCache* global_cache;
- Configuration config;
+ Configuration& config;
+ ConfigParser& user_variables;
Interrupts interrupts;
SymbolTable symbols;
- ConfigParser *user_config;
public:
- SharedState();
+ SharedState(Configuration& config, ConfigParser& cp);
~SharedState();
static void discard(SharedState* ss);
View
@@ -5,6 +5,7 @@
#include "config_parser.hpp"
#include "vm/object_utils.hpp"
#include "objectmemory.hpp"
+#include "configuration.hpp"
#include <cxxtest/TestSuite.h>
@@ -14,14 +15,14 @@ class VMTest {
public:
SharedState* shared;
VM* state;
- ConfigParser* config;
+ ConfigParser* config_parser;
+ Configuration config;
void create() {
- shared = new SharedState();
- config = new ConfigParser;
- shared->user_config = config;
+ config_parser = new ConfigParser;
+ shared = new SharedState(config, *config_parser);
state = shared->new_vm();
- state->initialize(VM::default_bytes);
+ state->initialize();
state->boot();
state->global_lock().lock();
Oops, something went wrong.

0 comments on commit 37dc489

Please sign in to comment.