Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into mcjit
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed May 1, 2016
2 parents b70bcca + 0b306fb commit 4b16760
Show file tree
Hide file tree
Showing 32 changed files with 342 additions and 303 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
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: 5 additions & 0 deletions core/call_site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def misses
raise PrimitiveFailure, "CallSite#misses primitive failed"
end

def reset
Rubinius.primitive :call_site_reset
raise PrimitiveFailure, "CallSite#reset primitive failed"
end

def inspect
"#<#{self.class.name}:0x#{self.object_id.to_s(16)} name=#{@name} ip=#{ip} depth=#{depth} invokes=#{invokes} hits=#{hits} misses=#{misses}>"
end
Expand Down
5 changes: 0 additions & 5 deletions core/rubinius.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
28 changes: 10 additions & 18 deletions machine/builtin/block_environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,9 @@ 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;

Expand All @@ -452,28 +454,18 @@ namespace rubinius {

OnStack<2> os(state, env, mod);

// Check the stack and interrupts here rather than in the interpreter
// loop itself.
if(state->check_interrupts(state)) {
tooling::BlockEntry method(state, env, mod);
value = (*mcode->run)(state, mcode);
}
tooling::BlockEntry method(state, env, mod);
value = (*mcode->run)(state, mcode);
} else {
// Check the stack and interrupts here rather than in the interpreter
// loop itself.
if(state->check_interrupts(state)) {
value = (*mcode->run)(state, mcode);
}
}
#else
// Check the stack and interrupts here rather than in the interpreter
// loop itself.
if(state->check_interrupts(state)) {
value = (*mcode->run)(state, mcode);
}
#else
value = (*mcode->run)(state, mcode);
#endif

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

return value;
}
Expand Down
18 changes: 15 additions & 3 deletions machine/builtin/call_site.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,9 @@ namespace rubinius {
if(atomic::compare_and_swap(reinterpret_cast<void**>(updated_caches),
previous_caches, inline_caches))
{
if(previous_caches) delete[] previous_caches;
if(previous_caches) delete previous_caches;
} else {
delete[] inline_caches;
delete inline_caches;
}

return;
Expand Down Expand Up @@ -397,7 +397,7 @@ namespace rubinius {
execute(CallSite::dispatch);
cache_miss(CallSite::dispatch);

delete[] caches();
delete caches();
caches(NULL);

atomic::memory_barrier();
Expand Down Expand Up @@ -506,6 +506,18 @@ namespace rubinius {
return Integer::from(state, misses());
}

// Rubinius.primitive :call_site_reset
CallSite* reset(STATE) {
if(caches()) delete caches();

invokes(0);
execute(default_execute);
cache_miss(default_execute);
caches(NULL);

return this;
}

class Info : public TypeInfo {
public:
Info(object_type type)
Expand Down
6 changes: 3 additions & 3 deletions machine/builtin/channel.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,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 @@ -336,13 +334,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
Original file line number Diff line number Diff line change
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 @@ -738,7 +740,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 @@ -748,15 +750,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
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,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 @@ -777,7 +777,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 @@ -1085,19 +1085,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
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,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
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,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 @@ -369,9 +370,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
Loading

0 comments on commit 4b16760

Please sign in to comment.