Permalink
Browse files

Introduce State class as STATE

  • Loading branch information...
1 parent a4e7f59 commit 35a49f38d836ebd5c339e152dac4d5f30a5e72cd @evanphx evanphx committed Nov 1, 2011
Showing with 1,475 additions and 1,193 deletions.
  1. +15 −11 vm/agent.cpp
  2. +6 −2 vm/agent.hpp
  3. +37 −29 vm/agent_components.cpp
  4. +3 −3 vm/builtin/access_variable.cpp
  5. +1 −1 vm/builtin/alias.cpp
  6. +1 −1 vm/builtin/array.cpp
  7. +1 −1 vm/builtin/autoload.cpp
  8. +3 −3 vm/builtin/bignum.cpp
  9. +9 −9 vm/builtin/block_environment.cpp
  10. +3 −3 vm/builtin/bytearray.cpp
  11. +1 −1 vm/builtin/call_unit.hpp
  12. +6 −6 vm/builtin/channel.cpp
  13. +3 −3 vm/builtin/chararray.cpp
  14. +18 −18 vm/builtin/class.cpp
  15. +2 −2 vm/builtin/compactlookuptable.cpp
  16. +2 −2 vm/builtin/compiledmethod.cpp
  17. +5 −5 vm/builtin/data.cpp
  18. +2 −2 vm/builtin/dir.cpp
  19. +2 −2 vm/builtin/encoding.cpp
  20. +5 −5 vm/builtin/exception.cpp
  21. +1 −1 vm/builtin/executable.cpp
  22. +2 −0 vm/builtin/executable.hpp
  23. +5 −5 vm/builtin/ffi_pointer.cpp
  24. +32 −31 vm/builtin/fiber.cpp
  25. +3 −3 vm/builtin/fiber.hpp
  26. +4 −4 vm/builtin/find_object.cpp
  27. +1 −1 vm/builtin/fixnum.cpp
  28. +2 −2 vm/builtin/float.cpp
  29. +4 −4 vm/builtin/global_cache_entry.cpp
  30. +4 −4 vm/builtin/heap_dump.cpp
  31. +30 −30 vm/builtin/io.cpp
  32. +1 −1 vm/builtin/iseq.cpp
  33. +2 −2 vm/builtin/list.cpp
  34. +1 −1 vm/builtin/location.cpp
  35. +5 −5 vm/builtin/module.cpp
  36. +31 −30 vm/builtin/nativefunction.cpp
  37. +1 −0 vm/builtin/nativefunction.hpp
  38. +14 −14 vm/builtin/nativemethod.cpp
  39. +11 −13 vm/builtin/nativemethod.hpp
  40. +23 −16 vm/builtin/object.cpp
  41. +14 −2 vm/builtin/object.hpp
  42. +1 −1 vm/builtin/proc.cpp
  43. +1 −1 vm/builtin/randomizer.cpp
  44. +6 −6 vm/builtin/regexp.cpp
  45. +1 −1 vm/builtin/staticscope.cpp
  46. +3 −3 vm/builtin/string.cpp
  47. +12 −8 vm/builtin/symbol.cpp
  48. +1 −0 vm/builtin/symbol.hpp
  49. +48 −48 vm/builtin/system.cpp
  50. +22 −20 vm/builtin/thread.cpp
  51. +1 −1 vm/builtin/thread.hpp
  52. +1 −1 vm/builtin/time.cpp
  53. +3 −3 vm/builtin/tuple.cpp
  54. +1 −1 vm/builtin/variable_scope.cpp
  55. +1 −1 vm/builtin/weakref.cpp
  56. +3 −2 vm/bytecode_verification.hpp
  57. +5 −2 vm/call_frame.cpp
  58. +1 −0 vm/call_frame.hpp
  59. +1 −1 vm/capi/array.cpp
  60. +18 −18 vm/capi/capi.cpp
  61. +1 −1 vm/capi/class.cpp
  62. +1 −1 vm/capi/float.cpp
  63. +3 −3 vm/capi/gc.cpp
  64. +2 −2 vm/capi/globals.cpp
  65. +2 −2 vm/capi/handle.cpp
  66. +8 −8 vm/capi/io.cpp
  67. +13 −13 vm/capi/thread.cpp
  68. +1 −1 vm/capi/time.cpp
  69. +11 −11 vm/codegen/field_extract.rb
  70. +3 −3 vm/configuration.hpp
  71. +1 −1 vm/dispatch.cpp
  72. +4 −4 vm/drivers/cli.cpp
  73. +24 −22 vm/environment.cpp
  74. +2 −1 vm/environment.hpp
  75. +3 −3 vm/executor.hpp
  76. +21 −21 vm/ffi.cpp
  77. +2 −1 vm/gc/baker.cpp
  78. +3 −1 vm/gc/code_manager.cpp
  79. +2 −1 vm/gc/code_resource.hpp
  80. +2 −2 vm/gc/gc.cpp
  81. +2 −2 vm/gc/gc.hpp
  82. +1 −1 vm/gc/heap.cpp
  83. +2 −1 vm/gc/immix.cpp
  84. +1 −1 vm/gc/inflated_headers.cpp
  85. +1 −1 vm/gc/inflated_headers.hpp
  86. +3 −3 vm/gc/marksweep.cpp
  87. +1 −1 vm/gc/marksweep.hpp
  88. +14 −0 vm/gc/root.cpp
  89. +10 −0 vm/gc/root.hpp
  90. +2 −2 vm/global_cache.cpp
  91. +4 −4 vm/helpers.cpp
  92. +13 −13 vm/helpers.hpp
  93. +8 −8 vm/inline_cache.cpp
  94. +14 −14 vm/instructions.cpp
  95. +21 −21 vm/instructions.def
  96. +14 −12 vm/instruments/rbxti.cpp
  97. +15 −15 vm/instruments/tooling.cpp
  98. +11 −11 vm/instruments/tooling.hpp
  99. +5 −5 vm/kcode.cpp
  100. +1 −1 vm/llvm/jit_runtime.cpp
  101. +1 −1 vm/llvm/jit_runtime.hpp
  102. +43 −43 vm/llvm/jit_util.cpp
  103. +26 −26 vm/llvm/state.cpp
  104. +22 −0 vm/lock.cpp
  105. +4 −1 vm/lock.hpp
  106. +1 −1 vm/marshal.cpp
  107. +59 −77 vm/objectmemory.cpp
  108. +8 −4 vm/objectmemory.hpp
  109. +4 −4 vm/on_stack.hpp
  110. +89 −92 vm/ontology.cpp
  111. +69 −69 vm/oop.cpp
  112. +4 −4 vm/oop.hpp
  113. +2 −1 vm/prelude.hpp
  114. +2 −2 vm/primitives.cpp
  115. +28 −12 vm/shared_state.cpp
  116. +12 −5 vm/shared_state.hpp
  117. +8 −10 vm/signal.cpp
  118. +8 −7 vm/signal.hpp
  119. +78 −0 vm/state.cpp
  120. +108 −0 vm/state.hpp
  121. +6 −4 vm/test/test.hpp
  122. +1 −1 vm/test/test_array.hpp
  123. +1 −1 vm/test/test_lookuptable.hpp
  124. +1 −1 vm/test/test_nativefunction.hpp
  125. +0 −1 vm/test/test_nativemethod.hpp
  126. +22 −22 vm/test/test_objectmemory.hpp
  127. +1 −1 vm/test/test_regexp.hpp
  128. +1 −1 vm/test/test_symbol.hpp
  129. +1 −1 vm/test/test_thread.hpp
  130. +3 −3 vm/test/test_vm.hpp
  131. +5 −5 vm/thread_state.cpp
  132. +1 −1 vm/thread_state.hpp
  133. +11 −4 vm/type_info.cpp
  134. +1 −3 vm/type_info.hpp
  135. +61 −103 vm/vm.cpp
  136. +33 −48 vm/vm.hpp
  137. +20 −20 vm/vmmethod.cpp
  138. +32 −0 vm/world_state.hpp
View
@@ -40,10 +40,10 @@
#endif
namespace rubinius {
- QueryAgent::QueryAgent(SharedState& shared, VM* state)
+ QueryAgent::QueryAgent(SharedState& shared, STATE)
: Thread()
, shared_(shared)
- , state_(state)
+ , state_(shared.new_vm())
, running_(false)
, port_(0)
, server_fd_(-1)
@@ -55,7 +55,8 @@ namespace rubinius {
, tmp_key_(0)
{
FD_ZERO(&fds_);
- vars_ = new agent::VariableAccess(state, shared);
+
+ vars_ = new agent::VariableAccess(this->state(), shared);
if(pipe(control_) != 0) {
perror("pipe");
@@ -81,14 +82,14 @@ namespace rubinius {
// This class is always created with the GIL locked, so it's ok
// to access ruby stuff here.
- IO* from = IO::create(state_, a2r_ruby());
+ IO* from = IO::create(state, a2r_ruby());
from->sync(state, Qtrue);
- IO* to = IO::create(state_, r2a_ruby());
+ IO* to = IO::create(state, r2a_ruby());
to->sync(state, Qtrue);
- shared_.globals.rubinius.get()->set_const(state_, "FROM_AGENT", from);
- shared_.globals.rubinius.get()->set_const(state_, "TO_AGENT", to);
+ shared_.globals.rubinius.get()->set_const(state, "FROM_AGENT", from);
+ shared_.globals.rubinius.get()->set_const(state, "TO_AGENT", to);
if(shared_.config.agent_password.set_p()) {
local_only_ = false;
@@ -98,6 +99,7 @@ namespace rubinius {
}
QueryAgent::~QueryAgent() {
+ VM::discard(&state_, state_.vm());
delete vars_;
}
@@ -450,9 +452,11 @@ namespace rubinius {
void QueryAgent::perform() {
running_ = true;
+ State state_obj(state_), *state = &state_obj;
+
// It's possible we call code that wants this to thread
// to be setup as a fully managed thread, so lets just make it one.
- NativeMethod::init_thread(state_);
+ NativeMethod::init_thread(state);
set_delete_on_exit();
while(1) {
@@ -589,7 +593,7 @@ namespace rubinius {
}
}
- NativeMethod::cleanup_thread(state_);
+ NativeMethod::cleanup_thread(state);
}
static char tmp_path[PATH_MAX];
@@ -609,8 +613,8 @@ namespace rubinius {
}
void QueryAgent::shutdown(STATE) {
- if(!state->shared.agent()) return;
- state->shared.agent()->shutdown_i();
+ if(!state->vm()->shared.agent()) return;
+ state->vm()->shared.agent()->shutdown_i();
}
void QueryAgent::shutdown_i() {
View
@@ -50,7 +50,7 @@ namespace rubinius {
private:
SharedState& shared_;
- VM* state_;
+ State state_;
bool running_;
int port_;
int server_fd_;
@@ -77,7 +77,7 @@ namespace rubinius {
const static int cBackLog = 10;
public:
- QueryAgent(SharedState& shared, VM* state);
+ QueryAgent(SharedState& shared, STATE);
~QueryAgent();
void set_verbose() {
@@ -92,6 +92,10 @@ namespace rubinius {
return port_;
}
+ State* state() {
+ return &state_;
+ }
+
void add_fd(int fd) {
FD_SET((int_fd_t)fd, &fds_);
if(fd > max_fd_) max_fd_ = fd;
View
@@ -276,18 +276,18 @@ namespace agent {
};
class Backtrace : public DynamicVariable {
+ State* state_;
SharedState& shared_;
- VM* state_;
public:
- Backtrace(STATE, SharedState& ss, const char* name)
+ Backtrace(State* state, SharedState& ss, const char* name)
: DynamicVariable(name)
- , shared_(ss)
, state_(state)
+ , shared_(ss)
{}
virtual void read(Output& output) {
- // GlobalLock::LockGuard guard(shared_.global_lock());
+ shared_.stop_threads_externally();
std::list<ManagedThread*>* threads = shared_.threads();
@@ -306,22 +306,24 @@ namespace agent {
output.e().write_binary("");
}
}
+
+ shared_.restart_threads_externally();
}
};
class ThreadBacktrace : public DynamicVariable {
SharedState& shared_;
- VM* state_;
+ State* state_;
public:
- ThreadBacktrace(STATE, SharedState& ss, const char* name)
+ ThreadBacktrace(State* state, SharedState& ss, const char* name)
: DynamicVariable(name)
, shared_(ss)
, state_(state)
{}
virtual void read(Output& output) {
- // GlobalLock::LockGuard guard(shared_.global_lock());
+ shared_.stop_threads_externally();
output.ok("list");
@@ -348,41 +350,45 @@ namespace agent {
output.e().write_binary(thr->name());
}
}
+
+ shared_.restart_threads_externally();
}
};
class ThreadCount : public DynamicVariable {
SharedState& shared_;
- VM* state_;
+ State* state_;
public:
- ThreadCount(STATE, SharedState& ss, const char* name)
+ ThreadCount(State* state, SharedState& ss, const char* name)
: DynamicVariable(name)
, shared_(ss)
, state_(state)
{}
virtual void read(Output& output) {
- // GlobalLock::LockGuard guard(shared_.global_lock());
+ shared_.stop_threads_externally();
output.ok("value");
std::list<ManagedThread*>* thrs = shared_.threads();
output.e().write_integer(thrs->size());
+
+ shared_.restart_threads_externally();
}
};
class DumpHeap: public DynamicVariable {
- VM* state_;
+ State* state_;
public:
- DumpHeap(STATE, const char* name)
+ DumpHeap(State* state, const char* name)
: DynamicVariable(name)
, state_(state)
{}
virtual void set(Output& output, bert::Value* val) {
- // GlobalLock::LockGuard guard(state_->global_lock());
+ state_->vm()->shared.stop_threads_externally();
if(val->string_p()) {
output.ok("value");
@@ -395,6 +401,8 @@ namespace agent {
} else {
output.error("format");
}
+
+ state_->vm()->shared.restart_threads_externally();
}
};
@@ -461,7 +469,7 @@ namespace agent {
}
};
- VariableAccess::VariableAccess(STATE, SharedState& ss)
+ VariableAccess::VariableAccess(State* state, SharedState& ss)
: root_(new Tree(""))
{
root_->add(new StaticInteger<int>("version", 2));
@@ -480,47 +488,47 @@ namespace agent {
young->add(new StaticInteger<int>("bytes", ss.config.gc_bytes * 2));
Tree* mature = mem->get_tree("mature");
- mature->add(new ReadInteger<size_t>("bytes", &state->om->immix_usage()));
+ mature->add(new ReadInteger<size_t>("bytes", &state->vm()->om->immix_usage()));
Tree* large = mem->get_tree("large");
- large->add(new ReadInteger<size_t>("bytes", &state->om->loe_usage()));
+ large->add(new ReadInteger<size_t>("bytes", &state->vm()->om->loe_usage()));
Tree* code = mem->get_tree("code");
- code->add(new ReadInteger<size_t>("bytes", &state->om->code_usage()));
+ code->add(new ReadInteger<size_t>("bytes", &state->vm()->om->code_usage()));
Tree* symbols = mem->get_tree("symbols");
symbols->add(new ReadInteger<size_t>("bytes", &ss.symbols.bytes_used()));
Tree* counter = mem->get_tree("counter");
counter->add(new ReadAtomicInteger("young_objects",
- state->om->gc_stats.young_objects_allocated));
+ state->vm()->om->gc_stats.young_objects_allocated));
counter->add(new ReadAtomicInteger("young_bytes",
- state->om->gc_stats.young_bytes_allocated));
+ state->vm()->om->gc_stats.young_bytes_allocated));
counter->add(new ReadAtomicInteger("promoted_objects",
- state->om->gc_stats.promoted_objects_allocated));
+ state->vm()->om->gc_stats.promoted_objects_allocated));
counter->add(new ReadAtomicInteger("promoted_bytes",
- state->om->gc_stats.promoted_bytes_allocated));
+ state->vm()->om->gc_stats.promoted_bytes_allocated));
counter->add(new ReadAtomicInteger("mature_objects",
- state->om->gc_stats.mature_objects_allocated));
+ state->vm()->om->gc_stats.mature_objects_allocated));
counter->add(new ReadAtomicInteger("mature_bytes",
- state->om->gc_stats.mature_bytes_allocated));
+ state->vm()->om->gc_stats.mature_bytes_allocated));
Tree* gc_young = system_->get_tree("gc")->get_tree("young");
gc_young->add(new ReadAtomicInteger("count",
- state->om->gc_stats.young_collection_count));
+ state->vm()->om->gc_stats.young_collection_count));
gc_young->add(new ReadAtomicInteger("total_wallclock",
- state->om->gc_stats.total_young_collection_time));
+ state->vm()->om->gc_stats.total_young_collection_time));
gc_young->add(new ReadAtomicInteger("last_wallclock",
- state->om->gc_stats.last_young_collection_time));
+ state->vm()->om->gc_stats.last_young_collection_time));
Tree* gc_full = system_->get_tree("gc")->get_tree("full");
gc_full->add(new ReadAtomicInteger("count",
- state->om->gc_stats.full_collection_count));
+ state->vm()->om->gc_stats.full_collection_count));
gc_full->add(new ReadAtomicInteger("total_wallclock",
- state->om->gc_stats.total_full_collection_time));
+ state->vm()->om->gc_stats.total_full_collection_time));
gc_full->add(new ReadAtomicInteger("last_wallclock",
- state->om->gc_stats.last_full_collection_time));
+ state->vm()->om->gc_stats.last_full_collection_time));
Tree* jit = system_->get_tree("jit");
jit->add(new ReadAtomicInteger("methods", ss.stats.jitted_methods));
@@ -16,7 +16,7 @@ namespace rubinius {
void AccessVariable::init(STATE) {
// HACK test superclass of AccessVariable
- GO(access_variable).set(state->new_class("AccessVariable", G(executable), G(rubinius)));
+ GO(access_variable).set(state->vm()->new_class("AccessVariable", G(executable), G(rubinius)));
G(access_variable)->set_object_type(state, AccessVariableType);
G(access_variable)->name(state, state->symbol("Rubinius::AccessVariable"));
}
@@ -91,7 +91,7 @@ namespace rubinius {
if(self->reference_p()) {
// Promote this to use a direct accessor
- if(TypeInfo* ti = state->om->find_type_info(self)) {
+ if(TypeInfo* ti = state->vm()->om->find_type_info(self)) {
TypeInfo::Slots::iterator it = ti->slots.find(access->name()->index());
if(it != ti->slots.end()) {
// Found one!
@@ -117,7 +117,7 @@ namespace rubinius {
if(self->reference_p()) {
// Promote this to use a direct accessor
- if(TypeInfo* ti = state->om->find_type_info(self)) {
+ if(TypeInfo* ti = state->vm()->om->find_type_info(self)) {
TypeInfo::Slots::iterator it = ti->slots.find(access->name()->index());
if(it != ti->slots.end()) {
// Found one!
View
@@ -4,7 +4,7 @@
namespace rubinius {
void Alias::init(STATE) {
- GO(alias).set(state->new_class("Alias", G(executable), G(rubinius)));
+ GO(alias).set(state->vm()->new_class("Alias", G(executable), G(rubinius)));
G(alias)->set_object_type(state, AliasType);
}
View
@@ -23,7 +23,7 @@
namespace rubinius {
void Array::init(STATE) {
- GO(array).set(state->new_class("Array", G(object)));
+ GO(array).set(state->vm()->new_class("Array", G(object)));
G(array)->set_object_type(state, ArrayType);
}
View
@@ -9,7 +9,7 @@ namespace rubinius {
}
void Autoload::init(STATE) {
- GO(autoload).set(state->new_class("Autoload"));
+ GO(autoload).set(state->vm()->new_class("Autoload"));
G(autoload)->set_object_type(state, AutoloadType);
}
View
@@ -193,7 +193,7 @@ namespace rubinius {
}
void Bignum::init(STATE) {
- GO(bignum).set(state->new_class("Bignum", G(integer)));
+ GO(bignum).set(state->vm()->new_class("Bignum", G(integer)));
G(bignum)->set_object_type(state, BignumType);
}
@@ -220,7 +220,7 @@ namespace rubinius {
}
Bignum* Bignum::create(STATE) {
- Bignum* o = state->new_struct<Bignum>(G(bignum));
+ Bignum* o = state->vm()->new_struct<Bignum>(G(bignum));
mp_init_managed(state, o->mp_val());
return o;
}
@@ -1268,7 +1268,7 @@ namespace rubinius {
extern "C" void* MANAGED_REALLOC_MPINT(void* s, mp_int* a, size_t bytes) {
assert(s);
- VM* state = reinterpret_cast<VM*>(s);
+ State* state = reinterpret_cast<State*>(s);
ByteArray* storage = ByteArray::create(state, bytes);
a->managed = reinterpret_cast<void*>(storage);
Oops, something went wrong.

0 comments on commit 35a49f3

Please sign in to comment.