Skip to content

Commit

Permalink
Raise DeadlockError instead of abort().
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Jun 29, 2016
1 parent 3a80de6 commit f786d38
Show file tree
Hide file tree
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
Expand Up @@ -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 ";
Expand Down
1 change: 1 addition & 0 deletions machine/builtin/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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

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

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

Expand Down
44 changes: 22 additions & 22 deletions machine/builtin/native_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -543,7 +543,7 @@ namespace rubinius {
break;
}

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


Expand Down Expand Up @@ -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 {
Expand All @@ -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));
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down
15 changes: 9 additions & 6 deletions machine/builtin/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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];

Expand Down Expand Up @@ -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();

Expand Down
10 changes: 5 additions & 5 deletions machine/builtin/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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()) {
Expand Down
4 changes: 2 additions & 2 deletions machine/capi/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion machine/diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions machine/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -724,7 +724,7 @@ namespace rubinius {

shared->set_initialized();

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

TypeInfo::auto_learn_fields(state);

Expand Down
2 changes: 1 addition & 1 deletion machine/jit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions machine/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...);
Expand Down
2 changes: 1 addition & 1 deletion machine/machine_threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions machine/memory/immix_marker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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;
Expand Down
Loading

0 comments on commit f786d38

Please sign in to comment.