Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5e104f483de0
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: fdc35398b81a
Choose a head ref
  • 2 commits
  • 9 files changed
  • 1 contributor

Commits on Jun 17, 2016

  1. Copy the full SHA
    745b599 View commit details
  2. Fixed VM tests.

    brixen committed Jun 17, 2016
    Copy the full SHA
    fdc3539 View commit details
5 changes: 4 additions & 1 deletion machine/builtin/exception.cpp
Original file line number Diff line number Diff line change
@@ -245,7 +245,10 @@ namespace rubinius {
}

void Exception::raise_fiber_error(STATE, const char* reason) {
RubyException::raise(make_exception(state, get_fiber_error(state), reason));
Exception* exc = make_exception(state, get_fiber_error(state), reason);
exc->locations(state, Location::from_call_stack(state, 0));

RubyException::raise(exc);
}

void Exception::raise_memory_error(STATE) {
98 changes: 59 additions & 39 deletions machine/builtin/fiber.cpp
Original file line number Diff line number Diff line change
@@ -57,6 +57,7 @@ namespace rubinius {
OnStack<1> os(state, fiber);

fiber->arguments(state, args.as_array(state));
fiber->function(Fiber::continue_fiber);

pthread_attr_t attrs;
pthread_attr_init(&attrs);
@@ -71,19 +72,23 @@ namespace rubinius {
// Wait for Fiber thread to start up and pause.
while(!fiber->vm()->wait_flag());

fiber->function(Fiber::continue_fiber);

return continue_fiber(state, fiber, args);
}

Object* Fiber::continue_fiber(STATE, Fiber* f, Arguments& args) {
Fiber* fiber = f;
OnStack<1> os(state, fiber);

fiber->value(state, unpack_arguments(state, args));
{
std::lock_guard<std::mutex> guard(fiber->vm()->wait_mutex());

fiber->value(state, unpack_arguments(state, args));

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

state->vm()->unmanaged_phase();
state->vm()->set_wait_flag(true);
state->vm()->thread()->vm()->set_current_fiber(fiber->vm());
}

while(fiber->vm()->wait_flag()) {
std::lock_guard<std::mutex> guard(fiber->vm()->wait_mutex());
@@ -92,18 +97,19 @@ namespace rubinius {

{
std::unique_lock<std::mutex> lk(state->vm()->wait_mutex());

// Through the worm hole...
while(!fiber->vm()->wait_flag()) {
state->vm()->wait_condition().wait(lk);
}
if(state->vm()->fiber()->status() != eTransfer) {
state->vm()->fiber()->status(eRunning);
}

// We're back...
state->vm()->set_wait_flag(false);
}

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

if(state->vm()->thread()->vm()->thread_state()->current_exception()->nil_p()) {
if(state->vm()->thread_state()->current_exception()->nil_p()) {
return fiber->value();
} else {
return NULL;
@@ -132,44 +138,49 @@ namespace rubinius {

NativeMethod::init_thread(state);

vm->set_wait_flag(true);

{
std::unique_lock<std::mutex> lk(vm->wait_mutex());

vm->set_wait_flag(true);

// Through the worm hole...
while(!vm->fiber()->resume_context()->wait_flag()) {
vm->wait_condition().wait(lk);
}

// We're back...
if(vm->fiber()->status() != eTransfer) {
vm->fiber()->status(eRunning);
}
vm->set_wait_flag(false);
}

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

Object* value = vm->fiber()->block()->send(state, G(sym_call),
vm->fiber()->arguments(), vm->fiber()->block());
vm->set_call_frame(NULL);

vm->fiber()->status(eDead);
{
std::lock_guard<std::mutex> guard(vm->fiber()->resume_context()->wait_mutex());

if(value) {
vm->fiber()->value(state, value);
} else {
vm->fiber()->resume_context()->thread_state()->set_state(vm->thread_state());
}

vm->fiber()->status(eDead);

VM* resume_context = 0;
vm->unmanaged_phase();
vm->fiber()->vm()->set_wait_flag(true);

if(value) {
vm->fiber()->value(state, value);
resume_context = vm->fiber()->resume_context();
} else {
vm->thread()->vm()->set_thread_state(vm->thread_state());
// Usurp whatever Fiber the Thread had invoked.
resume_context = vm->thread()->vm();
state->vm()->thread()->vm()->set_current_fiber(vm->fiber()->resume_context());
}

vm->unmanaged_phase();
vm->set_wait_flag(true);

while(resume_context->wait_flag()) {
std::lock_guard<std::mutex> guard(resume_context->wait_mutex());
resume_context->wait_condition().notify_one();
while(vm->fiber()->resume_context()->wait_flag()) {
std::lock_guard<std::mutex> guard(vm->fiber()->resume_context()->wait_mutex());
vm->fiber()->resume_context()->wait_condition().notify_one();
}

state->shared().report_profile(state);
@@ -207,6 +218,7 @@ namespace rubinius {
fiber->thread_name(state, String::create(state, vm->name().c_str()));
fiber->fiber_id(Fixnum::from(0));
fiber->status(eRunning);
fiber->function(Fiber::continue_fiber);

return fiber;
}
@@ -289,8 +301,8 @@ namespace rubinius {
Exception::raise_fiber_error(state, "attempt to resume root fiber");
}

status(eRunning);
resume_context(state->vm());
state->vm()->thread()->vm()->set_current_fiber(vm());

return _function_(state, this, args);
}
@@ -306,7 +318,6 @@ namespace rubinius {

status(eTransfer);
resume_context(state->vm()->thread()->vm());
state->vm()->thread()->vm()->set_current_fiber(vm());

return _function_(state, this, args);
}
@@ -321,34 +332,43 @@ namespace rubinius {
Exception::raise_fiber_error(state, "can't yield from transferred fiber");
}

fiber->value(state, unpack_arguments(state, args));
{
std::lock_guard<std::mutex> guard(fiber->resume_context()->wait_mutex());

fiber->value(state, unpack_arguments(state, args));
fiber->status(eYielding);

state->vm()->unmanaged_phase();
fiber->vm()->set_wait_flag(true);
state->vm()->unmanaged_phase();
fiber->vm()->set_wait_flag(true);

state->vm()->thread()->vm()->set_current_fiber(fiber->resume_context());
}

while(fiber->resume_context()->wait_flag()) {
std::lock_guard<std::mutex> guard(fiber->resume_context()->wait_mutex());
fiber->resume_context()->wait_condition().notify_one();
}

fiber->status(eYielding);
state->vm()->thread()->vm()->set_current_fiber(fiber->resume_context());

{
std::unique_lock<std::mutex> lk(state->vm()->wait_mutex());

// Through the worm hole...
while(!fiber->resume_context()->wait_flag()) {
state->vm()->wait_condition().wait(lk);
}
state->vm()->set_wait_flag(false);
}

if(fiber->status() != eTransfer) {
// We're back...
fiber->status(eRunning);
state->vm()->set_wait_flag(false);
}

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

return fiber->resume_context()->fiber()->value();
if(state->vm()->thread_state()->current_exception()->nil_p()) {
return fiber->value();
} else {
return NULL;
}
}

void Fiber::finalize(STATE, Fiber* fib) {
40 changes: 24 additions & 16 deletions machine/codegen/field_extract.rb
Original file line number Diff line number Diff line change
@@ -58,8 +58,9 @@ def output_call(str, call, args)
str << " ret = #{call}(#{args.join(', ')});\n"
str << " RUBINIUS_METHOD_PRIMITIVE_RETURN_HOOK(state, mod, args.name());\n"
str << " } catch(const RubyException& exc) {\n"
str << " exc.exception->locations(state,\n"
str << " Location::from_call_stack(state));\n"
str << " if(exc.exception->locations()->nil_p()) {\n"
str << " exc.exception->locations(state, Location::from_call_stack(state));\n"
str << " }\n"
str << " state->raise_exception(exc.exception);\n"
str << " RUBINIUS_METHOD_PRIMITIVE_RETURN_HOOK(state, mod, args.name());\n"
str << " return NULL;\n"
@@ -106,8 +107,9 @@ def generate_glue
str << " try {\n"
str << " ret = recv->#{@cpp_name}(state, exec, mod, args);\n"
str << " } catch(const RubyException& exc) {\n"
str << " exc.exception->locations(state,\n"
str << " Location::from_call_stack(state));\n"
str << " if(exc.exception->locations()->nil_p()) {\n"
str << " exc.exception->locations(state, Location::from_call_stack(state));\n"
str << " }\n"
str << " state->raise_exception(exc.exception);\n"
str << " return NULL;\n"
str << " }\n"
@@ -182,8 +184,9 @@ def generate_jit_stub
str << " try {\n"
str << " ret = self->#{@cpp_name}(#{args.join(', ')});\n"
str << " } catch(const RubyException& exc) {\n"
str << " exc.exception->locations(state,\n"
str << " Location::from_call_stack(state));\n"
str << " if(exc.exception->locations()->nil_p()) {\n"
str << " exc.exception->locations(state, Location::from_call_stack(state));\n"
str << " }\n"
str << " state->raise_exception(exc.exception);\n"
str << " return NULL;\n"
str << " }\n"
@@ -260,8 +263,9 @@ def generate_invoke_stub
str << " try {\n"
str << " ret = self->#{@cpp_name}(#{args.join(', ')});\n"
str << " } catch(const RubyException& exc) {\n"
str << " exc.exception->locations(state,\n"
str << " Location::from_call_stack(state));\n"
str << " if(exc.exception->locations()->nil_p()) {\n"
str << " exc.exception->locations(state, Location::from_call_stack(state));\n"
str << " }\n"
str << " state->raise_exception(exc.exception);\n"
str << " return NULL;\n"
str << " }\n"
@@ -288,8 +292,9 @@ def generate_glue
str << " try {\n"
str << " return #{@type}::#{@cpp_name}(state, exec, mod);\n"
str << " } catch(const RubyException& exc) {\n"
str << " exc.exception->locations(state,\n"
str << " Location::from_call_stack(state));\n"
str << " if(exc.exception->locations()->nil_p()) {\n"
str << " exc.exception->locations(state, Location::from_call_stack(state));\n"
str << " }\n"
str << " state->raise_exception(exc.exception);\n"
str << " return NULL;\n"
str << " }\n"
@@ -350,8 +355,9 @@ def generate_jit_stub
str << " try {\n"
str << " ret = #{@type}::#{@cpp_name}(#{args.join(', ')});\n"
str << " } catch(const RubyException& exc) {\n"
str << " exc.exception->locations(state,\n"
str << " Location::from_call_stack(state));\n"
str << " if(exc.exception->locations()->nil_p()) {\n"
str << " exc.exception->locations(state, Location::from_call_stack(state));\n"
str << " }\n"
str << " state->raise_exception(exc.exception);\n"
str << " return NULL;\n"
str << " }\n"
@@ -414,8 +420,9 @@ def generate_invoke_stub
str << " try {\n"
str << " ret = #{@type}::#{@cpp_name}(#{args.join(', ')});\n"
str << " } catch(const RubyException& exc) {\n"
str << " exc.exception->locations(state,\n"
str << " Location::from_call_stack(state));\n"
str << " if(exc.exception->locations()->nil_p()) {\n"
str << " exc.exception->locations(state, Location::from_call_stack(state));\n"
str << " }\n"
str << " state->raise_exception(exc.exception);\n"
str << " return NULL;\n"
str << " }\n"
@@ -466,8 +473,9 @@ def generate_glue
end
str << call
str << " } catch(const RubyException& exc) {\n"
str << " exc.exception->locations(state,\n"
str << " Location::from_call_stack(state));\n"
str << " if(exc.exception->locations()->nil_p()) {\n"
str << " exc.exception->locations(state, Location::from_call_stack(state));\n"
str << " }\n"
str << " state->raise_exception(exc.exception);\n"
str << " return NULL;\n"
str << " }\n"
20 changes: 12 additions & 8 deletions machine/instructions.cpp
Original file line number Diff line number Diff line change
@@ -116,8 +116,9 @@ Object* MachineCode::interpreter(STATE, MachineCode* const mcode) {
call_frame->scope->flush_to_heap(state);
return NULL;
} catch(const RubyException& exc) {
exc.exception->locations(state,
Location::from_call_stack(state));
if(exc.exception->locations()->nil_p()) {
exc.exception->locations(state, Location::from_call_stack(state));
}
state->raise_exception(exc.exception);
return NULL;
}
@@ -267,8 +268,9 @@ Object* MachineCode::uncommon_interpreter(STATE,
call_frame->scope->flush_to_heap(state);
return NULL;
} catch(const RubyException& exc) {
exc.exception->locations(state,
Location::from_call_stack(state));
if(exc.exception->locations()->nil_p()) {
exc.exception->locations(state, Location::from_call_stack(state));
}
state->raise_exception(exc.exception);
return NULL;
}
@@ -412,8 +414,9 @@ Object* MachineCode::debugger_interpreter(STATE, MachineCode* const mcode) {
call_frame->scope->flush_to_heap(state);
return NULL;
} catch(const RubyException& exc) {
exc.exception->locations(state,
Location::from_call_stack(state));
if(exc.exception->locations()->nil_p()) {
exc.exception->locations(state, Location::from_call_stack(state));
}
state->raise_exception(exc.exception);
return NULL;
}
@@ -547,8 +550,9 @@ Object* MachineCode::debugger_interpreter_continue(STATE,
call_frame->scope->flush_to_heap(state);
return NULL;
} catch(const RubyException& exc) {
exc.exception->locations(state,
Location::from_call_stack(state));
if(exc.exception->locations()->nil_p()) {
exc.exception->locations(state, Location::from_call_stack(state));
}
state->raise_exception(exc.exception);
return NULL;
}
4 changes: 2 additions & 2 deletions machine/test/test.hpp
Original file line number Diff line number Diff line change
@@ -44,8 +44,8 @@ class VMTest {
// Setup the main Thread, which is wrapper of the main native thread
// when the VM boots.
Thread::create(&state, vm);
vm->thread->alive(&state, cTrue);
vm->thread->sleep(&state, cFalse);
vm->thread()->alive(&state, cTrue);
vm->thread()->sleep(&state, cFalse);
}

void create() {
2 changes: 1 addition & 1 deletion machine/test/test_thread.hpp
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ class TestThread : public CxxTest::TestSuite, public VMTest {
}

void test_current() {
TS_ASSERT_EQUALS(Thread::current(state), state->vm()->thread.get());
TS_ASSERT_EQUALS(Thread::current(state), state->vm()->thread());
}

void test_create() {
4 changes: 0 additions & 4 deletions machine/vm.hpp
Original file line number Diff line number Diff line change
@@ -229,10 +229,6 @@ namespace rubinius {
return &thread_state_;
}

void set_thread_state(VMThreadState* thread_state) {
thread_state_ = *thread_state;
}

Memory* memory() {
return shared.memory();
}
Loading