Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Apr 30, 2016
2 parents 90db74d + 0b306fb commit 6dc84fb
Show file tree
Hide file tree
Showing 31 changed files with 318 additions and 294 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Expand Up @@ -4,7 +4,7 @@ GEM
daedalus-core (0.5.0)
rake (10.5.0)
redcard (1.1.0)
rubinius-ast (3.4)
rubinius-ast (3.5)
rubinius-bridge (2.2)
redcard (~> 1.0)
rubinius-code (3.0)
Expand Down
5 changes: 0 additions & 5 deletions core/rubinius.rb
Expand Up @@ -219,11 +219,6 @@ def self.thread_state
raise PrimitiveFailure, "Rubinius.thread_state primitive failed"
end

def self.check_interrupts
Rubinius.primitive :vm_check_interrupts
raise PrimitiveFailure, "Rubinius.check_interrupts primitive failed"
end

# Used to invoke a CompiledCode instance as a script body. Sets up the MAIN
# object as self and bypasses JIT'ing (because why JIT a script you only run
# once).
Expand Down
2 changes: 1 addition & 1 deletion gems_list.txt
Expand Up @@ -9,7 +9,7 @@ rake-10.5.0.gem
rb-readline-0.5.3.gem
rdoc-4.2.2.gem
redcard-1.1.0.gem
rubinius-ast-3.4.gem
rubinius-ast-3.5.gem
rubinius-bridge-2.2.gem
rubinius-code-3.0.gem
rubinius-compiler-3.3.gem
Expand Down
14 changes: 7 additions & 7 deletions machine/builtin/block_environment.cpp
Expand Up @@ -444,17 +444,17 @@ namespace rubinius {
call_frame->flags = invocation.flags | CallFrame::cMultipleScopes
| CallFrame::cBlock;

state->vm()->push_call_frame(call_frame, previous_frame);
if(!state->vm()->push_call_frame(state, call_frame, previous_frame)) {
return NULL;
}

Object* value = NULL;

// Check the stack and interrupts here rather than in the interpreter
// loop itself.
if(state->check_interrupts(state)) {
value = (*mcode->run)(state, mcode);
}
value = (*mcode->run)(state, mcode);

state->vm()->pop_call_frame(previous_frame);
if(!state->vm()->pop_call_frame(state, previous_frame)) {
return NULL;
}

return value;
}
Expand Down
6 changes: 3 additions & 3 deletions machine/builtin/channel.cpp
Expand Up @@ -134,7 +134,7 @@ namespace rubinius {
ts.tv_nsec = nano % NANOSECONDS;
}

if(!state->check_async(state)) {
if(state->vm()->thread_interrupted_p(state)) {
return NULL;
}

Expand All @@ -161,7 +161,7 @@ namespace rubinius {

// or there are values available.
if(self->semaphore_count() > 0 || !self->value()->empty_p()) break;
if(!state->check_async(state)) {
if(state->vm()->thread_interrupted_p(state)) {
exception = true;
break;
}
Expand All @@ -173,7 +173,7 @@ namespace rubinius {
self->unpin();
self->_waiters_--;

if(exception || !state->check_async(state)) return NULL;
if(exception) return NULL;

if(self->semaphore_count() > 0) {
self->dec_semaphore_count();
Expand Down
9 changes: 7 additions & 2 deletions machine/builtin/fiber.cpp
Expand Up @@ -98,7 +98,7 @@ namespace rubinius {

// TODO: CallFrame: return from this function

assert(0 && "fatal start_on_stack error");
rubinius::bug("returning from Fiber::start_on_stack");
#else
rubinius::bug("Fibers not supported on this platform");
#endif
Expand Down Expand Up @@ -155,10 +155,15 @@ namespace rubinius {

cur = Fiber::current(state);

// TODO: clean up this and the following conditional.
if(state->vm()->thread_interrupted_p(state)) {
return NULL;
}

if(!cur->exception()->nil_p()) {
state->raise_exception(cur->exception());
cur->exception(state, nil<Exception>());
return 0;
return NULL;
}

Array* ret = cur->value();
Expand Down
8 changes: 2 additions & 6 deletions machine/builtin/fiber.hpp
Expand Up @@ -69,16 +69,12 @@ namespace rubinius {
return data()->machine();
}

void* stack_region() const {
return data()->stack_address();
}

void* stack_end() const {
void* stack_address() const {
return data()->stack_address();
}

void* stack_start() const {
return (void*)((uintptr_t)stack_region() + stack_size());
return (void*)((uintptr_t)stack_address() + stack_size());
}

int stack_size() const {
Expand Down
10 changes: 5 additions & 5 deletions machine/builtin/io.cpp
Expand Up @@ -288,7 +288,7 @@ namespace rubinius {

if(events == -1) {
if(errno == EAGAIN || errno == EINTR) {
if(!state->check_async(state)) return NULL;
if(state->vm()->thread_interrupted_p(state)) return NULL;

// Recalculate the limit and go again.
if(maybe_limit) {
Expand Down Expand Up @@ -678,7 +678,7 @@ namespace rubinius {

if(bytes_read == -1) {
if(errno == EAGAIN || errno == EINTR) {
if(!state->check_async(state)) {
if(state->vm()->thread_interrupted_p(state)) {
if(malloc_buf) free(malloc_buf);
return NULL;
}
Expand Down Expand Up @@ -967,7 +967,7 @@ namespace rubinius {

if(bytes_read == -1) {
if(errno == EINTR) {
if(!state->check_async(state)) return NULL;
if(state->vm()->thread_interrupted_p(state)) return NULL;
ensure_open(state);
goto retry;
} else {
Expand Down Expand Up @@ -1321,7 +1321,7 @@ namespace rubinius {

if(code == -1) {
if(errno == EAGAIN || errno == EINTR) {
if(!state->check_async(state)) return NULL;
if(state->vm()->thread_interrupted_p(state)) return NULL;
ensure_open(state);
goto retry;
}
Expand Down Expand Up @@ -1429,7 +1429,7 @@ namespace rubinius {
break;
case EAGAIN:
case EINTR:
if(!state->check_async(state)) return NULL;
if(state->vm()->thread_interrupted_p(state)) return NULL;
io->ensure_open(state);
goto retry;
default:
Expand Down
10 changes: 1 addition & 9 deletions machine/builtin/native_function.cpp
Expand Up @@ -308,8 +308,6 @@ namespace rubinius {
FFIData* stub = reinterpret_cast<FFIData*>(user_data);

bool destroy_vm = false;
int stack_address = 0;

if(!env) {
// TODO: fix this, the threads should *always* be set up correctly
// Apparently we're running in a new thread here, setup
Expand All @@ -318,13 +316,7 @@ namespace rubinius {

VM* vm = stub->shared->thread_nexus()->new_vm(stub->shared, "ruby.ffi");

// Detect the stack size and set it up in the VM object
size_t stack_size;
pthread_attr_t attrs;
pthread_attr_init(&attrs);
pthread_attr_getstacksize (&attrs, &stack_size);
pthread_attr_destroy(&attrs);
vm->set_root_stack(reinterpret_cast<uintptr_t>(&stack_address), stack_size);
vm->set_stack_bounds(THREAD_STACK_SIZE);

// Setup nativemethod handles into thread local
State state(vm);
Expand Down
15 changes: 8 additions & 7 deletions machine/builtin/native_method.cpp
Expand Up @@ -675,7 +675,9 @@ namespace rubinius {
env->set_current_native_frame(&nmf);

// Register the CallFrame, because we might GC below this.
state->vm()->push_call_frame(call_frame, previous_frame);
if(!state->vm()->push_call_frame(state, call_frame, previous_frame)) {
return NULL;
}

// Be sure to do this after installing nmf as the current
// native frame.
Expand Down Expand Up @@ -706,7 +708,7 @@ namespace rubinius {
} catch(const RubyException& exc) {
LEAVE_CAPI(state);

state->vm()->pop_call_frame(previous_frame);
state->vm()->pop_call_frame(state, previous_frame);
env->set_current_call_frame(saved_frame);
env->set_current_native_frame(nmf.previous());
ep.pop(env);
Expand All @@ -716,15 +718,14 @@ namespace rubinius {

LEAVE_CAPI(state);

state->vm()->pop_call_frame(previous_frame);
if(!state->vm()->pop_call_frame(state, previous_frame)) {
value = NULL;
}

env->set_current_call_frame(saved_frame);
env->set_current_native_frame(nmf.previous());
ep.pop(env);

// Handle any signals that occurred while the native method
// was running.
if(!state->check_async(state)) return NULL;

return value;
}

Expand Down
14 changes: 3 additions & 11 deletions machine/builtin/system.cpp
Expand Up @@ -656,7 +656,7 @@ namespace rubinius {
switch(errno) {
case EAGAIN:
case EINTR:
if(!state->check_async(state)) {
if(state->vm()->thread_interrupted_p(state)) {
close(output[0]);
return NULL;
}
Expand Down Expand Up @@ -782,7 +782,7 @@ namespace rubinius {
if(pid == -1) {
if(errno == ECHILD) return cFalse;
if(errno == EINTR) {
if(!state->check_async(state)) return NULL;
if(state->vm()->thread_interrupted_p(state)) return NULL;
goto retry;
}

Expand Down Expand Up @@ -1029,19 +1029,11 @@ namespace rubinius {
if(!state->park(state)) return NULL;
}

if(!state->check_async(state)) return NULL;
if(state->vm()->thread_interrupted_p(state)) return NULL;

return Fixnum::from(time(0) - start);
}

Object* System::vm_check_interrupts(STATE) {
if(state->check_async(state)) {
return cNil;
} else {
return NULL;
}
}

static inline double tv_to_dbl(struct timeval* tv) {
return (double)tv->tv_sec + ((double)tv->tv_usec / 1000000.0);
}
Expand Down
3 changes: 0 additions & 3 deletions machine/builtin/system.hpp
Expand Up @@ -147,9 +147,6 @@ namespace rubinius {
// Rubinius.primitive :vm_sleep
static Object* vm_sleep(STATE, Object* duration);

// Rubinius.primitive :vm_check_interrupts
static Object* vm_check_interrupts(STATE);

// Rubinius.primitive :vm_times
static Array* vm_times(STATE);

Expand Down
4 changes: 1 addition & 3 deletions machine/builtin/thread.cpp
Expand Up @@ -356,6 +356,7 @@ namespace rubinius {
VM* vm = reinterpret_cast<VM*>(ptr);
State state_obj(vm), *state = &state_obj;

vm->set_stack_bounds(THREAD_STACK_SIZE);
vm->set_current_thread();

RUBINIUS_THREAD_START(
Expand All @@ -367,9 +368,6 @@ namespace rubinius {
vm->name().c_str(), vm->thread->pid()->to_native(),
(unsigned int)thread_debug_self());

int stack_address = 0;
vm->set_root_stack(reinterpret_cast<uintptr_t>(&stack_address), THREAD_STACK_SIZE);

NativeMethod::init_thread(state);

state->vm()->become_managed();
Expand Down
20 changes: 10 additions & 10 deletions machine/capi/capi.cpp
Expand Up @@ -51,14 +51,17 @@ namespace rubinius {
return map[type];
}

bool capi_check_interrupts(STATE, void* stack_marker) {
if(!state->check_stack(state, stack_marker)) {
bool capi_check_interrupts(STATE) {
void* stack_address;

if(!state->vm()->check_stack(state, &stack_address)) {
return false;
}

if(unlikely(state->check_local_interrupts())) {
if(!state->process_async(state)) return false;
if(unlikely(state->vm()->check_local_interrupts())) {
return state->vm()->check_thread_raise_or_kill(state);
}

return true;
}

Expand Down Expand Up @@ -115,8 +118,7 @@ namespace rubinius {
Object** args, Object* block,
bool allow_private)
{
int stack_marker = 0;
if(!capi_check_interrupts(env->state(), &stack_marker)) {
if(!capi_check_interrupts(env->state())) {
env->current_ep()->return_to(env);
}

Expand Down Expand Up @@ -208,8 +210,7 @@ namespace rubinius {
Object* blk,
size_t arg_count, Object** arg_vals)
{
int stack_marker = 0;
if(!capi_check_interrupts(env->state(), &stack_marker)) {
if(!capi_check_interrupts(env->state())) {
env->current_ep()->return_to(env);
}

Expand Down Expand Up @@ -258,8 +259,7 @@ namespace rubinius {
VALUE capi_call_super_native(NativeMethodEnvironment* env,
size_t arg_count, Object** args)
{
int stack_marker = 0;
if(!capi_check_interrupts(env->state(), &stack_marker)) {
if(!capi_check_interrupts(env->state())) {
env->current_ep()->return_to(env);
}

Expand Down
4 changes: 2 additions & 2 deletions machine/capi/thread.cpp
Expand Up @@ -63,7 +63,7 @@ extern "C" {
ret = select(max, read, write, except, tvp);
}

bool ok = env->state()->check_async(env->state());
bool ok = !env->state()->vm()->thread_interrupted_p(env->state());

ENTER_CAPI(env->state());

Expand Down Expand Up @@ -199,7 +199,7 @@ extern "C" {
State* state = env->state();
void* ret = NULL;

if(!state->check_async(env->state())) {
if(state->vm()->thread_interrupted_p(state)) {
return ret;
}
if(ubf == RUBY_UBF_IO || ubf == RUBY_UBF_PROCESS) {
Expand Down

0 comments on commit 6dc84fb

Please sign in to comment.