Skip to content

Commit

Permalink
Fixed invoking the GC.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Mar 15, 2016
1 parent 594a3b6 commit fa207b4
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 66 deletions.
37 changes: 14 additions & 23 deletions machine/builtin/block_environment.cpp
Expand Up @@ -89,11 +89,10 @@ namespace rubinius {
return execute_interpreter(state, env, args, invocation);
}

// TODO: this is a quick hack to process block arguments in 1.9.
// TODO: Specialize argument handlers for blocks like those for methods.
class GenericArguments {
public:
static bool call(STATE,
MachineCode* mcode, StackVariables* scope,
static bool call(STATE, MachineCode* mcode, StackVariables* scope,
Arguments& args, int flags)
{
/* There are 5 types of arguments, illustrated here:
Expand Down Expand Up @@ -422,6 +421,18 @@ namespace rubinius {
scope->initialize(invocation.self, block, mod, mcode->number_of_locals);
scope->set_parent(env->scope_);

if(!GenericArguments::call(state, mcode, scope, args, invocation.flags)) {
if(state->vm()->thread_state()->raise_reason() == cNone) {
Exception* exc =
Exception::make_argument_error(state, mcode->required_args, args.total(),
mcode->name());
exc->locations(state, Location::from_call_stack(state));
state->raise_exception(exc);
}

return NULL;
}

CallFrame* previous_frame = 0;
InterpreterCallFrame* frame = ALLOCA_CALL_FRAME(mcode->stack_size);

Expand All @@ -439,20 +450,6 @@ namespace rubinius {

state->vm()->push_call_frame(frame, previous_frame);

if(!GenericArguments::call(state, mcode, scope, args, invocation.flags)) {
state->vm()->pop_call_frame(previous_frame);

if(state->vm()->thread_state()->raise_reason() == cNone) {
Exception* exc =
Exception::make_argument_error(state, mcode->required_args, args.total(),
mcode->name());
exc->locations(state, Location::from_call_stack(state));
state->raise_exception(exc);
}

return NULL;
}

Object* value = 0;

#ifdef RBX_PROFILER
Expand All @@ -469,26 +466,20 @@ namespace rubinius {
// Check the stack and interrupts here rather than in the interpreter
// loop itself.
if(state->check_interrupts(state)) {
state->vm()->checkpoint(state);

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)) {
state->vm()->checkpoint(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)) {
state->vm()->checkpoint(state);

value = (*mcode->run)(state, mcode);
}
#endif
Expand Down
18 changes: 8 additions & 10 deletions machine/builtin/native_method.cpp
Expand Up @@ -689,7 +689,7 @@ namespace rubinius {
// wait before entering the extension code.
ENTER_CAPI(state);

Object* ret;
Object* value;
ExceptionPoint ep(env);

try {
Expand All @@ -706,9 +706,9 @@ namespace rubinius {
PLACE_EXCEPTION_POINT(ep);

if(unlikely(ep.jumped_to())) {
ret = NULL;
value = NULL;
} else {
ret = ArgumentHandler::invoke(state, nm, env, args);
value = ArgumentHandler::invoke(state, nm, env, args);
}
RUBINIUS_METHOD_NATIVE_RETURN_HOOK(state, mod, args.name());
} else {
Expand All @@ -717,9 +717,9 @@ namespace rubinius {
PLACE_EXCEPTION_POINT(ep);

if(unlikely(ep.jumped_to())) {
ret = NULL;
value = NULL;
} else {
ret = ArgumentHandler::invoke(state, nm, env, args);
value = ArgumentHandler::invoke(state, nm, env, args);
}
RUBINIUS_METHOD_NATIVE_RETURN_HOOK(state, mod, args.name());
}
Expand All @@ -729,9 +729,9 @@ namespace rubinius {
PLACE_EXCEPTION_POINT(ep);

if(unlikely(ep.jumped_to())) {
ret = NULL;
value = NULL;
} else {
ret = ArgumentHandler::invoke(state, nm, env, args);
value = ArgumentHandler::invoke(state, nm, env, args);
}
RUBINIUS_METHOD_NATIVE_RETURN_HOOK(state, mod, args.name());
#endif
Expand All @@ -753,13 +753,11 @@ namespace rubinius {
env->set_current_native_frame(nmf.previous());
ep.pop(env);

OnStack<1> os_ret(state, ret);

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

return ret;
return value;
}

NativeMethod* NativeMethod::load_extension_entry_point(STATE,
Expand Down
8 changes: 0 additions & 8 deletions machine/capi/capi.cpp
Expand Up @@ -156,8 +156,6 @@ namespace rubinius {
// An exception occurred
if(!ret) env->current_ep()->return_to(env);

env->state()->vm()->checkpoint(env->state());

return ret_handle;
}

Expand Down Expand Up @@ -203,8 +201,6 @@ namespace rubinius {
// An exception occurred
if(!ret) env->current_ep()->return_to(env);

env->state()->vm()->checkpoint(env->state());

return ret_handle;
}

Expand Down Expand Up @@ -256,8 +252,6 @@ namespace rubinius {
// An exception occurred
if(!ret) env->current_ep()->return_to(env);

env->state()->vm()->checkpoint(env->state());

return ret_handle;
}

Expand Down Expand Up @@ -304,8 +298,6 @@ namespace rubinius {
// An exception occurred
if(!ret) env->current_ep()->return_to(env);

env->state()->vm()->checkpoint(env->state());

return ret_handle;
}

Expand Down
2 changes: 0 additions & 2 deletions machine/environment.cpp
Expand Up @@ -595,8 +595,6 @@ namespace rubinius {

stop_jit(state);

state->vm()->checkpoint(state);

{
UnmanagedPhase unmanaged(state);
shared->internal_threads()->shutdown(state);
Expand Down
22 changes: 22 additions & 0 deletions machine/instructions.def
Expand Up @@ -1254,6 +1254,8 @@ instruction send_super_stack_with_block(literal count) [ block +count -- value ]
stack_clear(count);

CHECK_AND_PUSH(ret);

state->vm()->checkpoint(state);
end

# [Description]
Expand Down Expand Up @@ -1297,6 +1299,8 @@ instruction send_super_stack_with_splat(literal count) [ block array +count -- v
stack_clear(count);

CHECK_AND_PUSH(ret);

state->vm()->checkpoint(state);
end

section "Manipulate blocks"
Expand Down Expand Up @@ -1994,6 +1998,8 @@ instruction meta_send_op_plus(literal) [ value1 value2 -- sum ] => send
stack_clear(2);

CHECK_AND_PUSH(ret);

state->vm()->checkpoint(state);
}
end

Expand All @@ -2020,6 +2026,8 @@ instruction meta_send_op_minus(literal) [ value1 value2 -- difference ] => send
stack_clear(2);

CHECK_AND_PUSH(ret);

state->vm()->checkpoint(state);
}
end

Expand Down Expand Up @@ -2048,6 +2056,8 @@ instruction meta_send_op_equal(literal) [ value1 value2 -- boolean ] => send
stack_clear(2);

CHECK_AND_PUSH(ret);

state->vm()->checkpoint(state);
}
end

Expand Down Expand Up @@ -2075,6 +2085,8 @@ instruction meta_send_op_lt(literal) [ value1 value2 -- boolean ]
stack_clear(2);

CHECK_AND_PUSH(ret);

state->vm()->checkpoint(state);
}
end

Expand Down Expand Up @@ -2102,6 +2114,8 @@ instruction meta_send_op_gt(literal) [ value1 value2 -- boolean ]
stack_clear(2);

CHECK_AND_PUSH(ret);

state->vm()->checkpoint(state);
}
end

Expand Down Expand Up @@ -2131,6 +2145,8 @@ instruction meta_send_op_tequal(literal) [ value1 value2 -- boolean ] => send
stack_clear(2);

CHECK_AND_PUSH(ret);

state->vm()->checkpoint(state);
}
end

Expand Down Expand Up @@ -2164,6 +2180,8 @@ instruction meta_send_call(literal count) [ receiver +count -- value ] => send
stack_clear(count + 1);

CHECK_AND_PUSH(ret);

state->vm()->checkpoint(state);
end

section "More misc"
Expand Down Expand Up @@ -2259,6 +2277,8 @@ instruction zsuper(literal) [ block -- value ]
ret = call_site->execute(state, new_args);

CHECK_AND_PUSH(ret);

state->vm()->checkpoint(state);
end

# [Description]
Expand Down Expand Up @@ -2466,6 +2486,8 @@ instruction meta_to_s(literal) [ object -- string ] => send

(void)stack_pop();
CHECK_AND_PUSH(ret);

state->vm()->checkpoint(state);
}
end

Expand Down
29 changes: 15 additions & 14 deletions machine/machine_code.cpp
Expand Up @@ -786,29 +786,30 @@ namespace rubinius {
// Check the stack and interrupts here rather than in the interpreter
// loop itself.
OnStack<2> os(state, exec, code);
if(!state->check_interrupts(state)) return NULL;
if(state->check_interrupts(state)) {
tooling::MethodEntry method(state, exec, scope->module(), args, code);

tooling::MethodEntry method(state, exec, scope->module(), args, code);

RUBINIUS_METHOD_ENTRY_HOOK(state, scope->module(), args.name());
value = (*mcode->run)(state, mcode);
RUBINIUS_METHOD_RETURN_HOOK(state, scope->module(), args.name());
RUBINIUS_METHOD_ENTRY_HOOK(state, scope->module(), args.name());
value = (*mcode->run)(state, mcode);
RUBINIUS_METHOD_RETURN_HOOK(state, scope->module(), args.name());
}
} else {
if(!state->check_interrupts(state)) return NULL;

if(state->check_interrupts(state)) {
RUBINIUS_METHOD_ENTRY_HOOK(state, scope->module(), args.name());
value = (*mcode->run)(state, mcode);
RUBINIUS_METHOD_RETURN_HOOK(state, scope->module(), args.name());
}
}
#else
if(state->check_interrupts(state)) {
RUBINIUS_METHOD_ENTRY_HOOK(state, scope->module(), args.name());
value = (*mcode->run)(state, mcode);
RUBINIUS_METHOD_RETURN_HOOK(state, scope->module(), args.name());
}
#else
if(!state->check_interrupts(state)) return NULL;

RUBINIUS_METHOD_ENTRY_HOOK(state, scope->module(), args.name());
value = (*mcode->run)(state, mcode);
RUBINIUS_METHOD_RETURN_HOOK(state, scope->module(), args.name());
#endif

state->vm()->pop_call_frame(previous_frame);

return value;
}

Expand Down
14 changes: 13 additions & 1 deletion machine/memory.cpp
Expand Up @@ -454,7 +454,19 @@ namespace rubinius {
}

bool Memory::valid_object_p(Object* obj) {
if(obj->young_object_p()) {
if(obj->true_p()) {
return true;
} else if(obj->false_p()) {
return true;
} else if(obj->nil_p()) {
return true;
} else if(obj->undef_p()) {
return true;
} else if(obj->fixnum_p()) {
return true;
} else if(obj->symbol_p()) {
return true;
} else if(obj->young_object_p()) {
return false; /* young_->validate_object(obj) == cValid; */
} else if(obj->mature_object_p()) {
if(immix_->validate_object(obj) == cInImmix) {
Expand Down
4 changes: 2 additions & 2 deletions machine/memory/finalizer.cpp
Expand Up @@ -219,12 +219,12 @@ namespace memory {
PLACE_EXCEPTION_POINT(ep);

if(unlikely(ep.jumped_to())) {
// TODO: log this?
utilities::logger::warn(
"finalizer: an exception occurred running a NativeMethod finalizer");
} else {
(*process_item_->finalizer)(state, process_item_->object);
}


state->vm()->pop_call_frame(previous_frame);
env->set_current_call_frame(0);
env->set_current_native_frame(0);
Expand Down
7 changes: 1 addition & 6 deletions machine/memory/mark_sweep.cpp
Expand Up @@ -50,15 +50,10 @@ namespace memory {

Object* MarkSweepGC::allocate(size_t bytes, bool& collect_now) {
void* mem = malloc(bytes);
if(!mem) rubinius::abort();
if(!mem) return NULL;

Object* obj = reinterpret_cast<Object*>(mem);

// If the allocation failed, we return a NULL pointer
if(unlikely(!obj)) {
return NULL;
}

diagnostics_.objects_++;
diagnostics_.bytes_ += bytes;

Expand Down

0 comments on commit fa207b4

Please sign in to comment.