Skip to content

Commit 6dc84fb

Browse files
committed
Merge remote-tracking branch 'origin' into profiler
2 parents 90db74d + 0b306fb commit 6dc84fb

31 files changed

+318
-294
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ GEM
44
daedalus-core (0.5.0)
55
rake (10.5.0)
66
redcard (1.1.0)
7-
rubinius-ast (3.4)
7+
rubinius-ast (3.5)
88
rubinius-bridge (2.2)
99
redcard (~> 1.0)
1010
rubinius-code (3.0)

core/rubinius.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,6 @@ def self.thread_state
219219
raise PrimitiveFailure, "Rubinius.thread_state primitive failed"
220220
end
221221

222-
def self.check_interrupts
223-
Rubinius.primitive :vm_check_interrupts
224-
raise PrimitiveFailure, "Rubinius.check_interrupts primitive failed"
225-
end
226-
227222
# Used to invoke a CompiledCode instance as a script body. Sets up the MAIN
228223
# object as self and bypasses JIT'ing (because why JIT a script you only run
229224
# once).

gems_list.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rake-10.5.0.gem
99
rb-readline-0.5.3.gem
1010
rdoc-4.2.2.gem
1111
redcard-1.1.0.gem
12-
rubinius-ast-3.4.gem
12+
rubinius-ast-3.5.gem
1313
rubinius-bridge-2.2.gem
1414
rubinius-code-3.0.gem
1515
rubinius-compiler-3.3.gem

machine/builtin/block_environment.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,17 +444,17 @@ namespace rubinius {
444444
call_frame->flags = invocation.flags | CallFrame::cMultipleScopes
445445
| CallFrame::cBlock;
446446

447-
state->vm()->push_call_frame(call_frame, previous_frame);
447+
if(!state->vm()->push_call_frame(state, call_frame, previous_frame)) {
448+
return NULL;
449+
}
448450

449451
Object* value = NULL;
450452

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

457-
state->vm()->pop_call_frame(previous_frame);
455+
if(!state->vm()->pop_call_frame(state, previous_frame)) {
456+
return NULL;
457+
}
458458

459459
return value;
460460
}

machine/builtin/channel.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ namespace rubinius {
134134
ts.tv_nsec = nano % NANOSECONDS;
135135
}
136136

137-
if(!state->check_async(state)) {
137+
if(state->vm()->thread_interrupted_p(state)) {
138138
return NULL;
139139
}
140140

@@ -161,7 +161,7 @@ namespace rubinius {
161161

162162
// or there are values available.
163163
if(self->semaphore_count() > 0 || !self->value()->empty_p()) break;
164-
if(!state->check_async(state)) {
164+
if(state->vm()->thread_interrupted_p(state)) {
165165
exception = true;
166166
break;
167167
}
@@ -173,7 +173,7 @@ namespace rubinius {
173173
self->unpin();
174174
self->_waiters_--;
175175

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

178178
if(self->semaphore_count() > 0) {
179179
self->dec_semaphore_count();

machine/builtin/fiber.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ namespace rubinius {
9898

9999
// TODO: CallFrame: return from this function
100100

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

156156
cur = Fiber::current(state);
157157

158+
// TODO: clean up this and the following conditional.
159+
if(state->vm()->thread_interrupted_p(state)) {
160+
return NULL;
161+
}
162+
158163
if(!cur->exception()->nil_p()) {
159164
state->raise_exception(cur->exception());
160165
cur->exception(state, nil<Exception>());
161-
return 0;
166+
return NULL;
162167
}
163168

164169
Array* ret = cur->value();

machine/builtin/fiber.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,12 @@ namespace rubinius {
6969
return data()->machine();
7070
}
7171

72-
void* stack_region() const {
73-
return data()->stack_address();
74-
}
75-
76-
void* stack_end() const {
72+
void* stack_address() const {
7773
return data()->stack_address();
7874
}
7975

8076
void* stack_start() const {
81-
return (void*)((uintptr_t)stack_region() + stack_size());
77+
return (void*)((uintptr_t)stack_address() + stack_size());
8278
}
8379

8480
int stack_size() const {

machine/builtin/io.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ namespace rubinius {
288288

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

293293
// Recalculate the limit and go again.
294294
if(maybe_limit) {
@@ -678,7 +678,7 @@ namespace rubinius {
678678

679679
if(bytes_read == -1) {
680680
if(errno == EAGAIN || errno == EINTR) {
681-
if(!state->check_async(state)) {
681+
if(state->vm()->thread_interrupted_p(state)) {
682682
if(malloc_buf) free(malloc_buf);
683683
return NULL;
684684
}
@@ -967,7 +967,7 @@ namespace rubinius {
967967

968968
if(bytes_read == -1) {
969969
if(errno == EINTR) {
970-
if(!state->check_async(state)) return NULL;
970+
if(state->vm()->thread_interrupted_p(state)) return NULL;
971971
ensure_open(state);
972972
goto retry;
973973
} else {
@@ -1321,7 +1321,7 @@ namespace rubinius {
13211321

13221322
if(code == -1) {
13231323
if(errno == EAGAIN || errno == EINTR) {
1324-
if(!state->check_async(state)) return NULL;
1324+
if(state->vm()->thread_interrupted_p(state)) return NULL;
13251325
ensure_open(state);
13261326
goto retry;
13271327
}
@@ -1429,7 +1429,7 @@ namespace rubinius {
14291429
break;
14301430
case EAGAIN:
14311431
case EINTR:
1432-
if(!state->check_async(state)) return NULL;
1432+
if(state->vm()->thread_interrupted_p(state)) return NULL;
14331433
io->ensure_open(state);
14341434
goto retry;
14351435
default:

machine/builtin/native_function.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,6 @@ namespace rubinius {
308308
FFIData* stub = reinterpret_cast<FFIData*>(user_data);
309309

310310
bool destroy_vm = false;
311-
int stack_address = 0;
312-
313311
if(!env) {
314312
// TODO: fix this, the threads should *always* be set up correctly
315313
// Apparently we're running in a new thread here, setup
@@ -318,13 +316,7 @@ namespace rubinius {
318316

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

321-
// Detect the stack size and set it up in the VM object
322-
size_t stack_size;
323-
pthread_attr_t attrs;
324-
pthread_attr_init(&attrs);
325-
pthread_attr_getstacksize (&attrs, &stack_size);
326-
pthread_attr_destroy(&attrs);
327-
vm->set_root_stack(reinterpret_cast<uintptr_t>(&stack_address), stack_size);
319+
vm->set_stack_bounds(THREAD_STACK_SIZE);
328320

329321
// Setup nativemethod handles into thread local
330322
State state(vm);

machine/builtin/native_method.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,9 @@ namespace rubinius {
675675
env->set_current_native_frame(&nmf);
676676

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

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

709-
state->vm()->pop_call_frame(previous_frame);
711+
state->vm()->pop_call_frame(state, previous_frame);
710712
env->set_current_call_frame(saved_frame);
711713
env->set_current_native_frame(nmf.previous());
712714
ep.pop(env);
@@ -716,15 +718,14 @@ namespace rubinius {
716718

717719
LEAVE_CAPI(state);
718720

719-
state->vm()->pop_call_frame(previous_frame);
721+
if(!state->vm()->pop_call_frame(state, previous_frame)) {
722+
value = NULL;
723+
}
724+
720725
env->set_current_call_frame(saved_frame);
721726
env->set_current_native_frame(nmf.previous());
722727
ep.pop(env);
723728

724-
// Handle any signals that occurred while the native method
725-
// was running.
726-
if(!state->check_async(state)) return NULL;
727-
728729
return value;
729730
}
730731

machine/builtin/system.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ namespace rubinius {
656656
switch(errno) {
657657
case EAGAIN:
658658
case EINTR:
659-
if(!state->check_async(state)) {
659+
if(state->vm()->thread_interrupted_p(state)) {
660660
close(output[0]);
661661
return NULL;
662662
}
@@ -782,7 +782,7 @@ namespace rubinius {
782782
if(pid == -1) {
783783
if(errno == ECHILD) return cFalse;
784784
if(errno == EINTR) {
785-
if(!state->check_async(state)) return NULL;
785+
if(state->vm()->thread_interrupted_p(state)) return NULL;
786786
goto retry;
787787
}
788788

@@ -1029,19 +1029,11 @@ namespace rubinius {
10291029
if(!state->park(state)) return NULL;
10301030
}
10311031

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

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

1037-
Object* System::vm_check_interrupts(STATE) {
1038-
if(state->check_async(state)) {
1039-
return cNil;
1040-
} else {
1041-
return NULL;
1042-
}
1043-
}
1044-
10451037
static inline double tv_to_dbl(struct timeval* tv) {
10461038
return (double)tv->tv_sec + ((double)tv->tv_usec / 1000000.0);
10471039
}

machine/builtin/system.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,6 @@ namespace rubinius {
147147
// Rubinius.primitive :vm_sleep
148148
static Object* vm_sleep(STATE, Object* duration);
149149

150-
// Rubinius.primitive :vm_check_interrupts
151-
static Object* vm_check_interrupts(STATE);
152-
153150
// Rubinius.primitive :vm_times
154151
static Array* vm_times(STATE);
155152

machine/builtin/thread.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ namespace rubinius {
356356
VM* vm = reinterpret_cast<VM*>(ptr);
357357
State state_obj(vm), *state = &state_obj;
358358

359+
vm->set_stack_bounds(THREAD_STACK_SIZE);
359360
vm->set_current_thread();
360361

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

370-
int stack_address = 0;
371-
vm->set_root_stack(reinterpret_cast<uintptr_t>(&stack_address), THREAD_STACK_SIZE);
372-
373371
NativeMethod::init_thread(state);
374372

375373
state->vm()->become_managed();

machine/capi/capi.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,17 @@ namespace rubinius {
5151
return map[type];
5252
}
5353

54-
bool capi_check_interrupts(STATE, void* stack_marker) {
55-
if(!state->check_stack(state, stack_marker)) {
54+
bool capi_check_interrupts(STATE) {
55+
void* stack_address;
56+
57+
if(!state->vm()->check_stack(state, &stack_address)) {
5658
return false;
5759
}
5860

59-
if(unlikely(state->check_local_interrupts())) {
60-
if(!state->process_async(state)) return false;
61+
if(unlikely(state->vm()->check_local_interrupts())) {
62+
return state->vm()->check_thread_raise_or_kill(state);
6163
}
64+
6265
return true;
6366
}
6467

@@ -115,8 +118,7 @@ namespace rubinius {
115118
Object** args, Object* block,
116119
bool allow_private)
117120
{
118-
int stack_marker = 0;
119-
if(!capi_check_interrupts(env->state(), &stack_marker)) {
121+
if(!capi_check_interrupts(env->state())) {
120122
env->current_ep()->return_to(env);
121123
}
122124

@@ -208,8 +210,7 @@ namespace rubinius {
208210
Object* blk,
209211
size_t arg_count, Object** arg_vals)
210212
{
211-
int stack_marker = 0;
212-
if(!capi_check_interrupts(env->state(), &stack_marker)) {
213+
if(!capi_check_interrupts(env->state())) {
213214
env->current_ep()->return_to(env);
214215
}
215216

@@ -258,8 +259,7 @@ namespace rubinius {
258259
VALUE capi_call_super_native(NativeMethodEnvironment* env,
259260
size_t arg_count, Object** args)
260261
{
261-
int stack_marker = 0;
262-
if(!capi_check_interrupts(env->state(), &stack_marker)) {
262+
if(!capi_check_interrupts(env->state())) {
263263
env->current_ep()->return_to(env);
264264
}
265265

machine/capi/thread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ extern "C" {
6363
ret = select(max, read, write, except, tvp);
6464
}
6565

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

6868
ENTER_CAPI(env->state());
6969

@@ -199,7 +199,7 @@ extern "C" {
199199
State* state = env->state();
200200
void* ret = NULL;
201201

202-
if(!state->check_async(env->state())) {
202+
if(state->vm()->thread_interrupted_p(state)) {
203203
return ret;
204204
}
205205
if(ubf == RUBY_UBF_IO || ubf == RUBY_UBF_PROCESS) {

0 commit comments

Comments
 (0)