Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove Globals& from VM
  • Loading branch information
Evan Phoenix committed Feb 5, 2010
1 parent 9b196bb commit d6416f8
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 40 deletions.
6 changes: 3 additions & 3 deletions vm/builtin/nativemethod.cpp
Expand Up @@ -136,8 +136,8 @@ namespace rubinius {
}

void NativeMethod::init(STATE) {
state->globals.nmethod.set(state->new_class("NativeMethod", G(executable), G(rubinius)));
state->globals.nmethod.get()->set_object_type(state, NativeMethodType);
GO(nmethod).set(state->new_class("NativeMethod", G(executable), G(rubinius)));
G(nmethod)->set_object_type(state, NativeMethodType);

init_thread(state);
}
Expand Down Expand Up @@ -215,7 +215,7 @@ namespace rubinius {

NativeMethod* m = NativeMethod::create(state,
path,
state->globals.rubinius.get(),
G(rubinius),
name->to_sym(state),
reinterpret_cast<GenericFunctor>(func),
Fixnum::from(INIT_FUNCTION)
Expand Down
4 changes: 2 additions & 2 deletions vm/builtin/object.cpp
Expand Up @@ -50,7 +50,7 @@ namespace rubinius {
return as<Class>(mod);
}

return state->globals.special_classes[((uintptr_t)this) & SPECIAL_CLASS_MASK].get();
return state->globals().special_classes[((uintptr_t)this) & SPECIAL_CLASS_MASK].get();
}

void Object::cleanup(STATE) {
Expand Down Expand Up @@ -408,7 +408,7 @@ namespace rubinius {
Module* found = NULL;

if(!reference_p()) {
found = state->globals.special_classes[((uintptr_t)this) & SPECIAL_CLASS_MASK].get();
found = state->globals().special_classes[((uintptr_t)this) & SPECIAL_CLASS_MASK].get();
} else {
found = try_as<Module>(klass_);
}
Expand Down
2 changes: 1 addition & 1 deletion vm/builtin/object.hpp
Expand Up @@ -377,7 +377,7 @@ namespace rubinius {
return klass_;
}

return state->globals.special_classes[((uintptr_t)this) & SPECIAL_CLASS_MASK].get();
return state->globals().special_classes[((uintptr_t)this) & SPECIAL_CLASS_MASK].get();
}

inline bool Object::symbol_p() const {
Expand Down
4 changes: 2 additions & 2 deletions vm/capi/capi.cpp
Expand Up @@ -106,7 +106,7 @@ namespace rubinius {

if(type < 0 || type >= cCApiMaxConstant) {
NativeMethodEnvironment* env = NativeMethodEnvironment::get();
rb_raise(env->get_handle(env->state()->globals.exception.get()),
rb_raise(env->get_handle(env->state()->globals().exception.get()),
"C-API: invalid constant index");
}

Expand Down Expand Up @@ -258,7 +258,7 @@ extern "C" {
CApiConstantHandleMap::iterator entry = map.find(type);
if(entry == map.end()) {
NativeMethodEnvironment* env = NativeMethodEnvironment::get();
Object* obj = env->state()->globals.object.get()->get_const(env->state(),
Object* obj = env->state()->globals().object.get()->get_const(env->state(),
capi_get_constant_name(type).c_str());

VALUE val = env->get_handle(obj);
Expand Down
2 changes: 1 addition & 1 deletion vm/capi/module.cpp
Expand Up @@ -39,7 +39,7 @@ extern "C" {
}

// Try from Object as well.
module = env->state()->globals.object.get();
module = env->state()->globals().object.get();

while(!module->nil_p()) {
Object* val = module->get_const(env->state(), name, &found);
Expand Down
4 changes: 2 additions & 2 deletions vm/environment.cpp
Expand Up @@ -431,11 +431,11 @@ namespace rubinius {
std::ifstream sig_stream(sig_path.c_str());
if(sig_stream) {
sig_stream >> signature_;
state->globals.rubinius->set_const(state, "Signature",
G(rubinius)->set_const(state, "Signature",
Integer::from(state, signature_));
sig_stream.close();
} else {
state->globals.rubinius->set_const(state, "Signature", Integer::from(state, 0));
G(rubinius)->set_const(state, "Signature", Integer::from(state, 0));
}

// Load alpha
Expand Down
2 changes: 1 addition & 1 deletion vm/gc/gc.cpp
Expand Up @@ -22,7 +22,7 @@
namespace rubinius {

GCData::GCData(STATE)
: roots_(state->globals.roots)
: roots_(state->globals().roots)
, call_frames_(state->shared.call_frame_locations())
, variable_buffers_(*state->variable_buffers())
, handles_(state->shared.global_handles())
Expand Down
4 changes: 2 additions & 2 deletions vm/gc/root.cpp
Expand Up @@ -23,7 +23,7 @@ namespace rubinius {

Root::Root(STATE)
: LinkedList::Node()
, roots_(&state->globals.roots)
, roots_(&state->globals().roots)
, object_(Qundef)
{}

Expand All @@ -32,7 +32,7 @@ namespace rubinius {
, roots_(NULL)
, object_(Qundef)
{
set(obj, &state->globals.roots);
set(obj, &state->globals().roots);
}

void Root::set(Object* obj, Roots* r) {
Expand Down
3 changes: 2 additions & 1 deletion vm/native_libraries.cpp
Expand Up @@ -13,7 +13,8 @@
namespace rubinius {

void VM::init_native_libraries() {
globals.rubinius.get()->set_const(this, "LIBSUFFIX", String::create(this, RBX_LIBSUFFIX));
globals().rubinius.get()->set_const(this, "LIBSUFFIX",
String::create(this, RBX_LIBSUFFIX));

rbx_dlinit();
}
Expand Down
20 changes: 10 additions & 10 deletions vm/ontology.cpp
Expand Up @@ -55,8 +55,8 @@ namespace rubinius {
// Reset macros since we're inside state
#undef G
#undef GO
#define G(whatever) globals.whatever.get()
#define GO(whatever) globals.whatever
#define G(whatever) globals().whatever.get()
#define GO(whatever) globals().whatever

void VM::bootstrap_class() {
/* Class is created first by hand, and twiddle to setup the internal
Expand Down Expand Up @@ -200,17 +200,17 @@ namespace rubinius {
// the classes for Fixnum's, nil, true and false.
for(size_t i = 0; i < SPECIAL_CLASS_SIZE; i++) {
if(SYMBOL_P(i)) {
globals.special_classes[i] = GO(symbol);
globals().special_classes[i] = GO(symbol);
} else if(FIXNUM_P(i)) {
globals.special_classes[i] = GO(fixnum_class);
globals().special_classes[i] = GO(fixnum_class);
} else {
globals.special_classes[i] = GO(object); /* unused slot */
globals().special_classes[i] = GO(object); /* unused slot */
}
}

globals.special_classes[(uintptr_t)Qfalse] = GO(false_class);
globals.special_classes[(uintptr_t)Qnil ] = GO(nil_class);
globals.special_classes[(uintptr_t)Qtrue ] = GO(true_class);
globals().special_classes[(uintptr_t)Qfalse] = GO(false_class);
globals().special_classes[(uintptr_t)Qnil ] = GO(nil_class);
globals().special_classes[(uintptr_t)Qtrue ] = GO(true_class);

/* Create IncludedModule */
GO(included_module).set(new_class("IncludedModule", G(module), G(rubinius)));
Expand Down Expand Up @@ -409,7 +409,7 @@ namespace rubinius {

Object* key = Fixnum::from(num);

Object* current = state->globals.errno_mapping->fetch(state, key, &found);
Object* current = state->globals().errno_mapping->fetch(state, key, &found);
if(found) {
ern->set_const(state, symbol(name), current);
} else {
Expand All @@ -421,7 +421,7 @@ namespace rubinius {

cls->set_const(state, symbol("Errno"), key);
cls->set_const(state, symbol("Strerror"), String::create(state, strerror(num)));
state->globals.errno_mapping->store(state, key, cls);
state->globals().errno_mapping->store(state, key, cls);
}
}

Expand Down
4 changes: 2 additions & 2 deletions vm/prelude.hpp
Expand Up @@ -32,8 +32,8 @@ namespace rubinius {


#define STATE rubinius::VM* state
#define G(whatever) state->globals.whatever.get()
#define GO(whatever) state->globals.whatever
#define G(whatever) state->globals().whatever.get()
#define GO(whatever) state->globals().whatever

}

Expand Down
2 changes: 1 addition & 1 deletion vm/signal.cpp
Expand Up @@ -56,7 +56,7 @@ namespace rubinius {
i++) {
args->set(vm_, 0, Fixnum::from(*i));

vm_->globals.rubinius->send(vm_, call_frame,
vm_->globals().rubinius->send(vm_, call_frame,
vm_->symbol("received_signal"), args, Qnil);
}

Expand Down
2 changes: 1 addition & 1 deletion vm/test/test_objectmemory.hpp
Expand Up @@ -27,7 +27,7 @@ class TestObjectMemory : public CxxTest::TestSuite, public VMTest {

void setUp() {
create();
roots = &state->globals.roots;
roots = &state->globals().roots;
gc_data = new GCData(*roots, call_frames, variable_buffers,
&handles, &cached_handles, state->global_cache());
}
Expand Down
6 changes: 3 additions & 3 deletions vm/test/test_vm.hpp
Expand Up @@ -47,7 +47,7 @@ class TestVM : public CxxTest::TestSuite, public VMTest {
std::map<int, Object*> objs;

int index = 0;
Root* root = static_cast<Root*>(state->globals.roots.head());
Root* root = static_cast<Root*>(state->globals().roots.head());
while(root) {
Object* tmp = root->get();
if(tmp->reference_p() && tmp->zone() == YoungObjectZone) {
Expand All @@ -65,7 +65,7 @@ class TestVM : public CxxTest::TestSuite, public VMTest {
state->om->collect_young(gc_data);

index = 0;
root = static_cast<Root*>(state->globals.roots.head());
root = static_cast<Root*>(state->globals().roots.head());
while(root) {
if(Object* tmp = objs[index]) {
TS_ASSERT(root->get() != tmp);
Expand All @@ -76,7 +76,7 @@ class TestVM : public CxxTest::TestSuite, public VMTest {
}

HeapDebug hd(state->om);
hd.walk(state->globals.roots);
hd.walk(state->globals().roots);

//std::cout << "total: " << hd.seen_objects << " (" <<
// state->om->young.total_objects << ")" << std::endl;
Expand Down
13 changes: 6 additions & 7 deletions vm/vm.cpp
Expand Up @@ -38,8 +38,8 @@
// Reset macros since we're inside state
#undef G
#undef GO
#define G(whatever) globals.whatever.get()
#define GO(whatever) globals.whatever
#define G(whatever) globals().whatever.get()
#define GO(whatever) globals().whatever

namespace rubinius {

Expand All @@ -54,15 +54,14 @@ namespace rubinius {
, run_signals_(false)
, shared(shared)
, waiter_(NULL)
, globals(shared.globals)
, om(shared.om)
, interrupts(shared.interrupts)
, check_local_interrupts(false)
, thread_state_(this)
, thread(this, (Thread*)Qnil)
, current_fiber(this, (Fiber*)Qnil)
{
probe.set(Qnil, &globals.roots);
probe.set(Qnil, &globals().roots);
set_stack_size(cStackDepthMax);
}

Expand Down Expand Up @@ -166,7 +165,7 @@ namespace rubinius {
}

void VM::boot_threads() {
thread.set(Thread::create(this, this, pthread_self()), &globals.roots);
thread.set(Thread::create(this, this, pthread_self()), &globals().roots);
thread->sleep(this, Qfalse);

VM::set_current(this);
Expand Down Expand Up @@ -264,7 +263,7 @@ namespace rubinius {
}

Thread *VM::current_thread() {
return globals.current_thread.get();
return globals().current_thread.get();
}

void VM::run_gc_soon() {
Expand Down Expand Up @@ -369,7 +368,7 @@ namespace rubinius {
}

void VM::set_const(const char* name, Object* val) {
globals.object->set_const(this, (char*)name, val);
globals().object->set_const(this, (char*)name, val);
}

void VM::set_const(Module* mod, const char* name, Object* val) {
Expand Down
5 changes: 4 additions & 1 deletion vm/vm.hpp
Expand Up @@ -83,7 +83,6 @@ namespace rubinius {
thread::Mutex local_lock_;
Waiter* waiter_;

Globals& globals;
ObjectMemory* om;
TypedRoot<TaskProbe*> probe;
Interrupts& interrupts;
Expand Down Expand Up @@ -144,6 +143,10 @@ namespace rubinius {
return shared.global_cache;
}

Globals& globals() {
return shared.globals;
}

void* stack_start() {
return stack_start_;
}
Expand Down

0 comments on commit d6416f8

Please sign in to comment.