Skip to content

Commit fa207b4

Browse files
committedMar 15, 2016
Fixed invoking the GC.
1 parent 594a3b6 commit fa207b4

9 files changed

+75
-66
lines changed
 

‎machine/builtin/block_environment.cpp

+14-23
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,10 @@ namespace rubinius {
8989
return execute_interpreter(state, env, args, invocation);
9090
}
9191

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

424+
if(!GenericArguments::call(state, mcode, scope, args, invocation.flags)) {
425+
if(state->vm()->thread_state()->raise_reason() == cNone) {
426+
Exception* exc =
427+
Exception::make_argument_error(state, mcode->required_args, args.total(),
428+
mcode->name());
429+
exc->locations(state, Location::from_call_stack(state));
430+
state->raise_exception(exc);
431+
}
432+
433+
return NULL;
434+
}
435+
425436
CallFrame* previous_frame = 0;
426437
InterpreterCallFrame* frame = ALLOCA_CALL_FRAME(mcode->stack_size);
427438

@@ -439,20 +450,6 @@ namespace rubinius {
439450

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

442-
if(!GenericArguments::call(state, mcode, scope, args, invocation.flags)) {
443-
state->vm()->pop_call_frame(previous_frame);
444-
445-
if(state->vm()->thread_state()->raise_reason() == cNone) {
446-
Exception* exc =
447-
Exception::make_argument_error(state, mcode->required_args, args.total(),
448-
mcode->name());
449-
exc->locations(state, Location::from_call_stack(state));
450-
state->raise_exception(exc);
451-
}
452-
453-
return NULL;
454-
}
455-
456453
Object* value = 0;
457454

458455
#ifdef RBX_PROFILER
@@ -469,26 +466,20 @@ namespace rubinius {
469466
// Check the stack and interrupts here rather than in the interpreter
470467
// loop itself.
471468
if(state->check_interrupts(state)) {
472-
state->vm()->checkpoint(state);
473-
474469
tooling::BlockEntry method(state, env, mod);
475470
value = (*mcode->run)(state, mcode);
476471
}
477472
} else {
478473
// Check the stack and interrupts here rather than in the interpreter
479474
// loop itself.
480475
if(state->check_interrupts(state)) {
481-
state->vm()->checkpoint(state);
482-
483476
value = (*mcode->run)(state, mcode);
484477
}
485478
}
486479
#else
487480
// Check the stack and interrupts here rather than in the interpreter
488481
// loop itself.
489482
if(state->check_interrupts(state)) {
490-
state->vm()->checkpoint(state);
491-
492483
value = (*mcode->run)(state, mcode);
493484
}
494485
#endif

‎machine/builtin/native_method.cpp

+8-10
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ namespace rubinius {
689689
// wait before entering the extension code.
690690
ENTER_CAPI(state);
691691

692-
Object* ret;
692+
Object* value;
693693
ExceptionPoint ep(env);
694694

695695
try {
@@ -706,9 +706,9 @@ namespace rubinius {
706706
PLACE_EXCEPTION_POINT(ep);
707707

708708
if(unlikely(ep.jumped_to())) {
709-
ret = NULL;
709+
value = NULL;
710710
} else {
711-
ret = ArgumentHandler::invoke(state, nm, env, args);
711+
value = ArgumentHandler::invoke(state, nm, env, args);
712712
}
713713
RUBINIUS_METHOD_NATIVE_RETURN_HOOK(state, mod, args.name());
714714
} else {
@@ -717,9 +717,9 @@ namespace rubinius {
717717
PLACE_EXCEPTION_POINT(ep);
718718

719719
if(unlikely(ep.jumped_to())) {
720-
ret = NULL;
720+
value = NULL;
721721
} else {
722-
ret = ArgumentHandler::invoke(state, nm, env, args);
722+
value = ArgumentHandler::invoke(state, nm, env, args);
723723
}
724724
RUBINIUS_METHOD_NATIVE_RETURN_HOOK(state, mod, args.name());
725725
}
@@ -729,9 +729,9 @@ namespace rubinius {
729729
PLACE_EXCEPTION_POINT(ep);
730730

731731
if(unlikely(ep.jumped_to())) {
732-
ret = NULL;
732+
value = NULL;
733733
} else {
734-
ret = ArgumentHandler::invoke(state, nm, env, args);
734+
value = ArgumentHandler::invoke(state, nm, env, args);
735735
}
736736
RUBINIUS_METHOD_NATIVE_RETURN_HOOK(state, mod, args.name());
737737
#endif
@@ -753,13 +753,11 @@ namespace rubinius {
753753
env->set_current_native_frame(nmf.previous());
754754
ep.pop(env);
755755

756-
OnStack<1> os_ret(state, ret);
757-
758756
// Handle any signals that occurred while the native method
759757
// was running.
760758
if(!state->check_async(state)) return NULL;
761759

762-
return ret;
760+
return value;
763761
}
764762

765763
NativeMethod* NativeMethod::load_extension_entry_point(STATE,

‎machine/capi/capi.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ namespace rubinius {
156156
// An exception occurred
157157
if(!ret) env->current_ep()->return_to(env);
158158

159-
env->state()->vm()->checkpoint(env->state());
160-
161159
return ret_handle;
162160
}
163161

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

206-
env->state()->vm()->checkpoint(env->state());
207-
208204
return ret_handle;
209205
}
210206

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

259-
env->state()->vm()->checkpoint(env->state());
260-
261255
return ret_handle;
262256
}
263257

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

307-
env->state()->vm()->checkpoint(env->state());
308-
309301
return ret_handle;
310302
}
311303

‎machine/environment.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,6 @@ namespace rubinius {
595595

596596
stop_jit(state);
597597

598-
state->vm()->checkpoint(state);
599-
600598
{
601599
UnmanagedPhase unmanaged(state);
602600
shared->internal_threads()->shutdown(state);

‎machine/instructions.def

+22
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,8 @@ instruction send_super_stack_with_block(literal count) [ block +count -- value ]
12541254
stack_clear(count);
12551255

12561256
CHECK_AND_PUSH(ret);
1257+
1258+
state->vm()->checkpoint(state);
12571259
end
12581260

12591261
# [Description]
@@ -1297,6 +1299,8 @@ instruction send_super_stack_with_splat(literal count) [ block array +count -- v
12971299
stack_clear(count);
12981300

12991301
CHECK_AND_PUSH(ret);
1302+
1303+
state->vm()->checkpoint(state);
13001304
end
13011305

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

19962000
CHECK_AND_PUSH(ret);
2001+
2002+
state->vm()->checkpoint(state);
19972003
}
19982004
end
19992005

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

20222028
CHECK_AND_PUSH(ret);
2029+
2030+
state->vm()->checkpoint(state);
20232031
}
20242032
end
20252033

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

20502058
CHECK_AND_PUSH(ret);
2059+
2060+
state->vm()->checkpoint(state);
20512061
}
20522062
end
20532063

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

20772087
CHECK_AND_PUSH(ret);
2088+
2089+
state->vm()->checkpoint(state);
20782090
}
20792091
end
20802092

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

21042116
CHECK_AND_PUSH(ret);
2117+
2118+
state->vm()->checkpoint(state);
21052119
}
21062120
end
21072121

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

21332147
CHECK_AND_PUSH(ret);
2148+
2149+
state->vm()->checkpoint(state);
21342150
}
21352151
end
21362152

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

21662182
CHECK_AND_PUSH(ret);
2183+
2184+
state->vm()->checkpoint(state);
21672185
end
21682186

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

22612279
CHECK_AND_PUSH(ret);
2280+
2281+
state->vm()->checkpoint(state);
22622282
end
22632283

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

24672487
(void)stack_pop();
24682488
CHECK_AND_PUSH(ret);
2489+
2490+
state->vm()->checkpoint(state);
24692491
}
24702492
end
24712493

‎machine/machine_code.cpp

+15-14
Original file line numberDiff line numberDiff line change
@@ -786,29 +786,30 @@ namespace rubinius {
786786
// Check the stack and interrupts here rather than in the interpreter
787787
// loop itself.
788788
OnStack<2> os(state, exec, code);
789-
if(!state->check_interrupts(state)) return NULL;
789+
if(state->check_interrupts(state)) {
790+
tooling::MethodEntry method(state, exec, scope->module(), args, code);
790791

791-
tooling::MethodEntry method(state, exec, scope->module(), args, code);
792-
793-
RUBINIUS_METHOD_ENTRY_HOOK(state, scope->module(), args.name());
794-
value = (*mcode->run)(state, mcode);
795-
RUBINIUS_METHOD_RETURN_HOOK(state, scope->module(), args.name());
792+
RUBINIUS_METHOD_ENTRY_HOOK(state, scope->module(), args.name());
793+
value = (*mcode->run)(state, mcode);
794+
RUBINIUS_METHOD_RETURN_HOOK(state, scope->module(), args.name());
795+
}
796796
} else {
797-
if(!state->check_interrupts(state)) return NULL;
798-
797+
if(state->check_interrupts(state)) {
798+
RUBINIUS_METHOD_ENTRY_HOOK(state, scope->module(), args.name());
799+
value = (*mcode->run)(state, mcode);
800+
RUBINIUS_METHOD_RETURN_HOOK(state, scope->module(), args.name());
801+
}
802+
}
803+
#else
804+
if(state->check_interrupts(state)) {
799805
RUBINIUS_METHOD_ENTRY_HOOK(state, scope->module(), args.name());
800806
value = (*mcode->run)(state, mcode);
801807
RUBINIUS_METHOD_RETURN_HOOK(state, scope->module(), args.name());
802808
}
803-
#else
804-
if(!state->check_interrupts(state)) return NULL;
805-
806-
RUBINIUS_METHOD_ENTRY_HOOK(state, scope->module(), args.name());
807-
value = (*mcode->run)(state, mcode);
808-
RUBINIUS_METHOD_RETURN_HOOK(state, scope->module(), args.name());
809809
#endif
810810

811811
state->vm()->pop_call_frame(previous_frame);
812+
812813
return value;
813814
}
814815

‎machine/memory.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,19 @@ namespace rubinius {
454454
}
455455

456456
bool Memory::valid_object_p(Object* obj) {
457-
if(obj->young_object_p()) {
457+
if(obj->true_p()) {
458+
return true;
459+
} else if(obj->false_p()) {
460+
return true;
461+
} else if(obj->nil_p()) {
462+
return true;
463+
} else if(obj->undef_p()) {
464+
return true;
465+
} else if(obj->fixnum_p()) {
466+
return true;
467+
} else if(obj->symbol_p()) {
468+
return true;
469+
} else if(obj->young_object_p()) {
458470
return false; /* young_->validate_object(obj) == cValid; */
459471
} else if(obj->mature_object_p()) {
460472
if(immix_->validate_object(obj) == cInImmix) {

‎machine/memory/finalizer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,12 @@ namespace memory {
219219
PLACE_EXCEPTION_POINT(ep);
220220

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

227-
228228
state->vm()->pop_call_frame(previous_frame);
229229
env->set_current_call_frame(0);
230230
env->set_current_native_frame(0);

‎machine/memory/mark_sweep.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,10 @@ namespace memory {
5050

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

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

57-
// If the allocation failed, we return a NULL pointer
58-
if(unlikely(!obj)) {
59-
return NULL;
60-
}
61-
6257
diagnostics_.objects_++;
6358
diagnostics_.bytes_ += bytes;
6459

0 commit comments

Comments
 (0)
Please sign in to comment.