diff --git a/machine/bug.hpp b/machine/bug.hpp index 7a62264c9f..e3abbd0f27 100644 --- a/machine/bug.hpp +++ b/machine/bug.hpp @@ -8,7 +8,7 @@ #endif namespace rubinius { - NORETURN(void abort()); + NORETURN(void bug(void)); NORETURN(void bug(const char* message)); NORETURN(void bug(const char* message, const char* arg)); void warn(const char* message); diff --git a/machine/c_api.cpp b/machine/c_api.cpp new file mode 100644 index 0000000000..3a78daf6f0 --- /dev/null +++ b/machine/c_api.cpp @@ -0,0 +1,147 @@ +#include "c_api.hpp" + +namespace rubinius { + C_API::C_API() + : capi_constant_name_map_() + , capi_constant_map_() + , capi_black_list_() + , capi_locks_() + , capi_lock_map_() + , use_capi_lock_(false) + , capi_ds_lock_() + , capi_locks_lock_() + , capi_constant_lock_() + { + initialize_capi_black_list(); + setup_capi_constant_names(); + } + + void C_API::after_fork_child(STATE) { + // Reinit the locks for this object + capi_ds_lock_.init(); + capi_locks_lock_.init(); + capi_constant_lock_.init(); + } + + void C_API::enter_capi(STATE, const char* file, int line) { + NativeMethodEnvironment* env = state->vm()->native_method_environment; + if(int lock_index = env->current_native_frame()->capi_lock_index()) { + capi_locks_[lock_index - 1]->lock(); + } + } + + void C_API::leave_capi(STATE) { + NativeMethodEnvironment* env = state->vm()->native_method_environment; + if(int lock_index = env->current_native_frame()->capi_lock_index()) { + capi_locks_[lock_index - 1]->unlock(); + } + } + + int C_API::capi_lock_index(std::string name) { + utilities::thread::SpinLock::LockGuard guard(capi_locks_lock_); + int existing = capi_lock_map_[name]; + if(existing) return existing; + + CApiBlackList::const_iterator blacklisted = capi_black_list_.find(name); + + // Only disable locks if we have capi locks disabled + // and library is not in the blacklist. + if(!use_capi_lock_ && blacklisted == capi_black_list_.end()) { + capi_lock_map_[name] = 0; + return 0; + } + + utilities::thread::Mutex* lock = new utilities::thread::Mutex(true); + capi_locks_.push_back(lock); + + // We use a 1 offset index, so 0 can indicate no lock used + int lock_index = capi_locks_.size(); + capi_lock_map_[name] = lock_index; + return lock_index; + } + + void C_API::setup_capi_constant_names() { + capi_constant_name_map_.resize(cCApiMaxConstant + 1); + + capi_constant_name_map_[cCApiArray] = "Array"; + capi_constant_name_map_[cCApiBignum] = "Bignum"; + capi_constant_name_map_[cCApiClass] = "Class"; + capi_constant_name_map_[cCApiComparable] = "Comparable"; + capi_constant_name_map_[cCApiData] = "Data"; + capi_constant_name_map_[cCApiEnumerable] = "Enumerable"; + capi_constant_name_map_[cCApiFalse] = "FalseClass"; + capi_constant_name_map_[cCApiFile] = "File"; + capi_constant_name_map_[cCApiFixnum] = "Fixnum"; + capi_constant_name_map_[cCApiFloat] = "Float"; + capi_constant_name_map_[cCApiHash] = "Hash"; + capi_constant_name_map_[cCApiInteger] = "Integer"; + capi_constant_name_map_[cCApiIO] = "IO"; + capi_constant_name_map_[cCApiKernel] = "Kernel"; + capi_constant_name_map_[cCApiMatch] = "MatchData"; + capi_constant_name_map_[cCApiModule] = "Module"; + capi_constant_name_map_[cCApiNil] = "NilClass"; + capi_constant_name_map_[cCApiNumeric] = "Numeric"; + capi_constant_name_map_[cCApiObject] = "Object"; + capi_constant_name_map_[cCApiRange] = "Range"; + capi_constant_name_map_[cCApiRegexp] = "Regexp"; + capi_constant_name_map_[cCApiRubinius] = "Rubinius"; + capi_constant_name_map_[cCApiString] = "String"; + capi_constant_name_map_[cCApiStruct] = "Struct"; + capi_constant_name_map_[cCApiSymbol] = "Symbol"; + capi_constant_name_map_[cCApiThread] = "Thread"; + capi_constant_name_map_[cCApiTime] = "Time"; + capi_constant_name_map_[cCApiTrue] = "TrueClass"; + capi_constant_name_map_[cCApiProc] = "Proc"; + capi_constant_name_map_[cCApiGC] = "GC"; + capi_constant_name_map_[cCApiCAPI] = "Rubinius::CAPI"; + capi_constant_name_map_[cCApiMethod] = "Method"; + capi_constant_name_map_[cCApiRational] = "Rational"; + capi_constant_name_map_[cCApiComplex] = "Complex"; + capi_constant_name_map_[cCApiEnumerator] = "Enumerator"; + capi_constant_name_map_[cCApiMutex] = "Mutex"; + capi_constant_name_map_[cCApiDir] = "Dir"; + + capi_constant_name_map_[cCApiArgumentError] = "ArgumentError"; + capi_constant_name_map_[cCApiEOFError] = "EOFError"; + capi_constant_name_map_[cCApiErrno] = "Errno"; + capi_constant_name_map_[cCApiException] = "Exception"; + capi_constant_name_map_[cCApiFatal] = "FatalError"; + capi_constant_name_map_[cCApiFloatDomainError] = "FloatDomainError"; + capi_constant_name_map_[cCApiIndexError] = "IndexError"; + capi_constant_name_map_[cCApiInterrupt] = "Interrupt"; + capi_constant_name_map_[cCApiIOError] = "IOError"; + capi_constant_name_map_[cCApiLoadError] = "LoadError"; + capi_constant_name_map_[cCApiLocalJumpError] = "LocalJumpError"; + capi_constant_name_map_[cCApiNameError] = "NameError"; + capi_constant_name_map_[cCApiNoMemoryError] = "NoMemoryError"; + capi_constant_name_map_[cCApiNoMethodError] = "NoMethodError"; + capi_constant_name_map_[cCApiNotImplementedError] = "NotImplementedError"; + capi_constant_name_map_[cCApiRangeError] = "RangeError"; + capi_constant_name_map_[cCApiRegexpError] = "RegexpError"; + capi_constant_name_map_[cCApiRuntimeError] = "RuntimeError"; + capi_constant_name_map_[cCApiScriptError] = "ScriptError"; + capi_constant_name_map_[cCApiSecurityError] = "SecurityError"; + capi_constant_name_map_[cCApiSignalException] = "SignalException"; + capi_constant_name_map_[cCApiStandardError] = "StandardError"; + capi_constant_name_map_[cCApiSyntaxError] = "SyntaxError"; + capi_constant_name_map_[cCApiSystemCallError] = "SystemCallError"; + capi_constant_name_map_[cCApiSystemExit] = "SystemExit"; + capi_constant_name_map_[cCApiSystemStackError] = "SystemStackError"; + capi_constant_name_map_[cCApiTypeError] = "TypeError"; + capi_constant_name_map_[cCApiThreadError] = "ThreadError"; + capi_constant_name_map_[cCApiZeroDivisionError] = "ZeroDivisionError"; + + capi_constant_name_map_[cCApiMathDomainError] = "Math::DomainError"; + capi_constant_name_map_[cCApiEncoding] = "Encoding"; + capi_constant_name_map_[cCApiEncCompatError] = "Encoding::CompatibilityError"; + capi_constant_name_map_[cCApiWaitReadable] = "IO::WaitReadable"; + capi_constant_name_map_[cCApiWaitWritable] = "IO::WaitWritable"; + + } + +#define CAPI_BLACK_LIST(name) capi_black_list_.insert(std::string("Init_" # name)) + void C_API::initialize_capi_black_list() { + CAPI_BLACK_LIST(nkf); + CAPI_BLACK_LIST(nokogiri); + } +} diff --git a/machine/c_api.hpp b/machine/c_api.hpp new file mode 100644 index 0000000000..b173ff9fce --- /dev/null +++ b/machine/c_api.hpp @@ -0,0 +1,77 @@ +#ifndef RBX_C_API_HPP +#define RBX_C_API_HPP + +#include "memory.hpp" +#include "spinlock.hpp" +#include "vm.hpp" + +#include "class/native_method.hpp" + +#include "util/thread.hpp" + +#include "capi/capi_constants.h" + +#include +#include +#include + +namespace rubinius { + class C_API { + public: + typedef std::unordered_set CApiBlackList; + typedef std::vector CApiLocks; + typedef std::unordered_map CApiLockMap; + + typedef std::vector CApiConstantNameMap; + typedef std::unordered_map CApiConstantHandleMap; + + private: + CApiConstantNameMap capi_constant_name_map_; + CApiConstantHandleMap capi_constant_map_; + CApiBlackList capi_black_list_; + CApiLocks capi_locks_; + CApiLockMap capi_lock_map_; + + bool use_capi_lock_; + + utilities::thread::SpinLock capi_ds_lock_; + utilities::thread::SpinLock capi_locks_lock_; + utilities::thread::SpinLock capi_constant_lock_; + + public: + C_API(); + virtual ~C_API() { } + + void after_fork_child(STATE); + + void set_use_capi_lock(bool s) { + use_capi_lock_ = s; + } + + utilities::thread::SpinLock& capi_ds_lock() { + return capi_ds_lock_; + } + + utilities::thread::SpinLock& capi_constant_lock() { + return capi_constant_lock_; + } + + int capi_lock_index(std::string name); + + void enter_capi(STATE, const char* file, int line); + void leave_capi(STATE); + + void setup_capi_constant_names(); + CApiConstantNameMap& capi_constant_name_map() { + return capi_constant_name_map_; + } + + CApiConstantHandleMap& capi_constant_map() { + return capi_constant_map_; + } + + void initialize_capi_black_list(); + }; +} + +#endif diff --git a/machine/capi/capi.cpp b/machine/capi/capi.cpp index 86547ee5fe..9b1aaae1fd 100644 --- a/machine/capi/capi.cpp +++ b/machine/capi/capi.cpp @@ -17,6 +17,7 @@ #include "class/exception.hpp" #include "bug.hpp" +#include "c_api.hpp" #include "call_frame.hpp" #include "configuration.hpp" #include "lookup_data.hpp" @@ -111,7 +112,7 @@ namespace rubinius { "C-API: invalid constant index"); } - CApiConstantNameMap map = env->state()->shared().capi_constant_name_map(); + C_API::CApiConstantNameMap map = env->state()->c_api()->capi_constant_name_map(); return map[type]; } @@ -461,12 +462,12 @@ extern "C" { VALUE capi_get_constant(CApiConstant type) { NativeMethodEnvironment* env = NativeMethodEnvironment::get(); - env->shared().capi_constant_lock().lock(); - CApiConstantHandleMap& map = env->state()->shared().capi_constant_map(); + env->state()->c_api()->capi_constant_lock().lock(); + C_API::CApiConstantHandleMap& map = env->state()->c_api()->capi_constant_map(); VALUE value; - CApiConstantHandleMap::iterator entry = map.find(type); + C_API::CApiConstantHandleMap::iterator entry = map.find(type); if(entry == map.end()) { std::string constant_name = capi_get_constant_name(type); @@ -483,7 +484,7 @@ extern "C" { value = entry->second->as_value(); } - env->shared().capi_constant_lock().unlock(); + env->state()->c_api()->capi_constant_lock().unlock(); return value; } diff --git a/machine/capi/capi.hpp b/machine/capi/capi.hpp index ef2d3f0fc0..92df943e84 100644 --- a/machine/capi/capi.hpp +++ b/machine/capi/capi.hpp @@ -17,8 +17,8 @@ #include "capi/capi_constants.h" #include "capi/tag.hpp" -#define ENTER_CAPI(state) (state->vm()->shared.enter_capi(state, __FILE__, __LINE__)) -#define LEAVE_CAPI(state) (state->vm()->shared.leave_capi(state)) +#define ENTER_CAPI(state) (state->c_api()->enter_capi(state, __FILE__, __LINE__)) +#define LEAVE_CAPI(state) (state->c_api()->leave_capi(state)) namespace rubinius { class Integer; diff --git a/machine/capi/class.cpp b/machine/capi/class.cpp index 7c53bcdbdb..42e1345965 100644 --- a/machine/capi/class.cpp +++ b/machine/capi/class.cpp @@ -4,6 +4,7 @@ #include "class/string.hpp" #include "class/symbol.hpp" +#include "c_api.hpp" #include "helpers.hpp" #include "exception_point.hpp" #include "on_stack.hpp" diff --git a/machine/capi/io.cpp b/machine/capi/io.cpp index 4cad32413d..3e92ed572d 100644 --- a/machine/capi/io.cpp +++ b/machine/capi/io.cpp @@ -1,4 +1,5 @@ #include "vm.hpp" +#include "c_api.hpp" #include "state.hpp" #include "object_utils.hpp" diff --git a/machine/capi/kernel.cpp b/machine/capi/kernel.cpp index f1245a4207..1d9920ca83 100644 --- a/machine/capi/kernel.cpp +++ b/machine/capi/kernel.cpp @@ -168,7 +168,7 @@ extern "C" { vfprintf(stderr, fmt, args); va_end(args); - rubinius::abort(); + rubinius::bug(); exit(1); // compiler snack. } diff --git a/machine/capi/module.cpp b/machine/capi/module.cpp index 03c82eb554..b8fcf16433 100644 --- a/machine/capi/module.cpp +++ b/machine/capi/module.cpp @@ -4,6 +4,7 @@ #include "class/symbol.hpp" #include "class/autoload.hpp" +#include "c_api.hpp" #include "configuration.hpp" #include "helpers.hpp" diff --git a/machine/capi/thread.cpp b/machine/capi/thread.cpp index e3c844c3ea..7f2052e454 100644 --- a/machine/capi/thread.cpp +++ b/machine/capi/thread.cpp @@ -7,6 +7,7 @@ #include "capi/capi.hpp" #include "capi/ruby.h" +#include "c_api.hpp" #include "on_stack.hpp" #include "call_frame.hpp" #include "exception_point.hpp" diff --git a/machine/class/array.cpp b/machine/class/array.cpp index d77e10cc4b..d77e9bfab5 100644 --- a/machine/class/array.cpp +++ b/machine/class/array.cpp @@ -4,6 +4,7 @@ #include "object_utils.hpp" #include "memory.hpp" #include "on_stack.hpp" +#include "primitives.hpp" #include "class/array.hpp" #include "class/class.hpp" diff --git a/machine/class/bignum.cpp b/machine/class/bignum.cpp index 83e11e6649..79be3564da 100644 --- a/machine/class/bignum.cpp +++ b/machine/class/bignum.cpp @@ -1,6 +1,7 @@ #include "configuration.hpp" #include "object_utils.hpp" #include "memory.hpp" +#include "primitives.hpp" #include "class/array.hpp" #include "class/class.hpp" diff --git a/machine/class/channel.cpp b/machine/class/channel.cpp index ed342a8d07..ced33fcc66 100644 --- a/machine/class/channel.cpp +++ b/machine/class/channel.cpp @@ -1,6 +1,7 @@ #include "object_utils.hpp" #include "on_stack.hpp" #include "memory.hpp" +#include "primitives.hpp" #include "thread_phase.hpp" #include "class/class.hpp" diff --git a/machine/class/class.cpp b/machine/class/class.cpp index 220caf24dd..fa2cfda150 100644 --- a/machine/class/class.cpp +++ b/machine/class/class.cpp @@ -1,6 +1,7 @@ #include "configuration.hpp" #include "object_utils.hpp" #include "memory.hpp" +#include "primitives.hpp" #include "on_stack.hpp" #include "class/array.hpp" @@ -44,7 +45,7 @@ namespace rubinius { } void Class::initialize_data(STATE, Class* klass) { - klass->class_data(state->shared().inc_class_count(state)); + klass->class_data(state->memory()->inc_class_count()); klass->packed_size(0); klass->packed_ivar_info(nil()); diff --git a/machine/class/code_db.cpp b/machine/class/code_db.cpp index 58e94cac82..970722f398 100644 --- a/machine/class/code_db.cpp +++ b/machine/class/code_db.cpp @@ -110,7 +110,7 @@ namespace rubinius { CodeDB* CodeDB::open(STATE, std::string db_path, bool writable) { memory::Collector::Inhibit inhibitor(state); - std::lock_guard lock(state->shared().codedb_lock()); + std::lock_guard lock(state->memory()->codedb_lock()); CodeDB* codedb = state->memory()->new_object(state, G(codedb)); @@ -400,12 +400,12 @@ namespace rubinius { CompiledCode* CodeDB::load(STATE, const char* c_id) { memory::Collector::Inhibit inhibitor(state); - std::lock_guard lock(state->shared().codedb_lock()); + std::lock_guard lock(state->memory()->codedb_lock()); timer::StopWatch timer( - state->shared().codedb_metrics()->load_ns); + state->machine()->diagnostics()->codedb_metrics()->load_ns); - state->shared().codedb_metrics()->load_count++; + state->machine()->diagnostics()->codedb_metrics()->load_count++; CodeDBMap::const_iterator m = index()->find(std::string(c_id)); @@ -448,7 +448,7 @@ namespace rubinius { String* stem, String* ext, Object* reload, Object* record) { memory::Collector::Inhibit inhibitor(state); - std::lock_guard lock(state->shared().codedb_lock()); + std::lock_guard lock(state->memory()->codedb_lock()); std::string search(stem->c_str(state)); std::string extstr(ext->c_str(state)); @@ -522,7 +522,7 @@ namespace rubinius { String* stem, String* path, String* feature, Object* record) { memory::Collector::Inhibit inhibitor(state); - std::lock_guard lock(state->shared().codedb_lock()); + std::lock_guard lock(state->memory()->codedb_lock()); const char* c_id; diff --git a/machine/class/compiled_code.cpp b/machine/class/compiled_code.cpp index 1851dc0477..f95b75359c 100644 --- a/machine/class/compiled_code.cpp +++ b/machine/class/compiled_code.cpp @@ -371,15 +371,14 @@ namespace rubinius { MachineCode* mcode = code->machine_code(); mcode->set_mark(); - // TODO: pass State into GC! - VM* vm = VM::current(); - - if(vm->shared.profiler()->collecting_p()) { - if(mcode->sample_count > vm->shared.profiler()->sample_min()) { - vm->shared.profiler()->add_index(mcode->serial(), mcode->name(), + /* TODO: Machine + if(state->profiler()->collecting_p()) { + if(mcode->sample_count > state->profiler()->sample_min()) { + state->profiler()->add_index(mcode->serial(), mcode->name(), mcode->location(), mcode->sample_count, mcode->call_count); } } + */ for(size_t i = 0; i < mcode->references_count(); i++) { if(size_t ip = mcode->references()[i]) { diff --git a/machine/class/constant_cache.cpp b/machine/class/constant_cache.cpp index a861adf301..fa5280d04a 100644 --- a/machine/class/constant_cache.cpp +++ b/machine/class/constant_cache.cpp @@ -23,7 +23,7 @@ namespace rubinius { cache->value(state, value); cache->module(state, mod); cache->lexical_scope(state, scope); - cache->serial(state->shared().global_serial()); + cache->serial(state->memory()->global_serial()); return cache; } diff --git a/machine/class/constant_cache.hpp b/machine/class/constant_cache.hpp index 04b7dbe0ca..65e16e7539 100644 --- a/machine/class/constant_cache.hpp +++ b/machine/class/constant_cache.hpp @@ -51,7 +51,7 @@ namespace rubinius { static ConstantCache* empty(STATE, Symbol* name, Executable* executable, int ip); Object* retrieve(STATE, LexicalScope* scope) { - if(serial() == state->shared().global_serial() && + if(serial() == state->memory()->global_serial() && lexical_scope()->equal_p(scope)) { return value(); } @@ -59,7 +59,7 @@ namespace rubinius { } Object* retrieve(STATE, Module* mod, LexicalScope* scope) { - if(serial() == state->shared().global_serial() && + if(serial() == state->memory()->global_serial() && lexical_scope()->equal_p(scope) && module()->equal_p(mod)) { return value(); diff --git a/machine/class/data.cpp b/machine/class/data.cpp index 5001313d23..bd25c60e9d 100644 --- a/machine/class/data.cpp +++ b/machine/class/data.cpp @@ -39,7 +39,7 @@ namespace rubinius { (memory::FinalizerFunction)&Data::finalize); } - state->shared().memory_metrics()->data_objects++; + state->machine()->diagnostics()->memory_metrics()->data_objects++; return data; } @@ -65,7 +65,7 @@ namespace rubinius { (memory::FinalizerFunction)&Data::finalize); } - state->shared().memory_metrics()->data_objects++; + state->machine()->diagnostics()->memory_metrics()->data_objects++; return data; } diff --git a/machine/class/diagnostics.cpp b/machine/class/diagnostics.cpp deleted file mode 100644 index 9865239b3c..0000000000 --- a/machine/class/diagnostics.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "memory.hpp" - -#include "class/class.hpp" -#include "class/diagnostics.hpp" -#include "class/lookup_table.hpp" - -namespace rubinius { - void Diagnostics::bootstrap(STATE) { - state->memory()->new_class( - state, G(rubinius), "Diagnostics"); - } -} diff --git a/machine/class/diagnostics.hpp b/machine/class/diagnostics.hpp deleted file mode 100644 index 4c07c51a22..0000000000 --- a/machine/class/diagnostics.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef RBX_BUILTIN_DIAGNOSTICS_HPP -#define RBX_BUILTIN_DIAGNOSTICS_HPP - -#include "class/class.hpp" -#include "class/object.hpp" - -#include "object_utils.hpp" -#include "diagnostics.hpp" - -namespace rubinius { - class LookupTable; - - class Diagnostics : public Object { - public: - const static object_type type = DiagnosticsType; - - static void bootstrap(STATE); - - class Info : public TypeInfo { - public: - Info(object_type type) - : TypeInfo(type) - { - allow_user_allocate = false; - } - - void mark(STATE, Object* obj, std::function f) { } - void auto_mark(STATE, Object* obj, std::function f) { } - void set_field(STATE, Object* target, size_t index, Object* val) { } - Object* get_field(STATE, Object* target, size_t index) { return cNil; } - void populate_slot_locations() { } - }; - }; -} - -#endif diff --git a/machine/class/encoding.cpp b/machine/class/encoding.cpp index 4706f9a027..299c3f7446 100644 --- a/machine/class/encoding.cpp +++ b/machine/class/encoding.cpp @@ -7,6 +7,7 @@ #include "memory.hpp" #include "object_utils.hpp" #include "on_stack.hpp" +#include "primitives.hpp" #include "class/array.hpp" #include "class/byte_array.hpp" @@ -552,7 +553,7 @@ namespace rubinius { if(len > STACK_BUF_SZ) { malloc_buf = (uint8_t*)malloc(len); - if(!malloc_buf) rubinius::abort(); + if(!malloc_buf) rubinius::bug(); buf = malloc_buf; } diff --git a/machine/class/ffi_pointer.cpp b/machine/class/ffi_pointer.cpp index 4200de536c..9ed9f75727 100644 --- a/machine/class/ffi_pointer.cpp +++ b/machine/class/ffi_pointer.cpp @@ -1,6 +1,7 @@ #include "ffi_util.hpp" #include "object_utils.hpp" #include "memory.hpp" +#include "primitives.hpp" #include "windows_compat.h" #include "class/array.hpp" diff --git a/machine/class/fiber.cpp b/machine/class/fiber.cpp index 07c7bdb75b..7edb2b68c9 100644 --- a/machine/class/fiber.cpp +++ b/machine/class/fiber.cpp @@ -270,7 +270,7 @@ namespace rubinius { std::ostringstream name; name << "fiber." << fiber->fiber_id()->to_native(); - fiber->vm(state->thread_nexus()->new_vm(&state->shared(), name.str().c_str())); + fiber->vm(state->thread_nexus()->new_vm(state->machine(), name.str().c_str())); fiber->vm()->set_kind(memory::ManagedThread::eFiber); fiber->vm()->set_suspending(); @@ -459,7 +459,7 @@ namespace rubinius { } Array* Fiber::s_list(STATE) { - return state->shared().vm_fibers(state); + return state->machine()->vm_fibers(state); } Fiber* Fiber::s_main(STATE) { @@ -467,7 +467,7 @@ namespace rubinius { } Fixnum* Fiber::s_count(STATE) { - return state->shared().vm_fibers_count(state); + return state->machine()->vm_fibers_count(state); } void Fiber::finalize(STATE, Fiber* fiber) { @@ -477,7 +477,7 @@ namespace rubinius { } if(fiber->vm()) { - if(!state->shared().halting_p()) { + if(!state->machine()->machine_state()->halting_p()) { if(!fiber->vm()->zombie_p()) { fiber->cancel(state); } diff --git a/machine/class/fixnum.cpp b/machine/class/fixnum.cpp index 04a3de4dee..fab6a3ea49 100644 --- a/machine/class/fixnum.cpp +++ b/machine/class/fixnum.cpp @@ -7,6 +7,7 @@ #include "class/string.hpp" #include "configuration.hpp" #include "object_utils.hpp" +#include "primitives.hpp" namespace rubinius { diff --git a/machine/class/float.cpp b/machine/class/float.cpp index 34cdb45e17..ae84263234 100644 --- a/machine/class/float.cpp +++ b/machine/class/float.cpp @@ -1,6 +1,7 @@ #include "configuration.hpp" #include "memory.hpp" #include "object_utils.hpp" +#include "primitives.hpp" #include "class/array.hpp" #include "class/class.hpp" diff --git a/machine/class/fsevent.cpp b/machine/class/fsevent.cpp index 2204224dcf..cd54f49d51 100644 --- a/machine/class/fsevent.cpp +++ b/machine/class/fsevent.cpp @@ -10,6 +10,8 @@ #include "logger.hpp" +#include + namespace rubinius { using namespace utilities; diff --git a/machine/class/io.cpp b/machine/class/io.cpp index 18eb1364c4..62fc4e92d0 100644 --- a/machine/class/io.cpp +++ b/machine/class/io.cpp @@ -2,6 +2,7 @@ #include "memory.hpp" #include "object_utils.hpp" #include "on_stack.hpp" +#include "primitives.hpp" #include "thread_phase.hpp" #include "windows_compat.h" diff --git a/machine/class/lexical_scope.cpp b/machine/class/lexical_scope.cpp index aa11c27d25..5c8cb8fe4b 100644 --- a/machine/class/lexical_scope.cpp +++ b/machine/class/lexical_scope.cpp @@ -1,4 +1,5 @@ #include "memory.hpp" +#include "primitives.hpp" #include "call_frame.hpp" #include "class/class.hpp" diff --git a/machine/class/module.cpp b/machine/class/module.cpp index 6cf73844ea..f0b051791d 100644 --- a/machine/class/module.cpp +++ b/machine/class/module.cpp @@ -2,6 +2,7 @@ #include "memory.hpp" #include "object_utils.hpp" #include "on_stack.hpp" +#include "primitives.hpp" #include "class/array.hpp" #include "class/autoload.hpp" @@ -137,12 +138,12 @@ namespace rubinius { void Module::set_const(STATE, Symbol* sym, Object* val) { constant_table()->store(state, sym, val, G(sym_public)); - state->shared().inc_global_serial(state); + state->memory()->inc_global_serial(); } void Module::del_const(STATE, Symbol* sym) { constant_table()->remove(state, sym); - state->shared().inc_global_serial(state); + state->memory()->inc_global_serial(); } void Module::set_const(STATE, std::string name, Object* val) { diff --git a/machine/class/native_function.cpp b/machine/class/native_function.cpp index dcc7021aa5..c25335e88d 100644 --- a/machine/class/native_function.cpp +++ b/machine/class/native_function.cpp @@ -5,6 +5,7 @@ #include "memory.hpp" #include "object_utils.hpp" #include "on_stack.hpp" +#include "primitives.hpp" #include "class/array.hpp" #include "class/class.hpp" @@ -46,7 +47,6 @@ namespace rubinius { FFIData::FFIData(STATE, NativeFunction* func, int count, FFIArgInfo* args, FFIArgInfo* ret) : closure(0) - , shared(&state->shared()) , callable(0) , function(func) , args_info(args) diff --git a/machine/class/native_function.hpp b/machine/class/native_function.hpp index f7e9018b85..f72fdfb4f2 100644 --- a/machine/class/native_function.hpp +++ b/machine/class/native_function.hpp @@ -77,7 +77,6 @@ namespace rubinius { public: ffi_cif cif; ffi_closure* closure; - SharedState* shared; Object* callable; NativeFunction* function; FFIArgInfo* args_info; diff --git a/machine/class/native_method.cpp b/machine/class/native_method.cpp index 0c6ae581e4..d42fedf72f 100644 --- a/machine/class/native_method.cpp +++ b/machine/class/native_method.cpp @@ -1,3 +1,4 @@ +#include "c_api.hpp" #include "arguments.hpp" #include "call_frame.hpp" #include "configuration.hpp" @@ -606,7 +607,7 @@ namespace rubinius { String* library, Symbol* name, Pointer* ptr) { void* func = ptr->pointer; - int lock_index = state->shared().capi_lock_index(name->debug_str(state)); + int lock_index = state->c_api()->capi_lock_index(name->debug_str(state)); return NativeMethod::create(state, library, G(rubinius), name, func, diff --git a/machine/class/native_method.hpp b/machine/class/native_method.hpp index f6c46bf203..4e5884ac59 100644 --- a/machine/class/native_method.hpp +++ b/machine/class/native_method.hpp @@ -90,10 +90,6 @@ namespace rubinius { current_ep_ = ep; } - SharedState& shared() { - return state_.shared(); - } - StackVariables* scope(); }; diff --git a/machine/class/object.cpp b/machine/class/object.cpp index 958adf54b2..86343295a8 100644 --- a/machine/class/object.cpp +++ b/machine/class/object.cpp @@ -7,6 +7,7 @@ #include "memory.hpp" #include "object_utils.hpp" #include "on_stack.hpp" +#include "primitives.hpp" #include "thread_phase.hpp" #include "class/array.hpp" diff --git a/machine/class/pack.cpp b/machine/class/pack.cpp index ecfba2f43b..6b06ffceae 100644 --- a/machine/class/pack.cpp +++ b/machine/class/pack.cpp @@ -16,6 +16,7 @@ #include "memory.hpp" #include "object_utils.hpp" #include "on_stack.hpp" +#include "primitives.hpp" #include "state.hpp" #include "vm.hpp" diff --git a/machine/class/proc.cpp b/machine/class/proc.cpp index b3f737d106..c6d5ca79ca 100644 --- a/machine/class/proc.cpp +++ b/machine/class/proc.cpp @@ -5,6 +5,7 @@ #include "memory.hpp" #include "object_utils.hpp" #include "on_stack.hpp" +#include "primitives.hpp" #include "class/block_environment.hpp" #include "class/class.hpp" diff --git a/machine/class/regexp.cpp b/machine/class/regexp.cpp index 44853013a5..d0c0136308 100644 --- a/machine/class/regexp.cpp +++ b/machine/class/regexp.cpp @@ -6,6 +6,7 @@ #include "configuration.hpp" #include "memory.hpp" #include "object_utils.hpp" +#include "primitives.hpp" #include "class/block_environment.hpp" #include "class/byte_array.hpp" diff --git a/machine/class/string.cpp b/machine/class/string.cpp index 41791e1a38..3dfff27bc4 100644 --- a/machine/class/string.cpp +++ b/machine/class/string.cpp @@ -5,6 +5,7 @@ #include "configuration.hpp" #include "memory.hpp" #include "object_utils.hpp" +#include "primitives.hpp" #include "class/array.hpp" #include "class/byte_array.hpp" diff --git a/machine/class/system.cpp b/machine/class/system.cpp index 9ea100b17f..04b8d377b7 100644 --- a/machine/class/system.cpp +++ b/machine/class/system.cpp @@ -881,7 +881,7 @@ namespace rubinius { // We're in the child... state->vm()->after_fork_child(state); - state->shared().after_fork_child(state); + state->machine()->after_fork_child(state); state->machine_threads()->after_fork_child(state); // In the child, the PID is nil in Ruby. @@ -910,7 +910,7 @@ namespace rubinius { } Object* System::vm_get_config_item(STATE, String* var) { - ConfigParser::Entry* ent = state->shared().user_variables.find(var->c_str(state)); + ConfigParser::Entry* ent = state->environment()->user_variables()->find(var->c_str(state)); if(!ent) return cNil; if(ent->is_number()) { @@ -925,7 +925,7 @@ namespace rubinius { Object* System::vm_get_config_section(STATE, String* section) { ConfigParser::EntryList* list; - list = state->shared().user_variables.get_section( + list = state->environment()->user_variables()->get_section( reinterpret_cast(section->byte_address())); Array* ary = Array::create(state, list->size()); @@ -974,7 +974,7 @@ namespace rubinius { } Object* System::vm_watch_signal(STATE, Fixnum* sig, Object* ignored) { - SignalThread* st = state->shared().signals(); + SignalThread* st = state->machine()->signals(); if(st) { intptr_t i = sig->to_native(); @@ -992,7 +992,7 @@ namespace rubinius { } Object* System::vm_signal_thread(STATE) { - return state->shared().signals()->vm()->thread(); + return state->machine()->signals()->vm()->thread(); } Object* System::vm_time(STATE) { @@ -1278,20 +1278,20 @@ namespace rubinius { } Object* System::vm_global_serial(STATE) { - return Fixnum::from(state->shared().global_serial()); + return Fixnum::from(state->memory()->global_serial()); } Object* System::vm_inc_global_serial(STATE) { if(state->configuration()->serial_debug) { std::cerr << std::endl << "global serial increased from " - << state->shared().global_serial() + << state->memory()->global_serial() << std::endl; state->vm()->call_frame()->print_backtrace(state, std::cerr, 6, true); } - return Fixnum::from(state->shared().inc_global_serial(state)); + return Fixnum::from(state->memory()->inc_global_serial()); } Object* System::vm_deoptimize_all(STATE, Object* o_disable) { diff --git a/machine/class/thread.cpp b/machine/class/thread.cpp index b9b7cc8427..3b3f0f503e 100644 --- a/machine/class/thread.cpp +++ b/machine/class/thread.cpp @@ -3,6 +3,7 @@ #include "environment.hpp" #include "object_utils.hpp" #include "on_stack.hpp" +#include "primitives.hpp" #include "signal.hpp" #include "thread_phase.hpp" @@ -90,7 +91,7 @@ namespace rubinius { Thread* Thread::create(STATE, Object* self, ThreadFunction function) { return Thread::create(state, self, - state->thread_nexus()->new_vm(&state->shared()), + state->thread_nexus()->new_vm(state->machine()), function); } @@ -248,7 +249,7 @@ namespace rubinius { } Array* Thread::fiber_list(STATE) { - return state->shared().vm_thread_fibers(state, this); + return state->machine()->vm_thread_fibers(state, this); } Object* Thread::fiber_variable_get(STATE, Symbol* key) { @@ -290,16 +291,13 @@ namespace rubinius { state->vm()->thread()->pid(state, Fixnum::from(gettid())); - state->shared().env()->load_core(state); + state->environment()->load_core(state); state->vm()->thread_state()->clear(); - state->shared().start_console(state); - state->shared().start_compiler(state); - Object* klass = G(rubinius)->get_const(state, state->symbol("Loader")); if(klass->nil_p()) { - state->shared().env()->missing_core("unable to find class Rubinius::Loader"); + state->environment()->missing_core("unable to find class Rubinius::Loader"); return 0; } @@ -308,9 +306,9 @@ namespace rubinius { instance = klass->send(state, state->symbol("new")); if(instance) { - state->shared().env()->set_loader(instance); + state->environment()->set_loader(instance); } else { - state->shared().env()->missing_core("unable to instantiate Rubinius::Loader"); + state->environment()->missing_core("unable to instantiate Rubinius::Loader"); return 0; } @@ -319,7 +317,7 @@ namespace rubinius { Object* value = instance->send(state, state->symbol("main")); - state->shared().signals()->system_exit(state->vm()->thread_state()->raise_value()); + state->machine()->signals()->system_exit(state->vm()->thread_state()->raise_value()); return value; } @@ -372,7 +370,7 @@ namespace rubinius { vm->unmanaged_phase(state); if(vm->main_thread_p() || (!value && vm->thread_state()->raise_reason() == cExit)) { - state->shared().signals()->system_exit(vm->thread_state()->raise_value()); + state->machine()->signals()->system_exit(vm->thread_state()->raise_value()); } vm->set_zombie(state); @@ -407,11 +405,11 @@ namespace rubinius { } Array* Thread::list(STATE) { - return state->shared().vm_threads(state); + return state->machine()->vm_threads(state); } Fixnum* Thread::count(STATE) { - return state->shared().vm_threads_count(state); + return state->machine()->vm_threads_count(state); } Object* Thread::set_priority(STATE, Fixnum* new_priority) { diff --git a/machine/class/unpack.cpp b/machine/class/unpack.cpp index e90e1e6f0e..a23ab8d080 100644 --- a/machine/class/unpack.cpp +++ b/machine/class/unpack.cpp @@ -14,6 +14,7 @@ #include "memory.hpp" #include "object_utils.hpp" #include "on_stack.hpp" +#include "primitives.hpp" #include "state.hpp" #include "vm.hpp" diff --git a/machine/console.cpp b/machine/console.cpp index 1b0bd469fb..b9a3086810 100644 --- a/machine/console.cpp +++ b/machine/console.cpp @@ -406,66 +406,68 @@ namespace rubinius { } } } + } - Console::Console(STATE) - : listener_(0) - , response_(0) - , request_(0) - , ruby_console_(state) - { - console_path_ = state->configuration()->console_path.value; + using namespace console; - std::ostringstream basename; - basename << state->configuration()->console_path.value << "-" - << state->shared().env()->pid(); + Console::Console(STATE) + : listener_(0) + , response_(0) + , request_(0) + , ruby_console_(state) + { + console_path_ = state->configuration()->console_path.value; - request_path_ = basename.str() + "-request"; - response_path_ = basename.str() + "-response"; + std::ostringstream basename; + basename << state->configuration()->console_path.value << "-" + << state->environment()->pid(); - listener_ = new Listener(state, this); - } - - Console::~Console() { - if(listener_) delete listener_; - reset(); - } + request_path_ = basename.str() + "-request"; + response_path_ = basename.str() + "-response"; - bool Console::connected_p() { - return request_ && request_->enabled_p(); - } + listener_ = new Listener(state, this); + } - void Console::start(STATE) { - listener_->start(state); - } + Console::~Console() { + if(listener_) delete listener_; + reset(); + } - void Console::accept(STATE) { - ruby_console_.set(server_class(state)->send(state, 0, state->symbol("new"))); + bool Console::connected_p() { + return request_ && request_->enabled_p(); + } - response_ = new Response(state, this); - request_ = new Request(state, this, response_); - } + void Console::start(STATE) { + listener_->start(state); + } - void Console::reset() { - if(request_) { - delete request_; - request_ = 0; - } + void Console::accept(STATE) { + ruby_console_.set(server_class(state)->send(state, 0, state->symbol("new"))); - if(response_) { - delete response_; - response_ = 0; - } + response_ = new Response(state, this); + request_ = new Request(state, this, response_); + } - ruby_console_.set(cNil); + void Console::reset() { + if(request_) { + delete request_; + request_ = 0; } - void Console::after_fork_child(STATE) { - reset(); + if(response_) { + delete response_; + response_ = 0; } - Class* Console::server_class(STATE) { - Module* mod = as(G(rubinius)->get_const(state, "Console")); - return as(mod->get_const(state, "Server")); - } + ruby_console_.set(cNil); + } + + void Console::after_fork_child(STATE) { + reset(); + } + + Class* Console::server_class(STATE) { + Module* mod = as(G(rubinius)->get_const(state, "Console")); + return as(mod->get_const(state, "Server")); } } diff --git a/machine/console.hpp b/machine/console.hpp index be3a94a018..15294e67e8 100644 --- a/machine/console.hpp +++ b/machine/console.hpp @@ -11,6 +11,8 @@ #include namespace rubinius { + class Console; + class Channel; class VM; class State; class FSEvent; @@ -22,49 +24,6 @@ namespace rubinius { class Request; class Response; - class Console { - std::string console_path_; - std::string request_path_; - std::string response_path_; - - Listener* listener_; - Response* response_; - Request* request_; - - memory::TypedRoot ruby_console_; - - public: - Console(STATE); - virtual ~Console(); - - Object* ruby_console() { - return ruby_console_.get(); - } - - std::string& console_path() { - return console_path_; - } - - std::string& request_path() { - return request_path_; - } - - std::string& response_path() { - return response_path_; - } - - bool connected_p(); - - void reset(); - - void start(STATE); - void stop(STATE); - void after_fork_child(STATE); - - void accept(STATE); - Class* server_class(STATE); - }; - class Listener : public MachineThread { Console* console_; @@ -151,6 +110,51 @@ namespace rubinius { char* read_request(STATE); }; } + + using namespace console; + + class Console { + std::string console_path_; + std::string request_path_; + std::string response_path_; + + Listener* listener_; + Response* response_; + Request* request_; + + memory::TypedRoot ruby_console_; + + public: + Console(STATE); + virtual ~Console(); + + Object* ruby_console() { + return ruby_console_.get(); + } + + std::string& console_path() { + return console_path_; + } + + std::string& request_path() { + return request_path_; + } + + std::string& response_path() { + return response_path_; + } + + bool connected_p(); + + void reset(); + + void start(STATE); + void stop(STATE); + void after_fork_child(STATE); + + void accept(STATE); + Class* server_class(STATE); + }; } #endif diff --git a/machine/diagnostics.cpp b/machine/diagnostics.cpp index fd94944d8d..48b8bec2ff 100644 --- a/machine/diagnostics.cpp +++ b/machine/diagnostics.cpp @@ -1,3 +1,4 @@ +#include "configuration.hpp" #include "vm.hpp" #include "state.hpp" #include "environment.hpp" @@ -5,8 +6,12 @@ #include "thread_phase.hpp" #include "diagnostics.hpp" +#include "diagnostics/codedb.hpp" +#include "diagnostics/collector.hpp" #include "diagnostics/diagnostic.hpp" #include "diagnostics/emitter.hpp" +#include "diagnostics/machine.hpp" +#include "diagnostics/memory.hpp" #include #include @@ -15,15 +20,6 @@ namespace rubinius { using namespace utilities; namespace diagnostics { - Diagnostics::Diagnostics(STATE) - : recurring_reports_() - , intermittent_reports_() - , reporter_(nullptr) - , lock_() - , interval_(state->configuration()->diagnostics_interval) - { - } - Reporter::Reporter(STATE, Diagnostics* d) : MachineThread(state, "rbx.diagnostics", MachineThread::eSmall) , diagnostics_(d) @@ -100,4 +96,17 @@ namespace rubinius { } } } + + Diagnostics::Diagnostics(Configuration* configuration) + : boot_metrics_(new diagnostics::BootMetrics()) + , codedb_metrics_(new diagnostics::CodeDBMetrics()) + , collector_metrics_(new diagnostics::CollectorMetrics()) + , memory_metrics_(new diagnostics::MemoryMetrics()) + , recurring_reports_() + , intermittent_reports_() + , reporter_(nullptr) + , lock_() + , interval_(configuration->diagnostics_interval) + { + } } diff --git a/machine/diagnostics.hpp b/machine/diagnostics.hpp index ed5dd67381..378d6ab914 100644 --- a/machine/diagnostics.hpp +++ b/machine/diagnostics.hpp @@ -10,8 +10,10 @@ #include namespace rubinius { + class Configuration; + class Diagnostics; + namespace diagnostics { - class Diagnostics; class Diagnostic; class Emitter; class BootMetrics; @@ -57,75 +59,96 @@ namespace rubinius { void report(); }; + } - class Diagnostics { - RecurringReports recurring_reports_; - IntermittentReports intermittent_reports_; + class Diagnostics { + diagnostics::BootMetrics* boot_metrics_; + diagnostics::CodeDBMetrics* codedb_metrics_; + diagnostics::CollectorMetrics* collector_metrics_; + diagnostics::MemoryMetrics* memory_metrics_; - Reporter* reporter_; + diagnostics::RecurringReports recurring_reports_; + diagnostics::IntermittentReports intermittent_reports_; - std::mutex lock_; + diagnostics::Reporter* reporter_; - int interval_; + std::mutex lock_; - public: - Diagnostics(STATE); + int interval_; - ~Diagnostics() { - if(reporter_) { - delete reporter_; - reporter_ = nullptr; - } - } + public: + Diagnostics(Configuration* configuration); - std::mutex& lock() { - return lock_; + ~Diagnostics() { + if(reporter_) { + delete reporter_; + reporter_ = nullptr; } + } - int interval() const { - return interval_; - } + std::mutex& lock() { + return lock_; + } - RecurringReports& recurring_reports() { - return recurring_reports_; - } + int interval() const { + return interval_; + } - IntermittentReports& intermittent_reports() { - return intermittent_reports_; - } + diagnostics::BootMetrics* boot_metrics() { + return boot_metrics_; + } - void start_reporter(STATE) { - if(!reporter_) { - reporter_ = new Reporter(state, this); - reporter_->start(state); - } - } + diagnostics::CodeDBMetrics* codedb_metrics() { + return codedb_metrics_; + } - void report(Diagnostic* diagnostic) { - std::lock_guard guard(lock_); + diagnostics::CollectorMetrics* collector_metrics() { + return collector_metrics_; + } - intermittent_reports_.push_back(diagnostic); + diagnostics::MemoryMetrics* memory_metrics() { + return memory_metrics_; + } - if(reporter_) { - reporter_->report(); - } + diagnostics::RecurringReports& recurring_reports() { + return recurring_reports_; + } + + diagnostics::IntermittentReports& intermittent_reports() { + return intermittent_reports_; + } + + void start_reporter(STATE) { + if(!reporter_) { + reporter_ = new diagnostics::Reporter(state, this); + reporter_->start(state); } + } - void add_report(STATE, Diagnostic* diagnostic) { - std::lock_guard guard(lock_); + void report(diagnostics::Diagnostic* diagnostic) { + std::lock_guard guard(lock_); - recurring_reports_.insert(diagnostic); + intermittent_reports_.push_back(diagnostic); - start_reporter(state); + if(reporter_) { + reporter_->report(); } + } - void remove_report(Diagnostic* diagnostic) { - std::lock_guard guard(lock_); + void add_report(STATE, diagnostics::Diagnostic* diagnostic) { + std::lock_guard guard(lock_); - recurring_reports_.erase(diagnostic); - } - }; - } + recurring_reports_.insert(diagnostic); + + start_reporter(state); + } + + void remove_report(diagnostics::Diagnostic* diagnostic) { + std::lock_guard guard(lock_); + + recurring_reports_.erase(diagnostic); + } + }; } #endif diff --git a/machine/diagnostics/diagnostic.hpp b/machine/diagnostics/diagnostic.hpp index 40228d03d4..812a88b443 100644 --- a/machine/diagnostics/diagnostic.hpp +++ b/machine/diagnostics/diagnostic.hpp @@ -42,12 +42,12 @@ namespace rubinius { virtual ~Diagnostic() {} virtual void start_reporting(STATE) { - state->shared().diagnostics()->add_report(state, this); - set_nodename(state->shared().env()->nodename()); + state->machine()->diagnostics()->add_report(state, this); + set_nodename(state->environment()->nodename()); } virtual void stop_reporting(STATE) { - state->shared().diagnostics()->remove_report(this); + state->machine()->diagnostics()->remove_report(this); } virtual void update() { diff --git a/machine/diagnostics/emitter.cpp b/machine/diagnostics/emitter.cpp index 49e065d0c4..0f46ef130c 100644 --- a/machine/diagnostics/emitter.cpp +++ b/machine/diagnostics/emitter.cpp @@ -1,6 +1,5 @@ #include "configuration.hpp" #include "environment.hpp" -#include "shared_state.hpp" #include "state.hpp" #include "vm.hpp" @@ -9,6 +8,7 @@ #include "diagnostics/emitter.hpp" #include +#include namespace rubinius { namespace diagnostics { @@ -26,8 +26,8 @@ namespace rubinius { , fd_(-1) { // TODO: Make this a proper feature of the config facility. - state->shared().env()->expand_config_value( - path_, "$PID", state->shared().env()->pid().c_str()); + state->machine()->environment()->expand_config_value( + path_, "$PID", state->machine()->environment()->pid().c_str()); if((fd_ = ::open(path_.c_str(), O_CREAT | O_WRONLY | O_CLOEXEC, 0660)) < 0) { logger::error("%s: unable to open diagnostics file: %s", diff --git a/machine/diagnostics/measurement.cpp b/machine/diagnostics/measurement.cpp index 2b279db6e3..167101da8d 100644 --- a/machine/diagnostics/measurement.cpp +++ b/machine/diagnostics/measurement.cpp @@ -1,6 +1,5 @@ #include "configuration.hpp" #include "environment.hpp" -#include "shared_state.hpp" #include "state.hpp" #include "vm.hpp" #include "call_frame.hpp" diff --git a/machine/diagnostics/profiler.cpp b/machine/diagnostics/profiler.cpp index 917ef523b6..1fd29afef4 100644 --- a/machine/diagnostics/profiler.cpp +++ b/machine/diagnostics/profiler.cpp @@ -1,6 +1,5 @@ #include "configuration.hpp" #include "environment.hpp" -#include "shared_state.hpp" #include "state.hpp" #include "diagnostics/profiler.hpp" diff --git a/machine/environment.cpp b/machine/environment.cpp index 3222d46409..5f5845058d 100644 --- a/machine/environment.cpp +++ b/machine/environment.cpp @@ -1,5 +1,6 @@ #include "config.h" #include "paths.h" +#include "c_api.hpp" #include "defines.hpp" #include "environment.hpp" #include "config_parser.hpp" @@ -85,18 +86,8 @@ namespace rubinius { copy_argv(argc, argv); ruby_init_setproctitle(argc, argv); - shared = new SharedState(this, m, config_parser); - - } - - void Environment::initialize() { - load_vm_options(argc_, argv_); - - check_io_descriptors(); - - root_vm = _machine_->thread_nexus()->new_vm(shared, "ruby.main"); + root_vm = _machine_->thread_nexus()->new_vm(_machine_, "ruby.main"); root_vm->set_main_thread(); - shared->set_root_vm(root_vm); size_t stack_size = 0; struct rlimit rlim; @@ -109,6 +100,12 @@ namespace rubinius { root_vm->set_current_thread(); state = new State(root_vm); + } + + void Environment::initialize() { + load_vm_options(argc_, argv_); + + check_io_descriptors(); loader_ = new memory::TypedRoot(state); @@ -131,7 +128,6 @@ namespace rubinius { delete collector_; VM::discard(state, root_vm); - delete shared; delete state; for(int i = 0; i < argc_; i++) { @@ -147,7 +143,7 @@ namespace rubinius { logger::fatal("Please report this with the following backtrace to " \ "https://github.com/rubinius/rubinius/issues"); - rubinius::abort(); + rubinius::bug(); } void Environment::setup_cpp_terminate() { @@ -458,7 +454,7 @@ namespace rubinius { _machine_->configuration()->print(); } - state->shared().set_use_capi_lock(_machine_->configuration()->capi_lock); + _machine_->c_api()->set_use_capi_lock(_machine_->configuration()->capi_lock); } void Environment::load_platform_conf(std::string dir) { @@ -521,14 +517,14 @@ namespace rubinius { void Environment::halt(STATE, int exit_code) { std::lock_guard guard(halt_lock_); - state->shared().set_halting(); + state->machine()->machine_state()->set_halting(); if(state->configuration()->log_lifetime.value) { logger::write("process: exit: %s %d %lld %fs %fs", _pid_.c_str(), exit_code, - shared->codedb_metrics()->load_count, - timer::elapsed_seconds(shared->codedb_metrics()->load_ns), - shared->run_time()); + _machine_->diagnostics()->codedb_metrics()->load_count, + timer::elapsed_seconds(_machine_->diagnostics()->codedb_metrics()->load_ns), + state->machine()->machine_state()->run_time()); } state->machine_threads()->shutdown(state); @@ -542,7 +538,7 @@ namespace rubinius { NativeMethod::cleanup_thread(state); - state->shared().signals()->stop(state); + state->signals()->stop(state); exit(exit_code); } @@ -677,31 +673,30 @@ namespace rubinius { } void Environment::boot() { - state->shared().start_diagnostics(state); + // TODO: Machine + // state->diagnostics().start_diagnostics(state); std::string codedb_path = system_prefix() + RBX_CODEDB_PATH; { timer::StopWatch timer( - state->shared().boot_metrics()->platform_us); + state->diagnostics()->boot_metrics()->platform_us); load_platform_conf(codedb_path); } - shared->set_initialized(); - state->vm()->managed_phase(state); { timer::StopWatch timer( - state->shared().boot_metrics()->fields_us); + state->diagnostics()->boot_metrics()->fields_us); TypeInfo::auto_learn_fields(state); } { timer::StopWatch timer( - state->shared().boot_metrics()->ontology_us); + state->diagnostics()->boot_metrics()->ontology_us); state->vm()->bootstrap_ontology(state); } @@ -714,7 +709,7 @@ namespace rubinius { { timer::StopWatch timer( - state->shared().boot_metrics()->main_thread_us); + state->diagnostics()->boot_metrics()->main_thread_us); main = Thread::create(state, state->vm(), Thread::main_thread); main->start_thread(state, Thread::run); @@ -727,8 +722,6 @@ namespace rubinius { vm->set_stack_bounds(state->vm()->stack_size()); State main_state(vm); - state->shared().start_signals(&main_state); - - state->shared().set_running(); + state->machine()->start_signals(&main_state); } } diff --git a/machine/environment.hpp b/machine/environment.hpp index 8cc421bbc4..e9d0ab428b 100644 --- a/machine/environment.hpp +++ b/machine/environment.hpp @@ -57,7 +57,6 @@ namespace rubinius { std::string _pid_; public: - SharedState* shared; VM* root_vm; State* state; @@ -82,6 +81,11 @@ namespace rubinius { return argv_; } + ConfigParser* user_variables() { + // TODO: Machine + return &config_parser; + } + const std::string& nodename() const { return _nodename_; } diff --git a/machine/exception.cpp b/machine/exception.cpp index 3bc094a6cf..2010df880a 100644 --- a/machine/exception.cpp +++ b/machine/exception.cpp @@ -112,7 +112,7 @@ namespace rubinius { } } - void abort() { + void bug() { logger::fatal("The Rubinius process is aborting"); print_backtrace(); ::abort(); diff --git a/machine/machine.cpp b/machine/machine.cpp index a167387a1f..4babd3421b 100644 --- a/machine/machine.cpp +++ b/machine/machine.cpp @@ -1,48 +1,113 @@ +#include + #include "config.h" #include "paths.h" #include "debug.h" -#include "machine.hpp" -#include "machine_threads.hpp" -#include "environment.hpp" -#include "configuration.hpp" +#include "c_api.hpp" #include "config_parser.hpp" -#include "type_info.hpp" +#include "configuration.hpp" +#include "console.hpp" +#include "diagnostics.hpp" +#include "environment.hpp" #include "exception.hpp" -#include "thread_nexus.hpp" +#include "machine.hpp" +#include "machine_compiler.hpp" +#include "machine_threads.hpp" #include "memory.hpp" +#include "signal.hpp" +#include "thread_nexus.hpp" +#include "type_info.hpp" + +#include "class/array.hpp" +#include "class/fiber.hpp" +#include "class/fixnum.hpp" +#include "class/thread.hpp" + +#include "diagnostics/codedb.hpp" +#include "diagnostics/collector.hpp" +#include "diagnostics/memory.hpp" +#include "diagnostics/machine.hpp" +#include "diagnostics/profiler.hpp" +#include "diagnostics/timing.hpp" #include "memory/header.hpp" #include "memory/collector.hpp" +#include "sodium/randombytes.h" + #include namespace rubinius { + MachineState::MachineState() + : _start_time_(get_current_time()) + , _hash_seed_(randombytes_random()) + , _phase_(eBooting) + { + } + + void MachineState::set_start_time() { + _start_time_ = get_current_time(); + } + + double MachineState::run_time() { + return timer::time_elapsed_seconds(_start_time_); + } + Machine::Machine(int argc, char** argv) - : _machine_state_(nullptr) + : _machine_state_(new MachineState()) , _logger_(nullptr) , _thread_nexus_(new ThreadNexus) , _configuration_(new Configuration()) , _environment_(new Environment(argc, argv, this)) - , _diagnostics_(nullptr) + , _diagnostics_(new Diagnostics(_configuration_)) , _machine_threads_(new MachineThreads()) , _memory_(new Memory(_environment_->state, _configuration_)) , _collector_(new memory::Collector()) , _signals_(nullptr) , _codedb_(nullptr) - , _c_api_(nullptr) + , _c_api_(new C_API()) , _compiler_(nullptr) , _debugger_(nullptr) - , _profiler_(nullptr) - , _console_(nullptr) + , _profiler_(new Profiler()) + , _console_(new Console(_environment_->state)) { _environment_->initialize(); + } Machine::~Machine() { if(_machine_state_) halt(); } + SignalThread* Machine::start_signals(STATE) { + _signals_ = new SignalThread(state, state->vm()); + _signals_->start(state); + + return _signals_; + } + + Diagnostics* Machine::start_diagnostics(STATE) { + if(state->configuration()->diagnostics_target.value.compare("none")) { + _diagnostics_->start_reporter(state); + + _diagnostics_->boot_metrics()->start_reporting(state); + _diagnostics_->codedb_metrics()->start_reporting(state); + _diagnostics_->collector_metrics()->start_reporting(state); + _diagnostics_->memory_metrics()->start_reporting(state); + // _diagnostics_->profiler()->start_reporting(state); + } + + return _diagnostics_; + } + + void Machine::report_diagnostics(diagnostics::Diagnostic* diagnostic) { + if(_diagnostics_) { + _diagnostics_->report(diagnostic); + } + } + + /* TODO: * * [x] 1. Add Machine to SharedState; @@ -64,7 +129,7 @@ namespace rubinius { * [ ] 1. Move Debugger to Machine; * [ ] 1. Move Compiler to Machine; * [ ] 1. Move Profiler to Machine; - * [ ] 1. Move Console to Machine; + * [x] 1. Move Console to Machine; * [x] 1. Move SymbolTable into Memory; * [x] 1. Move Globals into Memory; * [ ] 1. Create ThreadState to replace State; @@ -76,6 +141,10 @@ namespace rubinius { void Machine::boot() { environment()->setup_cpp_terminate(); + // TODO: after removing Environment::boot + // _console_->start(_environment_->state); + // state->shared().start_compiler(state); + MachineException::guard(environment()->state, true, [&]{ if(const char* var = getenv("RBX_OPTIONS")) { environment()->load_string(var); @@ -89,6 +158,142 @@ namespace rubinius { }); } + void Machine::after_fork_child(STATE) { + _machine_state_->set_start_time(); + + _memory_->after_fork_child(state); + _signals_->after_fork_child(state); + } + + /* TODO + console_->after_fork_child(state); + */ + + /* TODO + jit::MachineCompiler* Machine::start_compiler(STATE) { + if(!compiler_) { + if(state->configuration()->jit_enabled.value) { + compiler_ = new jit::MachineCompiler(state); + } + } + + return compiler_; + } + */ + + Array* Machine::vm_threads(STATE) { + std::lock_guard guard(thread_nexus()->threads_mutex()); + + Array* threads = Array::create(state, 0); + + for(ThreadList::iterator i = thread_nexus()->threads()->begin(); + i != thread_nexus()->threads()->end(); + ++i) + { + if(VM* vm = (*i)->as_vm()) { + Thread *thread = vm->thread(); + if(vm->kind() == memory::ManagedThread::eThread + &&!thread->nil_p() && CBOOL(thread->alive())) { + threads->append(state, thread); + } + } + } + + return threads; + } + + Fixnum* Machine::vm_threads_count(STATE) { + std::lock_guard guard(thread_nexus()->threads_mutex()); + + intptr_t count = 0; + + for(ThreadList::iterator i = thread_nexus()->threads()->begin(); + i != thread_nexus()->threads()->end(); + ++i) + { + if(VM* vm = (*i)->as_vm()) { + Thread *thread = vm->thread(); + if(vm->kind() == memory::ManagedThread::eThread + &&!thread->nil_p() && CBOOL(thread->alive())) { + count++; + } + } + } + + return Fixnum::from(count); + } + + Array* Machine::vm_fibers(STATE) { + std::lock_guard guard(thread_nexus()->threads_mutex()); + + Array* fibers = Array::create(state, 0); + + for(ThreadList::iterator i = thread_nexus()->threads()->begin(); + i != thread_nexus()->threads()->end(); + ++i) + { + if(VM* vm = (*i)->as_vm()) { + if(vm->kind() == memory::ManagedThread::eFiber + && !vm->fiber()->nil_p() + && vm->fiber()->status() != Fiber::eDead) { + fibers->append(state, vm->fiber()); + } + } + } + + return fibers; + } + + Fixnum* Machine::vm_fibers_count(STATE) { + std::lock_guard guard(thread_nexus()->threads_mutex()); + + intptr_t count = 0; + + for(ThreadList::iterator i = thread_nexus()->threads()->begin(); + i != thread_nexus()->threads()->end(); + ++i) + { + if(VM* vm = (*i)->as_vm()) { + if(vm->kind() == memory::ManagedThread::eFiber + && !vm->fiber()->nil_p() + && vm->fiber()->status() != Fiber::eDead) { + count++; + } + } + } + + return Fixnum::from(count); + } + + void Machine::vm_thread_fibers(STATE, Thread* thread, + std::function f) + { + std::lock_guard guard(thread_nexus()->threads_mutex()); + + for(ThreadList::iterator i = thread_nexus()->threads()->begin(); + i != thread_nexus()->threads()->end(); + ++i) + { + if(VM* vm = (*i)->as_vm()) { + if(vm->kind() == memory::ManagedThread::eFiber + && !vm->fiber()->nil_p() + && vm->fiber()->status() != Fiber::eDead + && vm->fiber()->thread() == thread) { + f(state, vm->fiber()); + } + } + } + } + + Array* Machine::vm_thread_fibers(STATE, Thread* thread) { + Array* fibers = Array::create(state, 0); + + vm_thread_fibers(state, thread, + [fibers](STATE, Fiber* fiber){ fibers->append(state, fiber); }); + + return fibers; + } + void Machine::halt_console() { if(_console_) { delete _console_; diff --git a/machine/machine.hpp b/machine/machine.hpp index b9b49ad530..3f4ba055b2 100644 --- a/machine/machine.hpp +++ b/machine/machine.hpp @@ -1,11 +1,27 @@ #ifndef RBX_MACHINE_H #define RBX_MACHINE_H +#include "defines.hpp" + +#include +#include + namespace rubinius { + class Array; + class Fiber; + class Fixnum; + class Thread; + class ngLogger { }; class Environment; class Configuration; - class ngDiagnostics { }; + + class Diagnostics; + + namespace diagnostics { + class Diagnostic; + } + class ThreadNexus; class MachineThreads; class Memory; @@ -14,18 +30,64 @@ namespace rubinius { class Collector; } - class ngSignals { }; + class SignalThread; class ngCodeDB { }; - class C_API { - }; + class C_API; + + namespace jit { + class MachineCompiler; + } - class ngCompiler { }; class ngDebugger { }; - class ngProfiler { }; - class ngConsole { }; + + class Profiler { + public: + Profiler() { } + virtual ~Profiler() { } + }; + + class Console; class MachineState { + public: + enum Phase { + eBooting, + eRunning, + eHalting, + }; + + private: + uint64_t _start_time_; + uint32_t _hash_seed_; + std::atomic _phase_; + + public: + MachineState(); + virtual ~MachineState() { } + + const uint32_t hash_seed() { + return _hash_seed_; + } + + bool booting_p() { + return _phase_ == eBooting; + } + + bool running_p() { + return _phase_ == eRunning; + } + + bool halting_p() { + return _phase_ == eHalting; + } + + void set_halting() { + _phase_ = eHalting; + } + + void set_start_time(); + double run_time(); }; class Machine { @@ -34,23 +96,27 @@ namespace rubinius { ThreadNexus* _thread_nexus_; Configuration* _configuration_; Environment* _environment_; - ngDiagnostics* _diagnostics_; + Diagnostics* _diagnostics_; MachineThreads* _machine_threads_; Memory* _memory_; memory::Collector* _collector_; - ngSignals* _signals_; + SignalThread* _signals_; ngCodeDB* _codedb_; C_API* _c_api_; - ngCompiler* _compiler_; + jit::MachineCompiler* _compiler_; ngDebugger* _debugger_; - ngProfiler* _profiler_; - ngConsole* _console_; + Profiler* _profiler_; + Console* _console_; public: Machine(int argc, char** argv); virtual ~Machine(); + MachineState* const machine_state() { + return _machine_state_; + } + ThreadNexus* const thread_nexus() { return _thread_nexus_; } @@ -63,6 +129,10 @@ namespace rubinius { return _environment_; } + Diagnostics* const diagnostics() { + return _diagnostics_; + } + MachineThreads* const machine_threads() { return _machine_threads_; } @@ -75,9 +145,46 @@ namespace rubinius { return _collector_; } + SignalThread* const signals() { + return _signals_; + } + + C_API* const c_api() { + return _c_api_; + } + + jit::MachineCompiler* const compiler() { + return _compiler_; + } + + Profiler* const profiler() { + return _profiler_; + } + + Console* const console() { + return _console_; + } + void boot(); int halt(); + void after_fork_child(STATE); + + SignalThread* start_signals(STATE); + Diagnostics* start_diagnostics(STATE); + void report_diagnostics(diagnostics::Diagnostic* diagnostic); + + // TODO: Machine + Array* vm_threads(STATE); + Fixnum* vm_threads_count(STATE); + Array* vm_fibers(STATE); + Fixnum* vm_fibers_count(STATE); + Array* vm_thread_fibers(STATE, Thread* thread); + void vm_thread_fibers(STATE, Thread* thread, std::function f); + + uint32_t new_thread_id(); + // --- + void halt_console(); void halt_profiler(); void halt_debugger(); diff --git a/machine/machine_threads.cpp b/machine/machine_threads.cpp index cf7f3d9008..1046994fa7 100644 --- a/machine/machine_threads.cpp +++ b/machine/machine_threads.cpp @@ -14,7 +14,7 @@ namespace rubinius { using namespace utilities; MachineThread::MachineThread(STATE, std::string name, StackSize stack_size) - : vm_(state->thread_nexus()->new_vm(&state->shared(), name.c_str())) + : vm_(state->thread_nexus()->new_vm(state->machine(), name.c_str())) , stack_size_(stack_size) , thread_running_(false) , thread_exit_(false) @@ -104,7 +104,7 @@ namespace rubinius { } void MachineThread::after_fork_child(STATE) { - vm_ = state->thread_nexus()->new_vm(&state->shared()); + vm_ = state->thread_nexus()->new_vm(state->machine()); start(state); } diff --git a/machine/marshal.cpp b/machine/marshal.cpp index 662f5c4a5d..b613d1c4d3 100644 --- a/machine/marshal.cpp +++ b/machine/marshal.cpp @@ -203,7 +203,7 @@ namespace rubinius { if(count >= STACK_BUF_SZ) { malloc_data = (char*)malloc(count + 1); - if(!malloc_data) rubinius::abort(); + if(!malloc_data) rubinius::bug(); data = malloc_data; } @@ -229,7 +229,7 @@ namespace rubinius { if(count >= STACK_BUF_SZ) { malloc_data = (char*)malloc(count + 1); - if(!malloc_data) rubinius::abort(); + if(!malloc_data) rubinius::bug(); data = malloc_data; } @@ -329,7 +329,7 @@ namespace rubinius { if(count >= STACK_BUF_SZ) { malloc_data = (char*)malloc(count + 1); - if(!malloc_data) rubinius::abort(); + if(!malloc_data) rubinius::bug(); data = malloc_data; } diff --git a/machine/memory.cpp b/machine/memory.cpp index 764cc55b7c..21c847557d 100644 --- a/machine/memory.cpp +++ b/machine/memory.cpp @@ -62,6 +62,12 @@ namespace rubinius { , cycle_(0) , mark_(0x1) , visit_mark_(0x1) + , class_count_(0) + , global_serial_(0) + , codedb_lock_() + , wait_lock_() + , type_info_lock_() + , code_resource_lock_() , last_object_id(1) , last_snapshot_id(0) , large_object_threshold(configuration->memory_large_object) @@ -82,6 +88,13 @@ namespace rubinius { main_heap_ = nullptr; } + void Memory::after_fork_child(STATE) { + // Reinit the locks for this object + wait_lock_.init(); + type_info_lock_.init(); + code_resource_lock_.init(); + } + /* TODO: GC bool Memory::valid_object_p(Object* obj) { if(obj->true_p()) { @@ -129,8 +142,8 @@ namespace rubinius { Object* obj = nullptr; if(likely(obj = main_heap_->third_region()->allocate(state, bytes))) { - state->shared().memory_metrics()->large_objects++; - state->shared().memory_metrics()->large_bytes += bytes; + state->diagnostics()->memory_metrics()->large_objects++; + state->diagnostics()->memory_metrics()->large_bytes += bytes; MemoryHeader::initialize( obj, state->vm()->thread_id(), eThirdRegion, type, false); @@ -165,9 +178,9 @@ namespace rubinius { */ void Memory::add_code_resource(STATE, memory::CodeResource* cr) { - utilities::thread::SpinLock::LockGuard guard(state->shared().code_resource_lock()); + utilities::thread::SpinLock::LockGuard guard(code_resource_lock()); - state->shared().memory_metrics()->code_bytes += cr->size(); + state->diagnostics()->memory_metrics()->code_bytes += cr->size(); bool collect_flag = false; code_manager_.add_resource(cr, &collect_flag); @@ -182,8 +195,8 @@ namespace rubinius { void* XMALLOC(size_t bytes) { if(rubinius::VM* vm = rubinius::VM::current()) { /* TODO: VM, State => ThreadState - vm->shared.memory_metrics()->malloc++; - vm->shared.memory_metrics()->allocated_bytes += bytes; + state->diagnostics()->memory_metrics()->malloc++; + state->diagnostics()->memory_metrics()->allocated_bytes += bytes; */ } @@ -193,7 +206,7 @@ void* XMALLOC(size_t bytes) { void XFREE(void* ptr) { if(rubinius::VM* vm = rubinius::VM::current()) { /* TODO: VM, State => ThreadState - vm->shared.memory_metrics()->freed++; + state->diagnostics()->memory_metrics()->freed++; */ } @@ -203,9 +216,9 @@ void XFREE(void* ptr) { void* XREALLOC(void* ptr, size_t bytes) { if(rubinius::VM* vm = rubinius::VM::current()) { /* TODO: VM, State => ThreadState - vm->shared.memory_metrics()->realloc++; - vm->shared.memory_metrics()->freed++; - vm->shared.memory_metrics()->allocated_bytes += bytes; + state->diagnostics()->memory_metrics()->realloc++; + state->diagnostics()->memory_metrics()->freed++; + state->diagnostics()->memory_metrics()->allocated_bytes += bytes; */ } @@ -217,8 +230,8 @@ void* XCALLOC(size_t items, size_t bytes_per) { if(rubinius::VM* vm = rubinius::VM::current()) { /* TODO: VM, State => ThreadState - vm->shared.memory_metrics()->calloc++; - vm->shared.memory_metrics()->allocated_bytes += bytes; + state->diagnostics()->memory_metrics()->calloc++; + state->diagnostics()->memory_metrics()->allocated_bytes += bytes; */ } diff --git a/machine/memory.hpp b/machine/memory.hpp index 9ae3bd38db..cb7153d908 100644 --- a/machine/memory.hpp +++ b/machine/memory.hpp @@ -23,9 +23,10 @@ #include "util/thread.hpp" #include "state.hpp" -#include "shared_state.hpp" +#include #include +#include class TestMemory; // So we can friend it properly class TestVM; // So we can friend it properly @@ -100,6 +101,15 @@ namespace rubinius { unsigned int visit_mark_; + std::atomic class_count_; + std::atomic global_serial_; + + std::recursive_mutex codedb_lock_; + + utilities::thread::SpinLock wait_lock_; + utilities::thread::SpinLock type_info_lock_; + utilities::thread::SpinLock code_resource_lock_; + public: /// Counter used for issuing object ids when #object_id is called on a /// Ruby object. @@ -114,6 +124,9 @@ namespace rubinius { SymbolTable symbols; public: + Memory(STATE, Configuration* configuration); + virtual ~Memory(); + static void memory_error(STATE); void collect_cycle() { @@ -124,6 +137,34 @@ namespace rubinius { return allocation_lock_; } + int inc_class_count() { + return ++class_count_; + } + + int global_serial() const { + return global_serial_; + } + + int inc_global_serial() { + return ++global_serial_; + } + + std::recursive_mutex& codedb_lock() { + return codedb_lock_; + } + + utilities::thread::SpinLock& wait_lock() { + return wait_lock_; + } + + utilities::thread::SpinLock& type_info_lock() { + return type_info_lock_; + } + + utilities::thread::SpinLock& code_resource_lock() { + return code_resource_lock_; + } + memory::CodeManager& code_manager() { return code_manager_; } @@ -156,9 +197,7 @@ namespace rubinius { visit_mark_ ^= 0x3; } - public: - Memory(STATE, Configuration* configuration); - virtual ~Memory(); + void after_fork_child(STATE); // Object must be created in Immix or large object space. Object* new_object(STATE, intptr_t bytes, object_type type); diff --git a/machine/memory/code_manager.hpp b/machine/memory/code_manager.hpp index 9d7fed8e1e..b09f0d81f6 100644 --- a/machine/memory/code_manager.hpp +++ b/machine/memory/code_manager.hpp @@ -8,8 +8,6 @@ #include namespace rubinius { - class SharedState; - namespace memory { class CodeResource; @@ -52,8 +50,6 @@ namespace memory { utilities::thread::Mutex mutex_; - SharedState* shared_; - int chunk_size_; Chunk* first_chunk_; Chunk* last_chunk_; @@ -64,10 +60,6 @@ namespace memory { diagnostics::CodeManager* diagnostic_; public: - SharedState* shared() const { - return shared_; - } - diagnostics::CodeManager* diagnostic() { return diagnostic_; } diff --git a/machine/memory/collector.cpp b/machine/memory/collector.cpp index b8bd150b59..f380e89cf9 100644 --- a/machine/memory/collector.cpp +++ b/machine/memory/collector.cpp @@ -240,7 +240,7 @@ namespace rubinius { void Collector::collect(STATE) { timer::StopWatch timerx( - state->shared().collector_metrics()->first_region_stop_ms); + state->diagnostics()->collector_metrics()->first_region_stop_ms); stop_for_collection(state, [&]{ MemoryTracer tracer(state, state->memory()->main_heap()); @@ -321,7 +321,7 @@ namespace rubinius { object->finalize(state); delete object; - state->shared().collector_metrics()->objects_finalized++; + state->diagnostics()->collector_metrics()->objects_finalized++; } state->thread_nexus()->yield(state, state->vm()); @@ -370,7 +370,7 @@ namespace rubinius { fo->finalize(state); delete fo; - state->shared().collector_metrics()->objects_finalized++; + state->diagnostics()->collector_metrics()->objects_finalized++; } while(!finalizer_list_.empty()) { @@ -380,7 +380,7 @@ namespace rubinius { fo->finalize(state); delete fo; - state->shared().collector_metrics()->objects_finalized++; + state->diagnostics()->collector_metrics()->objects_finalized++; } for(auto i = state->collector()->weakrefs().begin(); @@ -476,7 +476,7 @@ namespace rubinius { obj->object()->set_finalizer(state); finalizer_list_.push_back(obj); - state->shared().collector_metrics()->objects_queued++; + state->diagnostics()->collector_metrics()->objects_queued++; } void Collector::trace_finalizers(STATE, MemoryTracer* tracer) { diff --git a/machine/memory/immix.hpp b/machine/memory/immix.hpp index c3e7b81fb6..5bf2086a36 100644 --- a/machine/memory/immix.hpp +++ b/machine/memory/immix.hpp @@ -1084,7 +1084,7 @@ namespace rubinius { { timer::StopWatch timer( - state->shared().collector_metrics()->first_region_diagnostics_us); + state->diagnostics()->collector_metrics()->first_region_diagnostics_us); // Now, calculate how much space we're still using. Chunks& chunks = block_allocator_.chunks(); @@ -1106,7 +1106,7 @@ namespace rubinius { if(state->configuration()->diagnostics_memory_enabled) { diagnostic()->update(); - state->shared().report_diagnostics(diagnostic()); + state->machine()->report_diagnostics(diagnostic()); } } diff --git a/machine/memory/main_heap.cpp b/machine/memory/main_heap.cpp index 9a0414bf95..6d1133477b 100644 --- a/machine/memory/main_heap.cpp +++ b/machine/memory/main_heap.cpp @@ -34,8 +34,8 @@ namespace rubinius { utilities::thread::SpinLock::LockGuard guard(state->memory()->allocation_lock()); if(Object* obj = first_region()->allocate(state, bytes)) { - state->shared().memory_metrics()->first_region_objects++; - state->shared().memory_metrics()->first_region_bytes += bytes; + state->diagnostics()->memory_metrics()->first_region_objects++; + state->diagnostics()->memory_metrics()->first_region_bytes += bytes; MemoryHeader::initialize( obj, state->vm()->thread_id(), eFirstRegion, type, false); @@ -44,8 +44,8 @@ namespace rubinius { } if(Object* obj = third_region()->allocate(state, bytes)) { - state->shared().memory_metrics()->large_objects++; - state->shared().memory_metrics()->large_bytes += bytes; + state->diagnostics()->memory_metrics()->large_objects++; + state->diagnostics()->memory_metrics()->large_bytes += bytes; MemoryHeader::initialize( obj, state->vm()->thread_id(), eThirdRegion, type, false); @@ -155,7 +155,7 @@ namespace rubinius { state->memory()->symbols.sweep(state); - diagnostics::CollectorMetrics* metrics = state->shared().collector_metrics(); + diagnostics::CollectorMetrics* metrics = state->diagnostics()->collector_metrics(); metrics->first_region_count++; metrics->large_count++; } diff --git a/machine/memory/managed.cpp b/machine/memory/managed.cpp index 68b2aad758..ceead76a69 100644 --- a/machine/memory/managed.cpp +++ b/machine/memory/managed.cpp @@ -1,9 +1,9 @@ #include "vm.hpp" #include "state.hpp" +#include "machine.hpp" #include "util/thread.hpp" #include "memory/managed.hpp" -#include "shared_state.hpp" #include "diagnostics/machine.hpp" #include "diagnostics/memory.hpp" @@ -15,7 +15,7 @@ namespace rubinius { namespace memory { utilities::thread::ThreadData _current_thread; - ManagedThread::ManagedThread(uint32_t id, SharedState& ss, + ManagedThread::ManagedThread(uint32_t id, Machine* m, ManagedThread::Kind kind, const char* name) : kind_(kind) , metrics_(new diagnostics::MachineMetrics()) diff --git a/machine/memory/managed.hpp b/machine/memory/managed.hpp index f5d0b52a41..197caf38a7 100644 --- a/machine/memory/managed.hpp +++ b/machine/memory/managed.hpp @@ -13,7 +13,7 @@ #include namespace rubinius { - class SharedState; + class Machine; class VM; namespace memory { @@ -38,7 +38,7 @@ namespace memory { uint32_t id_; public: - ManagedThread(uint32_t id, SharedState& ss, Kind kind, const char* name); + ManagedThread(uint32_t id, Machine* m, Kind kind, const char* name); ~ManagedThread(); static void set_current_thread(ManagedThread* vm); diff --git a/machine/memory/third_region.cpp b/machine/memory/third_region.cpp index 8a14c5f4ee..2b0ae35311 100644 --- a/machine/memory/third_region.cpp +++ b/machine/memory/third_region.cpp @@ -1,6 +1,5 @@ #include "memory.hpp" #include "object_utils.hpp" -#include "shared_state.hpp" #include "state.hpp" #include "memory/collector.hpp" @@ -55,8 +54,8 @@ namespace rubinius { diagnostic()->objects++; diagnostic()->bytes += bytes; - state->shared().memory_metrics()->large_objects++; - state->shared().memory_metrics()->large_bytes += bytes; + state->diagnostics()->memory_metrics()->large_objects++; + state->diagnostics()->memory_metrics()->large_bytes += bytes; entries.push_back(obj); @@ -64,7 +63,7 @@ namespace rubinius { if(next_collection_bytes < 0) { next_collection_bytes = collection_threshold; - state->shared().collector_metrics()->large_set++; + state->diagnostics()->collector_metrics()->large_set++; state->collector()->collect_requested(state, "collector: large object space triggered collection request"); } diff --git a/machine/ontology.cpp b/machine/ontology.cpp index ef2835f70b..9c4b8573c5 100644 --- a/machine/ontology.cpp +++ b/machine/ontology.cpp @@ -21,7 +21,6 @@ #include "class/compiled_code.hpp" #include "class/channel.hpp" #include "class/data.hpp" -#include "class/diagnostics.hpp" #include "class/dir.hpp" #include "class/encoding.hpp" #include "class/executable.hpp" @@ -270,7 +269,6 @@ namespace rubinius { Logger::bootstrap(state); JIT::bootstrap(state); CodeDB::bootstrap(state); - Diagnostics::bootstrap(state); Trie::bootstrap(state); UnwindSite::bootstrap(state); } @@ -359,7 +357,7 @@ namespace rubinius { * because some are passed to e.g. File.expand_path and having them * be uniform is simpler. */ - Environment* env = state->shared().env(); + Environment* env = state->environment(); if(env) { std::string prefix = env->system_prefix(); diff --git a/machine/shared_state.cpp b/machine/shared_state.cpp deleted file mode 100644 index f5ee1bf8db..0000000000 --- a/machine/shared_state.cpp +++ /dev/null @@ -1,405 +0,0 @@ -#include "vm.hpp" -#include "state.hpp" -#include "shared_state.hpp" -#include "call_frame.hpp" -#include "config_parser.hpp" -#include "config.h" -#include "machine_compiler.hpp" -#include "memory.hpp" -#include "environment.hpp" - -#include "util/thread.hpp" -#include "configuration.hpp" - -#include "console.hpp" -#include "signal.hpp" - -#include "class/randomizer.hpp" -#include "class/array.hpp" -#include "class/fixnum.hpp" -#include "class/thread.hpp" -#include "class/native_method.hpp" -#include "class/system.hpp" - -#include "diagnostics/codedb.hpp" -#include "diagnostics/collector.hpp" -#include "diagnostics/machine.hpp" -#include "diagnostics/memory.hpp" -#include "diagnostics/profiler.hpp" -#include "diagnostics/timing.hpp" - -#include -#include -#include - -namespace rubinius { - - SharedState::SharedState(Environment* env, Machine* m, ConfigParser& cp) - : signals_(nullptr) - , console_(nullptr) - , compiler_(nullptr) - , diagnostics_(nullptr) - , boot_metrics_(new diagnostics::BootMetrics()) - , codedb_metrics_(new diagnostics::CodeDBMetrics()) - , collector_metrics_(new diagnostics::CollectorMetrics()) - , memory_metrics_(new diagnostics::MemoryMetrics()) - , profiler_(new diagnostics::Profiler()) - , capi_constant_name_map_() - , capi_constant_map_() - , start_time_(get_current_time()) - , class_count_(1) - , global_serial_(1) - , initialized_(false) - , check_global_interrupts_(false) - , check_gc_(false) - , root_vm_(nullptr) - , env_(env) - , codedb_lock_() - , capi_ds_lock_() - , capi_locks_lock_() - , capi_constant_lock_() - , wait_lock_() - , type_info_lock_() - , code_resource_lock_() - , use_capi_lock_(false) - , phase_(eBooting) - , machine_(m) - , user_variables(cp) - { - for(int i = 0; i < Primitives::cTotalPrimitives; i++) { - primitive_hits_[i] = 0; - } - - hash_seed = Randomizer::random_uint32(); - initialize_capi_black_list(); - } - - SharedState::~SharedState() { - if(!initialized_) return; - - if(console_) { - delete console_; - console_ = nullptr; - } - - if(compiler_) { - delete compiler_; - compiler_ = nullptr; - } - - if(diagnostics_) { - delete diagnostics_; - diagnostics_ = nullptr; - } - } - - ThreadNexus* const SharedState::thread_nexus() { - return machine_->thread_nexus(); - } - - MachineThreads* const SharedState::machine_threads() { - return machine_->machine_threads(); - } - - Array* SharedState::vm_threads(STATE) { - std::lock_guard guard(thread_nexus()->threads_mutex()); - - Array* threads = Array::create(state, 0); - - for(ThreadList::iterator i = thread_nexus()->threads()->begin(); - i != thread_nexus()->threads()->end(); - ++i) - { - if(VM* vm = (*i)->as_vm()) { - Thread *thread = vm->thread(); - if(vm->kind() == memory::ManagedThread::eThread - &&!thread->nil_p() && CBOOL(thread->alive())) { - threads->append(state, thread); - } - } - } - - return threads; - } - - Fixnum* SharedState::vm_threads_count(STATE) { - std::lock_guard guard(thread_nexus()->threads_mutex()); - - intptr_t count = 0; - - for(ThreadList::iterator i = thread_nexus()->threads()->begin(); - i != thread_nexus()->threads()->end(); - ++i) - { - if(VM* vm = (*i)->as_vm()) { - Thread *thread = vm->thread(); - if(vm->kind() == memory::ManagedThread::eThread - &&!thread->nil_p() && CBOOL(thread->alive())) { - count++; - } - } - } - - return Fixnum::from(count); - } - - Array* SharedState::vm_fibers(STATE) { - std::lock_guard guard(thread_nexus()->threads_mutex()); - - Array* fibers = Array::create(state, 0); - - for(ThreadList::iterator i = thread_nexus()->threads()->begin(); - i != thread_nexus()->threads()->end(); - ++i) - { - if(VM* vm = (*i)->as_vm()) { - if(vm->kind() == memory::ManagedThread::eFiber - && !vm->fiber()->nil_p() - && vm->fiber()->status() != Fiber::eDead) { - fibers->append(state, vm->fiber()); - } - } - } - - return fibers; - } - - Fixnum* SharedState::vm_fibers_count(STATE) { - std::lock_guard guard(thread_nexus()->threads_mutex()); - - intptr_t count = 0; - - for(ThreadList::iterator i = thread_nexus()->threads()->begin(); - i != thread_nexus()->threads()->end(); - ++i) - { - if(VM* vm = (*i)->as_vm()) { - if(vm->kind() == memory::ManagedThread::eFiber - && !vm->fiber()->nil_p() - && vm->fiber()->status() != Fiber::eDead) { - count++; - } - } - } - - return Fixnum::from(count); - } - - void SharedState::vm_thread_fibers(STATE, Thread* thread, - std::function f) - { - std::lock_guard guard(thread_nexus()->threads_mutex()); - - for(ThreadList::iterator i = thread_nexus()->threads()->begin(); - i != thread_nexus()->threads()->end(); - ++i) - { - if(VM* vm = (*i)->as_vm()) { - if(vm->kind() == memory::ManagedThread::eFiber - && !vm->fiber()->nil_p() - && vm->fiber()->status() != Fiber::eDead - && vm->fiber()->thread() == thread) { - f(state, vm->fiber()); - } - } - } - } - - Array* SharedState::vm_thread_fibers(STATE, Thread* thread) { - Array* fibers = Array::create(state, 0); - - vm_thread_fibers(state, thread, - [fibers](STATE, Fiber* fiber){ fibers->append(state, fiber); }); - - return fibers; - } - - double SharedState::run_time() { - return timer::time_elapsed_seconds(start_time_); - } - - SignalThread* SharedState::start_signals(STATE) { - signals_ = new SignalThread(state, state->vm()); - signals_->start(state); - - return signals_; - } - - console::Console* SharedState::start_console(STATE) { - if(!console_) { - console_ = new console::Console(state); - console_->start(state); - } - - return console_; - } - - diagnostics::Diagnostics* SharedState::start_diagnostics(STATE) { - diagnostics_ = new diagnostics::Diagnostics(state); - - if(state->configuration()->diagnostics_target.value.compare("none")) { - diagnostics_->start_reporter(state); - - boot_metrics_->start_reporting(state); - codedb_metrics_->start_reporting(state); - collector_metrics_->start_reporting(state); - memory_metrics_->start_reporting(state); - profiler_->start_reporting(state); - } - - return diagnostics_; - } - - void SharedState::report_diagnostics(diagnostics::Diagnostic* diagnostic) { - if(diagnostics_) { - diagnostics_->report(diagnostic); - } - } - - jit::MachineCompiler* SharedState::start_compiler(STATE) { - if(!compiler_) { - if(state->configuration()->jit_enabled.value) { - compiler_ = new jit::MachineCompiler(state); - } - } - - return compiler_; - } - - void SharedState::after_fork_child(STATE) { - // Reinit the locks for this object - capi_ds_lock_.init(); - capi_locks_lock_.init(); - capi_constant_lock_.init(); - wait_lock_.init(); - type_info_lock_.init(); - code_resource_lock_.init(); - - start_time_ = get_current_time(); - - signals_->after_fork_child(state); - console_->after_fork_child(state); - } - - void SharedState::enter_capi(STATE, const char* file, int line) { - NativeMethodEnvironment* env = state->vm()->native_method_environment; - if(int lock_index = env->current_native_frame()->capi_lock_index()) { - capi_locks_[lock_index - 1]->lock(); - } - } - - void SharedState::leave_capi(STATE) { - NativeMethodEnvironment* env = state->vm()->native_method_environment; - if(int lock_index = env->current_native_frame()->capi_lock_index()) { - capi_locks_[lock_index - 1]->unlock(); - } - } - - int SharedState::capi_lock_index(std::string name) { - utilities::thread::SpinLock::LockGuard guard(capi_locks_lock_); - int existing = capi_lock_map_[name]; - if(existing) return existing; - - CApiBlackList::const_iterator blacklisted = capi_black_list_.find(name); - - // Only disable locks if we have capi locks disabled - // and library is not in the blacklist. - if(!use_capi_lock_ && blacklisted == capi_black_list_.end()) { - capi_lock_map_[name] = 0; - return 0; - } - - utilities::thread::Mutex* lock = new utilities::thread::Mutex(true); - capi_locks_.push_back(lock); - - // We use a 1 offset index, so 0 can indicate no lock used - int lock_index = capi_locks_.size(); - capi_lock_map_[name] = lock_index; - return lock_index; - } - - void SharedState::setup_capi_constant_names() { - capi_constant_name_map_.resize(cCApiMaxConstant + 1); - - capi_constant_name_map_[cCApiArray] = "Array"; - capi_constant_name_map_[cCApiBignum] = "Bignum"; - capi_constant_name_map_[cCApiClass] = "Class"; - capi_constant_name_map_[cCApiComparable] = "Comparable"; - capi_constant_name_map_[cCApiData] = "Data"; - capi_constant_name_map_[cCApiEnumerable] = "Enumerable"; - capi_constant_name_map_[cCApiFalse] = "FalseClass"; - capi_constant_name_map_[cCApiFile] = "File"; - capi_constant_name_map_[cCApiFixnum] = "Fixnum"; - capi_constant_name_map_[cCApiFloat] = "Float"; - capi_constant_name_map_[cCApiHash] = "Hash"; - capi_constant_name_map_[cCApiInteger] = "Integer"; - capi_constant_name_map_[cCApiIO] = "IO"; - capi_constant_name_map_[cCApiKernel] = "Kernel"; - capi_constant_name_map_[cCApiMatch] = "MatchData"; - capi_constant_name_map_[cCApiModule] = "Module"; - capi_constant_name_map_[cCApiNil] = "NilClass"; - capi_constant_name_map_[cCApiNumeric] = "Numeric"; - capi_constant_name_map_[cCApiObject] = "Object"; - capi_constant_name_map_[cCApiRange] = "Range"; - capi_constant_name_map_[cCApiRegexp] = "Regexp"; - capi_constant_name_map_[cCApiRubinius] = "Rubinius"; - capi_constant_name_map_[cCApiString] = "String"; - capi_constant_name_map_[cCApiStruct] = "Struct"; - capi_constant_name_map_[cCApiSymbol] = "Symbol"; - capi_constant_name_map_[cCApiThread] = "Thread"; - capi_constant_name_map_[cCApiTime] = "Time"; - capi_constant_name_map_[cCApiTrue] = "TrueClass"; - capi_constant_name_map_[cCApiProc] = "Proc"; - capi_constant_name_map_[cCApiGC] = "GC"; - capi_constant_name_map_[cCApiCAPI] = "Rubinius::CAPI"; - capi_constant_name_map_[cCApiMethod] = "Method"; - capi_constant_name_map_[cCApiRational] = "Rational"; - capi_constant_name_map_[cCApiComplex] = "Complex"; - capi_constant_name_map_[cCApiEnumerator] = "Enumerator"; - capi_constant_name_map_[cCApiMutex] = "Mutex"; - capi_constant_name_map_[cCApiDir] = "Dir"; - - capi_constant_name_map_[cCApiArgumentError] = "ArgumentError"; - capi_constant_name_map_[cCApiEOFError] = "EOFError"; - capi_constant_name_map_[cCApiErrno] = "Errno"; - capi_constant_name_map_[cCApiException] = "Exception"; - capi_constant_name_map_[cCApiFatal] = "FatalError"; - capi_constant_name_map_[cCApiFloatDomainError] = "FloatDomainError"; - capi_constant_name_map_[cCApiIndexError] = "IndexError"; - capi_constant_name_map_[cCApiInterrupt] = "Interrupt"; - capi_constant_name_map_[cCApiIOError] = "IOError"; - capi_constant_name_map_[cCApiLoadError] = "LoadError"; - capi_constant_name_map_[cCApiLocalJumpError] = "LocalJumpError"; - capi_constant_name_map_[cCApiNameError] = "NameError"; - capi_constant_name_map_[cCApiNoMemoryError] = "NoMemoryError"; - capi_constant_name_map_[cCApiNoMethodError] = "NoMethodError"; - capi_constant_name_map_[cCApiNotImplementedError] = "NotImplementedError"; - capi_constant_name_map_[cCApiRangeError] = "RangeError"; - capi_constant_name_map_[cCApiRegexpError] = "RegexpError"; - capi_constant_name_map_[cCApiRuntimeError] = "RuntimeError"; - capi_constant_name_map_[cCApiScriptError] = "ScriptError"; - capi_constant_name_map_[cCApiSecurityError] = "SecurityError"; - capi_constant_name_map_[cCApiSignalException] = "SignalException"; - capi_constant_name_map_[cCApiStandardError] = "StandardError"; - capi_constant_name_map_[cCApiSyntaxError] = "SyntaxError"; - capi_constant_name_map_[cCApiSystemCallError] = "SystemCallError"; - capi_constant_name_map_[cCApiSystemExit] = "SystemExit"; - capi_constant_name_map_[cCApiSystemStackError] = "SystemStackError"; - capi_constant_name_map_[cCApiTypeError] = "TypeError"; - capi_constant_name_map_[cCApiThreadError] = "ThreadError"; - capi_constant_name_map_[cCApiZeroDivisionError] = "ZeroDivisionError"; - - capi_constant_name_map_[cCApiMathDomainError] = "Math::DomainError"; - capi_constant_name_map_[cCApiEncoding] = "Encoding"; - capi_constant_name_map_[cCApiEncCompatError] = "Encoding::CompatibilityError"; - capi_constant_name_map_[cCApiWaitReadable] = "IO::WaitReadable"; - capi_constant_name_map_[cCApiWaitWritable] = "IO::WaitWritable"; - - } - -#define CAPI_BLACK_LIST(name) capi_black_list_.insert(std::string("Init_" # name)) - void SharedState::initialize_capi_black_list() { - CAPI_BLACK_LIST(nkf); - CAPI_BLACK_LIST(nokogiri); - } -} diff --git a/machine/shared_state.hpp b/machine/shared_state.hpp deleted file mode 100644 index 5ea9c6c625..0000000000 --- a/machine/shared_state.hpp +++ /dev/null @@ -1,353 +0,0 @@ -#ifndef RBX_SHARED_STATE_H -#define RBX_SHARED_STATE_H - -#include "config.h" - -#include "memory/variable_buffer.hpp" -#include "memory/root_buffer.hpp" - -#include "globals.hpp" -#include "machine_threads.hpp" -#include "primitives.hpp" -#include "spinlock.hpp" -#include "symbol_table.hpp" -#include "thread_nexus.hpp" - -#include "diagnostics.hpp" - -#include "util/thread.hpp" - -#include "capi/capi_constants.h" - -#include -#include -#include -#include -#include -#include -#include - -#ifdef RBX_WINDOWS -#include -#endif - -namespace rubinius { - namespace console { - class Console; - } - - namespace jit { - class MachineCompiler; - } - - namespace memory { - class Collector; - class ManagedThread; - } - - class Machine; - class ConfigParser; - class Configuration; - class Environment; - class Fiber; - class Fixnum; - class Memory; - class QueryAgent; - class SignalThread; - class State; - class VM; - - struct CallFrame; - - typedef std::unordered_set CApiBlackList; - typedef std::vector CApiLocks; - typedef std::unordered_map CApiLockMap; - - typedef std::vector CApiConstantNameMap; - typedef std::unordered_map CApiConstantHandleMap; - - /** - * SharedState represents the global shared state that needs to be shared - * across all VM instances. - * - * Rubinius makes no use of global variables; instead, all shared state is - * stored in a reference counted instance of this class. This makes it - * possible in theory to have multiple independent Rubinius runtimes in a - * single process. - */ - - class SharedState { - public: - enum Phase { - eBooting, - eRunning, - eHalting, - }; - - private: - SignalThread* signals_; - console::Console* console_; - jit::MachineCompiler* compiler_; - - diagnostics::Diagnostics* diagnostics_; - diagnostics::BootMetrics* boot_metrics_; - diagnostics::CodeDBMetrics* codedb_metrics_; - diagnostics::CollectorMetrics* collector_metrics_; - diagnostics::MemoryMetrics* memory_metrics_; - diagnostics::Profiler* profiler_; - - CApiConstantNameMap capi_constant_name_map_; - CApiConstantHandleMap capi_constant_map_; - - uint64_t start_time_; - uint64_t class_count_; - int global_serial_; - - bool initialized_; - bool check_global_interrupts_; - bool check_gc_; - - VM* root_vm_; - Environment* env_; - - std::recursive_mutex codedb_lock_; - - utilities::thread::SpinLock capi_ds_lock_; - utilities::thread::SpinLock capi_locks_lock_; - utilities::thread::SpinLock capi_constant_lock_; - utilities::thread::SpinLock wait_lock_; - utilities::thread::SpinLock type_info_lock_; - utilities::thread::SpinLock code_resource_lock_; - - CApiBlackList capi_black_list_; - CApiLocks capi_locks_; - CApiLockMap capi_lock_map_; - - bool use_capi_lock_; - int primitive_hits_[Primitives::cTotalPrimitives]; - - std::atomic phase_; - - Machine* machine_; - - public: - ConfigParser& user_variables; - uint32_t hash_seed; - - public: - SharedState(Environment* env, Machine* m, ConfigParser& cp); - ~SharedState(); - - bool booting_p() { - return phase_ == eBooting; - } - - void set_booting() { - phase_ = eBooting; - } - - bool running_p() { - return phase_ == eRunning; - } - - void set_running() { - phase_ = eRunning; - } - - bool halting_p() { - return phase_ == eHalting; - } - - void set_halting() { - phase_ = eHalting; - } - - int size(); - - void set_initialized() { - setup_capi_constant_names(); - initialized_ = true; - } - - double run_time(); - - Machine* const machine() { - return machine_; - } - - ThreadNexus* const thread_nexus(); - MachineThreads* const machine_threads(); - - Array* vm_threads(STATE); - Fixnum* vm_threads_count(STATE); - Array* vm_fibers(STATE); - Fixnum* vm_fibers_count(STATE); - Array* vm_thread_fibers(STATE, Thread* thread); - void vm_thread_fibers(STATE, Thread* thread, std::function f); - - int global_serial() const { - return global_serial_; - } - - int inc_global_serial(STATE) { - return atomic::fetch_and_add(&global_serial_, (int)1); - } - - uint32_t new_thread_id(); - - int* global_serial_address() { - return &global_serial_; - } - - uint64_t inc_class_count(STATE) { - return atomic::fetch_and_add(&class_count_, (uint64_t)1); - } - - int inc_primitive_hit(int primitive) { - return ++primitive_hits_[primitive]; - } - - int& primitive_hits(int primitive) { - return primitive_hits_[primitive]; - } - - SignalThread* signals() const { - return signals_; - } - - SignalThread* start_signals(STATE); - - console::Console* console() const { - return console_; - } - - console::Console* start_console(STATE); - - diagnostics::Diagnostics* diagnostics() const { - return diagnostics_; - } - - diagnostics::Diagnostics* start_diagnostics(STATE); - - void report_diagnostics(diagnostics::Diagnostic* diagnostic); - - diagnostics::BootMetrics* boot_metrics() { - return boot_metrics_; - } - - diagnostics::CodeDBMetrics* codedb_metrics() { - return codedb_metrics_; - } - - diagnostics::CollectorMetrics* collector_metrics() { - return collector_metrics_; - } - - diagnostics::MemoryMetrics* memory_metrics() { - return memory_metrics_; - } - - - diagnostics::Profiler* profiler() { - return profiler_; - } - - jit::MachineCompiler* start_compiler(STATE); - - jit::MachineCompiler* compiler() const { - return compiler_; - } - - Environment* const env() { - return env_; - } - - void set_root_vm(VM* vm) { - root_vm_ = vm; - } - - VM* root_vm() const { - return root_vm_; - } - - bool check_gc_p() { - bool c = check_gc_; - if(unlikely(c)) { - check_gc_ = false; - } - return c; - } - - void gc_soon() { - check_global_interrupts_ = true; - check_gc_ = true; - thread_nexus()->set_stop(); - } - - bool check_global_interrupts() const { - return check_global_interrupts_; - } - - void set_check_global_interrupts() { - check_global_interrupts_ = true; - } - - void clear_check_global_interrupts() { - check_global_interrupts_ = false; - } - - bool* check_global_interrupts_address() { - return &check_global_interrupts_; - } - - std::recursive_mutex& codedb_lock() { - return codedb_lock_; - } - - void set_use_capi_lock(bool s) { - use_capi_lock_ = s; - } - - utilities::thread::SpinLock& capi_ds_lock() { - return capi_ds_lock_; - } - - utilities::thread::SpinLock& capi_constant_lock() { - return capi_constant_lock_; - } - - int capi_lock_index(std::string name); - - utilities::thread::SpinLock& wait_lock() { - return wait_lock_; - } - - utilities::thread::SpinLock& type_info_lock() { - return type_info_lock_; - } - - utilities::thread::SpinLock& code_resource_lock() { - return code_resource_lock_; - } - - void scheduler_loop(); - - void after_fork_child(STATE); - - void enter_capi(STATE, const char* file, int line); - void leave_capi(STATE); - - void setup_capi_constant_names(); - CApiConstantNameMap& capi_constant_name_map() { - return capi_constant_name_map_; - } - - CApiConstantHandleMap& capi_constant_map() { - return capi_constant_map_; - } - - void initialize_capi_black_list(); - }; -} - -#endif diff --git a/machine/signal.cpp b/machine/signal.cpp index 5d9cc242d5..055ce7e113 100644 --- a/machine/signal.cpp +++ b/machine/signal.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -57,8 +58,7 @@ namespace rubinius { static struct utsname machine_info; SignalThread::SignalThread(STATE, VM* vm) - : shared_(state->shared()) - , vm_(vm) + : vm_(vm) , system_exit_(false) , exit_code_(0) , queue_index_(0) @@ -73,7 +73,7 @@ namespace rubinius { } VM* SignalThread::new_vm(STATE) { - VM* vm = state->thread_nexus()->new_vm(&state->shared(), "rbx.system"); + VM* vm = state->thread_nexus()->new_vm(state->machine(), "rbx.system"); vm->set_kind(memory::ManagedThread::eSystem); return vm; } @@ -127,18 +127,18 @@ namespace rubinius { initialize(state); if(state->configuration()->log_lifetime.value) { - state->shared().signals()->print_machine_info(logger::write); - state->shared().signals()->print_process_info(logger::write); + state->signals()->print_machine_info(logger::write); + state->signals()->print_process_info(logger::write); logger::write("process: boot stats: " \ "fields %lldus " \ "main thread: %lldus " \ "ontology: %lldus " \ "platform: %lldus", - state->shared().boot_metrics()->fields_us, - state->shared().boot_metrics()->main_thread_us, - state->shared().boot_metrics()->ontology_us, - state->shared().boot_metrics()->platform_us); + state->diagnostics()->boot_metrics()->fields_us, + state->diagnostics()->boot_metrics()->main_thread_us, + state->diagnostics()->boot_metrics()->ontology_us, + state->diagnostics()->boot_metrics()->platform_us); } run(state); @@ -237,7 +237,7 @@ namespace rubinius { Array* args = Array::create(state, 1); args->set(state, 0, exc); - state->shared().env()->loader()->send(state, + state->environment()->loader()->send(state, state->symbol("handle_exception"), args, cNil); system_exit_ = true; @@ -253,7 +253,7 @@ namespace rubinius { } } - state->shared().env()->halt(state, exit_code_); + state->environment()->halt(state, exit_code_); } void SignalThread::print_machine_info(logger::PrintFunction function) { @@ -268,8 +268,8 @@ namespace rubinius { llvm_version = RBX_LLVM_VERSION; - if(CBOOL(signal_thread_->shared().env()->state->globals().jit.get()->enabled_p( - signal_thread_->shared().env()->state))) + if(CBOOL(signal_thread_->vm()->machine()->environment()->state->globals().jit.get()->enabled_p( + signal_thread_->vm()->machine()->environment()->state))) { jit_status = "JIT"; } else { @@ -279,8 +279,8 @@ namespace rubinius { char process_info[RBX_PROCESS_INFO_LEN]; snprintf(process_info, RBX_PROCESS_INFO_LEN, "%s %s %s %s %s %s %.8s %s %s", - signal_thread_->shared().env()->username().c_str(), - RBX_PROGRAM_NAME, signal_thread_->shared().env()->pid().c_str(), + signal_thread_->vm()->machine()->environment()->username().c_str(), + RBX_PROGRAM_NAME, signal_thread_->vm()->machine()->environment()->pid().c_str(), RBX_VERSION, RBX_RUBY_VERSION, RBX_RELEASE_DATE, RBX_BUILD_REV, llvm_version, jit_status); @@ -312,8 +312,8 @@ namespace rubinius { } void SignalThread::print_backtraces() { - STATE = shared_.env()->state; - ThreadList* threads = shared_.thread_nexus()->threads(); + STATE = vm_->machine()->environment()->state; + ThreadList* threads = vm_->machine()->thread_nexus()->threads(); for(ThreadList::iterator i = threads->begin(); i != threads->end(); ++i) { VM* vm = (*i)->as_vm(); diff --git a/machine/signal.hpp b/machine/signal.hpp index 10b5954663..18fa7179c6 100644 --- a/machine/signal.hpp +++ b/machine/signal.hpp @@ -17,7 +17,6 @@ namespace rubinius { struct CallFrame; class SignalThread { - SharedState& shared_; VM* vm_; bool system_exit_; @@ -46,10 +45,6 @@ namespace rubinius { SignalThread(STATE, VM* vm); - SharedState& shared() { - return shared_; - } - VM* vm() { return vm_; } diff --git a/machine/state.cpp b/machine/state.cpp index 3883a4ba64..2773fb2b3a 100644 --- a/machine/state.cpp +++ b/machine/state.cpp @@ -28,24 +28,60 @@ namespace rubinius { return vm_->park_->park_timed(this, ts); } + const uint32_t State::hash_seed() { + return machine()->machine_state()->hash_seed(); + } + + MachineState* const State::machine_state() { + return vm_->machine()->machine_state(); + } + + Machine* const State::machine() { + return vm_->machine(); + } + Configuration* const State::configuration() { - return shared_.machine()->configuration(); + return machine()->configuration(); + } + + Environment* const State::environment() { + return machine()->environment(); } ThreadNexus* const State::thread_nexus() { - return shared_.machine()->thread_nexus(); + return machine()->thread_nexus(); + } + + Diagnostics* const State::diagnostics() { + return machine()->diagnostics(); } MachineThreads* const State::machine_threads() { - return shared_.machine()->machine_threads(); + return machine()->machine_threads(); } memory::Collector* const State::collector() { - return shared_.machine()->collector(); + return machine()->collector(); + } + + SignalThread* const State::signals() { + return machine()->signals(); } Memory* const State::memory() { - return shared_.machine()->memory(); + return machine()->memory(); + } + + C_API* const State::c_api() { + return machine()->c_api(); + } + + Profiler* const State::profiler() { + return machine()->profiler(); + } + + Console* const State::console() { + return machine()->console(); } Globals& State::globals() { diff --git a/machine/state.hpp b/machine/state.hpp index 04bc91286d..ad47dd3ecc 100644 --- a/machine/state.hpp +++ b/machine/state.hpp @@ -9,11 +9,17 @@ namespace rubinius { struct CallFrame; + class C_API; class Class; + class Console; + class Environment; class Exception; class Object; + class Machine; + class MachineState; class Memory; - class SharedState; + class Profiler; + class SignalThread; class String; class Symbol; class VM; @@ -26,19 +32,25 @@ namespace rubinius { class State { VM* vm_; - SharedState& shared_; public: State(VM* vm) : vm_(vm) - , shared_(vm->shared) {} + MachineState* const machine_state(); + Machine* const machine(); Configuration* const configuration(); + Environment* const environment(); ThreadNexus* const thread_nexus(); + Diagnostics* const diagnostics(); MachineThreads* const machine_threads(); memory::Collector* const collector(); + SignalThread* const signals(); Memory* const memory(); + C_API* const c_api(); + Profiler* const profiler(); + Console* const console(); VM* vm() { return vm_; @@ -64,18 +76,12 @@ namespace rubinius { Symbol* const symbol(std::string str); Symbol* const symbol(String* str); - uint32_t hash_seed() const { - return shared_.hash_seed; - } + const uint32_t hash_seed(); VMThreadState* thread_state() { return vm_->thread_state(); } - SharedState& shared() { - return shared_; - } - bool check_local_interrupts() const { return vm_->check_local_interrupts(); } diff --git a/machine/symbol_table.cpp b/machine/symbol_table.cpp index b7f6e9299f..aee922e885 100644 --- a/machine/symbol_table.cpp +++ b/machine/symbol_table.cpp @@ -36,7 +36,7 @@ namespace rubinius { void SymbolTable::sweep(STATE) { if(state->configuration()->diagnostics_memory_enabled) { diagnostic_->update(); - state->shared().report_diagnostics(diagnostic_); + state->machine()->report_diagnostics(diagnostic_); } } @@ -115,8 +115,8 @@ namespace rubinius { encodings.push_back(enc); kinds.push_back(eUnknown); - state->shared().memory_metrics()->symbols++; - state->shared().memory_metrics()->symbols_bytes += bytes; + state->diagnostics()->memory_metrics()->symbols++; + state->diagnostics()->memory_metrics()->symbols_bytes += bytes; return strings.size() - 1; } @@ -125,10 +125,6 @@ namespace rubinius { return lookup(state, str, length, Encoding::eAscii, state->hash_seed()); } - Symbol* SymbolTable::lookup(STATE, SharedState* shared, const std::string& str) { - return lookup(state, str.data(), str.size(), Encoding::eAscii, shared->hash_seed); - } - Symbol* SymbolTable::lookup(STATE, const std::string& str) { return lookup(state, str.data(), str.size(), Encoding::eAscii, state->hash_seed()); } diff --git a/machine/symbol_table.hpp b/machine/symbol_table.hpp index 6aef32a319..7d530c27ee 100644 --- a/machine/symbol_table.hpp +++ b/machine/symbol_table.hpp @@ -34,7 +34,6 @@ namespace rubinius { class Array; class String; class Symbol; - class SharedState; typedef std::vector SymbolStrings; typedef std::vector SymbolEncodings; @@ -82,7 +81,6 @@ namespace rubinius { void sweep(STATE); - Symbol* lookup(STATE, SharedState* shared, const std::string& str); Symbol* lookup(STATE, const std::string& str); Symbol* lookup(STATE, const char* str, size_t length); Symbol* lookup(STATE, const char* str, size_t length, int enc, uint32_t seed); diff --git a/machine/test/test.hpp b/machine/test/test.hpp index ae9432510b..e92cc82355 100644 --- a/machine/test/test.hpp +++ b/machine/test/test.hpp @@ -162,7 +162,6 @@ class ReturnConst : public ConstMissing { class VMTest { public: Machine* machine; - SharedState* shared; State* state; ConfigParser* config_parser; Configuration config; @@ -188,9 +187,6 @@ class VMTest { void initialize_as_root(STATE) { state->vm()->set_current_thread(); - state->vm()->shared.set_initialized(); - state->vm()->shared.set_root_vm(state->vm()); - state->vm()->managed_phase(state); TypeInfo::auto_learn_fields(state); @@ -207,14 +203,13 @@ class VMTest { void create() { machine = new Machine(0, nullptr); - VM* vm = machine->thread_nexus()->new_vm(machine->environment()->shared); + VM* vm = machine->thread_nexus()->new_vm(machine); state = new State(vm); initialize_as_root(state); } void destroy() { VM::discard(state, state->vm()); - delete shared; delete state; machine->halt(); diff --git a/machine/thread_nexus.cpp b/machine/thread_nexus.cpp index 3cdeb0468d..b163fe5493 100644 --- a/machine/thread_nexus.cpp +++ b/machine/thread_nexus.cpp @@ -1,5 +1,6 @@ +#include "environment.hpp" #include "logger.hpp" -#include "shared_state.hpp" +#include "machine.hpp" #include "thread_nexus.hpp" #include "thread_phase.hpp" #include "vm.hpp" @@ -105,7 +106,7 @@ namespace rubinius { return (phase & cYieldingPhase) == cYieldingPhase; } - VM* ThreadNexus::new_vm(SharedState* shared, const char* name) { + VM* ThreadNexus::new_vm(Machine* m, const char* name) { std::lock_guard guard(threads_mutex_); uint32_t max_id = thread_ids_; @@ -115,7 +116,7 @@ namespace rubinius { rubinius::bug("exceeded maximum number of threads"); } - VM* vm = new VM(id, *shared, name); + VM* vm = new VM(id, m, name); threads_.push_back(vm); @@ -173,7 +174,7 @@ namespace rubinius { } threads_.push_back(current); - state->shared().set_root_vm(current); + state->environment()->set_root_vm(current); } static const char* phase_name(VM* vm) { diff --git a/machine/thread_nexus.hpp b/machine/thread_nexus.hpp index aa869d59af..91bb5e2e1f 100644 --- a/machine/thread_nexus.hpp +++ b/machine/thread_nexus.hpp @@ -13,11 +13,12 @@ #include namespace rubinius { + class Machine; + namespace memory { class ManagedThread; } - class SharedState; class State; class VM; @@ -193,7 +194,7 @@ namespace rubinius { void list_threads(); void list_threads(logger::PrintFunction function); - VM* new_vm(SharedState* shared, const char* name = NULL); + VM* new_vm(Machine* m, const char* name = NULL); void delete_vm(VM* vm); void after_fork_child(STATE); diff --git a/machine/vm.cpp b/machine/vm.cpp index 3209255770..0cd7ac67fe 100644 --- a/machine/vm.cpp +++ b/machine/vm.cpp @@ -1,5 +1,6 @@ #include "vm.hpp" #include "state.hpp" +#include "machine.hpp" #include "memory.hpp" #include "machine_code.hpp" #include "environment.hpp" @@ -59,8 +60,9 @@ #define GO(whatever) globals().whatever namespace rubinius { - VM::VM(uint32_t id, SharedState& shared, const char* name) - : memory::ManagedThread(id, shared, memory::ManagedThread::eThread, name) + VM::VM(uint32_t id, Machine* m, const char* name) + : memory::ManagedThread(id, m, memory::ManagedThread::eThread, name) + , _machine_(m) , call_frame_(NULL) , park_(new Park) , thca_(new memory::OpenTHCA) @@ -68,7 +70,7 @@ namespace rubinius { , stack_barrier_start_(0) , stack_barrier_end_(0) , stack_size_(0) - , stack_cushion_(shared.machine()->configuration()->machine_stack_cushion.value) + , stack_cushion_(m->configuration()->machine_stack_cushion.value) , stack_probe_(0) , interrupt_with_signal_(false) , interrupt_by_kill_(false) @@ -87,12 +89,11 @@ namespace rubinius { , sample_counter_(0) , checkpoints_(0) , stops_(0) - , shared(shared) - , waiting_channel_(this, nil()) - , interrupted_exception_(this, nil()) - , thread_(this, nil()) - , fiber_(this, nil()) - , waiting_object_(this, cNil) + , waiting_channel_(nil()) + , interrupted_exception_(nil()) + , thread_(nil()) + , fiber_(nil()) + , waiting_object_(cNil) , start_time_(0) , native_method_environment(NULL) , custom_wakeup_(NULL) @@ -117,22 +118,34 @@ namespace rubinius { } } + Machine* const VM::machine() { + return _machine_; + } + void VM::discard(STATE, VM* vm) { state->vm()->metrics()->threads_destroyed++; delete vm; } + ThreadNexus* const VM::thread_nexus() { + return _machine_->thread_nexus(); + } + Globals& VM::globals() { - return shared.machine()->memory()->globals; + return _machine_->memory()->globals; + } + + void VM::clear_interrupted_exception() { + interrupted_exception_ = nil(); } void VM::set_thread(Thread* thread) { - thread_.set(thread); + thread_ = thread; } void VM::set_fiber(Fiber* fiber) { - fiber_.set(fiber); + fiber_ = fiber; } void VM::set_start_time() { @@ -328,7 +341,7 @@ namespace rubinius { } void VM::set_zombie(STATE) { - state->shared().thread_nexus()->delete_vm(this); + state->machine()->thread_nexus()->delete_vm(this); set_zombie(); } @@ -371,9 +384,9 @@ namespace rubinius { state->vm()->set_start_time(); // TODO: Remove need for root_vm. - state->shared().env()->set_root_vm(state->vm()); + state->environment()->set_root_vm(state->vm()); - state->shared().env()->after_fork_child(state); + state->machine()->environment()->after_fork_child(state); } Object* VM::path2class(STATE, const char* path) { @@ -408,7 +421,7 @@ namespace rubinius { std::lock_guard guard(interrupt_lock_); set_check_local_interrupts(); - Object* wait = waiting_object_.get(); + Object* wait = waiting_object_; if(park_->parked_p()) { park_->unpark(); @@ -425,7 +438,7 @@ namespace rubinius { interrupt_lock_.unlock(); return true; } else { - Channel* chan = waiting_channel_.get(); + Channel* chan = waiting_channel_; if(!chan->nil_p()) { interrupt_lock_.unlock(); @@ -442,11 +455,12 @@ namespace rubinius { } void VM::clear_waiter() { - utilities::thread::SpinLock::LockGuard guard(shared.wait_lock()); + // TODO: Machine + utilities::thread::SpinLock::LockGuard guard(_machine_->memory()->wait_lock()); interrupt_with_signal_ = false; - waiting_channel_.set(nil()); - waiting_object_.set(cNil); + waiting_channel_ = nil(); + waiting_object_ = cNil; custom_wakeup_ = 0; custom_wakeup_data_ = 0; } @@ -455,11 +469,12 @@ namespace rubinius { std::lock_guard guard(interrupt_lock_); thread()->sleep(state, cTrue); - waiting_channel_.set(chan); + waiting_channel_ = chan; } void VM::wait_on_custom_function(STATE, void (*func)(void*), void* data) { - utilities::thread::SpinLock::LockGuard guard(shared.wait_lock()); + // TODO: Machine + utilities::thread::SpinLock::LockGuard guard(_machine_->memory()->wait_lock()); custom_wakeup_ = func; custom_wakeup_data_ = data; @@ -479,7 +494,7 @@ namespace rubinius { void VM::register_raise(STATE, Exception* exc) { std::lock_guard guard(interrupt_lock_); - interrupted_exception_.set(exc); + interrupted_exception_ = exc; set_check_local_interrupts(); } @@ -562,6 +577,12 @@ namespace rubinius { metrics()->checkpoints = checkpoints_; metrics()->stops = stops_; + f(state, reinterpret_cast(&waiting_channel_)); + f(state, reinterpret_cast(&interrupted_exception_)); + f(state, reinterpret_cast(&thread_)); + f(state, reinterpret_cast(&fiber_)); + f(state, reinterpret_cast(&waiting_object_)); + thca_->collect(state); CallFrame* frame = call_frame_; diff --git a/machine/vm.hpp b/machine/vm.hpp index e592e7614f..c193926936 100644 --- a/machine/vm.hpp +++ b/machine/vm.hpp @@ -13,8 +13,6 @@ #include "thread_nexus.hpp" #include "spinlock.hpp" -#include "shared_state.hpp" - #include "unwind_info.hpp" #include "sodium/randombytes.h" @@ -34,6 +32,7 @@ namespace rubinius { class Fiber; class Exception; + class Machine; namespace event { class Loop; @@ -51,7 +50,6 @@ namespace rubinius { class Object; class Park; class Primitives; - class SharedState; class String; class Symbol; class SymbolTable; @@ -85,6 +83,8 @@ namespace rubinius { private: static const int cWaitLimit = 100; + Machine* _machine_; + UnwindInfoSet unwinds_; CallFrame* call_frame_; @@ -138,15 +138,14 @@ namespace rubinius { public: /* Data members */ - SharedState& shared; - memory::TypedRoot waiting_channel_; - memory::TypedRoot interrupted_exception_; + Channel* waiting_channel_; + Exception* interrupted_exception_; /// The Thread object for this VM state - memory::TypedRoot thread_; - memory::TypedRoot fiber_; + Thread* thread_; + Fiber* fiber_; /// Object that waits for inflation - memory::TypedRoot waiting_object_; + Object* waiting_object_; uint64_t start_time_; @@ -167,9 +166,7 @@ namespace rubinius { return id_; } - ThreadNexus* const thread_nexus() { - return shared.thread_nexus(); - } + ThreadNexus* const thread_nexus(); ThreadNexus::Phase thread_phase() { return thread_phase_.load(std::memory_order_acquire); @@ -247,11 +244,11 @@ namespace rubinius { void set_fiber(Fiber* fiber); Thread* thread() { - return thread_.get(); + return thread_; } Fiber* fiber() { - return fiber_.get(); + return fiber_; } void set_zombie(STATE); @@ -445,12 +442,10 @@ namespace rubinius { } Exception* interrupted_exception() const { - return interrupted_exception_.get(); + return interrupted_exception_; } - void clear_interrupted_exception() { - interrupted_exception_.set(cNil); - } + void clear_interrupted_exception(); memory::VariableRootBuffers& current_root_buffers(); @@ -462,9 +457,11 @@ namespace rubinius { public: /* Prototypes */ - VM(uint32_t id, SharedState& shared, const char* name = NULL); + VM(uint32_t id, Machine* machine, const char* name = NULL); ~VM(); + Machine* const machine(); + void bootstrap_class(STATE); void bootstrap_ontology(STATE); void bootstrap_symbol(STATE); diff --git a/machine/vm_thread_state.cpp b/machine/vm_thread_state.cpp index 2b0a09ef53..041261357c 100644 --- a/machine/vm_thread_state.cpp +++ b/machine/vm_thread_state.cpp @@ -9,15 +9,15 @@ namespace rubinius { VMThreadState::VMThreadState(VM* state) - : current_exception_(state, nil()) - , raise_value_(state, cNil) - , throw_dest_(state, cNil) - , destination_scope_(state, nil()) + : current_exception_(nil()) + , raise_value_(cNil) + , throw_dest_(cNil) + , destination_scope_(nil()) , raise_reason_(cNone) {} ThreadState* VMThreadState::state_as_object(STATE) { - if(raise_reason_ == cNone && current_exception_.get()->nil_p()) return nil(); + if(raise_reason_ == cNone && current_exception_->nil_p()) return nil(); ThreadState* thread_state = ThreadState::create(state); thread_state->raise_reason(state, Fixnum::from(raise_reason_)); @@ -30,33 +30,33 @@ namespace rubinius { void VMThreadState::set_state(STATE, ThreadState* thread_state) { raise_reason_ = (RaiseReason)thread_state->raise_reason()->to_native(); - current_exception_.set(thread_state->current_exception()); - raise_value_.set(thread_state->raise_value()); - destination_scope_.set(thread_state->destination_scope()); - throw_dest_.set(thread_state->throw_dest()); + current_exception_ = thread_state->current_exception(); + raise_value_ = thread_state->raise_value(); + destination_scope_ = thread_state->destination_scope(); + throw_dest_ = thread_state->throw_dest(); } void VMThreadState::set_state(VMThreadState* thread_state) { raise_reason_ = thread_state->raise_reason(); - current_exception_.set(thread_state->current_exception()); - raise_value_.set(thread_state->raise_value()); - destination_scope_.set(thread_state->destination_scope()); - throw_dest_.set(thread_state->throw_dest()); + current_exception_ = thread_state->current_exception(); + raise_value_ = thread_state->raise_value(); + destination_scope_ = thread_state->destination_scope(); + throw_dest_ = thread_state->throw_dest(); } void VMThreadState::clear() { - raise_value_.set(cNil); + raise_value_ = cNil; raise_reason_ = cNone; - destination_scope_.set(cNil); - throw_dest_.set(cNil); - current_exception_.set(cNil); + destination_scope_ = nil(); + throw_dest_ = cNil; + current_exception_ = nil(); } void VMThreadState::clear_break() { raise_reason_ = cNone; - raise_value_.set(cNil); - destination_scope_.set(cNil); - throw_dest_.set(cNil); + raise_value_ = cNil; + destination_scope_ = nil(); + throw_dest_ = cNil; } void VMThreadState::clear_return() { @@ -66,38 +66,38 @@ namespace rubinius { void VMThreadState::clear_raise() { clear_return(); - current_exception_.set(cNil); + current_exception_ = nil(); } void VMThreadState::raise_exception(Exception* exc) { raise_reason_ = cException; - current_exception_.set(exc); - destination_scope_.set(cNil); + current_exception_ = exc; + destination_scope_ = nil(); } void VMThreadState::raise_return(Object* value, VariableScope* dest) { raise_reason_ = cReturn; - raise_value_.set(value); - destination_scope_.set(dest); + raise_value_ = value; + destination_scope_ = nil(); } void VMThreadState::raise_break(Object* value, VariableScope* dest) { raise_reason_ = cBreak; - raise_value_.set(value); - destination_scope_.set(dest); + raise_value_ = value; + destination_scope_ = nil(); } void VMThreadState::raise_exit(Object* code) { raise_reason_ = cExit; - raise_value_.set(code); - destination_scope_.set(cNil); + raise_value_ = code; + destination_scope_ = nil(); } void VMThreadState::raise_throw(Object* dest, Object* value) { raise_reason_ = cCatchThrow; - raise_value_.set(value); - throw_dest_.set(dest); - current_exception_.set(cNil); + raise_value_ = value; + throw_dest_ = dest; + current_exception_ = nil(); } void VMThreadState::raise_thread_kill() { @@ -107,4 +107,11 @@ namespace rubinius { void VMThreadState::raise_fiber_cancel() { raise_reason_ = cFiberCancel; } + + void VMThreadState::gc_scan(STATE, std::function f) { + f(state, reinterpret_cast(¤t_exception_)); + f(state, reinterpret_cast(&raise_value_)); + f(state, reinterpret_cast(&throw_dest_)); + f(state, reinterpret_cast(&destination_scope_)); + } } diff --git a/machine/vm_thread_state.hpp b/machine/vm_thread_state.hpp index 513baf2b1a..c3b2740224 100644 --- a/machine/vm_thread_state.hpp +++ b/machine/vm_thread_state.hpp @@ -2,7 +2,7 @@ #define RBX_THREAD_STATE_HPP #include "raise_reason.hpp" -#include "memory/root.hpp" +#include #include namespace rubinius { @@ -13,25 +13,25 @@ namespace rubinius { class ThreadState; class VMThreadState { - memory::TypedRoot current_exception_; - memory::TypedRoot raise_value_; - memory::TypedRoot throw_dest_; - memory::TypedRoot destination_scope_; + Exception* current_exception_; + Object* raise_value_; + Object* throw_dest_; + VariableScope* destination_scope_; RaiseReason raise_reason_; public: VMThreadState(VM* state); Exception* current_exception() { - return current_exception_.get(); + return current_exception_; } void set_current_exception(Exception* exc) { - current_exception_.set(reinterpret_cast(exc)); + current_exception_ = exc; } Object* raise_value() const { - return raise_value_.get(); + return raise_value_; } RaiseReason raise_reason() const { @@ -39,11 +39,11 @@ namespace rubinius { } VariableScope* destination_scope() const { - return destination_scope_.get(); + return destination_scope_; } Object* throw_dest() const { - return throw_dest_.get(); + return throw_dest_; } void clear_break(); @@ -62,6 +62,8 @@ namespace rubinius { void raise_throw(Object* dest, Object* value); void raise_thread_kill(); void raise_fiber_cancel(); + + void gc_scan(STATE, std::function f); }; }; diff --git a/rakelib/vm.rake b/rakelib/vm.rake index 4a15b1df83..0950b29532 100644 --- a/rakelib/vm.rake +++ b/rakelib/vm.rake @@ -104,7 +104,6 @@ field_extract_headers = %w[ machine/class/thread_state.hpp machine/class/jit.hpp machine/class/code_db.hpp - machine/class/diagnostics.hpp machine/class/trie.hpp machine/class/unwind_site.hpp machine/class/prediction.hpp