Skip to content

Commit

Permalink
Showing 21 changed files with 134 additions and 122 deletions.
4 changes: 4 additions & 0 deletions machine/builtin/exception.cpp
Original file line number Diff line number Diff line change
@@ -136,6 +136,10 @@ namespace rubinius {
state->raise_exception(exc);
}

void Exception::raise_deadlock_error(STATE, const char* reason) {
RubyException::raise(Exception::make_deadlock_error(state, reason), true);
}

Exception* Exception::make_frozen_exception(STATE, Object* obj) {
std::ostringstream msg;
msg << "can't modify frozen instance of ";
1 change: 1 addition & 0 deletions machine/builtin/exception.hpp
Original file line number Diff line number Diff line change
@@ -85,6 +85,7 @@ namespace rubinius {
NORETURN(static void raise_errno_wait_writable(STATE, int error));
NORETURN(static void raise_errno_error(STATE, const char* reason = NULL,
int ern = 0, const char* entity = 0));
NORETURN(static void raise_deadlock_error(STATE, const char* reason));

static Exception* make_lje(STATE);

2 changes: 1 addition & 1 deletion machine/builtin/fiber.cpp
Original file line number Diff line number Diff line change
@@ -226,7 +226,7 @@ namespace rubinius {
vm->set_suspended();
}

vm->unmanaged_phase();
vm->unmanaged_phase(state);

state->shared().report_profile(state);

44 changes: 22 additions & 22 deletions machine/builtin/native_function.cpp
Original file line number Diff line number Diff line change
@@ -313,7 +313,7 @@ namespace rubinius {

State* state = env->state();

state->vm()->managed_phase();
state->vm()->managed_phase(state);

Array* args = Array::create(state, stub->arg_count);
OnStack<1> os(state, args);
@@ -543,7 +543,7 @@ namespace rubinius {
break;
}

state->vm()->unmanaged_phase();
state->vm()->unmanaged_phase(state);
}


@@ -987,104 +987,104 @@ namespace rubinius {
env->set_current_call_frame(state->vm()->call_frame());

state->vm()->interrupt_with_signal();
state->vm()->unmanaged_phase();
state->vm()->unmanaged_phase(state);

switch(ffi_data_local->ret_info.type) {
case RBX_FFI_TYPE_CHAR: {
ffi_arg result = 0;
ffi_call(cif, FFI_FN(ffi_data_local->ep), &result, values);
state->vm()->managed_phase();
state->vm()->managed_phase(state);
ret = Fixnum::from((native_int)result);
break;
}
case RBX_FFI_TYPE_UCHAR: {
ffi_arg result = 0;
ffi_call(cif, FFI_FN(ffi_data_local->ep), &result, values);
state->vm()->managed_phase();
state->vm()->managed_phase(state);
ret = Fixnum::from((native_int)result);
break;
}
case RBX_FFI_TYPE_BOOL: {
ffi_arg result = 0;
ffi_call(cif, FFI_FN(ffi_data_local->ep), &result, values);
state->vm()->managed_phase();
state->vm()->managed_phase(state);
ret = RBOOL(result);
break;
}
case RBX_FFI_TYPE_SHORT: {
ffi_arg result = 0;
ffi_call(cif, FFI_FN(ffi_data_local->ep), &result, values);
state->vm()->managed_phase();
state->vm()->managed_phase(state);
ret = Fixnum::from((native_int)result);
break;
}
case RBX_FFI_TYPE_USHORT: {
ffi_arg result = 0;
ffi_call(cif, FFI_FN(ffi_data_local->ep), &result, values);
state->vm()->managed_phase();
state->vm()->managed_phase(state);
ret = Fixnum::from((native_int)result);
break;
}
case RBX_FFI_TYPE_INT: {
ffi_arg result = 0;
ffi_call(cif, FFI_FN(ffi_data_local->ep), &result, values);
state->vm()->managed_phase();
state->vm()->managed_phase(state);
ret = Integer::from(state, (native_int)result);
break;
}
case RBX_FFI_TYPE_UINT: {
ffi_arg result = 0;
ffi_call(cif, FFI_FN(ffi_data_local->ep), &result, values);
state->vm()->managed_phase();
state->vm()->managed_phase(state);
ret = Integer::from(state, (unsigned int)result);
break;
}
case RBX_FFI_TYPE_LONG: {
long result = 0;
ffi_call(cif, FFI_FN(ffi_data_local->ep), &result, values);
state->vm()->managed_phase();
state->vm()->managed_phase(state);
ret = Integer::from(state, result);
break;
}
case RBX_FFI_TYPE_ULONG: {
unsigned long result = 0;
ffi_call(cif, FFI_FN(ffi_data_local->ep), &result, values);
state->vm()->managed_phase();
state->vm()->managed_phase(state);
ret = Integer::from(state, result);
break;
}
case RBX_FFI_TYPE_FLOAT: {
float result = 0.0;
ffi_call(cif, FFI_FN(ffi_data_local->ep), &result, values);
state->vm()->managed_phase();
state->vm()->managed_phase(state);
ret = Float::create(state, (double)result);
break;
}
case RBX_FFI_TYPE_DOUBLE: {
double result = 0.0;
ffi_call(cif, FFI_FN(ffi_data_local->ep), &result, values);
state->vm()->managed_phase();
state->vm()->managed_phase(state);
ret = Float::create(state, result);
break;
}
case RBX_FFI_TYPE_LONG_LONG: {
long long result = 0;
ffi_call(cif, FFI_FN(ffi_data_local->ep), &result, values);
state->vm()->managed_phase();
state->vm()->managed_phase(state);
ret = Integer::from(state, result);
break;
}
case RBX_FFI_TYPE_ULONG_LONG: {
unsigned long long result = 0;
ffi_call(cif, FFI_FN(ffi_data_local->ep), &result, values);
state->vm()->managed_phase();
state->vm()->managed_phase(state);
ret = Integer::from(state, result);
break;
}
case RBX_FFI_TYPE_PTR: {
void* result = NULL;
ffi_call(cif, FFI_FN(ffi_data_local->ep), &result, values);
state->vm()->managed_phase();
state->vm()->managed_phase(state);
if(result == NULL) {
ret = cNil;
} else {
@@ -1096,7 +1096,7 @@ namespace rubinius {
ffi_arg result = 0;
ffi_call(cif, FFI_FN(ffi_data_local->ep), &result, values);

state->vm()->managed_phase();
state->vm()->managed_phase(state);

Array* ary = Array::create(state, 1);
ary->set(state, 0, Integer::from(state, (native_int)result));
@@ -1107,7 +1107,7 @@ namespace rubinius {
case RBX_FFI_TYPE_CALLBACK: {
void* result = NULL;
ffi_call(cif, FFI_FN(ffi_data_local->ep), &result, values);
state->vm()->managed_phase();
state->vm()->managed_phase(state);
if(result == NULL) {
ret = cNil;
} else {
@@ -1126,7 +1126,7 @@ namespace rubinius {
case RBX_FFI_TYPE_STRING: {
char* result = NULL;
ffi_call(cif, FFI_FN(ffi_data_local->ep), &result, values);
state->vm()->managed_phase();
state->vm()->managed_phase(state);
if(result == NULL) {
ret = cNil;
} else {
@@ -1141,7 +1141,7 @@ namespace rubinius {
Object* p = cNil;

ffi_call(cif, FFI_FN(ffi_data_local->ep), &result, values);
state->vm()->managed_phase();
state->vm()->managed_phase(state);

if(result) {
s = String::create(state, result);
@@ -1159,7 +1159,7 @@ namespace rubinius {
case RBX_FFI_TYPE_VOID: {
ffi_arg result = 0;
ffi_call(cif, FFI_FN(ffi_data_local->ep), &result, values);
state->vm()->managed_phase();
state->vm()->managed_phase(state);
ret = cNil;
break;
}
15 changes: 9 additions & 6 deletions machine/builtin/system.cpp
Original file line number Diff line number Diff line change
@@ -388,13 +388,14 @@ namespace rubinius {
}

static int fork_exec(STATE, int errors_fd) {
state->vm()->thread_nexus()->waiting_phase(state->vm());
state->vm()->thread_nexus()->waiting_phase(state, state->vm());
std::lock_guard<std::mutex> guard(state->vm()->thread_nexus()->process_mutex());

state->shared().machine_threads()->before_fork_exec(state);
state->memory()->set_interrupt();

ThreadNexus::LockStatus status = state->vm()->thread_nexus()->fork_lock(state->vm());
ThreadNexus::LockStatus status =
state->vm()->thread_nexus()->fork_lock(state, state->vm());

// If execvp() succeeds, we'll read EOF and know.
fcntl(errors_fd, F_SETFD, FD_CLOEXEC);
@@ -715,7 +716,7 @@ namespace rubinius {
}

Object* System::vm_exec(STATE, String* path, Array* args) {
state->vm()->thread_nexus()->waiting_phase(state->vm());
state->vm()->thread_nexus()->waiting_phase(state, state->vm());
std::lock_guard<std::mutex> guard(state->vm()->thread_nexus()->process_mutex());

/* Setting up the command and arguments may raise an exception so do it
@@ -739,7 +740,8 @@ namespace rubinius {

state->shared().machine_threads()->before_exec(state);

ThreadNexus::LockStatus status = state->vm()->thread_nexus()->lock(state->vm());
ThreadNexus::LockStatus status =
state->vm()->thread_nexus()->lock(state, state->vm());

void* old_handlers[NSIG];

@@ -873,13 +875,14 @@ namespace rubinius {
// TODO: Windows
return force_as<Fixnum>(Primitives::failure());
#else
state->vm()->thread_nexus()->waiting_phase(state->vm());
state->vm()->thread_nexus()->waiting_phase(state, state->vm());
std::lock_guard<std::mutex> guard(state->vm()->thread_nexus()->process_mutex());

state->shared().machine_threads()->before_fork(state);
state->memory()->set_interrupt();

ThreadNexus::LockStatus status = state->vm()->thread_nexus()->fork_lock(state->vm());
ThreadNexus::LockStatus status =
state->vm()->thread_nexus()->fork_lock(state, state->vm());

int pid = ::fork();

10 changes: 5 additions & 5 deletions machine/builtin/thread.cpp
Original file line number Diff line number Diff line change
@@ -301,7 +301,7 @@ namespace rubinius {
}

Object* Thread::main_thread(STATE) {
state->vm()->managed_phase();
state->vm()->managed_phase(state);

std::string& runtime = state->shared().env()->runtime_path();

@@ -369,7 +369,7 @@ namespace rubinius {

NativeMethod::init_thread(state);

state->vm()->managed_phase();
state->vm()->managed_phase(state);

Object* value = vm->thread()->function()(state);
vm->set_call_frame(NULL);
@@ -397,7 +397,7 @@ namespace rubinius {
logger::write("thread: exit: %s %fs", vm->name().c_str(), vm->run_time());
}

vm->unmanaged_phase();
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());
@@ -513,11 +513,11 @@ namespace rubinius {
Thread* self = this;
OnStack<2> os(state, self, timeout);

state->vm()->unmanaged_phase();
state->vm()->unmanaged_phase(state);

{
utilities::thread::Mutex::LockGuard guard(self->join_lock_);
state->vm()->managed_phase();
state->vm()->managed_phase(state);
atomic::memory_barrier();

if(self->alive()->true_p()) {
4 changes: 2 additions & 2 deletions machine/capi/thread.cpp
Original file line number Diff line number Diff line change
@@ -228,11 +228,11 @@ extern "C" {

State* state = env->state();
ENTER_CAPI(state);
state->vm()->managed_phase();
state->vm()->managed_phase(state);

void* ret = (*func)(data);

env->state()->vm()->unmanaged_phase();
env->state()->vm()->unmanaged_phase(state);
LEAVE_CAPI(env->state());

return ret;
2 changes: 1 addition & 1 deletion machine/diagnostics.cpp
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ namespace rubinius {
}

void Diagnostics::run(STATE) {
state->vm()->unmanaged_phase();
state->vm()->unmanaged_phase(state);

while(!thread_exit_) {
DiagnosticsData* data = 0;
4 changes: 2 additions & 2 deletions machine/environment.cpp
Original file line number Diff line number Diff line change
@@ -566,7 +566,7 @@ namespace rubinius {

shared->finalizer()->dispose(state);

shared->thread_nexus()->lock(state->vm());
shared->thread_nexus()->lock(state, state->vm());

shared->finalizer()->finish(state);

@@ -724,7 +724,7 @@ namespace rubinius {

shared->set_initialized();

state->vm()->managed_phase();
state->vm()->managed_phase(state);

TypeInfo::auto_learn_fields(state);

2 changes: 1 addition & 1 deletion machine/jit.cpp
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ namespace rubinius {
}

void JIT::run(STATE) {
state->vm()->unmanaged_phase();
state->vm()->unmanaged_phase(state);

while(!thread_exit_) {
CompileRequest* request = 0;
2 changes: 2 additions & 0 deletions machine/logger.hpp
Original file line number Diff line number Diff line change
@@ -31,6 +31,8 @@ namespace rubinius {
void unlock();
void close();

typedef void (*PrintFunction)(const char* message, ...);

void write(const char* message, ...);
void fatal(const char* message, ...);
void error(const char* message, ...);
2 changes: 1 addition & 1 deletion machine/machine_threads.cpp
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ namespace rubinius {
const_cast<RBX_DTRACE_CHAR_P>(vm->name().c_str()), vm->thread_id(), 1);

vm->set_call_frame(NULL);
vm->unmanaged_phase();
vm->unmanaged_phase(state);

vm->set_zombie(state);

6 changes: 3 additions & 3 deletions machine/memory/immix_marker.cpp
Original file line number Diff line number Diff line change
@@ -61,13 +61,13 @@ namespace memory {
}

void ImmixMarker::run(STATE) {
state->vm()->managed_phase();
state->vm()->managed_phase(state);

while(!thread_exit_) {
timer::StopWatch<timer::milliseconds> timer(
state->vm()->metrics().gc.immix_concurrent_ms);

state->shared().thread_nexus()->blocking_phase(state->vm());
state->shared().thread_nexus()->blocking_phase(state, state->vm());

while(immix_->process_mark_stack(immix_->memory()->interrupt_p())) {
if(thread_exit_ || immix_->memory()->collect_full_p()) {
@@ -80,7 +80,7 @@ namespace memory {
immix_->memory()->reset_interrupt();
}

state->shared().thread_nexus()->blocking_phase(state->vm());
state->shared().thread_nexus()->blocking_phase(state, state->vm());
}

if(thread_exit_) break;
2 changes: 1 addition & 1 deletion machine/metrics.cpp
Original file line number Diff line number Diff line change
@@ -539,7 +539,7 @@ namespace rubinius {
}

void Metrics::run(STATE) {
state->vm()->unmanaged_phase();
state->vm()->unmanaged_phase(state);

timer_->set(interval_);

6 changes: 3 additions & 3 deletions machine/signal.cpp
Original file line number Diff line number Diff line change
@@ -186,7 +186,7 @@ namespace rubinius {
}

void SignalThread::run(STATE) {
state->vm()->unmanaged_phase();
state->vm()->unmanaged_phase(state);

#ifndef RBX_WINDOWS
sigset_t set;
@@ -242,13 +242,13 @@ namespace rubinius {
state->shared().env()->halt(state, exit_code_);
}

void SignalThread::print_machine_info(PrintFunction function) {
void SignalThread::print_machine_info(logger::PrintFunction function) {
function("node info: %s %s", machine_info.nodename, machine_info.version);
}

#define RBX_PROCESS_INFO_LEN 256

void SignalThread::print_process_info(PrintFunction function) {
void SignalThread::print_process_info(logger::PrintFunction function) {
const char* llvm_version;
const char* jit_status;

7 changes: 3 additions & 4 deletions machine/signal.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef RBX_SIGNAL_HPP
#define RBX_SIGNAL_HPP

#include "logger.hpp"
#include "memory/root.hpp"

#include "util/thread.hpp"
@@ -83,10 +84,8 @@ namespace rubinius {

void print_backtraces();

typedef void (*PrintFunction)(const char* message, ...);

void print_machine_info(PrintFunction function);
void print_process_info(PrintFunction function);
void print_machine_info(logger::PrintFunction function);
void print_process_info(logger::PrintFunction function);
};
}

2 changes: 1 addition & 1 deletion machine/test/test.hpp
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ class VMTest {
vm->shared.set_initialized();
vm->shared.set_root_vm(vm);

vm->managed_phase();
vm->managed_phase(state);

State state(vm);

69 changes: 36 additions & 33 deletions machine/thread_nexus.cpp
Original file line number Diff line number Diff line change
@@ -11,33 +11,32 @@

#include "instruments/timing.hpp"

#include <ostream>
#include <string>
#include <time.h>

namespace rubinius {
void ThreadNexus::blocking_phase(VM* vm) {
spinning_lock(vm, [vm]{ vm->set_thread_phase(eBlocking); });
void ThreadNexus::blocking_phase(STATE, VM* vm) {
spinning_lock(state, vm, [vm]{ vm->set_thread_phase(eBlocking); });
}

void ThreadNexus::managed_phase(VM* vm) {
spinning_lock(vm, [vm]{ vm->set_thread_phase(eManaged); });
void ThreadNexus::managed_phase(STATE, VM* vm) {
spinning_lock(state, vm, [vm]{ vm->set_thread_phase(eManaged); });
}

void ThreadNexus::unmanaged_phase(VM* vm) {
void ThreadNexus::unmanaged_phase(STATE, VM* vm) {
vm->set_thread_phase(eUnmanaged);
}

void ThreadNexus::waiting_phase(VM* vm) {
void ThreadNexus::waiting_phase(STATE, VM* vm) {
vm->set_thread_phase(eWaiting);
}

bool ThreadNexus::blocking_p(VM* vm) {
atomic::memory_barrier();
return (vm->thread_phase() & eBlocking) == eBlocking;
}

bool ThreadNexus::yielding_p(VM* vm) {
atomic::memory_barrier();

int phase = static_cast<int>(vm->thread_phase());

return (phase & cYieldingPhase) == cYieldingPhase;
@@ -128,36 +127,40 @@ namespace rubinius {
return "cUnknown";
}

void ThreadNexus::list_threads() {
void ThreadNexus::list_threads(logger::PrintFunction function) {
for(ThreadList::iterator i = threads_.begin();
i != threads_.end();
++i)
{
if(VM* other_vm = (*i)->as_vm()) {
logger::fatal("thread %d: %s, %s",
function("thread %d: %s, %s",
other_vm->thread_id(), other_vm->name().c_str(), phase_name(other_vm));
}
}
}

void ThreadNexus::detect_deadlock(uint64_t nanoseconds, uint64_t limit, VM* vm) {
void ThreadNexus::detect_deadlock(STATE, uint64_t nanoseconds, uint64_t limit, VM* vm) {
if(nanoseconds > limit) {
logger::fatal("thread nexus: thread will not yield: %s, %s",
logger::error("thread nexus: thread will not yield: %s, %s",
vm->name().c_str(), phase_name(vm));

list_threads();
list_threads(logger::error);

std::ostringstream msg;
msg << "thread will not yield: " << vm->name().c_str() << phase_name(vm);

rubinius::abort();
Exception::raise_deadlock_error(state, msg.str().c_str());
}
}

void ThreadNexus::detect_deadlock(uint64_t nanoseconds, uint64_t limit) {
void ThreadNexus::detect_deadlock(STATE, uint64_t nanoseconds, uint64_t limit) {
if(nanoseconds > limit) {
logger::fatal("thread nexus: unable to lock, possible deadlock");
logger::error("thread nexus: unable to lock, possible deadlock");

list_threads();
list_threads(logger::error);

rubinius::abort();
Exception::raise_deadlock_error(state,
"thread nexus: unable to lock, possible deadlock");
}
}

@@ -178,8 +181,8 @@ namespace rubinius {
return ns;
}

ThreadNexus::LockStatus ThreadNexus::fork_lock(VM* vm) {
waiting_phase(vm);
ThreadNexus::LockStatus ThreadNexus::fork_lock(STATE, VM* vm) {
waiting_phase(state, vm);

/* Preserve the state of the phase_flag_ in situations where we have the
* entire system serialized.
@@ -200,7 +203,7 @@ namespace rubinius {

ns += delay();

detect_deadlock(ns, cLockLimit);
detect_deadlock(state, ns, cLockLimit);

id = 0;
}
@@ -209,10 +212,10 @@ namespace rubinius {
set_stop();

ns = 0;
while(!try_checkpoint(vm)) {
while(!try_checkpoint(state, vm)) {
ns += delay();

detect_deadlock(ns, cLockLimit);
detect_deadlock(state, ns, cLockLimit);
}

/* Lock and hold the waiting_mutex to prevent any other thread from
@@ -222,7 +225,7 @@ namespace rubinius {
while(!waiting_mutex_.try_lock()) {
ns += delay();

detect_deadlock(ns, cLockLimit);
detect_deadlock(state, ns, cLockLimit);
}

/* Hold the logger lock so that the multi-process semaphore that the
@@ -232,7 +235,7 @@ namespace rubinius {
while(!logger::try_lock()) {
ns += delay();

detect_deadlock(ns, cLockLimit);
detect_deadlock(state, ns, cLockLimit);
}

return to_lock_status(held);
@@ -249,7 +252,7 @@ namespace rubinius {
}
}

bool ThreadNexus::try_checkpoint(VM* vm) {
bool ThreadNexus::try_checkpoint(STATE, VM* vm) {
timer::StopWatch<timer::nanoseconds> timer(
vm->metrics().lock.stop_the_world_ns);

@@ -273,15 +276,15 @@ namespace rubinius {

ns += delay();

detect_deadlock(ns, cLockLimit, other_vm);
detect_deadlock(state, ns, cLockLimit, other_vm);
}
}
}

return true;
}

void ThreadNexus::checkpoint(VM* vm) {
void ThreadNexus::checkpoint(STATE, VM* vm) {
timer::StopWatch<timer::nanoseconds> timer(
vm->metrics().lock.stop_the_world_ns);

@@ -303,13 +306,13 @@ namespace rubinius {

ns += delay();

detect_deadlock(ns, cLockLimit, other_vm);
detect_deadlock(state, ns, cLockLimit, other_vm);
}
}
}
}

bool ThreadNexus::waiting_lock(VM* vm) {
bool ThreadNexus::waiting_lock(STATE, VM* vm) {
uint32_t id = 0;

vm->set_thread_phase(eWaiting);
@@ -336,7 +339,7 @@ namespace rubinius {
return false;
}

void ThreadNexus::spinning_lock(VM* vm, std::function<void ()> f) {
void ThreadNexus::spinning_lock(STATE, VM* vm, std::function<void ()> f) {
uint32_t id = 0;
int spin = 0;
bool held = false;
@@ -356,7 +359,7 @@ namespace rubinius {
if(++spin > cSpinLimit) {
ns += delay();

detect_deadlock(ns, cLockLimit);
detect_deadlock(state, ns, cLockLimit);
}

id = 0;
40 changes: 20 additions & 20 deletions machine/thread_nexus.hpp
Original file line number Diff line number Diff line change
@@ -103,44 +103,44 @@ namespace rubinius {
stop_.store(false, std::memory_order_release);
}

void blocking_phase(VM* vm);
void managed_phase(VM* vm);
void unmanaged_phase(VM* vm);
void waiting_phase(VM* vm);
void blocking_phase(STATE, VM* vm);
void managed_phase(STATE, VM* vm);
void unmanaged_phase(STATE, VM* vm);
void waiting_phase(STATE, VM* vm);

bool blocking_p(VM* vm);
bool yielding_p(VM* vm);

void yield(VM* vm) {
void yield(STATE, VM* vm) {
while(stop_p()) {
waiting_phase(vm);
waiting_phase(state, vm);

{
std::unique_lock<std::mutex> lk(waiting_mutex_);
waiting_condition_.wait(lk,
[this]{ return !stop_.load(std::memory_order_acquire); });
}

managed_phase(vm);
managed_phase(state, vm);
}
}

bool waiting_lock(VM* vm);
void spinning_lock(VM* vm, std::function<void ()> f);
bool waiting_lock(STATE, VM* vm);
void spinning_lock(STATE, VM* vm, std::function<void ()> f);

LockStatus fork_lock(VM* vm);
LockStatus fork_lock(STATE, VM* vm);
void fork_unlock(LockStatus status);

void check_stop(VM* vm, std::function<void ()> f) {
void check_stop(STATE, VM* vm, std::function<void ()> f) {
while(stop_p()) {
spinning_lock(vm, [&, this]{ f(); unset_stop(); });
spinning_lock(state, vm, [&, this]{ f(); unset_stop(); });
}
}

LockStatus lock(VM* vm) {
bool held = waiting_lock(vm);
LockStatus lock(STATE, VM* vm) {
bool held = waiting_lock(state, vm);
set_stop();
checkpoint(vm);
checkpoint(state, vm);
unset_stop();
return to_lock_status(held);
}
@@ -150,14 +150,14 @@ namespace rubinius {
phase_flag_ = 0;
}

bool try_checkpoint(VM* vm);
void checkpoint(VM* vm);
bool try_checkpoint(STATE, VM* vm);
void checkpoint(STATE, VM* vm);

uint64_t delay();
void detect_deadlock(uint64_t nanoseconds, uint64_t limit, VM* vm);
void detect_deadlock(uint64_t nanoseconds, uint64_t limit);
void detect_deadlock(STATE, uint64_t nanoseconds, uint64_t limit, VM* vm);
void detect_deadlock(STATE, uint64_t nanoseconds, uint64_t limit);

void list_threads();
void list_threads(logger::PrintFunction function);

VM* new_vm(SharedState* shared, const char* name = NULL);
void delete_vm(VM* vm);
18 changes: 9 additions & 9 deletions machine/thread_phase.hpp
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ namespace rubinius {
LockPhase(STATE)
: state_(state)
{
status_ = state->vm()->thread_nexus()->lock(state->vm());
status_ = state->vm()->thread_nexus()->lock(state, state->vm());
}

~LockPhase() {
@@ -37,11 +37,11 @@ namespace rubinius {
BlockPhase(STATE)
: state_(state)
{
state->vm()->blocking_phase();
state->vm()->blocking_phase(state_);
}

~BlockPhase() {
state_->vm()->managed_phase();
state_->vm()->managed_phase(state_);
}
};

@@ -52,11 +52,11 @@ namespace rubinius {
ManagedPhase(STATE)
: state_(state)
{
state_->vm()->managed_phase();
state_->vm()->managed_phase(state_);
}

~ManagedPhase() {
state_->vm()->unmanaged_phase();
state_->vm()->unmanaged_phase(state_);
}

};
@@ -68,11 +68,11 @@ namespace rubinius {
UnmanagedPhase(STATE)
: state_(state)
{
state_->vm()->unmanaged_phase();
state_->vm()->unmanaged_phase(state_);
}

~UnmanagedPhase() {
state_->vm()->managed_phase();
state_->vm()->managed_phase(state_);
}
};

@@ -84,11 +84,11 @@ namespace rubinius {
LockWaiting(STATE, T& in_lock)
: lock_(in_lock)
{
state->vm()->thread_nexus()->waiting_phase(state->vm());
state->vm()->thread_nexus()->waiting_phase(state, state->vm());

lock_.lock();

state->vm()->thread_nexus()->managed_phase(state->vm());
state->vm()->thread_nexus()->managed_phase(state, state->vm());
}

~LockWaiting() {
14 changes: 7 additions & 7 deletions machine/vm.hpp
Original file line number Diff line number Diff line change
@@ -492,7 +492,7 @@ namespace rubinius {
void checkpoint(STATE) {
metrics().machine.checkpoints++;

thread_nexus_->check_stop(this, [this, state]{
thread_nexus_->check_stop(state, this, [this, state]{
metrics().machine.stops++;
collect_maybe(state);
});
@@ -506,16 +506,16 @@ namespace rubinius {
void blocking_suspend(STATE, metrics::metric& counter);
void sleeping_suspend(STATE, metrics::metric& counter);

void blocking_phase() {
thread_nexus_->blocking_phase(this);
void blocking_phase(STATE) {
thread_nexus_->blocking_phase(state, this);
}

void managed_phase() {
thread_nexus_->managed_phase(this);
void managed_phase(STATE) {
thread_nexus_->managed_phase(state, this);
}

void unmanaged_phase() {
thread_nexus_->unmanaged_phase(this);
void unmanaged_phase(STATE) {
thread_nexus_->unmanaged_phase(state, this);
}

void set_current_thread();

0 comments on commit f786d38

Please sign in to comment.