Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add real Configuration infrastructure

Pass -Xconfig.print to have the config printed out before rbx starts.
  • Loading branch information...
commit 37dc48942cc0b10894ff33ef32a798106c0d8ffb 1 parent 72d5ffe
Evan Phoenix authored
View
8 vm/builtin/system.cpp
@@ -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
27 vm/config_parser.cpp
@@ -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
4 vm/config_parser.hpp
@@ -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
37 vm/configuration.hpp
@@ -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
14 vm/environment.cpp
@@ -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
7 vm/environment.hpp
@@ -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
24 vm/objectmemory.cpp
@@ -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
3  vm/objectmemory.hpp
@@ -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
5 vm/ontology.cpp
@@ -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
6 vm/shared_state.cpp
@@ -7,7 +7,7 @@
#include "capi/handle.hpp"
namespace rubinius {
- SharedState::SharedState()
+ SharedState::SharedState(Configuration& config, ConfigParser& cp)
: initialized_(false)
, global_handles_(new capi::Handles)
, profiling_(false)
@@ -15,7 +15,8 @@ namespace rubinius {
, 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
13 vm/shared_state.hpp
@@ -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
11 vm/test/test.hpp
@@ -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();
View
153 vm/util/configuration.hpp
@@ -0,0 +1,153 @@
+#ifndef RBX_UTIL_CONFIGURATION_HPP
+#define RBX_UTIL_CONFIGURATION_HPP
+
+#include <list>
+
+namespace config {
+ class ConfigItem;
+
+ typedef std::list<ConfigItem*> Items;
+
+ class Configuration {
+ Items items_;
+
+ public:
+ void add_item(ConfigItem* item) {
+ items_.push_back(item);
+ }
+
+ void import(const char* key, const char* val);
+ void print();
+ };
+
+ class ConfigItem {
+ public:
+ const char* name_;
+ bool set_;
+
+ ConfigItem(Configuration* config, const char* name)
+ : name_(name)
+ {
+ config->add_item(this);
+ }
+
+ virtual ~ConfigItem() {}
+
+ virtual void set(const char* str) = 0;
+ virtual void print_value() = 0;
+
+ bool set_maybe(const char* key, const char* val) {
+ if(strcmp(name_, key) != 0) return false;
+
+ set_ = true;
+ set(val);
+ return true;
+ }
+
+ const char* name() {
+ return name_;
+ }
+
+ bool set_p() {
+ return set_;
+ }
+ };
+
+ class Integer : public ConfigItem {
+ public:
+ long value;
+
+ Integer(Configuration* config, const char* name, int def = 0)
+ : ConfigItem(config, name)
+ , value(def)
+ {}
+
+ virtual void set(const char* str) {
+ value = strtol(str, NULL, 0);
+ }
+
+ virtual void print_value() {
+ std::cout << value;
+ }
+
+ operator long() {
+ return value;
+ }
+ };
+
+ class String : public ConfigItem {
+ public:
+ std::string value;
+
+ String(Configuration* config, const char* name)
+ : ConfigItem(config, name)
+ , value("")
+ {}
+
+ virtual void set(const char* str) {
+ value = std::string(str);
+ }
+
+ virtual void print_value() {
+ std::cout << value;
+ }
+
+ operator const char*() {
+ return value.c_str();
+ }
+ };
+
+ class Bool : public ConfigItem {
+ public:
+ bool value;
+
+ Bool(Configuration* config, const char* name)
+ : ConfigItem(config, name)
+ , value(false)
+ {}
+
+ static bool convert(const char* str) {
+ if(*str == '0' ||
+ !strcmp(str, "no") ||
+ !strcmp(str, "NO") ||
+ !strcmp(str, "false") ||
+ !strcmp(str, "FALSE")) return false;
+
+ return true;
+ }
+
+ virtual void set(const char* str) {
+ value = convert(str);
+ }
+
+ virtual void print_value() {
+ std::cout << (value ? "true" : "false");
+ }
+
+ operator bool() {
+ return value;
+ }
+ };
+
+ inline void Configuration::import(const char* key, const char* val) {
+ for(Items::iterator i = items_.begin();
+ i != items_.end();
+ i++) {
+ ConfigItem* item = *i;
+ if(item->set_maybe(key, val)) return;
+ }
+ }
+
+ inline void Configuration::print() {
+ for(Items::iterator i = items_.begin();
+ i != items_.end();
+ i++) {
+ ConfigItem* item = *i;
+ std::cout << item->name() << ": ";
+ item->print_value();
+ std::cout << "\n";
+ }
+ }
+}
+
+#endif
View
30 vm/vm.cpp
@@ -44,11 +44,9 @@ namespace rubinius {
, profiler_(0)
, shared(shared)
, waiter_(NULL)
- , 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)
, check_local_interrupts(false)
@@ -70,21 +68,10 @@ namespace rubinius {
delete vm;
}
- void VM::initialize(size_t bytes)
- {
- config.compile_up_front = false;
- config.jit_enabled = false;
- config.dynamic_interpreter_enabled = false;
-
+ void VM::initialize() {
VM::register_state(this);
- if(user_config) {
- if(ConfigParser::Entry* entry = user_config->find("rbx.gc.young_space")) {
- bytes = entry->to_i();
- }
- }
-
- om = new ObjectMemory(this, bytes);
+ om = new ObjectMemory(this, shared.config);
shared.om = om;
probe.set(Qnil, &globals.roots);
@@ -100,19 +87,6 @@ namespace rubinius {
}
void VM::boot() {
-#ifdef USE_USAGE_JIT
- if(user_config->find("rbx.jit")) {
- config.jit_enabled = true;
- }
-#endif
-
-#ifdef USE_DYNAMIC_INTERPRETER
- if(user_config->find("rbx.dyni")) {
- config.dynamic_interpreter_enabled = true;
- }
-#endif
-
-// MethodContext::initialize_cache(this);
TypeInfo::auto_learn_fields(this);
bootstrap_ontology();
View
6 vm/vm.hpp
@@ -91,14 +91,12 @@ namespace rubinius {
thread::Mutex local_lock_;
Waiter* waiter_;
- ConfigParser *user_config;
Globals& globals;
ObjectMemory* om;
event::Loop* events;
event::Loop* signal_events;
GlobalCache* global_cache;
TypedRoot<TaskProbe*> probe;
- Configuration& config;
Interrupts& interrupts;
SymbolTable& symbols;
@@ -138,8 +136,6 @@ namespace rubinius {
static const int cReasonTypeError = 2;
static const int cReasonAssertion = 3;
- static const size_t default_bytes = 1048576 * 3;
-
static int cStackDepthMax;
public: /* Inline methods */
@@ -202,7 +198,7 @@ namespace rubinius {
void check_exception(CallFrame* call_frame);
- void initialize(size_t bytes = default_bytes);
+ void initialize();
// Initialize the basic objects and the execution machinery
void boot();
View
5 vm/vmmethod.cpp
@@ -26,6 +26,7 @@
#include "raise_reason.hpp"
#include "assembler/jit.hpp"
+#include "configuration.hpp"
#define CALLS_TIL_JIT 50
#define JIT_MAX_METHOD_SIZE 2048
@@ -47,7 +48,7 @@ namespace rubinius {
void VMMethod::init(STATE) {
#ifdef USE_DYNAMIC_INTERPRETER
- if(!state->config.dynamic_interpreter_enabled) {
+ if(!state->shared.config.dynamic_interpreter_enabled) {
dynamic_interpreter = NULL;
standard_interpreter = &VMMethod::interpreter;
return;
@@ -107,7 +108,7 @@ namespace rubinius {
#ifdef USE_USAGE_JIT
// Disable JIT for large methods
- if(state->config.jit_enabled && total < JIT_MAX_METHOD_SIZE) {
+ if(state->shared.config.jit_enabled && total < JIT_MAX_METHOD_SIZE) {
call_count = 0;
} else {
call_count = -1;
Please sign in to comment.
Something went wrong with that request. Please try again.